JayBeams  0.1
Another project to have fun coding.
ut_modify_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::modify_long_message works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(modify_message_long_basic) {
10  using namespace jb::pitch2;
11  BOOST_CHECK_EQUAL(true, std::is_pod<modify_long_message>::value);
12  BOOST_CHECK_EQUAL(sizeof(modify_long_message), std::size_t(27));
13 
14  char const buf[] = u8"\x1B" // Length (27)
15  "\x27" // Message Type (39)
16  "\x18\xD2\x06\x00" // Time Offset (447,000 ns)
17  "\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
18  "\xF8\x24\x01\x00" // Quantity (75,000)
19  "\xE8\xA3\x0F\x00\x00\x00\x00\x00" // Price ($102.50)
20  "\x03" // Modify Flags
21  ;
23  BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg));
24  std::memcpy(&msg, buf, sizeof(msg));
25  BOOST_CHECK_EQUAL(int(msg.length.value()), 27);
26  BOOST_CHECK_EQUAL(int(msg.message_type.value()), 39);
27  BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
28  BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
29  BOOST_CHECK_EQUAL(msg.quantity.value(), 75000);
30  BOOST_CHECK_EQUAL(msg.price.value(), 1025000);
31  BOOST_CHECK_EQUAL(msg.modify_flags.value(), 0x03);
32 
33  std::ostringstream os;
34  os << msg;
35  BOOST_CHECK_EQUAL(
36  os.str(), std::string("length=27,message_type=39,time_offset=447000"
37  ",order_id=800891482924597253,quantity=75000"
38  ",price=1025000,modify_flags=3"));
39 }
40 
41 /**
42  * @test Verify that jb::pitch2::modify_short_message works as expected.
43  */
44 BOOST_AUTO_TEST_CASE(modify_message_short_basic) {
45  using namespace jb::pitch2;
46  BOOST_CHECK_EQUAL(true, std::is_pod<modify_short_message>::value);
47  BOOST_CHECK_EQUAL(sizeof(modify_short_message), std::size_t(19));
48 
49  char const buf[] = u8"\x13" // Length (19)
50  "\x28" // Message Type (40)
51  "\x18\xD2\x06\x00" // Time Offset (447,000 ns)
52  "\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
53  "\x64\x00" // Quantity (100)
54  "\x0A\x28" // Price ($102.50)
55  "\x03" // Modify Flags
56  ;
58  BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg));
59  std::memcpy(&msg, buf, sizeof(msg));
60  BOOST_CHECK_EQUAL(int(msg.length.value()), 19);
61  BOOST_CHECK_EQUAL(int(msg.message_type.value()), 40);
62  BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
63  BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
64  BOOST_CHECK_EQUAL(msg.quantity.value(), 100);
65  BOOST_CHECK_EQUAL(msg.price.value(), 10250);
66  BOOST_CHECK_EQUAL(msg.modify_flags.value(), 0x03);
67 
68  std::ostringstream os;
69  os << msg;
70  BOOST_CHECK_EQUAL(
71  os.str(), std::string("length=19,message_type=40,time_offset=447000"
72  ",order_id=800891482924597253,quantity=100"
73  ",price=10250,modify_flags=3"));
74 }
boost::endian::little_uint32_buf_t time_offset
BOOST_AUTO_TEST_CASE(modify_message_long_basic)
boost::endian::little_uint8_buf_t modify_flags
Represent the &#39;Modify (short)&#39; messages in the PITCH-2.X protocol.
boost::endian::little_uint8_buf_t length
boost::endian::little_uint8_buf_t message_type
boost::endian::little_uint64_buf_t order_id
Represent the &#39;Modify (long)&#39; messages in the PITCH-2.X protocol.