JayBeams  0.1
Another project to have fun coding.
ut_reduce_size_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::reduce_size_long_message works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(reduce_size_message_long_basic) {
10  using namespace jb::pitch2;
11  BOOST_CHECK_EQUAL(true, std::is_pod<reduce_size_long_message>::value);
12  BOOST_CHECK_EQUAL(sizeof(reduce_size_long_message), std::size_t(18));
13 
14  char const buf[] = u8"\x12" // Length (18)
15  "\x25" // Message Type (0x25)
16  "\x18\xD2\x06\x00" // Time Offset (447,000 ns)
17  "\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
18  "\x64\x00\x00\x00" // Canceled Quantity (100)
19  ;
21  BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg));
22  std::memcpy(&msg, buf, sizeof(msg));
23  BOOST_CHECK_EQUAL(int(msg.length.value()), 18);
24  BOOST_CHECK_EQUAL(int(msg.message_type.value()), 0x25);
25  BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
26  BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
27  BOOST_CHECK_EQUAL(msg.canceled_quantity.value(), 100);
28 
29  std::ostringstream os;
30  os << msg;
31  BOOST_CHECK_EQUAL(
32  os.str(),
33  std::string("length=18,message_type=37,time_offset=447000"
34  ",order_id=800891482924597253,canceled_quantity=100"));
35 }
36 
37 /**
38  * @test Verify that jb::pitch2::reduce_size_short_message works as expected.
39  */
40 BOOST_AUTO_TEST_CASE(reduce_size_message_short_basic) {
41  using namespace jb::pitch2;
42  BOOST_CHECK_EQUAL(true, std::is_pod<reduce_size_short_message>::value);
43  BOOST_CHECK_EQUAL(sizeof(reduce_size_short_message), std::size_t(16));
44 
45  char const buf[] = u8"\x10" // Length (16)
46  "\x26" // Message Type (0x26)
47  "\x18\xD2\x06\x00" // Time Offset (447,000 ns)
48  "\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
49  "\x64\x00" // Canceled Quantity (100)
50  ;
52  BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg));
53  std::memcpy(&msg, buf, sizeof(msg));
54  BOOST_CHECK_EQUAL(int(msg.length.value()), 16);
55  BOOST_CHECK_EQUAL(int(msg.message_type.value()), 0x26);
56  BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
57  BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
58  BOOST_CHECK_EQUAL(msg.canceled_quantity.value(), 100);
59 
60  std::ostringstream os;
61  os << msg;
62  BOOST_CHECK_EQUAL(
63  os.str(),
64  std::string("length=16,message_type=38,time_offset=447000"
65  ",order_id=800891482924597253,canceled_quantity=100"));
66 }
boost::endian::little_uint64_buf_t order_id
boost::endian::little_uint8_buf_t length
Represent the &#39;Reduce Size (long)&#39; messages in the PITCH-2.X protocol.
Represent the &#39;Reduce Size (short)&#39; messages in the PITCH-2.X protocol.
boost::endian::little_uint8_buf_t message_type
BOOST_AUTO_TEST_CASE(reduce_size_message_long_basic)
boost::endian::little_uint32_buf_t time_offset