Question

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...

Was it helpful?

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.

OTHER TIPS

Added a different hack. Each State is created before it's used by the boost state machine (then destroyed after it goes to the next state...seems so inefficient), so each state was derived from another class that has a callback in it's constructor. Still seems kinda hackish...wish boost++ had a cleaner way to do this :-P

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top