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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
// 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)
#include <boost/core/ignore_unused.hpp>
#include <boost/msm/front/puml/puml.hpp>
#ifndef BOOST_MSM_NONSTANDALONE_TEST
#define BOOST_TEST_MODULE puml_test
#endif
#include <boost/test/unit_test.hpp>
using namespace boost::msm::front;
using namespace boost::msm::front::puml;
namespace
{
BOOST_AUTO_TEST_CASE( puml_test )
{
constexpr auto stt_ = R"([*]-> StateA
StateA -> StateB: evt1/ A2 [G1]
StateB -> StateB : evt1/ A1,A2 [G1]
StateB -> StateA: evt1)";
auto stt =
boost::msm::front::puml::create_transition_table([&]() {return stt_; });
static_assert(std::is_same_v<
decltype(stt),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Guard <by_name("G1")> >,
Row<State <by_name("StateB")>, Event <by_name("evt1")>, State <by_name("StateB")>, ActionSequence_<boost::fusion::vector< Action<by_name("A1")>, Action<by_name("A2")>>>, Guard <by_name("G1")> >,
Row<State <by_name("StateB")>, Event <by_name("evt1")>, State <by_name("StateA")>, none, none >
>
>);
constexpr auto stt2_ = R"([*]->StateA
StateA -> StateB: evt1/ A2 [G1&&G2]
StateB -> StateB : evt1/ A1, defer [G1]
StateB -> StateA: evt1)";
auto stt2 =
boost::msm::front::puml::create_transition_table([&]() {return stt2_; });
static_assert(std::is_same_v<
decltype(stt2),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, And_<Guard <by_name("G1")>, Guard <by_name("G2")>> >,
Row<State <by_name("StateB")>, Event <by_name("evt1")>, State <by_name("StateB")>, ActionSequence_<boost::fusion::vector< Action<by_name("A1")>, Defer>>, Guard <by_name("G1")> >,
Row<State <by_name("StateB")>, Event <by_name("evt1")>, State <by_name("StateA")>, none, none >
>
>);
constexpr auto stt3_ = R"(StateA -> StateB: evt1/ A2 [G1 && G2 && G3])";
auto stt3 =
boost::msm::front::puml::create_transition_table([&]() {return stt3_; });
static_assert(std::is_same_v<
decltype(stt3),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, And_<Guard <by_name("G1")>, And_<Guard <by_name("G2")>, Guard <by_name("G3")>>> >
>
>);
constexpr auto stt4_ = R"(StateA -> StateB: evt1/ A2 [G1 || G2])";
auto stt4 =
boost::msm::front::puml::create_transition_table([&]() {return stt4_; });
static_assert(std::is_same_v<
decltype(stt4),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<Guard <by_name("G1")>, Guard <by_name("G2")>> >
>
>);
constexpr auto stt5_ = R"(StateA -> StateB: evt1/ A2 [G1 && G2 || G3])";
auto stt5 =
boost::msm::front::puml::create_transition_table([&]() {return stt5_; });
static_assert(std::is_same_v<
decltype(stt5),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<And_<Guard <by_name("G1")>, Guard <by_name("G2")>>, Guard <by_name("G3")>> >
>
>);
constexpr auto stt6_ = R"(StateA ---> StateB: evt1/ A2 [!G1])";
auto stt6 =
boost::msm::front::puml::create_transition_table([&]() {return stt6_; });
static_assert(std::is_same_v<
decltype(stt6),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Not_<Guard <by_name("G1")>> >
>
>);
constexpr auto stt7_ = R"(StateA -> StateB: evt1/ A2 [G1 || !G2])";
auto stt7 =
boost::msm::front::puml::create_transition_table([&]() {return stt7_; });
static_assert(std::is_same_v<
decltype(stt7),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<Guard <by_name("G1")>, Not_<Guard <by_name("G2")>>> >
>
>);
constexpr auto stt8_ = R"(StateA -> StateB: evt1/ A2 [Or(G1,Not(G2))])";
auto stt8 =
boost::msm::front::puml::create_transition_table([&]() {return stt8_; });
static_assert(std::is_same_v<
decltype(stt8),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<Guard <by_name("G1")>, Not_<Guard <by_name("G2")>>> >
>
>);
auto stt9 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [(G1 || G2) && G3])"; });
static_assert(std::is_same_v<
decltype(stt9),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, And_<Or_<Guard <by_name("G1")>, Guard <by_name("G2")>>, Guard <by_name("G3")>> >
>
>);
auto stt10 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [(G1 && G2) || G3])"; });
static_assert(std::is_same_v<
decltype(stt10),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<And_<Guard <by_name("G1")>, Guard <by_name("G2")>>, Guard <by_name("G3")>> >
>
>);
auto stt11 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [G3 && ( G1 || G2 )])"; });
static_assert(std::is_same_v<
decltype(stt11),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, And_<Guard <by_name("G3")>, Or_<Guard <by_name("G1")>, Guard <by_name("G2")>>> >
>
>);
auto stt12 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [G3 || ( G1 && G2 )])"; });
static_assert(std::is_same_v<
decltype(stt12),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<Guard <by_name("G3")>, And_<Guard <by_name("G1")>, Guard <by_name("G2")>>> >
>
>);
auto stt13 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [!( G1 && G2 )])"; });
static_assert(std::is_same_v<
decltype(stt13),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Not_<And_<Guard <by_name("G1")>, Guard <by_name("G2")>>> >
>
>);
auto stt14 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [G3 || !( G1 && G2 )])"; });
static_assert(std::is_same_v<
decltype(stt14),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>, Or_<Guard <by_name("G3")>, Not_<And_<Guard <by_name("G1")>, Guard <by_name("G2")>>>> >
>
>);
auto stt15 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [(G3 && G1) || ( G1 && G2 )])"; });
static_assert(std::is_same_v<
decltype(stt15),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>,
Or_<And_<Guard <by_name("G3")>, Guard <by_name("G1")>>, And_<Guard <by_name("G1")>, Guard <by_name("G2")>>> >
>
>);
auto stt16 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateB: evt1/ A2 [(G3 && G1) || !(G1 && G2)])"; });
static_assert(std::is_same_v<
decltype(stt16),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateB")>, Action <by_name("A2")>,
Or_<And_<Guard <by_name("G3")>, Guard <by_name("G1")>>, Not_<And_<Guard <by_name("G1")>, Guard <by_name("G2")>>>> >
>
>);
// internal detail::Transition
auto stt17 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateA: -evt1/ A2 [G1])"; });
static_assert(std::is_same_v<
decltype(stt17),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, none, Action <by_name("A2")>, Guard <by_name("G1")>>
>
>);
// kleene
auto stt18 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateA: * / A2 [G1])"; });
static_assert(std::is_same_v<
decltype(stt18),
boost::fusion::vector<
Row<State <by_name("StateA")>, boost::any, State <by_name("StateA")>, Action <by_name("A2")>, Guard <by_name("G1")>>
>
>);
// internal + kleene
auto stt19 =
boost::msm::front::puml::create_transition_table([]() {return R"(StateA -> StateA: -* / A2 [G1])"; });
static_assert(std::is_same_v<
decltype(stt19),
boost::fusion::vector<
Row<State <by_name("StateA")>, boost::any, none, Action <by_name("A2")>, Guard <by_name("G1")>>
>
>);
// test init states
static_assert(std::is_same_v<
decltype(boost::msm::front::puml::create_transition_table([]() {return R"([*] -> StateA
StateA --> StateA: evt1 / defer)"; })),
boost::fusion::vector<
Row<State <by_name("StateA")>, Event <by_name("evt1")>, State <by_name("StateA")>, Defer, none >
>
> );
State< by_name("StateXXX")> s1;
boost::ignore_unused(s1);
// initial states
constexpr auto stt9_ = R"(
[*] --> StateA
StateA -> StateB: evt1 [G1]
StateB -> StateB : evt1 / A1 [G1]
--
[*]->StateC
StateC -> StateD: -*)";
auto inits =
create_initial_states([&]() {return stt9_; });
static_assert(std::is_same_v<
decltype(inits),
boost::fusion::vector< State <by_name("StateA")>, State <by_name("StateC")>>
>);
//constexpr auto name_ = "StateA";
//std::cout << typeid(boost::msm::front::puml::detail::parse_flags(stt_, name_)).name() << std::endl;
}
}
|