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 | ////////////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | |
---|
8 | |
---|
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> |
---|
15 | |
---|
16 | #include <boost/test/test_tools.hpp> |
---|
17 | |
---|
18 | #include <stdexcept> // std::logic_error |
---|
19 | |
---|
20 | namespace sc = boost::statechart; |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | struct E : sc::event< E > {}; |
---|
25 | |
---|
26 | struct A; |
---|
27 | struct InvalidResultCopyTest : |
---|
28 | sc::state_machine< InvalidResultCopyTest, A > {}; |
---|
29 | |
---|
30 | struct A : sc::simple_state< A, InvalidResultCopyTest > |
---|
31 | { |
---|
32 | typedef sc::custom_reaction< E > reactions; |
---|
33 | |
---|
34 | sc::result react( const E & ) |
---|
35 | { |
---|
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 ); |
---|
41 | |
---|
42 | // We must not make more than one copy of a result value |
---|
43 | sc::result rCopy2( r ); |
---|
44 | return rCopy2; |
---|
45 | } |
---|
46 | }; |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | int test_main( int, char* [] ) |
---|
51 | { |
---|
52 | InvalidResultCopyTest machine; |
---|
53 | machine.initiate(); |
---|
54 | |
---|
55 | #ifdef NDEBUG |
---|
56 | BOOST_REQUIRE_NO_THROW( machine.process_event( E() ) ); |
---|
57 | #else |
---|
58 | BOOST_REQUIRE_THROW( machine.process_event( E() ), std::logic_error ); |
---|
59 | #endif |
---|
60 | |
---|
61 | return 0; |
---|
62 | } |
---|