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 7 8 9 #include <boost/statechart/state_machine.hpp> 10 #include <boost/statechart/simple_state.hpp> 11 12 #include <boost/test/test_tools.hpp> 13 14 15 16 namespace sc = boost::statechart; 17 18 19 20 struct A; 21 struct TypeInfoTest : sc::state_machine< TypeInfoTest, A > {}; 22 23 struct B; 24 struct A : sc::simple_state< A, TypeInfoTest, B > {}; 25 26 struct B : sc::simple_state< B, A > {}; 27 28 test_main(int,char * [])29int test_main( int, char* [] ) 30 { 31 TypeInfoTest machine; 32 machine.initiate(); 33 34 const TypeInfoTest::state_base_type & activeState = 35 *machine.state_begin(); 36 const TypeInfoTest::state_base_type::id_type bType = 37 activeState.dynamic_type(); 38 const TypeInfoTest::state_base_type::id_type aType = 39 activeState.outer_state_ptr()->dynamic_type(); 40 41 BOOST_REQUIRE( bType == B::static_type() ); 42 BOOST_REQUIRE( bType != A::static_type() ); 43 BOOST_REQUIRE( aType == A::static_type() ); 44 BOOST_REQUIRE( aType != B::static_type() ); 45 46 #ifndef BOOST_STATECHART_USE_NATIVE_RTTI 47 // Ensure that a null custom type id pointer can be of any type 48 BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< void >() == 0 ); 49 BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 ); 50 BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< bool >() == 0 ); 51 BOOST_REQUIRE( 52 activeState.outer_state_ptr()->custom_dynamic_type_ptr< void >() == 0 ); 53 BOOST_REQUIRE( 54 activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 ); 55 BOOST_REQUIRE( 56 activeState.outer_state_ptr()->custom_dynamic_type_ptr< bool >() == 0 ); 57 58 const char * bCustomType = "B"; 59 const char * aCustomType = "A"; 60 B::custom_static_type_ptr( bCustomType ); 61 A::custom_static_type_ptr( aCustomType ); 62 BOOST_REQUIRE( B::custom_static_type_ptr< char >() == bCustomType ); 63 BOOST_REQUIRE( A::custom_static_type_ptr< char >() == aCustomType ); 64 BOOST_REQUIRE( 65 activeState.custom_dynamic_type_ptr< char >() == bCustomType ); 66 BOOST_REQUIRE( 67 activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 68 aCustomType ); 69 70 // Ensure that a null custom type id pointer can be of any type 71 bool * pNull = 0; 72 B::custom_static_type_ptr( pNull ); 73 A::custom_static_type_ptr( pNull ); 74 BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 ); 75 BOOST_REQUIRE( 76 activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 ); 77 #endif 78 79 return 0; 80 } 81