GlobalSignal_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (GlobalSignal_t)
2 #include "boost/test/tools/output_test_stream.hpp"
3 #include "boost/test/unit_test.hpp"
4 
6 
7 #include <ostream>
8 #include <string>
9 
10 namespace {
11 
12  using TestSignal0 =
15  void(std::ostream&)>;
16  using TestSignal2 =
18  void(std::ostream&, std::string const&)>;
19  using TestSignal2a =
21  void(std::ostream&, std::string const&)>;
22 
23  template <uint16_t n>
24  void
25  testCallback(std::ostream& os, std::string const& text)
26  {
27  if (n > 0) {
28  os << n << ": ";
29  }
30  os << text;
31  }
32  struct CallBackClass {
33  void
34  func(std::ostream& os, std::string const& text)
35  {
36  os << text;
37  }
38  void
39  cfunc(std::ostream& os, std::string const& text) const
40  {
41  os << text;
42  }
43  };
44 } // namespace
45 
46 BOOST_AUTO_TEST_SUITE(GlobalSignal_t)
47 
48 BOOST_AUTO_TEST_CASE(TestSignal2_t)
49 {
50  TestSignal2 s;
51  std::string const test_text{"Test text.\n"};
52  boost::test_tools::output_test_stream os;
53  s.watch(testCallback<1>);
54  s.watch(testCallback<2>);
55  s.watch(testCallback<3>);
56  std::string const cmp_text{std::string("1: ") + test_text +
57  "2: " + test_text + "3: " + test_text};
58  BOOST_CHECK_NO_THROW(s.invoke(os, test_text));
59  BOOST_TEST(os.is_equal(cmp_text));
60 }
61 
62 BOOST_AUTO_TEST_CASE(TestSignal2a_t)
63 {
64  TestSignal2a s;
65  std::string const test_text{"Test text.\n"};
66  boost::test_tools::output_test_stream os;
67  s.watch(testCallback<1>);
68  s.watch(testCallback<2>);
69  s.watch(testCallback<3>);
70  std::string const cmp_text{std::string("3: ") + test_text +
71  "2: " + test_text + "1: " + test_text};
72  BOOST_CHECK_NO_THROW(s.invoke(os, test_text));
73  BOOST_TEST(os.is_equal(cmp_text));
74 }
75 
76 BOOST_AUTO_TEST_CASE(TestSignal2_func_t)
77 {
78  TestSignal2 s;
79  std::string const test_text{"Test text"};
80  boost::test_tools::output_test_stream os;
81  CallBackClass cbc;
82  s.watch(&CallBackClass::func, cbc);
83  BOOST_CHECK_NO_THROW(s.invoke(os, test_text));
84  BOOST_TEST(os.is_equal(test_text));
85 }
86 
87 BOOST_AUTO_TEST_CASE(TestSignal2_cfunc_t)
88 {
89  TestSignal2 s;
90  std::string const test_text{"Test text"};
91  boost::test_tools::output_test_stream os;
92  CallBackClass const cbc;
93  s.watch(&CallBackClass::cfunc, cbc);
94  BOOST_CHECK_NO_THROW(s.invoke(os, test_text));
95  BOOST_TEST(os.is_equal(test_text));
96 }
97 
98 BOOST_AUTO_TEST_CASE(TestSignal1_t)
99 {
100  TestSignal1 s;
101  std::string const test_text{"Test text"};
102  boost::test_tools::output_test_stream os;
103  s.watch([&test_text](auto& x) { testCallback<0>(x, test_text); });
104  BOOST_CHECK_NO_THROW(s.invoke(os));
105  BOOST_TEST(os.is_equal(test_text));
106 }
107 
108 BOOST_AUTO_TEST_CASE(TestSignal0_t)
109 {
110  TestSignal0 s;
111  std::string const test_text{"Test text"};
112  boost::test_tools::output_test_stream os;
113  // 2012/02/13 CG This explicit reference to base clase below is
114  // necessary because std::ref(os) fails due to a private typedef
115  // output_test_stream::result_type (in Boost <=1.53.0 at least)
116  // screwing up std::ref's attempt to determine whether
117  // output_test_stream is a callable entity.
118  std::ostringstream& osr [[maybe_unused]]{os};
119  s.watch([&osr, &test_text] { testCallback<0>(osr, test_text); });
120  BOOST_CHECK_NO_THROW(s.invoke());
121  BOOST_TEST(os.is_equal(test_text));
122 }
123 
124 BOOST_AUTO_TEST_SUITE_END()
std::string string
Definition: nybbler.cc:12
BOOST_AUTO_TEST_CASE(TestSignal2_t)
std::void_t< T > n
def func()
Definition: docstring.py:7
list x
Definition: train.py:276
static QCString * s
Definition: config.cpp:1042