TypeInfoTest.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2005-2006 Andreas Huber Doenni
  3. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  4. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. //////////////////////////////////////////////////////////////////////////////
  6. #include <boost/statechart/state_machine.hpp>
  7. #include <boost/statechart/simple_state.hpp>
  8. #include <boost/test/test_tools.hpp>
  9. namespace sc = boost::statechart;
  10. struct A;
  11. struct TypeInfoTest : sc::state_machine< TypeInfoTest, A > {};
  12. struct B;
  13. struct A : sc::simple_state< A, TypeInfoTest, B > {};
  14. struct B : sc::simple_state< B, A > {};
  15. int test_main( int, char* [] )
  16. {
  17. TypeInfoTest machine;
  18. machine.initiate();
  19. const TypeInfoTest::state_base_type & activeState =
  20. *machine.state_begin();
  21. const TypeInfoTest::state_base_type::id_type bType =
  22. activeState.dynamic_type();
  23. const TypeInfoTest::state_base_type::id_type aType =
  24. activeState.outer_state_ptr()->dynamic_type();
  25. BOOST_REQUIRE( bType == B::static_type() );
  26. BOOST_REQUIRE( bType != A::static_type() );
  27. BOOST_REQUIRE( aType == A::static_type() );
  28. BOOST_REQUIRE( aType != B::static_type() );
  29. #ifndef BOOST_STATECHART_USE_NATIVE_RTTI
  30. // Ensure that a null custom type id pointer can be of any type
  31. BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< void >() == 0 );
  32. BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 );
  33. BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< bool >() == 0 );
  34. BOOST_REQUIRE(
  35. activeState.outer_state_ptr()->custom_dynamic_type_ptr< void >() == 0 );
  36. BOOST_REQUIRE(
  37. activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 );
  38. BOOST_REQUIRE(
  39. activeState.outer_state_ptr()->custom_dynamic_type_ptr< bool >() == 0 );
  40. const char * bCustomType = "B";
  41. const char * aCustomType = "A";
  42. B::custom_static_type_ptr( bCustomType );
  43. A::custom_static_type_ptr( aCustomType );
  44. BOOST_REQUIRE( B::custom_static_type_ptr< char >() == bCustomType );
  45. BOOST_REQUIRE( A::custom_static_type_ptr< char >() == aCustomType );
  46. BOOST_REQUIRE(
  47. activeState.custom_dynamic_type_ptr< char >() == bCustomType );
  48. BOOST_REQUIRE(
  49. activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() ==
  50. aCustomType );
  51. // Ensure that a null custom type id pointer can be of any type
  52. bool * pNull = 0;
  53. B::custom_static_type_ptr( pNull );
  54. A::custom_static_type_ptr( pNull );
  55. BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 );
  56. BOOST_REQUIRE(
  57. activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 );
  58. #endif
  59. return 0;
  60. }