1 //
2 // streambuf.cpp
3 // ~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 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/streambuf.hpp>
18 
19 #include <boost/asio/buffer.hpp>
20 #include "unit_test.hpp"
21 
streambuf_test()22 void streambuf_test()
23 {
24   boost::asio::streambuf sb;
25 
26   sb.sputn("abcd", 4);
27 
28   BOOST_ASIO_CHECK(sb.size() == 4);
29 
30   for (int i = 0; i < 100; ++i)
31   {
32     sb.consume(3);
33 
34     BOOST_ASIO_CHECK(sb.size() == 1);
35 
36     char buf[1];
37     sb.sgetn(buf, 1);
38 
39     BOOST_ASIO_CHECK(sb.size() == 0);
40 
41     sb.sputn("ab", 2);
42 
43     BOOST_ASIO_CHECK(sb.size() == 2);
44 
45     boost::asio::buffer_copy(sb.prepare(10), boost::asio::buffer("cd", 2));
46     sb.commit(2);
47 
48     BOOST_ASIO_CHECK(sb.size() == 4);
49   }
50 
51   BOOST_ASIO_CHECK(sb.size() == 4);
52 
53   sb.consume(4);
54 
55   BOOST_ASIO_CHECK(sb.size() == 0);
56 }
57 
58 BOOST_ASIO_TEST_SUITE
59 (
60   "streambuf",
61   BOOST_ASIO_TEST_CASE(streambuf_test)
62 )
63