]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // is_write_buffered.cpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
b32b8144 | 5 | // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | ||
11 | // Disable autolinking for unit tests. | |
12 | #if !defined(BOOST_ALL_NO_LIB) | |
13 | #define BOOST_ALL_NO_LIB 1 | |
14 | #endif // !defined(BOOST_ALL_NO_LIB) | |
15 | ||
16 | // Test that header file is self-contained. | |
17 | #include <boost/asio/is_write_buffered.hpp> | |
18 | ||
19 | #include <boost/asio/buffered_read_stream.hpp> | |
20 | #include <boost/asio/buffered_write_stream.hpp> | |
b32b8144 | 21 | #include <boost/asio/io_context.hpp> |
7c673cae FG |
22 | #include <boost/asio/ip/tcp.hpp> |
23 | #include "unit_test.hpp" | |
24 | ||
25 | using namespace std; // For memcmp, memcpy and memset. | |
26 | ||
27 | class test_stream | |
28 | { | |
29 | public: | |
b32b8144 | 30 | typedef boost::asio::io_context io_context_type; |
7c673cae FG |
31 | |
32 | typedef test_stream lowest_layer_type; | |
33 | ||
b32b8144 FG |
34 | typedef io_context_type::executor_type executor_type; |
35 | ||
36 | test_stream(boost::asio::io_context& io_context) | |
37 | : io_context_(io_context) | |
7c673cae FG |
38 | { |
39 | } | |
40 | ||
b32b8144 | 41 | io_context_type& io_context() |
7c673cae | 42 | { |
b32b8144 | 43 | return io_context_; |
7c673cae FG |
44 | } |
45 | ||
46 | lowest_layer_type& lowest_layer() | |
47 | { | |
48 | return *this; | |
49 | } | |
50 | ||
51 | template <typename Const_Buffers> | |
52 | size_t write(const Const_Buffers&) | |
53 | { | |
54 | return 0; | |
55 | } | |
56 | ||
57 | template <typename Const_Buffers> | |
58 | size_t write(const Const_Buffers&, boost::system::error_code& ec) | |
59 | { | |
60 | ec = boost::system::error_code(); | |
61 | return 0; | |
62 | } | |
63 | ||
64 | template <typename Const_Buffers, typename Handler> | |
65 | void async_write(const Const_Buffers&, Handler handler) | |
66 | { | |
67 | boost::system::error_code error; | |
b32b8144 FG |
68 | boost::asio::post(io_context_, |
69 | boost::asio::detail::bind_handler(handler, error, 0)); | |
7c673cae FG |
70 | } |
71 | ||
72 | template <typename Mutable_Buffers> | |
73 | size_t read(const Mutable_Buffers&) | |
74 | { | |
75 | return 0; | |
76 | } | |
77 | ||
78 | template <typename Mutable_Buffers> | |
79 | size_t read(const Mutable_Buffers&, boost::system::error_code& ec) | |
80 | { | |
81 | ec = boost::system::error_code(); | |
82 | return 0; | |
83 | } | |
84 | ||
85 | template <typename Mutable_Buffers, typename Handler> | |
86 | void async_read(const Mutable_Buffers&, Handler handler) | |
87 | { | |
88 | boost::system::error_code error; | |
b32b8144 FG |
89 | boost::asio::post(io_context_, |
90 | boost::asio::detail::bind_handler(handler, error, 0)); | |
7c673cae FG |
91 | } |
92 | ||
93 | private: | |
b32b8144 | 94 | io_context_type& io_context_; |
7c673cae FG |
95 | }; |
96 | ||
97 | void is_write_buffered_test() | |
98 | { | |
99 | BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< | |
100 | boost::asio::ip::tcp::socket>::value); | |
101 | ||
102 | BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< | |
103 | boost::asio::buffered_read_stream< | |
104 | boost::asio::ip::tcp::socket> >::value); | |
105 | ||
106 | BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< | |
107 | boost::asio::buffered_write_stream< | |
108 | boost::asio::ip::tcp::socket> >::value); | |
109 | ||
110 | BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< | |
111 | boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value); | |
112 | ||
113 | BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<test_stream>::value); | |
114 | ||
115 | BOOST_ASIO_CHECK(!boost::asio::is_write_buffered< | |
116 | boost::asio::buffered_read_stream<test_stream> >::value); | |
117 | ||
118 | BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< | |
119 | boost::asio::buffered_write_stream<test_stream> >::value); | |
120 | ||
121 | BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered< | |
122 | boost::asio::buffered_stream<test_stream> >::value); | |
123 | } | |
124 | ||
125 | BOOST_ASIO_TEST_SUITE | |
126 | ( | |
127 | "is_write_buffered", | |
128 | BOOST_ASIO_TEST_CASE(is_write_buffered_test) | |
129 | ) |