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/core/make_printable.hpp>
12
13#include <boost/beast/_experimental/unit_test/suite.hpp>
14#include <boost/beast/core/buffer_traits.hpp>
15#include <iostream>
16#include <sstream>
17
18#include "test_buffer.hpp"
19
20namespace boost {
21namespace beast {
22
23class make_printable_test : public beast::unit_test::suite
24{
25public:
26 template <class ConstBufferSequence>
27 void
28 print (ConstBufferSequence const& buffers)
29 {
30 std::cout <<
31 "Buffer size: " << buffer_bytes(buffers) << " bytes\n"
32 "Buffer data: '" << make_printable(buffers) << "'\n";
33 }
34
35 void
36 testJavadoc()
37 {
38 BEAST_EXPECT(&make_printable_test::print<buffers_triple>);
39 }
40
41 void
42 testMakePrintable()
43 {
44 char buf[13];
45 buffers_triple b(buf, sizeof(buf));
46 string_view src = "Hello, world!";
47 BEAST_EXPECT(src.size() == sizeof(buf));
48 net::buffer_copy(target: b,
49 source: net::const_buffer(src.data(), src.size()));
50 std::ostringstream ss;
51 ss << make_printable(buffers: b);
52 BEAST_EXPECT(ss.str() == src);
53 }
54
55 void
56 run() override
57 {
58 testJavadoc();
59 testMakePrintable();
60 }
61};
62
63BEAST_DEFINE_TESTSUITE(beast,core,make_printable);
64
65} // beast
66} // boost
67

source code of boost/libs/beast/test/beast/core/make_printable.cpp