JayBeams  0.1
Another project to have fun coding.
ut_stock_trading_action_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::stock_trading_action_message decoder works
8  * as expected.
9  */
10 BOOST_AUTO_TEST_CASE(decode_stock_trading_action_message) {
11  using namespace jb::itch5;
12  using namespace std::chrono;
13 
16 
17  auto x =
18  decoder<true, stock_trading_action_message>::r(buf.second, buf.first, 0);
19  BOOST_CHECK_EQUAL(
20  x.header.message_type, stock_trading_action_message::message_type);
21  BOOST_CHECK_EQUAL(x.header.stock_locate, 0);
22  BOOST_CHECK_EQUAL(x.header.tracking_number, 1);
23  BOOST_CHECK_EQUAL(x.header.timestamp.ts.count(), expected_ts.count());
24  BOOST_CHECK_EQUAL(x.stock, "HSART");
25  BOOST_CHECK_EQUAL(x.trading_state, u'T');
26  BOOST_CHECK_EQUAL(x.reason, u8"MWC1");
27 
28  x = decoder<false, stock_trading_action_message>::r(buf.second, buf.first, 0);
29  BOOST_CHECK_EQUAL(
30  x.header.message_type, stock_trading_action_message::message_type);
31  BOOST_CHECK_EQUAL(x.header.stock_locate, 0);
32  BOOST_CHECK_EQUAL(x.header.tracking_number, 1);
33  BOOST_CHECK_EQUAL(x.header.timestamp.ts.count(), expected_ts.count());
34  BOOST_CHECK_EQUAL(x.stock, "HSART");
35  BOOST_CHECK_EQUAL(x.trading_state, u'T');
36  BOOST_CHECK_EQUAL(x.reason, u8"MWC1");
37 }
38 
39 /**
40  * @test Verify that jb::itch5::stock_trading_action_message iostream
41  * operator works as expected.
42  */
43 BOOST_AUTO_TEST_CASE(stream_stock_trading_action_message) {
44  using namespace std::chrono;
45  using namespace jb::itch5;
46 
48  auto tmp =
49  decoder<false, stock_trading_action_message>::r(buf.second, buf.first, 0);
50  std::ostringstream os;
51  os << tmp;
52  BOOST_CHECK_EQUAL(
53  os.str(), "message_type=H,stock_locate=0"
54  ",tracking_number=1,timestamp=113231.123456789"
55  ",stock=HSART"
56  ",trading_state=T"
57  ",reserved=0"
58  ",reason=MWC1");
59 }
60 
61 /**
62  * @test Verify that trading_state_t works as expected.
63  */
64 BOOST_AUTO_TEST_CASE(simple_trading_state) {
65  using namespace jb::itch5;
66  BOOST_CHECK_NO_THROW(trading_state_t(u'H'));
67  BOOST_CHECK_NO_THROW(trading_state_t(u'P'));
68  BOOST_CHECK_NO_THROW(trading_state_t(u'Q'));
69  BOOST_CHECK_NO_THROW(trading_state_t(u'T'));
70  BOOST_CHECK_THROW(trading_state_t(u' '), std::runtime_error);
71 }
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...
char_list_field< u 'H', u 'P', u 'Q', u 'T'> trading_state_t
Represent the &#39;Trading State&#39; field on a &#39;Stock Trading Action&#39; message.
std::chrono::nanoseconds expected_ts()
Return the expected timestamp for all the test messages.
Definition: data.cpp:19
BOOST_AUTO_TEST_CASE(decode_stock_trading_action_message)
std::pair< char const *, std::size_t > stock_trading_action()
Definition: data.cpp:250