示例#1
0
 Waiting( my_context ctx ) :
   my_base( ctx ),
   noOfReturns_( 0 ),
   pBallReturned_( new BallReturned() )
 {
   outermost_context_type & machine = outermost_context();
   // as we will always return the same event to the opponent, we construct
   // and fill it here so that we can reuse it over and over
   pBallReturned_->returnToOpponent = boost::bind(
     &MyScheduler::queue_event,
     &machine.my_scheduler(), machine.my_handle(), _1 );
   pBallReturned_->abortGame = boost::bind(
     &MyScheduler::queue_event,
     &machine.my_scheduler(), machine.my_handle(),
     MakeIntrusive( new GameAborted() ) );
 }
示例#2
0
int test_main( int, char* [] )
{
  DeferralTest machine;
  machine.initiate();
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvNodeDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( EvNodeDeferred() );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvDestroy() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 5 );


  DeferralEventBaseTest eventBaseMachine;
  // state_cast sanity check
  BOOST_REQUIRE_THROW( eventBaseMachine.state_cast< const X1 & >(), std::bad_cast );
  eventBaseMachine.initiate();
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  // Deferral must work with heap-allocated and stack-allocated events
  eventBaseMachine.process_event( EvToX3() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  eventBaseMachine.process_event( EvToX2() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X3 & >() );
  eventBaseMachine.initiate();
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  eventBaseMachine.process_event( EvToX2() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X2 & >() );

  return 0;
}