]> granicus.if.org Git - icinga2/blob - test/base-stream.cpp
Merge pull request #7383 from K0nne/K0nne-patch-1
[icinga2] / test / base-stream.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/stdiostream.hpp"
4 #include "base/string.hpp"
5 #include <BoostTestTargetConfig.h>
6 #include <sstream>
7
8 using namespace icinga;
9
10 BOOST_AUTO_TEST_SUITE(base_stream)
11
12 BOOST_AUTO_TEST_CASE(readline_stdio)
13 {
14         std::stringstream msgbuf;
15         msgbuf << "Hello\nWorld\n\n";
16
17         StdioStream::Ptr stdstream = new StdioStream(&msgbuf, false);
18
19         StreamReadContext rlc;
20
21         String line;
22         BOOST_CHECK(stdstream->ReadLine(&line, rlc) == StatusNewItem);
23         BOOST_CHECK(line == "Hello");
24
25         BOOST_CHECK(stdstream->ReadLine(&line, rlc) == StatusNewItem);
26         BOOST_CHECK(line == "World");
27
28         BOOST_CHECK(stdstream->ReadLine(&line, rlc) == StatusNewItem);
29         BOOST_CHECK(line == "");
30
31         BOOST_CHECK(stdstream->ReadLine(&line, rlc) == StatusNewItem);
32         BOOST_CHECK(line == "");
33
34         BOOST_CHECK(stdstream->ReadLine(&line, rlc) == StatusEof);
35
36         stdstream->Close();
37 }
38
39 BOOST_AUTO_TEST_SUITE_END()