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/zlib/error.hpp>
12
13#include <boost/beast/_experimental/unit_test/suite.hpp>
14#include <memory>
15
16namespace boost {
17namespace beast {
18namespace zlib {
19
20class error_test : public unit_test::suite
21{
22public:
23 void check(char const* name, error ev)
24 {
25 auto const ec = make_error_code(ev);
26 auto const& cat = make_error_code(
27 ev: static_cast<zlib::error>(0)).category();
28 BEAST_EXPECT(std::string{ec.category().name()} == name);
29 BEAST_EXPECT(! ec.message().empty());
30 BEAST_EXPECT(
31 std::addressof(ec.category()) == std::addressof(cat));
32 BEAST_EXPECT(cat.equivalent(
33 static_cast<std::underlying_type<error>::type>(ev),
34 ec.category().default_error_condition(
35 static_cast<std::underlying_type<error>::type>(ev))));
36 BEAST_EXPECT(cat.equivalent(ec,
37 static_cast<std::underlying_type<error>::type>(ev)));
38
39 BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
40 }
41
42 void run() override
43 {
44 check(name: "boost.beast.zlib", ev: error::need_buffers);
45 check(name: "boost.beast.zlib", ev: error::end_of_stream);
46 check(name: "boost.beast.zlib", ev: error::need_dict);
47 check(name: "boost.beast.zlib", ev: error::stream_error);
48
49 check(name: "boost.beast.zlib", ev: error::invalid_block_type);
50 check(name: "boost.beast.zlib", ev: error::invalid_stored_length);
51 check(name: "boost.beast.zlib", ev: error::too_many_symbols);
52 check(name: "boost.beast.zlib", ev: error::invalid_code_lengths);
53 check(name: "boost.beast.zlib", ev: error::invalid_bit_length_repeat);
54 check(name: "boost.beast.zlib", ev: error::missing_eob);
55 check(name: "boost.beast.zlib", ev: error::invalid_literal_length);
56 check(name: "boost.beast.zlib", ev: error::invalid_distance_code);
57 check(name: "boost.beast.zlib", ev: error::invalid_distance);
58
59 check(name: "boost.beast.zlib", ev: error::over_subscribed_length);
60 check(name: "boost.beast.zlib", ev: error::incomplete_length_set);
61
62 check(name: "boost.beast.zlib", ev: error::general);
63 }
64};
65
66BEAST_DEFINE_TESTSUITE(beast,zlib,error);
67
68} // zlib
69} // beast
70} // boost
71

source code of boost/libs/beast/test/beast/zlib/error.cpp