]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/websocket/error.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / beast / test / beast / websocket / error.cpp
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/websocket/error.hpp>
12
13 #include <boost/beast/_experimental/unit_test/suite.hpp>
14 #include <memory>
15
16 namespace boost {
17 namespace beast {
18 namespace websocket {
19
20 class error_test : public unit_test::suite
21 {
22 public:
23 void check(error e)
24 {
25 auto const ec = make_error_code(e);
26 ec.category().name();
27 BEAST_EXPECT(! ec.message().empty());
28 BEAST_EXPECT(ec != condition::handshake_failed);
29 BEAST_EXPECT(ec != condition::protocol_violation);
30 }
31
32 void check(condition c, error e)
33 {
34 auto const ec = make_error_code(e);
35 BEAST_EXPECT(ec.category().name() != nullptr);
36 BEAST_EXPECT(! ec.message().empty());
37 BEAST_EXPECT(ec == c);
38 }
39
40 void run() override
41 {
42 check(error::closed);
43 check(error::buffer_overflow);
44 check(error::partial_deflate_block);
45 check(error::message_too_big);
46
47 check(condition::protocol_violation, error::bad_opcode);
48 check(condition::protocol_violation, error::bad_data_frame);
49 check(condition::protocol_violation, error::bad_continuation);
50 check(condition::protocol_violation, error::bad_reserved_bits);
51 check(condition::protocol_violation, error::bad_control_fragment);
52 check(condition::protocol_violation, error::bad_control_size);
53 check(condition::protocol_violation, error::bad_unmasked_frame);
54 check(condition::protocol_violation, error::bad_masked_frame);
55 check(condition::protocol_violation, error::bad_size);
56 check(condition::protocol_violation, error::bad_frame_payload);
57 check(condition::protocol_violation, error::bad_close_code);
58 check(condition::protocol_violation, error::bad_close_size);
59 check(condition::protocol_violation, error::bad_close_payload);
60
61 check(condition::handshake_failed, error::bad_http_version);
62 check(condition::handshake_failed, error::bad_method);
63 check(condition::handshake_failed, error::no_host);
64 check(condition::handshake_failed, error::no_connection);
65 check(condition::handshake_failed, error::no_connection_upgrade);
66 check(condition::handshake_failed, error::no_upgrade);
67 check(condition::handshake_failed, error::no_upgrade_websocket);
68 check(condition::handshake_failed, error::no_sec_key);
69 check(condition::handshake_failed, error::bad_sec_key);
70 check(condition::handshake_failed, error::no_sec_version);
71 check(condition::handshake_failed, error::bad_sec_version);
72 check(condition::handshake_failed, error::no_sec_accept);
73 check(condition::handshake_failed, error::bad_sec_accept);
74 check(condition::handshake_failed, error::upgrade_declined);
75 }
76 };
77
78 BEAST_DEFINE_TESTSUITE(beast,websocket,error);
79
80 } // websocket
81 } // beast
82 } // boost