5 #include <boost/array.hpp> 6 #include <boost/asio.hpp> 7 #include <boost/test/unit_test.hpp> 17 std::vector<std::vector<char>> packets;
19 template <
typename const_buffer_sequence>
20 void operator()(const_buffer_sequence
const& buffers) {
21 std::vector<char> packet(boost::asio::buffer_size(buffers));
22 buffer_copy(boost::asio::buffer(packet), buffers);
23 packets.push_back(packet);
27 struct mock_clock_interface {
31 static mock_clock_interface& instance() {
32 static mock_clock_interface ins;
36 ::testing::Mock::VerifyAndClearExpectations(&instance());
40 struct mock_clock :
public std::chrono::steady_clock {
42 return mock_clock_interface::instance().now();
52 auto mock_sleep = [](mock_clock::duration
const&) {};
54 using namespace ::testing;
55 mock_clock_interface::clear();
56 EXPECT_CALL(mock_clock_interface::instance(), now())
57 .WillRepeatedly(Invoke([]() {
87 BOOST_REQUIRE_EQUAL(sink.packets.size(), 3);
88 BOOST_CHECK_EQUAL(100 + 2 + hdrsize, sink.packets.at(0).size());
89 BOOST_CHECK_EQUAL(90 + 2 + hdrsize, sink.packets.at(1).size());
90 BOOST_CHECK_EQUAL(80 + 2 + hdrsize, sink.packets.at(2).size());
99 auto mock_sleep = [](mock_clock::duration
const&) {};
100 using namespace ::testing;
101 mock_clock_interface::clear();
102 EXPECT_CALL(mock_clock_interface::instance(), now())
103 .WillRepeatedly(Invoke([]() {
116 using namespace std::chrono;
141 BOOST_CHECK_EQUAL(sink.packets.size(), 0);
148 BOOST_REQUIRE_EQUAL(sink.packets.size(), 1);
150 hdrsize + 100 + 2 + 90 + 2 + 80 + 2, sink.packets.at(0).size());
159 auto mock_sleep = [](mock_clock::duration
const&) {};
160 using namespace ::testing;
161 mock_clock_interface::clear();
162 EXPECT_CALL(mock_clock_interface::instance(), now())
163 .WillRepeatedly(Invoke([]() {
176 using namespace std::chrono;
194 BOOST_CHECK_EQUAL(sink.packets.size(), 0);
205 BOOST_REQUIRE_EQUAL(sink.packets.size(), 1);
206 BOOST_CHECK_EQUAL(hdrsize + 100 + 2 + 90 + 2, sink.packets.at(0).size());
210 BOOST_REQUIRE_EQUAL(sink.packets.size(), 2);
211 BOOST_CHECK_EQUAL(hdrsize + 80 + 2, sink.packets.at(1).size());
219 using namespace ::testing;
220 mock_clock_interface::clear();
221 EXPECT_CALL(mock_clock_interface::instance(), now())
222 .WillRepeatedly(Invoke([]() {
228 MOCK_METHOD1(m,
void(mock_clock::duration));
230 auto mock_sleep = [&sleeper](mock_clock::duration d) { sleeper.m(d); };
231 EXPECT_CALL(sleeper, m(Truly([](
auto const& d) {
232 return d == std::chrono::microseconds(2020);
244 using namespace std::chrono;
262 BOOST_CHECK_EQUAL(sink.packets.size(), 0);
274 BOOST_REQUIRE_EQUAL(sink.packets.size(), 1);
275 BOOST_CHECK_EQUAL(hdrsize + 100 + 2 + 90 + 2, sink.packets.at(0).size());
284 auto mock_sleep = [&sleep_count](mock_clock::duration) { ++sleep_count; };
285 using namespace ::testing;
286 mock_clock_interface::clear();
287 EXPECT_CALL(mock_clock_interface::instance(), now())
288 .WillRepeatedly(Invoke([]() {
300 using namespace std::chrono;
308 BOOST_CHECK_EQUAL(sink.packets.size(), 0);
315 BOOST_REQUIRE_EQUAL(sink.packets.size(), 1);
316 BOOST_CHECK_EQUAL(hdrsize + 100 + 2, sink.packets.at(0).size());
320 BOOST_REQUIRE_EQUAL(sink.packets.size(), 1);
325 BOOST_REQUIRE_EQUAL(sink.packets.size(), 2);
326 BOOST_CHECK_EQUAL(hdrsize, sink.packets.at(1).size());
BOOST_AUTO_TEST_CASE(itch5_mold_udp_pacer_basic)
int maximum_delay_microseconds
void handle_message(time_point ts, unknown_message const &msg, message_sink_type &sink, sleep_functor_type &sleeper)
Process a raw ITCH-5.x message.
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
void heartbeat(message_sink_type &sink)
Send a heartbeat packet.
Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time inte...
int maximum_transmission_unit
Represent a ITCH-5.0 timestamp.
std::vector< char > create_message(int message_type, jb::itch5::timestamp ts, std::size_t total_size)
Generate test messages with a more-or-less valid header.
Initialize GMock to work with Boost.Test.
void flush(timestamp ts, message_sink_type &sink)
Flush the current messages, if any.
Configuration object for the jb::itch5::mold_udp_pacer class.
constexpr std::size_t header_size
The total size of the MoldUDP64 header.