JayBeams  0.1
Another project to have fun coding.
ut_add_order_message.cpp
Go to the documentation of this file.
3 
4 #include <boost/test/unit_test.hpp>
5 
6 /**
7  * @test Verify that the jb::itch5::add_order_message decoder works
8  * as expected.
9  */
10 BOOST_AUTO_TEST_CASE(decode_add_order_message) {
11  using namespace jb::itch5;
12  using namespace std::chrono;
13 
14  auto buf = jb::itch5::testing::add_order();
16 
17  auto x = decoder<true, add_order_message>::r(buf.second, buf.first, 0);
18  BOOST_CHECK_EQUAL(x.header.message_type, add_order_message::message_type);
19  BOOST_CHECK_EQUAL(x.header.stock_locate, 0);
20  BOOST_CHECK_EQUAL(x.header.tracking_number, 1);
21  BOOST_CHECK_EQUAL(x.header.timestamp.ts.count(), expected_ts.count());
22  BOOST_CHECK_EQUAL(x.order_reference_number, 42ULL);
23  BOOST_CHECK_EQUAL(x.buy_sell_indicator, buy_sell_indicator_t(u'B'));
24  BOOST_CHECK_EQUAL(x.shares, 100);
25  BOOST_CHECK_EQUAL(x.stock, "HSART");
26  BOOST_CHECK_EQUAL(x.price, price4_t(1230500));
27 
28  x = decoder<false, add_order_message>::r(buf.second, buf.first, 0);
29  BOOST_CHECK_EQUAL(x.header.message_type, add_order_message::message_type);
30  BOOST_CHECK_EQUAL(x.header.stock_locate, 0);
31  BOOST_CHECK_EQUAL(x.header.tracking_number, 1);
32  BOOST_CHECK_EQUAL(x.header.timestamp.ts.count(), expected_ts.count());
33  BOOST_CHECK_EQUAL(x.order_reference_number, 42ULL);
34  BOOST_CHECK_EQUAL(x.buy_sell_indicator, buy_sell_indicator_t(u'B'));
35  BOOST_CHECK_EQUAL(x.shares, 100);
36  BOOST_CHECK_EQUAL(x.stock, "HSART");
37  BOOST_CHECK_EQUAL(x.price, price4_t(1230500));
38 }
39 
40 /**
41  * @test Verify that jb::itch5::add_order_message iostream
42  * operator works as expected.
43  */
44 BOOST_AUTO_TEST_CASE(stream_add_order_message) {
45  using namespace std::chrono;
46  using namespace jb::itch5;
47 
48  auto buf = jb::itch5::testing::add_order();
49  auto tmp = decoder<false, add_order_message>::r(buf.second, buf.first, 0);
50  std::ostringstream os;
51  os << tmp;
52  BOOST_CHECK_EQUAL(
53  os.str(), "message_type=A,stock_locate=0"
54  ",tracking_number=1,timestamp=113231.123456789"
55  ",order_reference_number=42"
56  ",buy_sell_indicator=B"
57  ",shares=100"
58  ",stock=HSART"
59  ",price=123.0500");
60 }
61 
62 /**
63  * @test Verify that buy_sell_indicator_t works as expected.
64  */
65 BOOST_AUTO_TEST_CASE(simple_buy_sell_indicator) {
66  using namespace jb::itch5;
67  BOOST_CHECK_NO_THROW(buy_sell_indicator_t(u'B'));
68  BOOST_CHECK_NO_THROW(buy_sell_indicator_t(u'S'));
69  BOOST_CHECK_THROW(buy_sell_indicator_t(u'*'), std::runtime_error);
70 }
static constexpr int message_type
static T r(std::size_t size, void const *msg, std::size_t offset)
Read a single message or field.
Contains classes and functions to parse NASDAQ ITCH-5.0 messages, more information about ITCH-5...
std::pair< char const *, std::size_t > add_order()
Definition: data.cpp:33
char_list_field< u 'S', u 'B'> buy_sell_indicator_t
Represent the &#39;Buy/Sell Indicator&#39; field on several messages.
std::chrono::nanoseconds expected_ts()
Return the expected timestamp for all the test messages.
Definition: data.cpp:19
BOOST_AUTO_TEST_CASE(decode_add_order_message)