2 // is_read_buffered.cpp
3 // ~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
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)
16 // Test that header file is self-contained.
17 #include <boost/asio/is_read_buffered.hpp>
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"
25 using namespace std; // For memcmp, memcpy and memset.
30 typedef boost::asio::io_service io_service_type;
32 typedef test_stream lowest_layer_type;
34 test_stream(boost::asio::io_service& io_service)
35 : io_service_(io_service)
39 io_service_type& io_service()
44 lowest_layer_type& lowest_layer()
49 template <typename Const_Buffers>
50 size_t write(const Const_Buffers&)
55 template <typename Const_Buffers>
56 size_t write(const Const_Buffers&, boost::system::error_code& ec)
58 ec = boost::system::error_code();
62 template <typename Const_Buffers, typename Handler>
63 void async_write(const Const_Buffers&, Handler handler)
65 boost::system::error_code error;
66 io_service_.post(boost::asio::detail::bind_handler(handler, error, 0));
69 template <typename Mutable_Buffers>
70 size_t read(const Mutable_Buffers&)
75 template <typename Mutable_Buffers>
76 size_t read(const Mutable_Buffers&, boost::system::error_code& ec)
78 ec = boost::system::error_code();
82 template <typename Mutable_Buffers, typename Handler>
83 void async_read(const Mutable_Buffers&, Handler handler)
85 boost::system::error_code error;
86 io_service_.post(boost::asio::detail::bind_handler(handler, error, 0));
90 io_service_type& io_service_;
93 void is_read_buffered_test()
95 BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
96 boost::asio::ip::tcp::socket>::value);
98 BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
99 boost::asio::buffered_read_stream<
100 boost::asio::ip::tcp::socket> >::value);
102 BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
103 boost::asio::buffered_write_stream<
104 boost::asio::ip::tcp::socket> >::value);
106 BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
107 boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value);
109 BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<test_stream>::value);
111 BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
112 boost::asio::buffered_read_stream<test_stream> >::value);
114 BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
115 boost::asio::buffered_write_stream<test_stream> >::value);
117 BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
118 boost::asio::buffered_stream<test_stream> >::value);
121 BOOST_ASIO_TEST_SUITE
124 BOOST_ASIO_TEST_CASE(is_read_buffered_test)