forked from erikzenker/hsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransition_logging.cpp
50 lines (40 loc) · 1005 Bytes
/
transition_logging.cpp
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
#include "hsm/hsm.h"
#include <boost/hana.hpp>
#include <boost/hana/experimental/printable.hpp>
#include <gtest/gtest.h>
namespace {
using namespace ::testing;
using namespace boost::hana;
// States
struct S1 {
};
struct S2 {
};
// Events
struct e1 {
};
// Transition logging action
const auto log = [](auto event, auto source, auto target) {
std::cout << experimental::print(typeid_(source)) << " + "
<< experimental::print(typeid_(event)) << " = "
<< experimental::print(typeid_(target)) << std::endl;
};
struct MainState {
static constexpr auto make_transition_table()
{
// clang-format off
return hsm::transition_table(
* hsm::state<S1> {} + hsm::event<e1> {} / log = hsm::state<S2> {}
);
// clang-format on
}
};
}
class TransitionLoggingTests : public Test {
protected:
hsm::sm<MainState> sm;
};
TEST_F(TransitionLoggingTests, should_log_transition)
{
ASSERT_TRUE(sm.is(hsm::state<S1> {}));
}