| 153 | } |
| 154 | |
| 155 | void check_diagnostic_details(boost::json::value const & j, bool has_source_location) |
| 156 | { |
| 157 | BOOST_TEST(boost::json::value_to<int>(j.at("boost::leaf::error_id")) > 0); |
| 158 | |
| 159 | auto const & e1j = j.at("my_error<1>"); |
| 160 | BOOST_TEST_EQ(boost::json::value_to<int>(e1j.at("code")), 1); |
| 161 | BOOST_TEST_EQ(boost::json::value_to<std::string>(e1j.at("message")), "error one"); |
| 162 | |
| 163 | if( has_source_location ) |
| 164 | { |
| 165 | auto const & loc = j.at("boost::leaf::e_source_location"); |
| 166 | BOOST_TEST(!boost::json::value_to<std::string>(loc.at("file")).empty()); |
| 167 | BOOST_TEST(boost::json::value_to<int>(loc.at("line")) > 0); |
| 168 | BOOST_TEST(!boost::json::value_to<std::string>(loc.at("function")).empty()); |
| 169 | } |
| 170 | |
| 171 | if( BOOST_LEAF_CFG_CAPTURE ) |
| 172 | { |
| 173 | BOOST_TEST_EQ(boost::json::value_to<int>(j.at("int")), 42); |
| 174 | |
| 175 | auto const & e2j = j.at("my_error<2>"); |
| 176 | BOOST_TEST_EQ(boost::json::value_to<int>(e2j.at("code")), 2); |
| 177 | BOOST_TEST_EQ(boost::json::value_to<std::string>(e2j.at("message")), "error two"); |
| 178 | |
| 179 | auto const & vj = j.at("my_error_with_vector"); |
| 180 | BOOST_TEST(vj.is_array()); |
| 181 | BOOST_TEST_EQ(vj.as_array().size(), 3); |
| 182 | BOOST_TEST_EQ(boost::json::value_to<int>(vj.as_array()[0]), 10); |
| 183 | BOOST_TEST_EQ(boost::json::value_to<int>(vj.as_array()[1]), 20); |
| 184 | BOOST_TEST_EQ(boost::json::value_to<int>(vj.as_array()[2]), 30); |
| 185 | |
| 186 | auto const & ej = j.at("boost::leaf::e_errno"); |
| 187 | BOOST_TEST_EQ(boost::json::value_to<int>(ej.at("errno")), ENOENT); |
| 188 | BOOST_TEST(!boost::json::value_to<std::string>(ej.at("strerror")).empty()); |
| 189 | |
| 190 | BOOST_TEST_EQ(boost::json::value_to<std::string>(j.at("boost::leaf::e_api_function")), "my_api_function"); |
| 191 | |
| 192 | if( BOOST_LEAF_CFG_STD_SYSTEM_ERROR ) |
| 193 | { |
| 194 | auto const & ecj = j.at("std::error_code"); |
| 195 | BOOST_TEST_EQ(boost::json::value_to<int>(ecj.at("value")), static_cast<int>(std::errc::invalid_argument)); |
| 196 | BOOST_TEST(!boost::json::value_to<std::string>(ecj.at("category")).empty()); |
| 197 | BOOST_TEST(!boost::json::value_to<std::string>(ecj.at("message")).empty()); |
| 198 | |
| 199 | auto const & econdj = j.at("std::error_condition"); |
| 200 | BOOST_TEST_EQ(boost::json::value_to<int>(econdj.at("value")), static_cast<int>(std::errc::io_error)); |
| 201 | BOOST_TEST(!boost::json::value_to<std::string>(econdj.at("category")).empty()); |
| 202 | BOOST_TEST(!boost::json::value_to<std::string>(econdj.at("message")).empty()); |
| 203 | |
| 204 | auto const & mecj = j.at("my_error_code"); |
| 205 | BOOST_TEST_EQ(boost::json::value_to<int>(mecj.at("value")), static_cast<int>(std::errc::invalid_argument)); |
| 206 | BOOST_TEST(!boost::json::value_to<std::string>(mecj.at("category")).empty()); |
| 207 | BOOST_TEST(!boost::json::value_to<std::string>(mecj.at("message")).empty()); |
| 208 | } |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | BOOST_TEST(j.as_object().find("int") == j.as_object().end()); |