]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/json/test/error.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / json / test / error.cpp
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:
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
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
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(condition::pointer_parse_error, error::missing_slash);
69 check(condition::pointer_parse_error, error::invalid_escape);
70
71 check(condition::pointer_use_error, error::token_not_number);
72 check(condition::pointer_use_error, error::value_is_scalar);
73 check(condition::pointer_use_error, error::not_found);
74 check(condition::pointer_use_error, error::token_overflow);
75 check(condition::pointer_use_error, error::past_the_end);
76
77 check(error::test_failure);
78
79 // check std interop
80 std::error_code const ec = error::syntax;
81 BOOST_TEST(ec == error::syntax);
82 BOOST_TEST(ec == condition::parse_error);
83 }
84 };
85
86 TEST_SUITE(error_test, "boost.json.error");
87
88 BOOST_JSON_NS_END