• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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/beast
8 //
9 
10 // Test that header file is self-contained.
11 #include <boost/beast/http/error.hpp>
12 
13 #include <boost/beast/_experimental/unit_test/suite.hpp>
14 #include <memory>
15 
16 namespace boost {
17 namespace beast {
18 namespace http {
19 
20 class error_test : public unit_test::suite
21 {
22 public:
23     void
check(char const * name,error ev)24     check(char const* name, error ev)
25     {
26         auto const ec = make_error_code(ev);
27         auto const& cat = make_error_code(
28             static_cast<http::error>(0)).category();
29         BEAST_EXPECT(std::string(ec.category().name()) == name);
30         BEAST_EXPECT(! ec.message().empty());
31         BEAST_EXPECT(
32             std::addressof(ec.category()) == std::addressof(cat));
33         BEAST_EXPECT(cat.equivalent(
34             static_cast<std::underlying_type<error>::type>(ev),
35                 ec.category().default_error_condition(
36                     static_cast<std::underlying_type<error>::type>(ev))));
37         BEAST_EXPECT(cat.equivalent(ec,
38             static_cast<std::underlying_type<error>::type>(ev)));
39     }
40 
41     void
run()42     run() override
43     {
44         check("beast.http", error::end_of_stream);
45         check("beast.http", error::partial_message);
46         check("beast.http", error::need_more);
47         check("beast.http", error::unexpected_body);
48         check("beast.http", error::need_buffer);
49         check("beast.http", error::end_of_chunk);
50         check("beast.http", error::buffer_overflow);
51         check("beast.http", error::header_limit);
52         check("beast.http", error::body_limit);
53         check("beast.http", error::bad_alloc);
54 
55         check("beast.http", error::bad_line_ending);
56         check("beast.http", error::bad_method);
57         check("beast.http", error::bad_target);
58         check("beast.http", error::bad_version);
59         check("beast.http", error::bad_status);
60         check("beast.http", error::bad_reason);
61         check("beast.http", error::bad_field);
62         check("beast.http", error::bad_value);
63         check("beast.http", error::bad_content_length);
64         check("beast.http", error::bad_transfer_encoding);
65         check("beast.http", error::bad_chunk);
66         check("beast.http", error::bad_chunk_extension);
67         check("beast.http", error::bad_obs_fold);
68 
69         check("beast.http", error::stale_parser);
70         check("beast.http", error::short_read);
71     }
72 };
73 
74 BEAST_DEFINE_TESTSUITE(beast,http,error);
75 
76 } // http
77 } // beast
78 } // boost
79