JayBeams  0.1
Another project to have fun coding.
ut_message_header.cpp
Go to the documentation of this file.
3 
4 #include <boost/test/unit_test.hpp>
5 
6 /**
7  * @test Verify that jb::itch5::message_header decoder works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(decode_message_header) {
11  using jb::itch5::decoder;
12  using namespace std::chrono;
13 
16 
17  auto x = decoder<true, message_header>::r(buf.second, buf.first, 0);
18  BOOST_CHECK_EQUAL(x.message_type, u' ');
19  BOOST_CHECK_EQUAL(x.stock_locate, 0);
20  BOOST_CHECK_EQUAL(x.tracking_number, 1);
21  BOOST_CHECK_EQUAL(x.timestamp.ts.count(), expected_ts.count());
22 
23  x = decoder<false, message_header>::r(buf.second, buf.first, 0);
24  BOOST_CHECK_EQUAL(x.message_type, u' ');
25  BOOST_CHECK_EQUAL(x.stock_locate, 0);
26  BOOST_CHECK_EQUAL(x.tracking_number, 1);
27  BOOST_CHECK_EQUAL(x.timestamp.ts.count(), expected_ts.count());
28 }
29 
30 /**
31  * @test Verify that jb::itch5::message_header iostream operator works
32  * as expected.
33  */
34 BOOST_AUTO_TEST_CASE(stream_message_header) {
35  using namespace std::chrono;
37 
38  auto ts = jb::itch5::timestamp{duration_cast<nanoseconds>(
39  hours(11) + minutes(32) + seconds(31) + nanoseconds(123456789L))};
40 
41  {
42  message_header tmp{u' ', 0, 1, ts};
43  std::ostringstream os;
44  os << tmp;
45  BOOST_CHECK_EQUAL(
46  os.str(), "message_type= ,stock_locate=0,"
47  "tracking_number=1,timestamp=113231.123456789");
48  }
49 
50  {
51  message_header tmp{255, 0, 1, ts};
52  std::ostringstream os;
53  os << tmp;
54  BOOST_CHECK_EQUAL(
55  os.str(), "message_type=.(255),stock_locate=0,"
56  "tracking_number=1,timestamp=113231.123456789");
57  }
58 }
BOOST_AUTO_TEST_CASE(decode_message_header)
std::pair< char const *, std::size_t > message_header()
Definition: data.cpp:25
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