9 #include <boost/test/unit_test.hpp>
15 namespace tt = boost::test_tools;
39 states::Pinging, states::Connected> {
51 std::cout <<
"ping!" << std::endl;
57 std::cout <<
"pong!" << std::endl;
69 template <
typename State,
typename Event>
74 template <
typename State,
typename... Args>
77 template <
typename State,
typename... Args>
80 template <
typename... Args>
84 BOOST_AUTO_TEST_SUITE(Utilities)
89 sm.dispatch(events::Connect{});
90 BOOST_CHECK(
sm.is(states::Connecting{}));
91 sm.dispatch(events::Established{});
92 BOOST_CHECK(
sm.is(states::Connected{}));
93 sm.dispatch(events::Ping{});
94 sm.dispatch(events::Ping{});
95 sm.dispatch(events::Ping{});
96 sm.dispatch(events::Ping{});
97 BOOST_CHECK(
sm.is(states::Connected{}));
98 sm.dispatch(events::Timeout{});
99 BOOST_CHECK(
sm.is(states::Connecting{}));
100 sm.dispatch(events::Established{});
101 BOOST_CHECK(
sm.is(states::Connected{}));
102 sm.dispatch(events::Disconnect{});
103 BOOST_CHECK(
sm.is(states::Disconnected{}));
110 sm.dispatch(events::Disconnect{});
111 BOOST_CHECK(
sm.terminated());
120 std::cout <<
"f: " << f << std::endl;
125 std::cout <<
"disconnect!" << std::endl;
129 template <
typename State,
typename Event,
typename... Args>
134 template <
typename... Args>
136 throw std::runtime_error(
"FSM terminated!");
139 template <
typename State,
typename... Args>
142 template <
typename State,
typename... Args>
144 template <
typename... Args>
152 sm.dispatch(events::Connect{}, 42.);
153 BOOST_CHECK(
sm.is(states::Connected{}));
154 sm.dispatch(events::Disconnect{});
155 BOOST_CHECK(
sm.is(states::Disconnected{}));
156 sm.dispatch(events::Connect{}, -1.);
159 BOOST_REQUIRE_THROW(
sm.dispatch(events::Disconnect{}, 9), std::runtime_error);
160 BOOST_CHECK(
sm.terminated());
164 BOOST_REQUIRE_THROW(
sm.dispatch(events::Connect{}), std::runtime_error);
166 BOOST_CHECK(
sm.terminated());
169 sm.setState(states::Disconnected{});
170 BOOST_CHECK(
sm.is(states::Disconnected{}));
171 sm.dispatch(events::Connect{}, -1.);
172 BOOST_CHECK(
sm.is(states::Connected{}));
184 bool on_exit_called =
false;
185 bool on_enter_called =
false;
186 bool on_process_called =
false;
188 on_exit_called =
false;
189 on_enter_called =
false;
190 on_process_called =
false;
213 template <
typename State,
typename Event,
typename... Args>
218 template <
typename State,
typename... Args>
220 on_enter_called =
true;
223 template <
typename State,
typename... Args>
225 on_exit_called =
true;
228 template <
typename... Args>
230 on_process_called =
true;
236 BOOST_CHECK(sm.
is(
S1{}));
239 BOOST_CHECK(
sm.is(S2{}));
240 BOOST_CHECK(
sm.on_exit_called);
241 BOOST_CHECK(
sm.on_enter_called);
242 BOOST_CHECK(
sm.on_process_called);
248 BOOST_CHECK(
sm.is(S2{}));
250 BOOST_CHECK(
sm.on_exit_called);
251 BOOST_CHECK(
sm.on_enter_called);
252 BOOST_CHECK(
sm.on_process_called);
257 BOOST_CHECK(
sm.is(S2{}));
259 BOOST_CHECK(!
sm.on_exit_called);
260 BOOST_CHECK(!
sm.on_enter_called);
261 BOOST_CHECK(
sm.on_process_called);
265 BOOST_CHECK(
sm.is(S3{}));
267 BOOST_CHECK(
sm.on_exit_called);
268 BOOST_CHECK(
sm.on_enter_called);
269 BOOST_CHECK(
sm.on_process_called);
273 BOOST_CHECK(
sm.is(S1{}));
277 BOOST_CHECK(
sm.terminated());
279 BOOST_CHECK(
sm.on_exit_called);
280 BOOST_CHECK(
sm.on_enter_called);
281 BOOST_CHECK(
sm.on_process_called);
284 BOOST_AUTO_TEST_SUITE_END()