File: StringTerminatePuml.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (93 lines) | stat: -rw-r--r-- 3,436 bytes parent folder | download | duplicates (3)
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
// Copyright 2024 Christophe Henry
// henry UNDERSCORE christophe AT hotmail DOT com
// This is an extended version of the state machine available in the boost::mpl library
// Distributed under the same license as the original.
// Copyright for the original version:
// Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
// under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


// back-end
#include "BackCommon.hpp"
//front-end
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/puml/puml.hpp>
#include "PumlCommon.hpp"

#ifndef BOOST_MSM_NONSTANDALONE_TEST
#define BOOST_TEST_MODULE string_terminate_puml_test
#endif
#include <boost/test/unit_test.hpp>

using namespace std;
namespace msm = boost::msm;
using namespace msm::front;
using namespace msm::front::puml;

namespace
{
    // note in the puml tests will be non-specialized types marked with _ 

    // front-end: define the FSM structure 
    struct front_ : public msm::front::state_machine_def<front_>
    {
        BOOST_MSM_PUML_DECLARE_TABLE(
            R"( 
            @startuml Player
            skinparam linetype polyline
            state Player{
                [*]-> StateA
                StateA          -> StateB        : some_event
                StateB          -> StateA        : some_event                
                --
                [*]-> StateC
                StateC          -> TerminalState : terminate_event
                TerminalState   -> [*]
            }
            @enduml
        )"
        )

        // Replaces the default no-transition response.
        template <class FSM,class Event>
        void no_transition(Event const&, FSM&,int)
        {
            BOOST_FAIL("no_transition called!");
        }
    };
    // Pick a back-end
    typedef get_test_machines<front_> machines;


    BOOST_AUTO_TEST_CASE_TEMPLATE(string_terminate_puml_test, machine, machines)
    {     
        machine p;
        static_assert(msm::back11::get_number_of_regions<typename machine::initial_state>::type::value == 2);
        static_assert(::boost::mpl::size<typename machine::transition_table>::type::value == 3);

        p.start(); 
        BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
        BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");

        p.process_event(Event<by_name("some_event")>{});
        BOOST_CHECK_MESSAGE(p.current_state()[0] == 1, "StateB should be active");
        BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");

        p.process_event(Event<by_name("some_event")>{});
        BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
        BOOST_CHECK_MESSAGE(p.current_state()[1] == 2, "StateC should be active");

        // force termination
        p.process_event(Event<by_name("terminate_event")>{});
        BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
        BOOST_CHECK_MESSAGE(p.current_state()[1] == 3, "TerminalState should be active");

        // no more event processing => no state changes
        p.process_event(Event<by_name("some_event")>{});
        BOOST_CHECK_MESSAGE(p.current_state()[0] == 0, "StateA should be active");
        BOOST_CHECK_MESSAGE(p.current_state()[1] == 3, "TerminalState should be active");

    }
}