1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/json
8 //
9 
10 // Test that header file is self-contained.
11 #include <boost/json/error.hpp>
12 
13 #include <memory>
14 
15 #include "test_suite.hpp"
16 
17 BOOST_JSON_NS_BEGIN
18 
19 class error_test
20 {
21 public:
check(error e)22     void check(error e)
23     {
24         auto const ec = make_error_code(e);
25         BOOST_TEST(ec.category().name() != nullptr);
26         BOOST_TEST(! ec.message().empty());
27         BOOST_TEST(ec.category().default_error_condition(
28             static_cast<int>(e)).category() == ec.category());
29     }
30 
check(condition c,error e)31     void check(condition c, error e)
32     {
33         {
34             auto const ec = make_error_code(e);
35             BOOST_TEST(ec.category().name() != nullptr);
36             BOOST_TEST(! ec.message().empty());
37             BOOST_TEST(ec == c);
38         }
39         {
40             auto ec = make_error_condition(c);
41             BOOST_TEST(ec.category().name() != nullptr);
42             BOOST_TEST(! ec.message().empty());
43             BOOST_TEST(ec == c);
44         }
45     }
46 
47     void
run()48     run()
49     {
50         check(condition::parse_error, error::syntax);
51         check(condition::parse_error, error::extra_data);
52         check(condition::parse_error, error::incomplete);
53         check(condition::parse_error, error::exponent_overflow);
54         check(condition::parse_error, error::too_deep);
55         check(condition::parse_error, error::illegal_leading_surrogate);
56         check(condition::parse_error, error::illegal_trailing_surrogate);
57         check(condition::parse_error, error::expected_hex_digit);
58         check(condition::parse_error, error::expected_utf16_escape);
59         check(condition::parse_error, error::object_too_large);
60         check(condition::parse_error, error::array_too_large);
61         check(condition::parse_error, error::key_too_large);
62         check(condition::parse_error, error::string_too_large);
63         check(condition::parse_error, error::exception);
64 
65         check(condition::assign_error, error::not_number);
66         check(condition::assign_error, error::not_exact);
67 
68         check(error::test_failure);
69     }
70 };
71 
72 TEST_SUITE(error_test, "boost.json.error");
73 
74 BOOST_JSON_NS_END
75