OrthogonalDeferred2.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. typedef player_ p; // makes transition table cleaner
  230. // Transition table for player
  231. struct transition_table : mpl::vector<
  232. // Start Event Next Action Guard
  233. // +---------+-------------+---------+---------------------+----------------------+
  234. a_row < Stopped , play , Playing , &p::start_playback >,
  235. a_row < Stopped , open_close , Open , &p::open_drawer >,
  236. _row < Stopped , stop , Stopped >,
  237. // +---------+-------------+---------+---------------------+----------------------+
  238. g_row < Open , open_close , Empty , &p::can_close_drawer >,
  239. Row < Open , play , none , Defer , none >,
  240. // +---------+-------------+---------+---------------------+----------------------+
  241. a_row < Empty , open_close , Open , &p::open_drawer >,
  242. a_row < Empty , cd_detected , Stopped , &p::store_cd_info >,
  243. Row < Empty , play , none , Defer , none >,
  244. // +---------+-------------+---------+---------------------+----------------------+
  245. a_row < Playing , stop , Stopped , &p::stop_playback >,
  246. a_row < Playing , pause , Paused , &p::pause_playback >,
  247. a_row < Playing , open_close , Open , &p::stop_and_open >,
  248. // +---------+-------------+---------+---------------------+----------------------+
  249. a_row < Paused , end_pause , Playing , &p::resume_playback >,
  250. a_row < Paused , stop , Stopped , &p::stop_playback >,
  251. a_row < Paused , open_close , Open , &p::stop_and_open >,
  252. // +---------+-------------+---------+---------------------+----------------------+
  253. a_row < AllOk , error_found ,ErrorMode, &p::report_error >,
  254. a_row <ErrorMode, end_error ,AllOk , &p::report_end_error >,
  255. _row < AllOk , do_terminate,ErrorTerminate >
  256. // +---------+-------------+---------+---------------------+----------------------+
  257. > {};
  258. // Replaces the default no-transition response.
  259. template <class FSM,class Event>
  260. void no_transition(Event const& , FSM&,int)
  261. {
  262. BOOST_FAIL("no_transition called!");
  263. }
  264. // init counters
  265. template <class Event,class FSM>
  266. void on_entry(Event const&,FSM& fsm)
  267. {
  268. fsm.template get_state<player_::Stopped&>().entry_counter=0;
  269. fsm.template get_state<player_::Stopped&>().exit_counter=0;
  270. fsm.template get_state<player_::Open&>().entry_counter=0;
  271. fsm.template get_state<player_::Open&>().exit_counter=0;
  272. fsm.template get_state<player_::Empty&>().entry_counter=0;
  273. fsm.template get_state<player_::Empty&>().exit_counter=0;
  274. fsm.template get_state<player_::Playing&>().entry_counter=0;
  275. fsm.template get_state<player_::Playing&>().exit_counter=0;
  276. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song1&>().entry_counter=0;
  277. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song1&>().exit_counter=0;
  278. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song2&>().entry_counter=0;
  279. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song2&>().exit_counter=0;
  280. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song3&>().entry_counter=0;
  281. fsm.template get_state<player_::Playing&>().template get_state<player_::Playing::Song3&>().exit_counter=0;
  282. fsm.template get_state<player_::Paused&>().entry_counter=0;
  283. fsm.template get_state<player_::Paused&>().exit_counter=0;
  284. fsm.template get_state<player_::AllOk&>().entry_counter=0;
  285. fsm.template get_state<player_::AllOk&>().exit_counter=0;
  286. fsm.template get_state<player_::ErrorMode&>().entry_counter=0;
  287. fsm.template get_state<player_::ErrorMode&>().exit_counter=0;
  288. fsm.template get_state<player_::ErrorTerminate&>().entry_counter=0;
  289. fsm.template get_state<player_::ErrorTerminate&>().exit_counter=0;
  290. }
  291. };
  292. // Pick a back-end
  293. typedef msm::back::state_machine<player_> player;
  294. //static char const* const state_names[] = { "Stopped", "Open", "Empty", "Playing", "Paused","AllOk","ErrorMode" };
  295. BOOST_AUTO_TEST_CASE( my_test )
  296. {
  297. player p;
  298. // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
  299. p.start();
  300. // test deferred event
  301. // deferred in Empty and Open, will be handled only after event cd_detected
  302. p.process_event(play());
  303. BOOST_CHECK_MESSAGE(p.current_state()[0] == 2,"Empty should be active"); //Empty
  304. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().exit_counter == 0,"Open exit not called correctly");
  305. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 0,"Playing entry not called correctly");
  306. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().entry_counter == 1,"Empty entry not called correctly");
  307. //flags
  308. BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded>() == false,"CDLoaded should not be active");
  309. p.process_event(open_close());
  310. BOOST_CHECK_MESSAGE(p.current_state()[0] == 1,"Open should be active"); //Open
  311. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().exit_counter == 1,"Empty exit not called correctly");
  312. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().entry_counter == 1,"Open entry not called correctly");
  313. p.process_event(open_close());
  314. BOOST_CHECK_MESSAGE(p.current_state()[0] == 2,"Empty should be active"); //Empty
  315. BOOST_CHECK_MESSAGE(p.get_state<player_::Open&>().exit_counter == 1,"Open exit not called correctly");
  316. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().entry_counter == 2,"Empty entry not called correctly");
  317. BOOST_CHECK_MESSAGE(p.can_close_drawer_counter == 1,"guard not called correctly");
  318. //deferred event should have been processed
  319. p.process_event(cd_detected("louie, louie"));
  320. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  321. BOOST_CHECK_MESSAGE(p.get_state<player_::Empty&>().exit_counter == 2,"Empty exit not called correctly");
  322. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 1,"Stopped entry not called correctly");
  323. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 1,"Stopped exit not called correctly");
  324. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 1,"Playing entry not called correctly");
  325. BOOST_CHECK_MESSAGE(p.start_playback_counter == 1,"action not called correctly");
  326. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 0,"Song1 should be active");
  327. BOOST_CHECK_MESSAGE(
  328. p.get_state<player_::Playing&>().get_state<player_::Playing::Song1&>().entry_counter == 1,
  329. "Song1 entry not called correctly");
  330. //flags
  331. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  332. BOOST_CHECK_MESSAGE(p.is_flag_active<FirstSongPlaying>() == true,"FirstSongPlaying should be active");
  333. p.process_event(NextSong());
  334. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  335. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 1,"Song2 should be active");
  336. BOOST_CHECK_MESSAGE(
  337. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().entry_counter == 1,
  338. "Song2 entry not called correctly");
  339. BOOST_CHECK_MESSAGE(
  340. p.get_state<player_::Playing&>().get_state<player_::Playing::Song1&>().exit_counter == 1,
  341. "Song1 exit not called correctly");
  342. BOOST_CHECK_MESSAGE(
  343. p.get_state<player_::Playing&>().start_next_song_counter == 0,
  344. "submachine action not called correctly");
  345. p.process_event(NextSong());
  346. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  347. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 2,"Song3 should be active");
  348. BOOST_CHECK_MESSAGE(
  349. p.get_state<player_::Playing&>().get_state<player_::Playing::Song3&>().entry_counter == 1,
  350. "Song3 entry not called correctly");
  351. BOOST_CHECK_MESSAGE(
  352. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().exit_counter == 1,
  353. "Song2 exit not called correctly");
  354. BOOST_CHECK_MESSAGE(
  355. p.get_state<player_::Playing&>().start_next_song_counter == 1,
  356. "submachine action not called correctly");
  357. p.process_event(PreviousSong());
  358. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  359. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().current_state()[0] == 1,"Song2 should be active");
  360. BOOST_CHECK_MESSAGE(
  361. p.get_state<player_::Playing&>().get_state<player_::Playing::Song2&>().entry_counter == 2,
  362. "Song2 entry not called correctly");
  363. BOOST_CHECK_MESSAGE(
  364. p.get_state<player_::Playing&>().get_state<player_::Playing::Song3&>().exit_counter == 1,
  365. "Song3 exit not called correctly");
  366. BOOST_CHECK_MESSAGE(
  367. p.get_state<player_::Playing&>().start_prev_song_guard_counter == 1,
  368. "submachine guard not called correctly");
  369. //flags
  370. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  371. BOOST_CHECK_MESSAGE(p.is_flag_active<FirstSongPlaying>() == false,"FirstSongPlaying should not be active");
  372. p.process_event(pause());
  373. BOOST_CHECK_MESSAGE(p.current_state()[0] == 4,"Paused should be active"); //Paused
  374. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 1,"Playing exit not called correctly");
  375. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().entry_counter == 1,"Paused entry not called correctly");
  376. //flags
  377. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == true,"PlayingPaused should be active");
  378. // go back to Playing
  379. p.process_event(end_pause());
  380. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  381. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().exit_counter == 1,"Paused exit not called correctly");
  382. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 2,"Playing entry not called correctly");
  383. p.process_event(pause());
  384. BOOST_CHECK_MESSAGE(p.current_state()[0] == 4,"Paused should be active"); //Paused
  385. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  386. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().entry_counter == 2,"Paused entry not called correctly");
  387. p.process_event(stop());
  388. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  389. BOOST_CHECK_MESSAGE(p.get_state<player_::Paused&>().exit_counter == 2,"Paused exit not called correctly");
  390. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 2,"Stopped entry not called correctly");
  391. //flags
  392. BOOST_CHECK_MESSAGE(p.is_flag_active<PlayingPaused>() == false,"PlayingPaused should not be active");
  393. BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded>() == true,"CDLoaded should be active");
  394. //BOOST_CHECK_MESSAGE(p.is_flag_active<CDLoaded,player::Flag_AND>() == false,"CDLoaded with AND should not be active");
  395. p.process_event(stop());
  396. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  397. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 2,"Stopped exit not called correctly");
  398. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  399. //test interrupt
  400. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  401. p.process_event(error_found());
  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. // try generating more events
  406. p.process_event(play());
  407. BOOST_CHECK_MESSAGE(p.current_state()[1] == 6,"ErrorMode should be active"); //ErrorMode
  408. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().exit_counter == 1,"AllOk exit not called correctly");
  409. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorMode&>().entry_counter == 1,"ErrorMode entry not called correctly");
  410. BOOST_CHECK_MESSAGE(p.current_state()[0] == 0,"Stopped should be active"); //Stopped
  411. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 2,"Stopped exit not called correctly");
  412. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  413. p.process_event(end_error());
  414. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  415. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorMode&>().exit_counter == 1,"ErrorMode exit not called correctly");
  416. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().entry_counter == 2,"AllOk entry not called correctly");
  417. p.process_event(play());
  418. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  419. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().exit_counter == 3,"Stopped exit not called correctly");
  420. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().entry_counter == 3,"Playing entry not called correctly");
  421. //test terminate
  422. BOOST_CHECK_MESSAGE(p.current_state()[1] == 5,"AllOk should be active"); //AllOk
  423. p.process_event(do_terminate());
  424. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  425. BOOST_CHECK_MESSAGE(p.get_state<player_::AllOk&>().exit_counter == 2,"AllOk exit not called correctly");
  426. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorTerminate&>().entry_counter == 1,"ErrorTerminate entry not called correctly");
  427. // try generating more events
  428. p.process_event(stop());
  429. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  430. BOOST_CHECK_MESSAGE(p.get_state<player_::ErrorTerminate&>().exit_counter == 0,"ErrorTerminate exit not called correctly");
  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(end_error());
  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. p.process_event(stop());
  440. BOOST_CHECK_MESSAGE(p.current_state()[1] == 7,"ErrorTerminate should be active"); //ErrorTerminate
  441. BOOST_CHECK_MESSAGE(p.current_state()[0] == 3,"Playing should be active"); //Playing
  442. BOOST_CHECK_MESSAGE(p.get_state<player_::Playing&>().exit_counter == 2,"Playing exit not called correctly");
  443. BOOST_CHECK_MESSAGE(p.get_state<player_::Stopped&>().entry_counter == 3,"Stopped entry not called correctly");
  444. }
  445. }