-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathtesting.cpp
More file actions
48 lines (41 loc) · 1.04 KB
/
testing.cpp
File metadata and controls
48 lines (41 loc) · 1.04 KB
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
//
// Copyright (c) 2016-2020 Kris Jusiak (kris at jusiak dot net)
//
// 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/sml.hpp>
#include <cassert>
namespace sml = boost::sml;
namespace {
struct e1 {};
struct e2 {};
struct e3 {};
struct data {
int value = 0;
};
struct testing {
auto operator()() const noexcept {
using namespace sml;
const auto guard = [](data& d) { return !d.value; };
const auto action = [](data& d) { d.value = 42; };
// clang-format off
return make_transition_table(
*"idle"_s + event<e1> = "s1"_s
, "s1"_s + event<e2> = "s2"_s
, "s2"_s + event<e3> [guard] / action = X // transition under test
);
// clang-format on
}
};
} // namespace
int main() {
using namespace sml;
data fake_data{0};
sml::sm<::testing, sml::testing> sm{fake_data};
sm.set_current_states("s2"_s);
sm.process_event(e3{});
assert(sm.is(X));
assert(fake_data.value == 42);
}