JayBeams  0.1
Another project to have fun coding.
ut_process_buffer_mlist.cpp
Go to the documentation of this file.
5 
7 
8 #include <jb/gmock/init.hpp>
9 #include <boost/test/unit_test.hpp>
10 
11 namespace {
12 
13 class mock_message_handler {
14 public:
15  mock_message_handler() {
16  }
17 
18  typedef int time_point;
19 
20  MOCK_METHOD0(now, int());
21  MOCK_METHOD2(
22  handle_unknown, void(int const&, jb::itch5::unknown_message const&));
23  MOCK_METHOD4(
24  handle_message,
25  void(
26  int const&, std::uint64_t msgcnt, std::size_t msgoffset,
28  MOCK_METHOD4(
29  handle_message,
30  void(
31  int const&, std::uint64_t msgcnt, std::size_t msgoffset,
33  MOCK_METHOD4(
34  handle_message,
35  void(
36  int const&, std::uint64_t msgcnt, std::size_t msgoffset,
38 };
39 
40 } // anonymous namespace
41 
42 /**
43  * Verify that jb::itch5::process_buffer_mlist<> works for empty lists.
44  */
45 BOOST_AUTO_TEST_CASE(process_buffer_mlist_empty) {
46  mock_message_handler handler;
47  using namespace ::testing;
48  EXPECT_CALL(handler, handle_unknown(Eq(42), _)).Times(1);
49 
52  handler, 42, 2, 100, p.first, p.second);
53 }
54 
55 /**
56  * Verify that jb::itch5::process_buffer_mlist<> works for a list with
57  * a single element.
58  */
59 BOOST_AUTO_TEST_CASE(process_buffer_mlist_single) {
60  mock_message_handler handler;
61  using namespace ::testing;
62 
63  {
65  EXPECT_CALL(
66  handler,
67  handle_message(42, _, _, An<jb::itch5::system_event_message const&>()))
68  .Times(1);
70  mock_message_handler, jb::itch5::system_event_message>::
71  process(handler, 42, 2, 100, p.first, p.second);
72  }
73 
74  {
76  EXPECT_CALL(handler, handle_unknown(4242, _)).Times(1);
78  mock_message_handler, jb::itch5::system_event_message>::
79  process(handler, 4242, 3, 200, p.first, p.second);
80  }
81 }
82 
83 /**
84  * Verify that jb::itch5::process_buffer_mlist<> works for a list with
85  * 3 elements.
86  */
87 BOOST_AUTO_TEST_CASE(process_buffer_mlist_3) {
88  mock_message_handler handler;
89  using namespace ::testing;
90 
92  mock_message_handler, jb::itch5::system_event_message,
94  tested;
95 
96  {
97  EXPECT_CALL(
98  handler,
99  handle_message(42, _, _, An<jb::itch5::system_event_message const&>()))
100  .Times(1);
102  tested::process(handler, 42, 2, 100, p.first, p.second);
103  }
104  {
105  EXPECT_CALL(
106  handler, handle_message(
107  43, _, _, An<jb::itch5::stock_directory_message const&>()))
108  .Times(1);
110  tested::process(handler, 43, 3, 120, p.first, p.second);
111  }
112  {
113  EXPECT_CALL(
114  handler,
115  handle_message(44, _, _, An<jb::itch5::add_order_message const&>()))
116  .Times(1);
118  tested::process(handler, 44, 4, 140, p.first, p.second);
119  }
120 }
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
std::pair< char const *, std::size_t > add_order()
Definition: data.cpp:33
std::pair< char const *, std::size_t > system_event()
Definition: data.cpp:262
std::pair< char const *, std::size_t > stock_directory()
Definition: data.cpp:228
Initialize GMock to work with Boost.Test.
Process a buffer with a single message: parse it and call the handler.
BOOST_AUTO_TEST_CASE(process_buffer_mlist_empty)
Verify that jb::itch5::process_buffer_mlist<> works for empty lists.
Represent a &#39;Stock Directory&#39; message in the ITCH-5.0 protocol.
Represent an &#39;Add Order&#39; message in the ITCH-5.0 protocol.
Represent a &#39;System Event Message&#39; in the ITCH-5.0 protocol.