OrthogonalDeferred3.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // Copyright 2010 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <iostream>
  11. // back-end
  12. #include <boost/msm/back/state_machine.hpp>
  13. //front-end
  14. #include <boost/msm/front/state_machine_def.hpp>
  15. #include <boost/msm/front/functor_row.hpp>
  16. #ifndef BOOST_MSM_NONSTANDALONE_TEST
  17. #define BOOST_TEST_MODULE MyTest
  18. #endif
  19. #include <boost/test/unit_test.hpp>
  20. namespace msm = boost::msm;
  21. namespace mpl = boost::mpl;
  22. using namespace boost::msm::front;
  23. namespace
  24. {
  25. // events
  26. struct play {};
  27. struct end_pause {};
  28. struct stop {};
  29. struct pause {};
  30. struct open_close {};
  31. struct NextSong {};
  32. struct PreviousSong {};
  33. struct error_found {};
  34. struct end_error {};
  35. struct do_terminate {};
  36. // Flags. Allow information about a property of the current state
  37. struct PlayingPaused{};
  38. struct CDLoaded {};
  39. struct FirstSongPlaying {};
  40. // A "complicated" event type that carries some data.
  41. struct cd_detected
  42. {
  43. cd_detected(std::string name)
  44. : name(name)
  45. {}
  46. std::string name;
  47. };
  48. // front-end: define the FSM structure
  49. struct player_ : public msm::front::state_machine_def<player_>
  50. {
  51. // we want deferred events and no state requires deferred events (only the fsm in the
  52. // transition table), so the fsm does.
  53. typedef int activate_deferred_events;
  54. unsigned int start_playback_counter;
  55. unsigned int can_close_drawer_counter;
  56. unsigned int report_error_counter;
  57. unsigned int report_end_error_counter;
  58. player_():
  59. start_playback_counter(0),
  60. can_close_drawer_counter(0),
  61. report_error_counter(0),
  62. report_end_error_counter(0)
  63. {}
  64. // The list of FSM states
  65. struct Empty : public msm::front::state<>
  66. {
  67. template <class Event,class FSM>
  68. void on_entry(Event const&,FSM& ) {++entry_counter;}
  69. template <class Event,class FSM>
  70. void on_exit(Event const&,FSM& ) {++exit_counter;}
  71. int entry_counter;
  72. int exit_counter;
  73. };
  74. struct Open : public msm::front::state<>
  75. {
  76. typedef mpl::vector1<CDLoaded> flag_list;
  77. template <class Event,class FSM>
  78. void on_entry(Event const&,FSM& ) {++entry_counter;}
  79. template <class Event,class FSM>
  80. void on_exit(Event const&,FSM& ) {++exit_counter;}
  81. int entry_counter;
  82. int exit_counter;
  83. };
  84. struct Stopped : public msm::front::state<>
  85. {
  86. typedef mpl::vector1<CDLoaded> flag_list;
  87. template <class Event,class FSM>
  88. void on_entry(Event const&,FSM& ) {++entry_counter;}
  89. template <class Event,class FSM>
  90. void on_exit(Event const&,FSM& ) {++exit_counter;}
  91. int entry_counter;
  92. int exit_counter;
  93. };
  94. // the player state machine contains a state which is himself a state machine
  95. // as you see, no need to declare it anywhere so Playing can be developed separately
  96. // by another team in another module. For simplicity I just declare it inside player
  97. struct Playing_ : public msm::front::state_machine_def<Playing_>
  98. {
  99. // when playing, the CD is loaded and we are in either pause or playing (duh)
  100. typedef mpl::vector2<PlayingPaused,CDLoaded> flag_list;
  101. template <class Event,class FSM>
  102. void on_entry(Event const&,FSM& ) {++entry_counter;}
  103. template <class Event,class FSM>
  104. void on_exit(Event const&,FSM& ) {++exit_counter;}
  105. int entry_counter;
  106. int exit_counter;
  107. unsigned int start_next_song_counter;
  108. unsigned int start_prev_song_guard_counter;
  109. Playing_():
  110. start_next_song_counter(0),
  111. start_prev_song_guard_counter(0)
  112. {}
  113. // The list of FSM states
  114. struct Song1 : public msm::front::state<>
  115. {
  116. typedef mpl::vector1<FirstSongPlaying> flag_list;
  117. template <class Event,class FSM>
  118. void on_entry(Event const&,FSM& ) {++entry_counter;}
  119. template <class Event,class FSM>
  120. void on_exit(Event const&,FSM& ) {++exit_counter;}
  121. int entry_counter;
  122. int exit_counter;
  123. };
  124. struct Song2 : public msm::front::state<>
  125. {
  126. template <class Event,class FSM>
  127. void on_entry(Event const&,FSM& ) {++entry_counter;}
  128. template <class Event,class FSM>
  129. void on_exit(Event const&,FSM& ) {++exit_counter;}
  130. int entry_counter;
  131. int exit_counter;
  132. };
  133. struct Song3 : public msm::front::state<>
  134. {
  135. template <class Event,class FSM>
  136. void on_entry(Event const&,FSM& ) {++entry_counter;}
  137. template <class Event,class FSM>
  138. void on_exit(Event const&,FSM& ) {++exit_counter;}
  139. int entry_counter;
  140. int exit_counter;
  141. };
  142. // the initial state. Must be defined
  143. typedef Song1 initial_state;
  144. // transition actions
  145. void start_next_song(NextSong const&) {++start_next_song_counter; }
  146. void start_prev_song(PreviousSong const&) { }
  147. // guard conditions
  148. bool start_prev_song_guard(PreviousSong const&) {++start_prev_song_guard_counter;return true; }
  149. typedef Playing_ pl; // makes transition table cleaner
  150. // Transition table for Playing
  151. struct transition_table : mpl::vector4<
  152. // Start Event Next Action Guard
  153. // +---------+-------------+---------+---------------------+----------------------+
  154. _row < Song1 , NextSong , Song2 >,
  155. row < Song2 , PreviousSong, Song1 , &pl::start_prev_song,&pl::start_prev_song_guard>,
  156. a_row < Song2 , NextSong , Song3 , &pl::start_next_song >,
  157. g_row < Song3 , PreviousSong, Song2 ,&pl::start_prev_song_guard>
  158. // +---------+-------------+---------+---------------------+----------------------+
  159. > {};
  160. // Replaces the default no-transition response.
  161. template <class FSM,class Event>
  162. void no_transition(Event const&, FSM&,int)
  163. {
  164. BOOST_FAIL("no_transition called!");
  165. }
  166. };
  167. // back-end
  168. typedef msm::back::state_machine<Playing_> Playing;
  169. // state not defining any entry or exit
  170. struct Paused : public msm::front::state<>
  171. {
  172. typedef mpl::vector2<PlayingPaused,CDLoaded> flag_list;
  173. template <class Event,class FSM>
  174. void on_entry(Event const&,FSM& ) {++entry_counter;}
  175. template <class Event,class FSM>
  176. void on_exit(Event const&,FSM& ) {++exit_counter;}
  177. int entry_counter;
  178. int exit_counter;
  179. };
  180. struct AllOk : public msm::front::state<>
  181. {
  182. template <class Event,class FSM>
  183. void on_entry(Event const&,FSM& ) {++entry_counter;}
  184. template <class Event,class FSM>
  185. void on_exit(Event const&,FSM& ) {++exit_counter;}
  186. int entry_counter;
  187. int exit_counter;
  188. };
  189. // this state is also made terminal so that all the events are blocked
  190. struct ErrorMode : //public msm::front::terminate_state<> // ErrorMode terminates the state machine
  191. public msm::front::interrupt_state<end_error> // ErroMode just interrupts. Will resume if
  192. // the event end_error is generated
  193. {
  194. template <class Event,class FSM>
  195. void on_entry(Event const&,FSM& ) {++entry_counter;}
  196. template <class Event,class FSM>
  197. void on_exit(Event const&,FSM& ) {++exit_counter;}
  198. int entry_counter;
  199. int exit_counter;
  200. };
  201. struct ErrorTerminate : public msm::front::terminate_state<> // terminates the state machine
  202. {
  203. template <class Event,class FSM>
  204. void on_entry(Event const&,FSM& ) {++entry_counter;}
  205. template <class Event,class FSM>
  206. void on_exit(Event const&,FSM& ) {++exit_counter;}
  207. int entry_counter;
  208. int exit_counter;
  209. };
  210. // the initial state of the player SM. Must be defined
  211. typedef mpl::vector<Empty,AllOk> initial_state;
  212. // transition actions
  213. void start_playback(play const&) {++start_playback_counter; }
  214. void open_drawer(open_close const&) { }
  215. void store_cd_info(cd_detected const&) { }
  216. void stop_playback(stop const&) { }
  217. void pause_playback(pause const&) { }
  218. void resume_playback(end_pause const&) { }
  219. void stop_and_open(open_close const&) { }
  220. void stopped_again(stop const&){}
  221. void report_error(error_found const&) {++report_error_counter;}
  222. void report_end_error(end_error const&) {++report_end_error_counter;}
  223. //guards
  224. bool can_close_drawer(open_close const&)
  225. {
  226. ++can_close_drawer_counter;
  227. return true;
  228. }
  229. struct is_play_event
  230. {
  231. template <class EVT,class FSM,class SourceState,class TargetState>
  232. bool operator()(EVT const& evt,FSM&,SourceState& ,TargetState& )
  233. {
  234. bool is_play = boost::any_cast<play>(&evt) != 0;
  235. return is_play;
  236. }
  237. };
  238. struct MyDefer
  239. {
  240. // mark as deferring to avoid stack overflows in certain conditions
  241. typedef int deferring_action;
  242. template <class EVT,class FSM,class SourceState,class TargetState>
  243. void operator()(EVT const& ,FSM& fsm,SourceState& ,TargetState& ) const
  244. {
  245. fsm.defer_event(play());
  246. }
  247. };
  248. typedef player_ p; // makes transition table cleaner
  249. // Transition table for player
  250. struct transition_table : mpl::vector<
  251. // Start Event Next Action Guard
  252. // +---------+-------------+---------+---------------------+----------------------+
  253. a_row < Stopped , play , Playing , &p::start_playback >,
  254. a_row < Stopped , open_close , Open , &p::open_drawer >,
  255. _row < Stopped , stop , Stopped >,
  256. // +---------+-------------+---------+---------------------+----------------------+
  257. g_row < Open , open_close , Empty , &p::can_close_drawer >,
  258. Row < Open , play , none , Defer , none >,
  259. // +---------+-------------+---------+---------------------+----------------------+
  260. a_row < Empty , open_close , Open , &p::open_drawer >,
  261. a_row < Empty , cd_detected , Stopped , &p::store_cd_info >,
  262. Row < Empty , boost::any , none , MyDefer , is_play_event >,
  263. // +---------+-------------+---------+---------------------+----------------------+
  264. a_row < Playing , stop , Stopped , &p::stop_playback >,
  265. a_row < Playing , pause , Paused , &p::pause_playback >,
  266. a_row < Playing , open_close , Open , &p::stop_and_open >,
  267. // +---------+-------------+---------+---------------------+----------------------+
  268. a_row < Paused , end_pause , Playing , &p::resume_playback >,
  269. a_row < Paused , stop , Stopped , &p::stop_playback >,
  270. a_row < Paused , open_close , Open , &p::stop_and_open >,
  271. // +---------+-------------+---------+---------------------+----------------------+
  272. a_row < AllOk , error_found ,ErrorMode, &p::report_error >,
  273. a_row <ErrorMode, end_error ,AllOk , &p::report_end_error >,
  274. _row < AllOk , do_terminate,ErrorTerminate >
  275. // +---------+-------------+---------+---------------------+----------------------+
  276. > {};
  277. // Replaces the default no-transition response.
  278. template <class FSM,class Event>
  279. void no_transition(Event const& , FSM&,int)
  280. {
  281. BOOST_ERROR("no_transition called!");
  282. }
  283. // init counters
  284. template <class Event,class FSM>
  285. void on_entry(Event const&,FSM& fsm)
  286. {
  287. fsm.template get_state<player_::Stopped&>().entry_counter=0;
  288. fsm.template get_state<player_::Stopped&>().exit_counter=0;
  289. fsm.template get_state<player_::Open&>().entry_counter=0;
  290. fsm.template get_state<player_::Open&>().exit_counter=0;
  291. fsm.template get_state<player_::Empty&>().entry_counter=0;
  292. fsm.template get_state<player_::Empty&>().exit_counter=0;
  293. fsm.template get_state<player_::Playing&>().entry_counter=0;
  294. fsm.template get_state<player_::Playing&>().exit_counter=0;
  295. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song1&>().entry_counter=0;
  296. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song1&>().exit_counter=0;
  297. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song2&>().entry_counter=0;
  298. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song2&>().exit_counter=0;
  299. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song3&>().entry_counter=0;
  300. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song3&>().exit_counter=0;
  301. fsm.template get_state<player_::Paused&>().entry_counter=0;
  302. fsm.template get_state<player_::Paused&>().exit_counter=0;
  303. fsm.template get_state<player_::AllOk&>().entry_counter=0;
  304. fsm.template get_state<player_::AllOk&>().exit_counter=0;
  305. fsm.template get_state<player_::ErrorMode&>().entry_counter=0;
  306. fsm.template get_state<player_::ErrorMode&>().exit_counter=0;
  307. fsm.template get_state<player_::ErrorTerminate&>().entry_counter=0;
  308. fsm.template get_state<player_::ErrorTerminate&>().exit_counter=0;
  309. }
  310. };
  311. // Pick a back-end
  312. typedef msm::back::state_machine<player_> player;
  313. //static char const* const state_names[] = { "Stopped", "Open", "Empty", "Playing", "Paused","AllOk","ErrorMode" };
  314. BOOST_AUTO_TEST_CASE( my_test )
  315. {
  316. player p;
  317. // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
  318. p.start();
  319. // test deferred event
  320. // deferred in Empty and Open, will be handled only after event cd_detected
  321. p.process_event(play());
  322. BOOST_CHECK_MESSAGE(p.current_state()[0] == 2,"Empty should be active"); //Empty
  323. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().exit_counter == 0,"Open exit not called correctly");
  324. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 0,"Playing entry not called correctly");
  325. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().entry_counter == 1,"Empty entry not called correctly");
  326. //flags
  327. BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded>() == false,"CDLoaded should not be active");
  328. p.process_event(open_close());
  329. BOOST_CHECK_MESSAGE(p.current_state()[0] == 1,"Open should be active"); //Open
  330. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().exit_counter == 1,"Empty exit not called correctly");
  331. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().entry_counter == 1,"Open entry not called correctly");
  332. p.process_event(open_close());
  333. BOOST_CHECK_MESSAGE(p.current_state()[0] == 2,"Empty should be active"); //Empty
  334. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().exit_counter == 1,"Open exit not called correctly");
  335. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().entry_counter == 2,"Empty entry not called correctly");
  336. BOOST_CHECK_MESSAGE(p.can_close_drawer_counter == 1,"guard not called correctly");
  337. //deferred event should have been processed
  338. p.process_event(cd_detected("louie, louie"));
  339. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  340. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().exit_counter == 2,"Empty exit not called correctly");
  341. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 1,"Stopped entry not called correctly");
  342. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 1,"Stopped exit not called correctly");
  343. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 1,"Playing entry not called correctly");
  344. BOOST_CHECK_MESSAGE(p.start_playback_counter == 1,"action not called correctly");
  345. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 0,"Song1 should be active");
  346. BOOST_CHECK_MESSAGE(
  347. p.get_state<player_::Playing&>().get_state<player_::Playing::Song1&>().entry_counter == 1,
  348. "Song1 entry not called correctly");
  349. //flags
  350. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  351. BOOST_CHECK_MESSAGE(p.is_flag_active<FirstSongPlaying>() == true,"FirstSongPlaying should be active");
  352. p.process_event(NextSong());
  353. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  354. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 1,"Song2 should be active");
  355. BOOST_CHECK_MESSAGE(
  356. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().entry_counter == 1,
  357. "Song2 entry not called correctly");
  358. BOOST_CHECK_MESSAGE(
  359. p.get_state<player_::Playing&>().get_state<player_::Playing::Song1&>().exit_counter == 1,
  360. "Song1 exit not called correctly");
  361. BOOST_CHECK_MESSAGE(
  362. p.get_state<player_::Playing&>().start_next_song_counter == 0,
  363. "submachine action not called correctly");
  364. p.process_event(NextSong());
  365. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  366. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 2,"Song3 should be active");
  367. BOOST_CHECK_MESSAGE(
  368. p.get_state<player_::Playing&>().get_state<player_::Playing::Song3&>().entry_counter == 1,
  369. "Song3 entry not called correctly");
  370. BOOST_CHECK_MESSAGE(
  371. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().exit_counter == 1,
  372. "Song2 exit not called correctly");
  373. BOOST_CHECK_MESSAGE(
  374. p.get_state<player_::Playing&>().start_next_song_counter == 1,
  375. "submachine action not called correctly");
  376. p.process_event(PreviousSong());
  377. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  378. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 1,"Song2 should be active");
  379. BOOST_CHECK_MESSAGE(
  380. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().entry_counter == 2,
  381. "Song2 entry not called correctly");
  382. BOOST_CHECK_MESSAGE(
  383. p.get_state<player_::Playing&>().get_state<player_::Playing::Song3&>().exit_counter == 1,
  384. "Song3 exit not called correctly");
  385. BOOST_CHECK_MESSAGE(
  386. p.get_state<player_::Playing&>().start_prev_song_guard_counter == 1,
  387. "submachine guard not called correctly");
  388. //flags
  389. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  390. BOOST_CHECK_MESSAGE(p.is_flag_active<FirstSongPlaying>() == false,"FirstSongPlaying should not be active");
  391. p.process_event(pause());
  392. BOOST_CHECK_MESSAGE(p.current_state()[0] == 4,"Paused should be active"); //Paused
  393. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 1,"Playing exit not called correctly");
  394. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().entry_counter == 1,"Paused entry not called correctly");
  395. //flags
  396. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  397. // go back to Playing
  398. p.process_event(end_pause());
  399. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  400. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().exit_counter == 1,"Paused exit not called correctly");
  401. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 2,"Playing entry not called correctly");
  402. p.process_event(pause());
  403. BOOST_CHECK_MESSAGE(p.current_state()[0] == 4,"Paused should be active"); //Paused
  404. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  405. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().entry_counter == 2,"Paused entry not called correctly");
  406. p.process_event(stop());
  407. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  408. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().exit_counter == 2,"Paused exit not called correctly");
  409. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 2,"Stopped entry not called correctly");
  410. //flags
  411. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == false,"PlayingPaused should not be active");
  412. BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded>() == true,"CDLoaded should be active");
  413. //BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded,player::Flag_AND>() == false,"CDLoaded with AND should not be active");
  414. p.process_event(stop());
  415. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  416. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 2,"Stopped exit not called correctly");
  417. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  418. //test interrupt
  419. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  420. p.process_event(error_found());
  421. BOOST_CHECK_MESSAGE(p.current_state()[1] == 6,"ErrorMode should be active"); //ErrorMode
  422. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().exit_counter == 1,"AllOk exit not called correctly");
  423. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorMode&>().entry_counter == 1,"ErrorMode entry not called correctly");
  424. // try generating more events
  425. p.process_event(play());
  426. BOOST_CHECK_MESSAGE(p.current_state()[1] == 6,"ErrorMode should be active"); //ErrorMode
  427. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().exit_counter == 1,"AllOk exit not called correctly");
  428. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorMode&>().entry_counter == 1,"ErrorMode entry not called correctly");
  429. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  430. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 2,"Stopped exit not called correctly");
  431. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  432. p.process_event(end_error());
  433. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  434. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorMode&>().exit_counter == 1,"ErrorMode exit not called correctly");
  435. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().entry_counter == 2,"AllOk entry not called correctly");
  436. p.process_event(play());
  437. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  438. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 3,"Stopped exit not called correctly");
  439. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 3,"Playing entry not called correctly");
  440. //test terminate
  441. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  442. p.process_event(do_terminate());
  443. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  444. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().exit_counter == 2,"AllOk exit not called correctly");
  445. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorTerminate&>().entry_counter == 1,"ErrorTerminate entry not called correctly");
  446. // try generating more events
  447. p.process_event(stop());
  448. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  449. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorTerminate&>().exit_counter == 0,"ErrorTerminate exit not called correctly");
  450. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  451. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  452. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  453. p.process_event(end_error());
  454. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  455. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  456. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  457. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  458. p.process_event(stop());
  459. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  460. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  461. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  462. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  463. }
  464. }