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/detail/read.hpp>
12
13#include <boost/beast/core/buffers_to_string.hpp>
14#include <boost/beast/core/flat_buffer.hpp>
15#include <boost/beast/core/ostream.hpp>
16#include <boost/beast/_experimental/test/stream.hpp>
17#include <boost/beast/_experimental/unit_test/suite.hpp>
18#include <boost/asio/completion_condition.hpp>
19
20namespace boost {
21namespace beast {
22namespace detail {
23
24class read_test : public unit_test::suite
25{
26public:
27#if 0
28 void
29 testRead()
30 {
31 {
32 net::io_context ioc;
33 test::stream ts(ioc);
34 ostream(ts.buffer()) << "test";
35 error_code ec;
36 flat_buffer b;
37 read(ts, b, boost::asio::transfer_at_least(4), ec);
38 BEAST_EXPECTS(! ec, ec.message());
39 BEAST_EXPECT(buffers_to_string(b.data()) == "test");
40 }
41 {
42 net::io_context ioc;
43 test::stream ts(ioc);
44 auto tc = connect(ts);
45 ostream(ts.buffer()) << "test";
46 tc.close();
47 error_code ec;
48 flat_buffer b;
49 read(ts, b, boost::asio::transfer_all(), ec);
50 BEAST_EXPECTS(ec == boost::asio::error::eof, ec.message());
51 BEAST_EXPECT(buffers_to_string(b.data()) == "test");
52 }
53 }
54
55 void
56 testAsyncRead()
57 {
58 {
59 net::io_context ioc;
60 test::stream ts(ioc);
61 ostream(ts.buffer()) << "test";
62 flat_buffer b;
63 error_code ec;
64 bool invoked = false;
65 async_read(ts, b, boost::asio::transfer_at_least(4),
66 [&invoked, &ec](error_code ec_, std::size_t)
67 {
68 ec = ec_;
69 invoked = true;
70 });
71 ioc.run();
72 BEAST_EXPECT(invoked);
73 BEAST_EXPECTS(! ec, ec.message());
74 BEAST_EXPECT(buffers_to_string(b.data()) == "test");
75 }
76 {
77 net::io_context ioc;
78 test::stream ts(ioc);
79 auto tc = connect(ts);
80 ostream(ts.buffer()) << "test";
81 tc.close();
82 flat_buffer b;
83 error_code ec;
84 bool invoked = false;
85 async_read(ts, b, boost::asio::transfer_all(),
86 [&invoked, &ec](error_code ec_, std::size_t)
87 {
88 ec = ec_;
89 invoked = true;
90 });
91 ioc.run();
92 BEAST_EXPECT(invoked);
93 BEAST_EXPECTS(ec == boost::asio::error::eof, ec.message());
94 BEAST_EXPECT(buffers_to_string(b.data()) == "test");
95 }
96 }
97#endif
98 void
99 run() override
100 {
101 pass();
102 //testRead();
103 //testAsyncRead();
104 }
105};
106
107BEAST_DEFINE_TESTSUITE(beast,core,read);
108
109} // detail
110} // beast
111} // boost
112

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