OrthogonalDeferred.cpp 26 KB

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