This source file includes following definitions.
- BOOST_AUTO_TEST_SUITE
- BOOST_AUTO_TEST_CASE_TEMPLATE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "stdafx.h"
22
23 #define BOOST_TEST_MODULE libjmmcg_tests
24 #include <boost/test/included/unit_test.hpp>
25
26 #include <boost/test/test_case_template.hpp>
27 #include <boost/mpl/list.hpp>
28
29 #include "../exchanges/FIX/v5.0sp2/fix.hpp"
30 #include "../exchanges/MIT/BIT/messages.hpp"
31 #include "../exchanges/MIT/JSE/messages.hpp"
32 #include "../exchanges/MIT/LSE/messages.hpp"
33 #include "../exchanges/MIT/OSLO/messages.hpp"
34 #include "../exchanges/MIT/TRQ/messages.hpp"
35
36 #include "core/msm.hpp"
37
38 using namespace jmmcg;
39
40 using msg_types=boost::mpl::list<
41 isimud::exchanges::MIT::BIT::MsgTypes,
42 isimud::exchanges::MIT::JSE::MsgTypes,
43 isimud::exchanges::MIT::LSE::MsgTypes,
44 isimud::exchanges::MIT::OSLO::MsgTypes,
45 isimud::exchanges::MIT::TRQ::MsgTypes
46 >;
47
48 BOOST_AUTO_TEST_SUITE(isimud)
49
50 BOOST_AUTO_TEST_SUITE(msm_tests)
51
52 template<class DestMsgsT>
53 struct data_with_payload {
54 using dest_msg_details_t=DestMsgsT;
55 typename dest_msg_details_t::ExgchgMsgTypes state{};
56 unsigned j{68};
57 };
58
59 template<class SrcMsgsT, class DestMsgsT>
60 struct assign_driver_states {
61 using src_msg_details_t=SrcMsgsT;
62 using dest_msg_details_t=DestMsgsT;
63 struct fn_event {
64 explicit fn_event(unsigned &j)
65 : j_(j) {}
66
67 template<auto state, auto next, class Params>
68 void operator()(Params &p) const noexcept(true) {
69 p.state=next;
70 p.j+=j_;
71 }
72
73 private:
74 unsigned &j_;
75 };
76
77 struct state_machine_t : msm::unroll::state_transition_table<state_machine_t> {
78 using base_t=msm::unroll::state_transition_table<state_machine_t>;
79 using row_t=msm::unroll::row_types<typename src_msg_details_t::MsgTypes_t, typename dest_msg_details_t::ExgchgMsgTypes>;
80 using transition_table=typename base_t::template rows<
81 typename row_t::template row<
82 src_msg_details_t::NewOrder::type_const,
83 fn_event,
84 dest_msg_details_t::NewOrder::type_const
85 >
86 >;
87 };
88 using machine=msm::unroll::machine<state_machine_t>;
89
90 assign_driver_states()
91 : j(42), msm(j) {
92 }
93
94 template<class Arg>
95 void process(typename src_msg_details_t::MsgTypes_t state, Arg &p) noexcept(false) {
96 msm.process(state, p);
97 }
98
99 unsigned j;
100 machine msm;
101 };
102
103 BOOST_AUTO_TEST_CASE_TEMPLATE(start_state_assign_driver_states, msg, msg_types) {
104 assign_driver_states<msg, isimud::exchanges::FIX::v5_0sp2::MsgTypes> msm;
105 data_with_payload<isimud::exchanges::FIX::v5_0sp2::MsgTypes> d;
106 BOOST_CHECK_NO_THROW(msm.process(msg::NewOrder::type_const, d));
107 BOOST_CHECK_EQUAL(d.state, isimud::exchanges::FIX::v5_0sp2::MsgTypes::NewOrder::type_const);
108 BOOST_CHECK_EQUAL(d.j, 68+42);
109 }
110
111 BOOST_AUTO_TEST_SUITE_END()
112
113 BOOST_AUTO_TEST_SUITE_END()