root/isimud/tests/mit_msm.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. BOOST_AUTO_TEST_SUITE
  2. BOOST_AUTO_TEST_CASE_TEMPLATE

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/tests/mit_msm.cpp 2364 2018-10-24 20:51:15Z jmmcg $
   3 **
   4 ** Copyright © 2018 by J.M.McGuiness, coder@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  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()

/* [<][>][^][v][top][bottom][index][help] */