LocalSignal_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (LocalSignal_t)
2 #include "boost/test/tools/output_test_stream.hpp"
3 #include "boost/test/unit_test.hpp"
4 
7 
8 #include <ostream>
9 #include <stdexcept>
10 #include <string>
11 
12 namespace {
13 
15  void(std::ostream&, std::string const&)>;
16  using TestSignal2a =
18  void(std::ostream&, std::string const&)>;
20  void(std::ostream&)>;
21  using TestSignal0 =
23 
24  template <uint16_t n>
25  void
26  testCallback(std::ostream& os, std::string const& text)
27  {
28  if (n > 0) {
29  os << n << ": ";
30  }
31  os << text;
32  }
33 
34  struct CallBackClass {
35  void
36  func(std::ostream& os, std::string const& text)
37  {
38  os << text;
39  }
40  void
41  cfunc(std::ostream& os, std::string const& text) const
42  {
43  os << text;
44  }
45  };
46 
47  size_t const nSchedules{3};
48  art::ScheduleID const sID{1};
49 } // namespace
50 
51 BOOST_AUTO_TEST_SUITE(LocalSignal_t)
52 
53 BOOST_AUTO_TEST_CASE(TestSignal2_t)
54 {
55  TestSignal2 s{nSchedules};
56  std::string const test_text{"Test text.\n"};
57  boost::test_tools::output_test_stream os;
58  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<1>));
59  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<2>));
60  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<3>));
61  std::string const cmp_text{std::string("1: ") + test_text +
62  "2: " + test_text + "3: " + test_text};
63  BOOST_CHECK_NO_THROW(s.invoke(sID, os, test_text));
64  BOOST_TEST(os.is_equal(cmp_text));
65 }
66 
67 BOOST_AUTO_TEST_CASE(TestSignal2a_t)
68 {
69  TestSignal2a s{nSchedules};
70  std::string const test_text{"Test text.\n"};
71  boost::test_tools::output_test_stream os;
72  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<1>));
73  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<2>));
74  BOOST_CHECK_NO_THROW(s.watch(sID, testCallback<3>));
75  std::string const cmp_text{std::string("3: ") + test_text +
76  "2: " + test_text + "1: " + test_text};
77  BOOST_CHECK_NO_THROW(s.invoke(sID, os, test_text));
78  BOOST_TEST(os.is_equal(cmp_text));
79 }
80 
81 BOOST_AUTO_TEST_CASE(TestSignal2_func_t)
82 {
83  TestSignal2 s{nSchedules};
84  std::string const test_text{"Test text"};
85  boost::test_tools::output_test_stream os;
86  CallBackClass cbc;
87  BOOST_CHECK_NO_THROW(s.watch(sID, &CallBackClass::func, cbc));
88  BOOST_CHECK_NO_THROW(s.invoke(sID, os, test_text));
89  BOOST_TEST(os.is_equal(test_text));
90 }
91 
92 BOOST_AUTO_TEST_CASE(TestSignal2_cfunc_t)
93 {
94  TestSignal2 s{nSchedules};
95  std::string const test_text{"Test text"};
96  boost::test_tools::output_test_stream os;
97  CallBackClass const cbc;
98  BOOST_CHECK_NO_THROW(s.watch(sID, &CallBackClass::cfunc, cbc));
99  BOOST_CHECK_NO_THROW(s.invoke(sID, os, test_text));
100  BOOST_TEST(os.is_equal(test_text));
101 }
102 
103 BOOST_AUTO_TEST_CASE(TestSignal1_t)
104 {
105  TestSignal1 s{nSchedules};
106  std::string const test_text{"Test text"};
107  boost::test_tools::output_test_stream os;
108  BOOST_CHECK_NO_THROW(
109  s.watch(sID, [&test_text](auto& x) { testCallback<0>(x, test_text); }));
110  BOOST_CHECK_NO_THROW(s.invoke(sID, os));
111  BOOST_TEST(os.is_equal(test_text));
112 }
113 
114 BOOST_AUTO_TEST_CASE(TestSignal0_t)
115 {
116  TestSignal0 s{nSchedules};
117  std::string const test_text{"Test text"};
118  boost::test_tools::output_test_stream os;
119  BOOST_CHECK_NO_THROW(
120  s.watch(sID, [&os, &test_text] { testCallback<0>(os, test_text); }));
121  BOOST_CHECK_NO_THROW(s.invoke(sID));
122  BOOST_TEST(os.is_equal(test_text));
123 }
124 
125 BOOST_AUTO_TEST_CASE(TestSignal1_All_t)
126 {
127  TestSignal1 s{nSchedules};
128  std::string const test_text{"Test text"};
129  boost::test_tools::output_test_stream os;
130  BOOST_CHECK_NO_THROW(
131  s.watchAll([&test_text](auto& x) { testCallback<0>(x, test_text); }));
132  BOOST_CHECK_NO_THROW(s.invoke(sID, os));
133  BOOST_TEST(os.is_equal(test_text));
134 }
135 
136 BOOST_AUTO_TEST_CASE(TestSignal2_All_t)
137 {
138  TestSignal2 s{nSchedules};
139  std::string const test_text{"Test text"};
140  boost::test_tools::output_test_stream os;
141  BOOST_CHECK_NO_THROW(s.watchAll(testCallback<0>));
142  BOOST_CHECK_NO_THROW(s.invoke(sID, os, test_text));
143  BOOST_TEST(os.is_equal(test_text));
144 }
145 
146 BOOST_AUTO_TEST_CASE(TestSignal0_All_t)
147 {
148  TestSignal0 s{nSchedules};
149  std::string const test_text{"Test text"};
150  boost::test_tools::output_test_stream os;
151  BOOST_CHECK_NO_THROW(
152  s.watchAll([&os, &test_text] { testCallback<0>(os, test_text); }));
153  BOOST_CHECK_NO_THROW(s.invoke(sID));
154  BOOST_TEST(os.is_equal(test_text));
155 }
156 
158 {
159  TestSignal0 s{nSchedules};
160  std::string const test_text{"Test text"};
161  boost::test_tools::output_test_stream os;
162  BOOST_CHECK_THROW(
163  (s.watch(art::ScheduleID{4},
164  [&os, &test_text] { testCallback<0>(os, test_text); })),
165  std::out_of_range);
166 }
167 
168 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