1 //////////////////////////////////////////////////////////////////////////////
2 // Copyright 2005-2006 Andreas Huber Doenni
3 // Distributed under the Boost Software License, Version 1.0. (See accompany-
4 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 //////////////////////////////////////////////////////////////////////////////
9 #include <libs/statechart/test/ThrowingBoostAssert.hpp>
10 #include <boost/statechart/state_machine.hpp>
11 #include <boost/statechart/event.hpp>
12 #include <boost/statechart/simple_state.hpp>
13 #include <boost/statechart/custom_reaction.hpp>
14 #include <boost/statechart/result.hpp>
16 #include <boost/test/test_tools.hpp>
18 #include <stdexcept> // std::logic_error
20 namespace sc
= boost::statechart
;
24 struct E
: sc::event
< E
> {};
27 struct InvalidResultCopyTest
:
28 sc::state_machine
< InvalidResultCopyTest
, A
> {};
30 struct A
: sc::simple_state
< A
, InvalidResultCopyTest
>
32 typedef sc::custom_reaction
< E
> reactions
;
34 sc::result
react( const E
& )
36 sc::result
r( discard_event() );
37 sc::result
rCopy1( r
);
38 // Ensure the copy is consumed so that we're not accidentally tripping
39 // the assert in the sc::result dtor
40 sc::detail::result_utility::get_result( rCopy1
);
42 // We must not make more than one copy of a result value
43 sc::result
rCopy2( r
);
50 int test_main( int, char* [] )
52 InvalidResultCopyTest machine
;
56 BOOST_REQUIRE_NO_THROW( machine
.process_event( E() ) );
58 BOOST_REQUIRE_THROW( machine
.process_event( E() ), std::logic_error
);