root/isimud/tests/fix_simulators.cpp

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

DEFINITIONS

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

   1 /******************************************************************************

   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/tests/fix_simulators.cpp 2177 2017-10-11 21:29:22Z jmmcg $

   3 **

   4 ** Copyright (c) 2015 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/FIX/v5.0sp2/fix_sim.hpp"
  31 
  32 const boost::asio::ip::address localhost(boost::asio::ip::address_v4::loopback());
  33 const unsigned short unused_primary_port=12347u;
  34 const unsigned short unused_secondary_port=12348u;
  35 const isimud::exchanges::FIX::common::ClientOrderID_t clientOrderId1{"00000000000000test1"};
  36 
  37 typedef boost::mpl::list<
  38         std::pair<isimud::exchanges::FIX::v5_0sp2::connection_t, isimud::exchanges::FIX::v5_0sp2::simulator_t>
  39 > exchg_t_types;
  40 
  41 BOOST_AUTO_TEST_SUITE(exchanges)
  42 
  43 BOOST_AUTO_TEST_SUITE(links)
  44 
  45 /**

  46         \test "Connectivity Policy" Test: gateway unavailable.

  47                         ================================================

  48         Verify that more than 1*5 seconds passes if both gateways are unavailable.

  49 */
  50 BOOST_AUTO_TEST_CASE_TEMPLATE(gateway_unavailable, exchg_t, exchg_t_types) {
  51         using connection_t=typename exchg_t::first_type;
  52         using conn_pol_t=typename connection_t::conn_pol_t;
  53         typename conn_pol_t::gateways_t gateways(
  54                 std::make_pair(localhost, unused_primary_port)
  55         );
  56         conn_pol_t conn_pol(gateways);
  57         auto const &begin=std::chrono::system_clock::now();
  58         BOOST_CHECK_THROW(typename exchg_t::first_type link(conn_pol), std::exception);
  59         auto const &end=std::chrono::system_clock::now();
  60         BOOST_CHECK_GE(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), (conn_pol_t::max_attempts*conn_pol_t::min_timeout).count());
  61 }
  62 
  63 /**

  64         \test "Connectivity Policy" Test: primary gateway available.

  65                         ======================================================

  66         Verify that less than 5 seconds passes if just the primary gateway is available.

  67 */
  68 BOOST_AUTO_TEST_CASE_TEMPLATE(gateway_available, exchg_t, exchg_t_types) {
  69         using connection_t=typename exchg_t::first_type;
  70         using simulator_t=typename exchg_t::second_type;
  71         using conn_pol_t=typename connection_t::conn_pol_t;
  72         typename simulator_t::proc_rules_t proc_rules;
  73         simulator_t svr(boost::asio::ip::address(), unused_primary_port, proc_rules);
  74         typename conn_pol_t::gateways_t gateways(
  75                 std::make_pair(localhost, unused_primary_port)
  76         );
  77         conn_pol_t conn_pol(gateways);
  78         auto const &begin=std::chrono::system_clock::now();
  79         BOOST_CHECK_NO_THROW(typename exchg_t::first_type link(conn_pol));
  80         auto const &end=std::chrono::system_clock::now();
  81         BOOST_CHECK_LT(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), conn_pol_t::min_timeout.count());
  82 }
  83 
  84 BOOST_AUTO_TEST_SUITE_END()
  85 
  86 BOOST_AUTO_TEST_SUITE(admin)
  87 
  88 /**

  89         \test "Heartbeats" Test: Client Heartbeat.

  90                         ====================================

  91         Verify that the response to a Heartbeat is nothing.

  92 */
  93 BOOST_AUTO_TEST_CASE_TEMPLATE(client_heartbeat, exchg_t, exchg_t_types) {
  94         using connection_t=typename exchg_t::first_type;
  95         using simulator_t=typename exchg_t::second_type;
  96         using conn_pol_t=typename connection_t::conn_pol_t;
  97         typename simulator_t::proc_rules_t proc_rules;
  98         simulator_t svr(boost::asio::ip::address(), unused_primary_port, proc_rules);
  99         typename conn_pol_t::gateways_t gateways(
 100                 std::make_pair(localhost, unused_primary_port)
 101         );
 102         conn_pol_t conn_pol(gateways);
 103         typename exchg_t::first_type link(conn_pol);
 104         const isimud::exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
 105                 "8=FIX.5.0\0019=005\00135=0\00110=093\001"
 106         };
 107         typename connection_t::msg_details_t::ClientHeartbeat const &msg=reinterpret_cast<typename connection_t::msg_details_t::ClientHeartbeat const &>(*fix_buffer.begin());
 108         BOOST_CHECK(msg.is_valid());
 109         BOOST_CHECK_NO_THROW(link.send(msg));
 110 }
 111 
 112 BOOST_AUTO_TEST_SUITE_END()
 113 
 114 BOOST_AUTO_TEST_SUITE_END()

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