1//
2// is_write_buffered.cpp
3// ~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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>
21#include <boost/asio/io_service.hpp>
22#include <boost/asio/ip/tcp.hpp>
23#include "unit_test.hpp"
24
25using namespace std; // For memcmp, memcpy and memset.
26
27class test_stream
28{
29public:
30 typedef boost::asio::io_service io_service_type;
31
32 typedef test_stream lowest_layer_type;
33
34 test_stream(boost::asio::io_service& io_service)
35 : io_service_(io_service)
36 {
37 }
38
39 io_service_type& io_service()
40 {
41 return io_service_;
42 }
43
44 lowest_layer_type& lowest_layer()
45 {
46 return *this;
47 }
48
49 template <typename Const_Buffers>
50 size_t write(const Const_Buffers&)
51 {
52 return 0;
53 }
54
55 template <typename Const_Buffers>
56 size_t write(const Const_Buffers&, boost::system::error_code& ec)
57 {
58 ec = boost::system::error_code();
59 return 0;
60 }
61
62 template <typename Const_Buffers, typename Handler>
63 void async_write(const Const_Buffers&, Handler handler)
64 {
65 boost::system::error_code error;
66 io_service_.post(boost::asio::detail::bind_handler(handler, error, 0));
67 }
68
69 template <typename Mutable_Buffers>
70 size_t read(const Mutable_Buffers&)
71 {
72 return 0;
73 }
74
75 template <typename Mutable_Buffers>
76 size_t read(const Mutable_Buffers&, boost::system::error_code& ec)
77 {
78 ec = boost::system::error_code();
79 return 0;
80 }
81
82 template <typename Mutable_Buffers, typename Handler>
83 void async_read(const Mutable_Buffers&, Handler handler)
84 {
85 boost::system::error_code error;
86 io_service_.post(boost::asio::detail::bind_handler(handler, error, 0));
87 }
88
89private:
90 io_service_type& io_service_;
91};
92
93void is_write_buffered_test()
94{
95 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<
96 boost::asio::ip::tcp::socket>::value);
97
98 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<
99 boost::asio::buffered_read_stream<
100 boost::asio::ip::tcp::socket> >::value);
101
102 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered<
103 boost::asio::buffered_write_stream<
104 boost::asio::ip::tcp::socket> >::value);
105
106 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered<
107 boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value);
108
109 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<test_stream>::value);
110
111 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered<
112 boost::asio::buffered_read_stream<test_stream> >::value);
113
114 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered<
115 boost::asio::buffered_write_stream<test_stream> >::value);
116
117 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered<
118 boost::asio::buffered_stream<test_stream> >::value);
119}
120
121BOOST_ASIO_TEST_SUITE
122(
123 "is_write_buffered",
124 BOOST_ASIO_TEST_CASE(is_write_buffered_test)
125)
126

source code of boost/libs/asio/test/is_write_buffered.cpp