1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
//////////////////////////////////////////////////////////////////////////////
// Copyright 2009 Andreas Huber Doenni
// Distributed under the Boost Software License, Version 1.0. (See accompany-
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//////////////////////////////////////////////////////////////////////////////
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/exception_translator.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/in_state_reaction.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/mpl/list.hpp>
#include <boost/test/test_tools.hpp>
#include <memory> // std::allocator
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
struct EvGoToB : sc::event< EvGoToB > {};
struct EvDoIt : sc::event< EvDoIt > {};
struct A;
struct TriggringEventTest : sc::state_machine<
TriggringEventTest, A,
std::allocator< sc::none >, sc::exception_translator<> >
{
void Transit(const EvGoToB &)
{
BOOST_REQUIRE(dynamic_cast<const EvGoToB *>(triggering_event()) != 0);
}
};
struct B : sc::state< B, TriggringEventTest >
{
B( my_context ctx ) : my_base( ctx )
{
BOOST_REQUIRE(dynamic_cast<const EvGoToB *>(triggering_event()) != 0);
}
~B()
{
BOOST_REQUIRE(triggering_event() == 0);
}
void DoIt( const EvDoIt & )
{
BOOST_REQUIRE(dynamic_cast<const EvDoIt *>(triggering_event()) != 0);
throw std::exception();
}
void HandleException( const sc::exception_thrown & )
{
BOOST_REQUIRE(dynamic_cast<const sc::exception_thrown *>(triggering_event()) != 0);
}
typedef mpl::list<
sc::in_state_reaction< EvDoIt, B, &B::DoIt >,
sc::in_state_reaction< sc::exception_thrown, B, &B::HandleException >
> reactions;
};
struct A : sc::state< A, TriggringEventTest >
{
typedef sc::transition<
EvGoToB, B, TriggringEventTest, &TriggringEventTest::Transit
> reactions;
A( my_context ctx ) : my_base( ctx )
{
BOOST_REQUIRE(triggering_event() == 0);
}
~A()
{
BOOST_REQUIRE(dynamic_cast<const EvGoToB *>(triggering_event()) != 0);
}
};
int test_main( int, char* [] )
{
TriggringEventTest machine;
machine.initiate();
machine.process_event(EvGoToB());
machine.process_event(EvDoIt());
machine.terminate();
return 0;
}
|