JayBeams  0.1
Another project to have fun coding.
ut_system_event_message.cpp
Go to the documentation of this file.
3 
4 #include <boost/test/unit_test.hpp>
5 
6 /**
7  * @test Verify that jb::itch5::system_event_message decoder works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(decode_system_event_message) {
11  using jb::itch5::decoder;
12  using namespace std::chrono;
13 
16 
17  auto x = decoder<true, system_event_message>::r(buf.second, buf.first, 0);
18  BOOST_CHECK_EQUAL(x.header.message_type, system_event_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.event_code, u'O');
23 
24  x = decoder<false, system_event_message>::r(buf.second, buf.first, 0);
25  BOOST_CHECK_EQUAL(x.header.message_type, system_event_message::message_type);
26  BOOST_CHECK_EQUAL(x.header.stock_locate, 0);
27  BOOST_CHECK_EQUAL(x.header.tracking_number, 1);
28  BOOST_CHECK_EQUAL(x.header.timestamp.ts.count(), expected_ts.count());
29  BOOST_CHECK_EQUAL(x.event_code, u'O');
30 }
31 
32 /**
33  * @test Verify that jb::itch5::system_event_message iostream operator works
34  * as expected.
35  */
36 BOOST_AUTO_TEST_CASE(stream_system_event_message) {
37  using namespace std::chrono;
38  using namespace jb::itch5;
39 
40  auto ts = timestamp{duration_cast<nanoseconds>(
41  hours(11) + minutes(32) + seconds(31) + nanoseconds(123456789L))};
42 
43  system_event_message tmp{message_header{u' ', 0, 1, ts}, event_code_t(u'O')};
44  std::ostringstream os;
45  os << tmp;
46  BOOST_CHECK_EQUAL(
47  os.str(), "message_type= ,stock_locate=0,"
48  "tracking_number=1,timestamp=113231.123456789"
49  ",event_code=O");
50 }
51 
52 /**
53  * @test Verify that event_code_t works as expected.
54  */
55 BOOST_AUTO_TEST_CASE(simple_event_code) {
56  using namespace jb::itch5;
57  BOOST_CHECK_NO_THROW(event_code_t(u'O'));
58  BOOST_CHECK_NO_THROW(event_code_t(u'S'));
59  BOOST_CHECK_NO_THROW(event_code_t(u'Q'));
60  BOOST_CHECK_NO_THROW(event_code_t(u'M'));
61  BOOST_CHECK_NO_THROW(event_code_t(u'E'));
62  BOOST_CHECK_NO_THROW(event_code_t(u'C'));
63  BOOST_CHECK_THROW(event_code_t(u'*'), std::runtime_error);
64 }
Define the header common to all ITCH 5.0 messages.
Contains classes and functions to parse NASDAQ ITCH-5.0 messages, more information about ITCH-5...
BOOST_AUTO_TEST_CASE(decode_system_event_message)
std::pair< char const *, std::size_t > system_event()
Definition: data.cpp:262
Define the interface to decode ITCH-5.0 messages and message fields.
Definition: decoder.hpp:24
Represent a ITCH-5.0 timestamp.
Definition: timestamp.hpp:17
std::chrono::nanoseconds expected_ts()
Return the expected timestamp for all the test messages.
Definition: data.cpp:19
char_list_field< u 'O', u 'S', u 'Q', u 'M', u 'E', u 'C'> event_code_t
Represent the &#39;Event Code&#39; field on a &#39;System Event Message&#39;.
Represent a &#39;System Event Message&#39; in the ITCH-5.0 protocol.