JayBeams  0.1
Another project to have fun coding.
ut_expanded_add_order_message.cpp
Go to the documentation of this file.
2 
3 #include <boost/test/unit_test.hpp>
4 #include <type_traits>
5 
6 /**
7  * @test Verify that jb::pitch2::expanded_add_order_message works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(expanded_add_order_message_basic) {
10  using namespace jb::pitch2;
11  // This test fails, but the class has exactly the right size and
12  // padding, so I do not care ...
13  // BOOST_CHECK_EQUAL(true, std::is_pod<expanded_add_order_message>::value);
14  BOOST_CHECK_EQUAL(sizeof(expanded_add_order_message), std::size_t(40));
15 
16  char const buf[] = u8"\x28" // Length (40)
17  "\x2F" // Message Type (47)
18  "\x18\xD2\x06\x00" // Time Offset (447,000)
19  "\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
20  "\x42" // Side Indicator (66 'B' Buy)
21  "\x20\x4E\x00\x00" // Quantity (20,000)
22  "\x5A\x56\x5A\x5A\x54\x20\x20\x20" // Symbol (ZVZZT)
23  "\x5A\x23\x00\x00\x00\x00\x00\x00" // Price ($0.9050)
24  "\x01" // Add Flags (Bit 0 on -> Displayed)
25  "\x4D\x50\x49\x44" // Participant ID (MPID)
26  ;
28  BOOST_CHECK_EQUAL(sizeof(buf) - 1, sizeof(msg));
29  BOOST_CHECK_EQUAL(
30  reinterpret_cast<char*>(&msg.participant_id) -
31  reinterpret_cast<char*>(&msg),
32  std::size_t(36));
33 
34  std::memcpy(&msg, buf, sizeof(msg));
35  BOOST_CHECK_EQUAL(int(msg.length.value()), 40);
36  BOOST_CHECK_EQUAL(int(msg.message_type.value()), 47);
37  BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
38  BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
39  BOOST_CHECK_EQUAL(msg.side_indicator.value(), 0x42);
40  BOOST_CHECK_EQUAL(msg.quantity.value(), 20000);
41  BOOST_CHECK_EQUAL(msg.symbol, jb::fixed_string<8>("ZVZZT"));
42  BOOST_CHECK_EQUAL(msg.price.value(), 9050);
43  BOOST_CHECK_EQUAL(msg.add_flags.value(), 0x01);
44  BOOST_CHECK_EQUAL(msg.participant_id, jb::fixed_string<4>("MPID"));
45 
46  std::ostringstream os;
47  os << msg;
48  BOOST_CHECK_EQUAL(
49  os.str(),
50  std::string("length=40,message_type=47,time_offset=447000,"
51  "order_id=800891482924597253,side_indicator=B,"
52  "quantity=20000,symbol=ZVZZT ,price=9050,add_flags=1,"
53  "participant_id=MPID"));
54 }
BOOST_AUTO_TEST_CASE(expanded_add_order_message_basic)
boost::endian::little_uint8_buf_t side_indicator
boost::endian::little_uint32_buf_t time_offset
Represent the &#39;Add Order&#39; message in the PITCH-2.X protocol.
boost::endian::little_uint8_buf_t message_type
boost::endian::little_uint8_buf_t length
boost::endian::little_uint64_buf_t order_id
boost::endian::little_uint8_buf_t add_flags