Ticket #8309: nonblocking_indirect_streambuf_write.cpp

File nonblocking_indirect_streambuf_write.cpp, 1.3 KB (added by fpascutti@…, 10 years ago)

unit-test

Line 
1#define BOOST_TEST_MODULE nonblocking_indirect_streambuf_write
2
3#include <boost/algorithm/string/predicate.hpp>
4#include <boost/iostreams/categories.hpp>
5#include <boost/iostreams/filtering_stream.hpp>
6#include <boost/test/included/unit_test.hpp>
7
8struct sink
9{
10public:
11 typedef char char_type;
12 typedef boost::iostreams::sink_tag category;
13
14 sink()
15 : state_(0)
16 { }
17
18 ~sink()
19 {
20 BOOST_REQUIRE_EQUAL(state_, 4);
21 }
22
23 std::streamsize write(const char* in, std::streamsize n)
24 {
25 BOOST_REQUIRE_GE(n, 2);
26 switch(state_++)
27 {
28 case 0:
29 BOOST_REQUIRE_EQUAL(std::string(in, 2), "AB"); break;
30 case 1:
31 BOOST_REQUIRE_EQUAL(std::string(in, 2), "CD"); break;
32 case 2:
33 BOOST_REQUIRE_EQUAL(std::string(in, 2), "EF"); break;
34 case 3:
35 BOOST_REQUIRE_EQUAL(std::string(in, 2), "GH"); break;
36 default:
37 BOOST_FAIL("'write' called too many times!");
38 }
39 return 2;
40 }
41
42 size_t state_;
43};
44
45BOOST_AUTO_TEST_CASE(nonblocking_indirect_streambuf_write)
46{
47 boost::iostreams::filtering_ostream ostream;
48 ostream.push((sink()));
49
50 ostream << "ABCDEFGH";
51 ostream.flush();
52}