3 #include <boost/test/unit_test.hpp> 13 int values[] = {10, 20, 30, 40, 15, 25};
14 std::uint64_t expected = 0;
15 for (
int i = 0; i != 6; ++i) {
16 buffer[i] = values[i];
17 expected = expected * 256 + values[i];
20 auto actual = decoder<true, timestamp>::r(16, buffer, 0);
21 BOOST_CHECK_EQUAL(actual.ts.count(), expected);
23 actual = decoder<false, timestamp>::r(16, buffer, 0);
24 BOOST_CHECK_EQUAL(actual.ts.count(), expected);
28 std::memset(buffer, 0,
sizeof(buffer));
29 BOOST_CHECK_NO_THROW((decoder<true, timestamp>::r(16, buffer, 2)));
30 BOOST_CHECK_NO_THROW((decoder<true, timestamp>::r(16, buffer, 10)));
32 (decoder<true, timestamp>::r(16, buffer, 11)), std::runtime_error);
33 BOOST_CHECK_NO_THROW((decoder<false, timestamp>::r(16, buffer, 11)));
44 int values[] = {255, 255, 255, 255, 255, 255};
45 for (
int i = 0; i != 6; ++i) {
46 buffer[i] = values[i];
50 (decoder<true, timestamp>::r(16, buffer, 0)), std::runtime_error);
51 BOOST_CHECK_NO_THROW((decoder<false, timestamp>::r(16, buffer, 0)));
58 using namespace std::chrono;
63 (duration_cast<nanoseconds>(hours(7)) +
64 duration_cast<nanoseconds>(minutes(8)) +
65 duration_cast<nanoseconds>(seconds(9)) + nanoseconds(20));
66 std::ostringstream os;
68 BOOST_CHECK_EQUAL(os.str(),
"070809.000000020");
73 (duration_cast<nanoseconds>(hours(9)) +
74 duration_cast<nanoseconds>(minutes(30)) +
75 duration_cast<nanoseconds>(seconds(0)) + nanoseconds(0));
76 std::ostringstream os;
78 BOOST_CHECK_EQUAL(os.str(),
"093000.000000000");
83 (duration_cast<nanoseconds>(hours(15)) +
84 duration_cast<nanoseconds>(minutes(59)) +
85 duration_cast<nanoseconds>(seconds(59)) + nanoseconds(999999999));
86 std::ostringstream os;
88 BOOST_CHECK_EQUAL(os.str(),
"155959.999999999");
93 (duration_cast<nanoseconds>(hours(16)) +
94 duration_cast<nanoseconds>(minutes(0)) +
95 duration_cast<nanoseconds>(seconds(0)) + nanoseconds(0));
96 std::ostringstream os;
98 BOOST_CHECK_EQUAL(os.str(),
"160000.000000000");
111 using namespace std::chrono;
112 timestamp expected{hours(9) + minutes(31) + seconds(10) + nanoseconds(1234)};
115 encoder<true, timestamp>::w(16, buffer, 0, expected);
116 auto actual = decoder<true, timestamp>::r(16, buffer, 0);
117 BOOST_CHECK_EQUAL(actual.ts.count(), expected.ts.count());
119 encoder<false, timestamp>::w(16, buffer, 0, expected);
120 actual = decoder<false, timestamp>::r(16, buffer, 0);
121 BOOST_CHECK_EQUAL(actual.ts.count(), expected.ts.count());
123 timestamp ts{seconds(100)};
124 BOOST_CHECK_NO_THROW((encoder<true, timestamp>::w(16, buffer, 2, ts)));
125 BOOST_CHECK_NO_THROW((encoder<true, timestamp>::w(16, buffer, 10, ts)));
127 (encoder<true, timestamp>::w(16, buffer, 11, ts)), std::runtime_error);
128 BOOST_CHECK_NO_THROW((encoder<false, timestamp>::w(16, buffer, 11, ts)));
140 timestamp ts{std::chrono::hours(48)};
142 (encoder<true, timestamp>::w(16, buffer, 0, ts)), std::runtime_error);
143 BOOST_CHECK_NO_THROW((encoder<false, timestamp>::w(16, buffer, 0, ts)));
BOOST_AUTO_TEST_CASE(decode_timestamp)
TODO(#19) all this code should be replaced with Boost.Endian.
Define the interface to decode ITCH-5.0 messages and message fields.
Represent a ITCH-5.0 timestamp.