DeferralBug.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2010 Igor R (http://thread.gmane.org/gmane.comp.lib.boost.user/62985)
  3. // Copyright 2010 Andreas Huber Doenni
  4. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  5. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //////////////////////////////////////////////////////////////////////////////
  7. #include <boost/statechart/event.hpp>
  8. #include <boost/statechart/state_machine.hpp>
  9. #include <boost/statechart/simple_state.hpp>
  10. #include <boost/statechart/transition.hpp>
  11. #include <boost/statechart/deferral.hpp>
  12. #include <boost/mpl/list.hpp>
  13. #include <boost/test/test_tools.hpp>
  14. namespace sc = boost::statechart;
  15. namespace mpl = boost::mpl;
  16. struct ev1to2 : sc::event< ev1to2 > {};
  17. struct ev2to3 : sc::event< ev2to3 > {};
  18. struct ev3to4_1 : sc::event< ev3to4_1 > {};
  19. struct ev3to4_2 : sc::event< ev3to4_2 > {};
  20. struct s1;
  21. struct fsm : sc::state_machine< fsm, s1 > {};
  22. struct s2;
  23. struct s1 : sc::simple_state< s1, fsm >
  24. {
  25. typedef mpl::list<
  26. sc::transition< ev1to2, s2 >,
  27. sc::deferral< ev2to3 >,
  28. sc::deferral< ev3to4_1 >,
  29. sc::deferral< ev3to4_2 >
  30. > reactions;
  31. };
  32. struct s3;
  33. struct s2 : sc::simple_state< s2, fsm >
  34. {
  35. typedef mpl::list<
  36. sc::transition< ev2to3, s3 >,
  37. sc::deferral< ev3to4_1 >,
  38. sc::deferral< ev3to4_2 >
  39. > reactions;
  40. };
  41. struct s4_1;
  42. struct s4_2;
  43. struct s3 : sc::simple_state< s3, fsm >
  44. {
  45. typedef mpl::list<
  46. sc::transition< ev3to4_1, s4_1 >,
  47. sc::transition< ev3to4_2, s4_2 >
  48. > reactions;
  49. };
  50. struct s4_1 : sc::simple_state< s4_1, fsm > {};
  51. struct s4_2 : sc::simple_state< s4_2, fsm > {};
  52. int test_main( int, char* [] )
  53. {
  54. fsm machine;
  55. machine.initiate();
  56. machine.process_event( ev3to4_1() );
  57. machine.process_event( ev2to3() );
  58. machine.process_event( ev3to4_2() );
  59. machine.process_event( ev1to2() );
  60. BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 );
  61. machine.initiate();
  62. machine.process_event( ev3to4_1() );
  63. machine.process_event( ev3to4_2() );
  64. machine.process_event( ev1to2() );
  65. machine.process_event( ev2to3() );
  66. BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 );
  67. return 0;
  68. }