📄 transitiontest.cpp
字号:
Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, A >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > > }; machine.CompareToExpectedActionSequence( a1 ); machine.process_event( B() ); ActionArray b1 = { Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, B >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > > }; machine.CompareToExpectedActionSequence( b1 ); machine.process_event( C() ); ActionArray c1 = { Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, C >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( c1 ); machine.process_event( D() ); ActionArray d2 = { Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Trans< S0< M >, D >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( d2 ); machine.process_event( E() ); ActionArray e2 = { Exit< Default2< S0< M > > >, Exit< Default1< S0< M > > >, Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Exit< Default1< S2< M > > >, Exit< Default0< S2< M > > >, Exit< S2< M > >, Exit< S0< M > >, Entry< S0< M > >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > > }; machine.CompareToExpectedActionSequence( e2 ); machine.process_event( F() ); ActionArray f2 = { Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Exit< Default1< S2< M > > >, Exit< Default0< S2< M > > >, Exit< S2< M > >, Trans< S0< M >, F >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > > }; machine.CompareToExpectedActionSequence( f2 ); machine.process_event( G() ); ActionArray g1 = { Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, G >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( g1 ); machine.process_event( H() ); ActionArray h2 = { Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Trans< S0< M >, H >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( h2 ); BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 0 ); machine.process_event( A() ); BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 1 ); ActionArray a2 = { }; machine.CompareToExpectedActionSequence( a2 ); machine.process_event( B() ); ActionArray b2 = { Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Trans< S0< M >, B >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( b2 ); machine.process_event( C() ); ActionArray c2 = { Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Exit< Default1< S2< M > > >, Exit< Default0< S2< M > > >, Exit< S2< M > >, Trans< S0< M >, C >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > > }; machine.CompareToExpectedActionSequence( c2 ); machine.process_event( D() ); ActionArray d1 = { Exit< Default2< S0< M > > >, Exit< Default1< S0< M > > >, Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Exit< S0< M > >, Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > > }; machine.CompareToExpectedActionSequence( d1 ); machine.process_event( F() ); ActionArray f1 = { Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, F >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > > }; machine.CompareToExpectedActionSequence( f1 ); machine.process_event( G() ); ActionArray g2 = { Exit< Default2< S0< M > > >, Exit< Default1< S0< M > > >, Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Exit< Default1< S2< M > > >, Exit< Default0< S2< M > > >, Exit< S2< M > >, Exit< S0< M > >, Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > > }; machine.CompareToExpectedActionSequence( g2 ); machine.process_event( H() ); ActionArray h1 = { Trans< S11< M >, H > }; machine.CompareToExpectedActionSequence( h1 ); machine.process_event( E() ); ActionArray e1 = { Exit< Default2< S0< M > > >, Exit< Default1< S0< M > > >, Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Exit< S0< M > >, Entry< S0< M > >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, Entry< S211< M > >, Entry< Default2< S21< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > > }; machine.CompareToExpectedActionSequence( e1 ); machine.terminate(); ActionArray term = { Exit< Default2< S0< M > > >, Exit< Default1< S0< M > > >, Exit< Default2< S21< M > > >, Exit< S211< M > >, Exit< Default0< S21< M > > >, Exit< S21< M > >, Exit< Default1< S2< M > > >, Exit< Default0< S2< M > > >, Exit< S2< M > >, Exit< S0< M > > }; machine.CompareToExpectedActionSequence( term ); machine.ThrowAction( &Entry< Default0< S1< M > > > ); BOOST_REQUIRE_THROW( machine.initiate(), TransitionTestException ); ActionArray initThrow1 = { Entry< S0< M > >, Entry< S1< M > >, &::Throw< &::Entry< Default0< S1< M > > > >, Dtor< S1< M > >, Dtor< S0< M > > }; machine.CompareToExpectedActionSequence( initThrow1 ); BOOST_REQUIRE( machine.terminated() ); machine.ThrowAction( &Entry< S11< M > > ); BOOST_REQUIRE_THROW( machine.initiate(), TransitionTestException ); ActionArray initThrow2 = { Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, &::Throw< &::Entry< S11< M > > >, Dtor< Default0< S1< M > > >, Dtor< S1< M > >, Dtor< S0< M > > }; machine.CompareToExpectedActionSequence( initThrow2 ); BOOST_REQUIRE( machine.terminated() ); machine.ThrowAction( &Trans< S0< M >, A > ); machine.initiate(); BOOST_REQUIRE_THROW( machine.process_event( A() ), TransitionTestException ); ActionArray a1Throw1 = { Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > >, Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, &::Throw< &::Trans< S0< M >, A > >, Dtor< Default2< S0< M > > >, Dtor< Default1< S0< M > > >, Dtor< S0< M > > }; machine.CompareToExpectedActionSequence( a1Throw1 ); BOOST_REQUIRE( machine.terminated() ); machine.ThrowAction( &Entry< S211< M > > ); machine.initiate(); BOOST_REQUIRE_THROW( machine.process_event( C() ), TransitionTestException ); ActionArray c1Throw1 = { Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > >, Exit< Default2< S1< M > > >, Exit< S11< M > >, Exit< Default0< S1< M > > >, Exit< S1< M > >, Trans< S0< M >, C >, Entry< S2< M > >, Entry< Default0< S2< M > > >, Entry< Default1< S2< M > > >, Entry< S21< M > >, Entry< Default0< S21< M > > >, &::Throw< &::Entry< S211< M > > >, Dtor< Default2< S0< M > > >, Dtor< Default1< S0< M > > >, Dtor< Default0< S21< M > > >, Dtor< S21< M > >, Dtor< Default1< S2< M > > >, Dtor< Default0< S2< M > > >, Dtor< S2< M > >, Dtor< S0< M > > }; machine.CompareToExpectedActionSequence( c1Throw1 ); BOOST_REQUIRE( machine.terminated() ); machine.ThrowAction( &ExitFn< S11< M > > ); machine.initiate(); BOOST_REQUIRE_THROW( machine.process_event( C() ), TransitionTestException ); ActionArray c1Throw2 = { Entry< S0< M > >, Entry< S1< M > >, Entry< Default0< S1< M > > >, Entry< S11< M > >, Entry< Default2< S1< M > > >, Entry< Default1< S0< M > > >, Entry< Default2< S0< M > > >, Exit< Default2< S1< M > > >, &::Throw< &::ExitFn< S11< M > > >, Dtor< S11< M > >, Dtor< Default2< S0< M > > >, Dtor< Default1< S0< M > > >, Dtor< Default0< S1< M > > >, Dtor< S1< M > >, Dtor< S0< M > > }; machine.CompareToExpectedActionSequence( c1Throw2 ); BOOST_REQUIRE( machine.terminated() ); BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 1 );}int test_main( int, char* [] ){ TransitionTest< sc::null_exception_translator > null_machine; TestTransitions( null_machine ); TransitionTest< sc::exception_translator<> > machine; TestTransitions( machine ); TransitionEventBaseTest eventBaseMachine; eventBaseMachine.initiate(); BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() ); eventBaseMachine.process_event( A() ); BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X2 & >() ); BOOST_REQUIRE( eventBaseMachine.GetActionCallCounter() == 0 ); eventBaseMachine.process_event( B() ); BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() ); BOOST_REQUIRE( eventBaseMachine.GetActionCallCounter() == 1 ); eventBaseMachine.process_event( C() ); BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X2 & >() ); BOOST_REQUIRE( eventBaseMachine.GetActionCallCounter() == 1 ); eventBaseMachine.process_event( D() ); BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() ); BOOST_REQUIRE( eventBaseMachine.GetActionCallCounter() == 2 ); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -