Release 1.39.0
[boost.git] / Boost_1_39_0 / libs / asio / test / is_write_buffered.cpp
blob6a530706d5714792ede6fdb70feceb5a31ea2361
1 //
2 // is_write_buffered.cpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 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 //
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_write_buffered.hpp>
19 #include <boost/bind.hpp>
20 #include <boost/noncopyable.hpp>
21 #include <boost/asio.hpp>
22 #include "unit_test.hpp"
24 using namespace std; // For memcmp, memcpy and memset.
26 class test_stream
27 : private boost::noncopyable
29 public:
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()
41 return io_service_;
44 lowest_layer_type& lowest_layer()
46 return *this;
49 template <typename Const_Buffers>
50 size_t write(const Const_Buffers&)
52 return 0;
55 template <typename Const_Buffers>
56 size_t write(const Const_Buffers&, boost::system::error_code& ec)
58 ec = boost::system::error_code();
59 return 0;
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&)
72 return 0;
75 template <typename Mutable_Buffers>
76 size_t read(const Mutable_Buffers&, boost::system::error_code& ec)
78 ec = boost::system::error_code();
79 return 0;
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));
89 private:
90 io_service_type& io_service_;
93 void is_write_buffered_test()
95 BOOST_CHECK(!boost::asio::is_write_buffered<
96 boost::asio::ip::tcp::socket>::value);
98 BOOST_CHECK(!boost::asio::is_write_buffered<
99 boost::asio::buffered_read_stream<
100 boost::asio::ip::tcp::socket> >::value);
102 BOOST_CHECK(!!boost::asio::is_write_buffered<
103 boost::asio::buffered_write_stream<
104 boost::asio::ip::tcp::socket> >::value);
106 BOOST_CHECK(!!boost::asio::is_write_buffered<
107 boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value);
109 BOOST_CHECK(!boost::asio::is_write_buffered<test_stream>::value);
111 BOOST_CHECK(!boost::asio::is_write_buffered<
112 boost::asio::buffered_read_stream<test_stream> >::value);
114 BOOST_CHECK(!!boost::asio::is_write_buffered<
115 boost::asio::buffered_write_stream<test_stream> >::value);
117 BOOST_CHECK(!!boost::asio::is_write_buffered<
118 boost::asio::buffered_stream<test_stream> >::value);
121 test_suite* init_unit_test_suite(int, char*[])
123 test_suite* test = BOOST_TEST_SUITE("is_write_buffered");
124 test->add(BOOST_TEST_CASE(&is_write_buffered_test));
125 return test;