Boost logo

Boost Users :

From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2007-12-11 19:31:15


Hi Sean

> I have statechart implementation that I have spread over multiple
> translation units - I would like to unit test the control logic by
> inserting mock transition actions. The library is explicitly designed
> not to be dynamic - Can anyone suggest a way I could accomplish this -

You could have the transition actions call functions of an abstract base
class, derivations of which can be passed to the state machine ctor or even
set dynamically.

> Its also likely that I could reuse the statechart control logic with
> different implementations of transition actions so if it is possible to
> inject this dependency I can reuse the code.

For better reuse, I personally often use template parameters. See e.g.
<http://www.boost.org/libs/statechart/doc/tutorial.html#SubmachinesAndParameterizedStates>.
If you need variability with transition actions, you could also pass member
function pointers as template arguments. This is the compile-time
alternative to the abstract base class above.

HTH,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net