1// Copyright 2024 Christophe Henry
2// henry UNDERSCORE christophe AT hotmail DOT com
3// This is an extended version of the state machine available in the boost::mpl library
4// Distributed under the same license as the original.
5// Copyright for the original version:
6// Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
7// under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10
11
12// back-end
13#include <boost/msm/back11/state_machine.hpp>
14//front-end
15#include <boost/msm/front/state_machine_def.hpp>
16#include <boost/msm/front/puml/puml.hpp>
17#include <PumlCommon.hpp>
18
19#ifndef BOOST_MSM_NONSTANDALONE_TEST
20#define BOOST_TEST_MODULE back11_only_string_puml_test
21#endif
22#include <boost/test/unit_test.hpp>
23
24using namespace std;
25namespace msm = boost::msm;
26using namespace msm::front;
27using namespace msm::front::puml;
28
29namespace
30{
31 // note in the puml tests will be non-specialized types marked with _
32
33 // front-end: define the FSM structure
34 struct front_ : public msm::front::state_machine_def<front_>
35 {
36 BOOST_MSM_PUML_DECLARE_TABLE(
37 R"(
38 @startuml Player
39 skinparam linetype polyline
40 state Player{
41 [*]-> StateA
42 StateA -> StateB : some_event
43 StateB -> StateA : some_event
44 --
45 [*]-> StateC
46 StateC -> TerminalState : terminate_event
47 TerminalState -> [*]
48 }
49 @enduml
50 )"
51 )
52
53 // Replaces the default no-transition response.
54 template <class FSM,class Event>
55 void no_transition(Event const&, FSM&,int)
56 {
57 BOOST_FAIL("no_transition called!");
58 }
59 };
60 // Pick a back-end
61 typedef msm::back11::state_machine<front_> machine;
62
63
64 BOOST_AUTO_TEST_CASE(back11_string_terminate_puml_test)
65 {
66 machine p;
67 static_assert(msm::back11::get_number_of_regions<typename machine::initial_state>::type::value == 2);
68 static_assert(::boost::mpl::size<typename machine::transition_table>::type::value == 3);
69
70 p.start();
71 BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
72 BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");
73
74 p.process_event(Event<by_name(str: "some_event")>{});
75 BOOST_CHECK_MESSAGE(p.current_state()[0] == 1, "StateB should be active");
76 BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");
77
78 p.process_event(Event<by_name(str: "some_event")>{});
79 BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
80 BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");
81
82 // force termination
83 p.process_event(Event<by_name(str: "terminate_event")>{});
84 BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
85 BOOST_CHECK_MESSAGE(p.current_state()[1] == 3, "TerminalState should be active");
86
87 // no more event processing => no state changes
88 p.process_event(Event<by_name(str: "some_event")>{});
89 BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
90 BOOST_CHECK_MESSAGE(p.current_state()[1] == 3, "TerminalState should be active");
91
92 }
93}
94
95

source code of boost/libs/msm/test/Back11StringTerminatePuml.cpp