ostream_handle_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (ostream_handle test)
2 #include "boost/test/unit_test.hpp"
3 
5 
6 #include <fstream>
7 #include <string>
8 
10 using namespace std::string_literals;
11 
12 namespace {
14  file_contents(std::string const& fileName)
15  {
17  std::ifstream file{fileName};
18  for (std::string l{}; std::getline(file, l); result += l) {
19  }
20  return result;
21  }
22 }
23 
24 BOOST_AUTO_TEST_SUITE(ostream_handle_test)
25 
27 {
28  std::ostringstream oss;
29  ostream_handle obs{oss};
30  obs << "a";
31  BOOST_TEST(oss.str() == "a"s);
32 }
33 
35 {
36  std::string const fileName{"owner.txt"};
37  {
39  BOOST_TEST(static_cast<bool>(own));
40  own << "a";
41  }
42  BOOST_TEST(file_contents(fileName) == "a"s);
43 }
44 
45 BOOST_AUTO_TEST_CASE(observerThenOwner)
46 {
47  std::string const fileName{"observerThenOwner.txt"};
48  {
49  std::ostringstream oss;
50  ostream_handle os{oss};
51  os << "a";
53  own << "b";
54  os = std::move(own);
55  os << "c";
56  }
57  BOOST_TEST(file_contents(fileName) == "bc"s);
58 }
59 
60 BOOST_AUTO_TEST_CASE(ownerThenObserver)
61 {
62  std::string const fileName{"ownerThenObserver.txt"};
63  {
65  os << "a";
66  std::ostringstream oss;
67  ostream_handle obs{oss};
68  obs << "b";
69  os = std::move(obs);
70  os << "c";
71  BOOST_TEST(oss.str() == "bc"s);
72  }
73  BOOST_TEST(file_contents(fileName) == "a"s);
74 }
75 
76 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(observer)
static QCString result
std::string string
Definition: nybbler.cc:12
static QStrList * l
Definition: config.cpp:1044
fileName
Definition: dumpTree.py:9
def move(depos, offset)
Definition: depos.py:107
static QCString * s
Definition: config.cpp:1042