21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include <boost/mpl/list.hpp>
26 #include "core/msm.hpp"
28 using namespace libjmmcg;
39 operator<<(
std::ostream &os,
states const s)
noexcept(
false) {
40 os<<
static_cast<std::underlying_type<states>::type>(s);
53 operator<<(
std::ostream &os,
end_states const s)
noexcept(
false) {
54 os<<
static_cast<std::underlying_type<end_states>::type>(s);
67 using msm_types=boost::mpl::list<
77 using argument_type=
std::function<
void()>;
79 template<
auto state,
auto next>
80 void operator()(argument_type &p)
const noexcept(
true) {
83 template<
auto state,
auto next,
class Params>
84 void operator()(Params &p)
const noexcept(
true) {
89 struct state_machine_t
final : MSMT::
template state_transition_table<state_machine_t> {
90 using base_t=
typename MSMT::
template state_transition_table<state_machine_t>;
92 using transition_table=
typename base_t::
template rows<
96 using machine=
typename MSMT::
template machine<state_machine_t>;
99 auto fn=
std::bind(&state_machine_t::no_op::noop);
100 msm.process(state, fn);
115 void operator()(argument_type &p)
const noexcept(
true) {
119 template<
auto state,
auto next,
class Params>
129 struct state_machine_t
final : MSMT::
template state_transition_table<state_machine_t> {
130 using base_t=
typename MSMT::
template state_transition_table<state_machine_t>;
132 using transition_table=
typename base_t::
template rows<
138 using machine=
typename MSMT::
template machine<state_machine_t>;
146 msm.process(state, p);
156 using argument_type=data;
158 template<
auto state,
states next>
159 void operator()(argument_type &p)
const noexcept(
true) {
162 template<
auto state,
auto next,
class Params>
168 template<
auto state,
auto next,
class Params>
174 struct state_machine_t
final : MSMT::
template state_transition_table<state_machine_t> {
175 using base_t=
typename MSMT::
template state_transition_table<state_machine_t>;
177 using transition_table=
typename base_t::
template rows<
183 using machine=
typename MSMT::
template machine<state_machine_t>;
187 msm.process(state, p);
193 BOOST_AUTO_TEST_SUITE(msm_tests)
195 BOOST_AUTO_TEST_CASE_TEMPLATE(noop_driver_ctor, msm_type, msm_types) {
196 BOOST_CHECK_NO_THROW([[maybe_unused]]
const noop_driver<msm_type> msm);
199 BOOST_AUTO_TEST_CASE_TEMPLATE(start_state_noop_driver, msm_type, msm_types) {
201 BOOST_CHECK_NO_THROW(msm.process(states::start));
204 BOOST_AUTO_TEST_CASE_TEMPLATE(assign_driver_states_ctor, msm_type, msm_types) {
205 BOOST_CHECK_NO_THROW([[maybe_unused]]
const assign_driver_states<msm_type> msm);
208 BOOST_AUTO_TEST_CASE_TEMPLATE(start_state_assign_driver_states, msm_type, msm_types) {
211 BOOST_CHECK_NO_THROW(msm.process(states::start, d));
212 BOOST_CHECK_EQUAL(d.state, end_states::middle);
213 BOOST_CHECK_EQUAL(d.j, 68+42);
214 BOOST_CHECK_NO_THROW(msm.process(states::middle, d));
215 BOOST_CHECK_EQUAL(d.state, end_states::middle1);
216 BOOST_CHECK_EQUAL(d.j, 68+42+42);
219 BOOST_AUTO_TEST_CASE_TEMPLATE(assign_driver_ctor, msm_type, msm_types) {
220 BOOST_CHECK_NO_THROW([[maybe_unused]]
const assign_driver<msm_type> msm);
223 BOOST_AUTO_TEST_CASE_TEMPLATE(start_state_assign_event, msm_type, msm_types) {
226 BOOST_CHECK_NO_THROW(msm.process(states::start, d));
227 BOOST_CHECK_EQUAL(d.state, states::middle);
228 BOOST_CHECK_NO_THROW(msm.process(states::middle, d));
229 BOOST_CHECK_EQUAL(d.state, states::middle1);
230 BOOST_CHECK_NO_THROW(msm.process(states::middle1, d));
231 BOOST_CHECK_EQUAL(d.state, states::end);
234 BOOST_AUTO_TEST_SUITE_END()