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

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