JayBeams  0.1
Another project to have fun coding.
ut_price_field.cpp
Go to the documentation of this file.
2 
3 #include <boost/test/unit_test.hpp>
4 
5 /**
6  * @test Verify that jb::itch5::decoder for jb::itch5::price_field
7  * works as expected.
8  */
9 BOOST_AUTO_TEST_CASE(decode_price_field_4) {
11  using jb::itch5::decoder;
12 
13  char buffer[32];
14  std::memset(buffer, 0, sizeof(buffer));
15  std::memcpy(buffer, "\x00\x12\xD6\x87", 4);
16  auto actual = decoder<true, tested>::r(16, buffer, 0);
17  BOOST_CHECK_EQUAL(actual.as_integer(), 1234567);
18  BOOST_CHECK_CLOSE(actual.as_double(), 123.4567, 0.0001);
19 
20  actual = decoder<false, tested>::r(16, buffer, 0);
21  BOOST_CHECK_EQUAL(actual.as_integer(), 1234567);
22  BOOST_CHECK_CLOSE(actual.as_double(), 123.4567, 0.0001);
23 
24  std::memset(buffer, 0, sizeof(buffer));
25  std::memcpy(buffer, "\x0D\xFB\x38\xD2", 4);
26  actual = decoder<true, tested>::r(16, buffer, 0);
27  BOOST_CHECK_EQUAL(actual.as_integer(), 234567890);
28  BOOST_CHECK_CLOSE(actual.as_double(), 23456.7890, 0.0001);
29 
30  actual = decoder<false, tested>::r(16, buffer, 0);
31  BOOST_CHECK_EQUAL(actual.as_integer(), 234567890);
32  BOOST_CHECK_CLOSE(actual.as_double(), 23456.7890, 0.0001);
33 }
34 
35 /**
36  * @test Verify that jb::itch5::decoder for jb::itch5::price_field
37  * works as expected.
38  */
39 BOOST_AUTO_TEST_CASE(decode_price_field_8) {
41  using jb::itch5::decoder;
42 
43  char buffer[32];
44  std::memset(buffer, 0, sizeof(buffer));
45  std::memcpy(buffer, "\x00\x04\x62\xD5\x37\xE7\xEF\x4E", 8);
46  auto actual = decoder<true, tested>::r(16, buffer, 0);
47  BOOST_CHECK_EQUAL(actual.as_integer(), 1234567812345678ULL);
48  BOOST_CHECK_CLOSE(actual.as_double(), 12345678.12345678, 0.0001);
49 
50  actual = decoder<false, tested>::r(16, buffer, 0);
51  BOOST_CHECK_EQUAL(actual.as_integer(), 1234567812345678ULL);
52  BOOST_CHECK_CLOSE(actual.as_double(), 12345678.12345678, 0.0001);
53 }
54 
55 /**
56  * @test Verify that jb::itch5::price_field iostream operator
57  * works as expected.
58  */
59 BOOST_AUTO_TEST_CASE(stream_price_field_4) {
61  using jb::itch5::decoder;
62  char buffer[32];
63 
64  std::memset(buffer, 0, sizeof(buffer));
65  std::memcpy(buffer, "\x00\xBC\x4B\x9B", 4);
66  auto actual = decoder<true, tested>::r(16, buffer, 0);
67 
68  std::ostringstream os;
69  os << actual;
70  BOOST_CHECK_EQUAL(os.str(), "1234.0123");
71 }
72 
73 /**
74  * @test Verify that jb::itch5::price_field iostream operator
75  * works as expected.
76  */
77 BOOST_AUTO_TEST_CASE(stream_price_field_8) {
79  using jb::itch5::decoder;
80  char buffer[32];
81 
82  std::memset(buffer, 0, sizeof(buffer));
83  std::memcpy(buffer, "\x00\x2B\xDC\x54\x5D\x58\xA3\xE0", 8);
84  auto actual = decoder<true, tested>::r(16, buffer, 0);
85 
86  std::ostringstream os;
87  os << actual;
88  BOOST_CHECK_EQUAL(os.str(), "123456789.00012000");
89 }
90 
91 /**
92  * @test Verify addition and addition assignment operator work as expected.
93  */
94 BOOST_AUTO_TEST_CASE(addition_operators_field_4) {
95  jb::itch5::price4_t px_1(5000);
96  jb::itch5::price4_t px_2(10000);
97  jb::itch5::price4_t px_res;
98  px_res += px_1;
99  BOOST_CHECK_EQUAL(px_res, jb::itch5::price4_t(5000));
100  px_res = px_1 + px_2;
101  BOOST_CHECK_EQUAL(px_res, jb::itch5::price4_t(15000));
102 }
103 
104 /**
105  * @test Verify addition and addition assignment operator work as expected.
106  */
107 BOOST_AUTO_TEST_CASE(addition_operators_field_8) {
108  jb::itch5::price8_t px_1(5000);
109  jb::itch5::price8_t px_2(10000);
110  jb::itch5::price8_t px_res;
111  px_res += px_1;
112  BOOST_CHECK_EQUAL(px_res, jb::itch5::price8_t(5000));
113  px_res = px_1 + px_2;
114  BOOST_CHECK_EQUAL(px_res, jb::itch5::price8_t(15000));
115 }
Define the interface to decode ITCH-5.0 messages and message fields.
Definition: decoder.hpp:24
BOOST_AUTO_TEST_CASE(decode_price_field_4)