]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/test/core/dynabuf_readstream.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // Test that header file is self-contained.
9 #include <beast/core/dynabuf_readstream.hpp>
11 #include <beast/core/streambuf.hpp>
12 #include <beast/test/fail_stream.hpp>
13 #include <beast/test/string_istream.hpp>
14 #include <beast/test/yield_to.hpp>
15 #include <beast/unit_test/suite.hpp>
16 #include <boost/asio.hpp>
20 class dynabuf_readstream_test
21 : public unit_test::suite
22 , public test::enable_yield_to
24 using self
= dynabuf_readstream_test
;
27 void testSpecialMembers()
29 using socket_type
= boost::asio::ip::tcp::socket
;
30 boost::asio::io_service ios
;
32 dynabuf_readstream
<socket_type
, streambuf
> srs(ios
);
33 dynabuf_readstream
<socket_type
, streambuf
> srs2(std::move(srs
));
34 srs
= std::move(srs2
);
35 BEAST_EXPECT(&srs
.get_io_service() == &ios
);
36 BEAST_EXPECT(&srs
.get_io_service() == &srs2
.get_io_service());
39 socket_type
sock(ios
);
40 dynabuf_readstream
<socket_type
&, streambuf
> srs(sock
);
41 dynabuf_readstream
<socket_type
&, streambuf
> srs2(std::move(srs
));
45 void testRead(yield_context do_yield
)
47 using boost::asio::buffer
;
48 using boost::asio::buffer_copy
;
49 static std::size_t constexpr limit
= 100;
54 for(n
= 0; n
< limit
; ++n
)
57 test::string_istream
> fs(n
, ios_
, ", world!");
59 decltype(fs
)&, streambuf
> srs(fs
);
60 srs
.buffer().commit(buffer_copy(
61 srs
.buffer().prepare(5), buffer("Hello", 5)));
63 boost::asio::read(srs
, buffer(&s
[0], s
.size()), ec
);
66 BEAST_EXPECT(s
== "Hello, world!");
70 BEAST_EXPECT(n
< limit
);
72 for(n
= 0; n
< limit
; ++n
)
75 test::string_istream
> fs(n
, ios_
, ", world!");
77 decltype(fs
)&, streambuf
> srs(fs
);
79 srs
.buffer().commit(buffer_copy(
80 srs
.buffer().prepare(5), buffer("Hello", 5)));
82 boost::asio::read(srs
, buffer(&s
[0], s
.size()), ec
);
85 BEAST_EXPECT(s
== "Hello, world!");
89 BEAST_EXPECT(n
< limit
);
91 for(n
= 0; n
< limit
; ++n
)
94 test::string_istream
> fs(n
, ios_
, ", world!");
96 decltype(fs
)&, streambuf
> srs(fs
);
97 srs
.buffer().commit(buffer_copy(
98 srs
.buffer().prepare(5), buffer("Hello", 5)));
100 boost::asio::async_read(
101 srs
, buffer(&s
[0], s
.size()), do_yield
[ec
]);
104 BEAST_EXPECT(s
== "Hello, world!");
108 BEAST_EXPECT(n
< limit
);
110 for(n
= 0; n
< limit
; ++n
)
113 test::string_istream
> fs(n
, ios_
, ", world!");
115 decltype(fs
)&, streambuf
> srs(fs
);
117 srs
.buffer().commit(buffer_copy(
118 srs
.buffer().prepare(5), buffer("Hello", 5)));
120 boost::asio::async_read(
121 srs
, buffer(&s
[0], s
.size()), do_yield
[ec
]);
124 BEAST_EXPECT(s
== "Hello, world!");
128 BEAST_EXPECT(n
< limit
);
133 testSpecialMembers();
135 yield_to(&self::testRead
, this);
139 BEAST_DEFINE_TESTSUITE(dynabuf_readstream
,core
,beast
);