3 #include <boost/test/unit_test.hpp> 20 auto actual = decoder<true, std::uint8_t>::r(16, buffer, 1);
21 BOOST_CHECK_EQUAL(actual, 20);
23 actual = decoder<false, std::uint8_t>::r(16, buffer, 3);
24 BOOST_CHECK_EQUAL(actual, 25);
26 BOOST_CHECK_NO_THROW((decoder<true, std::uint8_t>::r(16, buffer, 0)));
27 BOOST_CHECK_NO_THROW((decoder<true, std::uint8_t>::r(16, buffer, 8)));
28 BOOST_CHECK_NO_THROW((decoder<true, std::uint8_t>::r(16, buffer, 15)));
30 (decoder<true, std::uint8_t>::r(16, buffer, 16)), std::runtime_error);
31 BOOST_CHECK_NO_THROW((decoder<false, std::uint8_t>::r(16, buffer, 16)));
43 auto actual = decoder<true, std::uint16_t>::r(16, buffer, 0);
44 BOOST_CHECK_EQUAL(actual, 10 * 256 + 20);
46 actual = decoder<false, std::uint16_t>::r(16, buffer, 0);
47 BOOST_CHECK_EQUAL(actual, 10 * 256 + 20);
49 BOOST_CHECK_NO_THROW((decoder<true, std::uint16_t>::r(16, buffer, 0)));
50 BOOST_CHECK_NO_THROW((decoder<true, std::uint16_t>::r(16, buffer, 8)));
51 BOOST_CHECK_NO_THROW((decoder<true, std::uint16_t>::r(16, buffer, 14)));
53 (decoder<true, std::uint16_t>::r(16, buffer, 15)), std::runtime_error);
54 BOOST_CHECK_NO_THROW((decoder<false, std::uint16_t>::r(16, buffer, 15)));
68 auto actual = decoder<true, std::uint32_t>::r(16, buffer, 0);
69 BOOST_CHECK_EQUAL(actual, ((10 * 256 + 20) * 256 + 30) * 256 + 40);
71 actual = decoder<false, std::uint32_t>::r(16, buffer, 0);
72 BOOST_CHECK_EQUAL(actual, ((10 * 256 + 20) * 256 + 30) * 256 + 40);
74 BOOST_CHECK_NO_THROW((decoder<true, std::uint32_t>::r(16, buffer, 0)));
75 BOOST_CHECK_NO_THROW((decoder<true, std::uint32_t>::r(16, buffer, 8)));
76 BOOST_CHECK_NO_THROW((decoder<true, std::uint32_t>::r(16, buffer, 12)));
78 (decoder<true, std::uint32_t>::r(16, buffer, 13)), std::runtime_error);
79 BOOST_CHECK_NO_THROW((decoder<false, std::uint32_t>::r(16, buffer, 13)));
88 int values[] = {10, 20, 30, 40, 15, 25, 35, 45};
89 std::uint64_t expected = 0;
90 for (
int i = 0; i != 8; ++i) {
91 buffer[i] = values[i];
92 expected = expected * 256 + values[i];
95 auto actual = decoder<true, std::uint64_t>::r(16, buffer, 0);
96 BOOST_CHECK_EQUAL(actual, expected);
98 actual = decoder<false, std::uint64_t>::r(16, buffer, 0);
99 BOOST_CHECK_EQUAL(actual, expected);
101 BOOST_CHECK_NO_THROW((decoder<true, std::uint64_t>::r(16, buffer, 2)));
102 BOOST_CHECK_NO_THROW((decoder<true, std::uint64_t>::r(16, buffer, 7)));
104 (decoder<true, std::uint64_t>::r(16, buffer, 9)), std::runtime_error);
105 BOOST_CHECK_NO_THROW((decoder<false, std::uint64_t>::r(16, buffer, 9)));
BOOST_AUTO_TEST_CASE(decode_uint8)
Define the interface to decode ITCH-5.0 messages and message fields.