JayBeams  0.1
Another project to have fun coding.
ut_char_list_field.cpp
Go to the documentation of this file.
2 
3 #include <boost/test/unit_test.hpp>
4 
5 /**
6  * Define types used in the tests.
7  */
8 namespace {
10 } // anonymous namespace
11 
12 /**
13  * @test Verify that jb::itch5::decoder works for jb::itch5::char_list_field.
14  */
15 BOOST_AUTO_TEST_CASE(decode_char_list_field) {
16  using jb::itch5::decoder;
17 
18  char buffer[32] = {u'Y', u'N', u' ', u'A', u'B'};
19 
20  auto actual = decoder<true, tested>::r(16, buffer, 0);
21  BOOST_CHECK_EQUAL(actual, u'Y');
22 
23  actual = decoder<false, tested>::r(16, buffer, 0);
24  BOOST_CHECK_EQUAL(actual, u'Y');
25 
26  actual = decoder<true, tested>::r(16, buffer, 1);
27  BOOST_CHECK_EQUAL(actual, u'N');
28  actual = decoder<false, tested>::r(16, buffer, 1);
29  BOOST_CHECK_EQUAL(actual, u'N');
30 
31  BOOST_CHECK_THROW(
32  (decoder<true, tested>::r(16, buffer, 3)), std::runtime_error);
33  BOOST_CHECK_NO_THROW((decoder<false, tested>::r(16, buffer, 3)));
34 
35  BOOST_CHECK_THROW(
36  (decoder<true, tested>::r(16, buffer, 16)), std::runtime_error);
37  BOOST_CHECK_NO_THROW((decoder<false, tested>::r(16, buffer, 16)));
38 }
39 
40 /**
41  * @test Verify that jb::itch5::char_list_field iostream operator
42  * works as expected.
43  */
44 BOOST_AUTO_TEST_CASE(stream_char_list_field) {
45  using jb::itch5::decoder;
46 
47  {
48  std::ostringstream os;
49  os << tested(u'Y');
50  BOOST_CHECK_EQUAL(os.str(), "Y");
51  }
52 
53  {
54  char buffer[32] = {u'\0'};
55  auto actual = decoder<false, tested>::r(16, buffer, 0);
56 
57  std::ostringstream os;
58  os << actual;
59  BOOST_CHECK_EQUAL(os.str(), ".(0)");
60  }
61 
62  {
63  char buffer[32] = {u'\n'};
64  auto actual = decoder<false, tested>::r(16, buffer, 0);
65 
66  std::ostringstream os;
67  os << actual;
68  BOOST_CHECK_EQUAL(os.str(), ".(10)");
69  }
70 }
Define the interface to decode ITCH-5.0 messages and message fields.
Definition: decoder.hpp:24
BOOST_AUTO_TEST_CASE(decode_char_list_field)