Search code examples
c++boostboost-statechartstatechart

Recording state changes in boost::statechart


For Unit Testing, I'm trying to record all the state transactions after I kick off a state machine event.
E.g., if I post_event A to the fifo_scheduler of an async_state_machine, the state machine will go through states B, C, then back to D. Without being able to record all the event states, I can only check that it went to State D after it was done when doing a unit test :-(

The only thing I can think of is to modify all the react methods or constructors of all the states I create (derived off simple_state) so they do the recording. This seems a bit hackish when I really want to hook into the async_state_machine just before it calls a state's react() method...


Solution

  • This seems a bit hackish when I really want to hook into the async_state_machine just before it calls a state's react() method...

    Why don't you? Create a new class that extends async_state_machine and add your desired hooks into it. If access is a problem (It probably will be), do the ever spectacular #define private public (or protected hack before including statechart.

    I've done something similar to add local variables to the history of a state and add a new kind of state-ctor so I have for-real full history.