JayBeams  0.1
Another project to have fun coding.
ut_make_socket_udp_recv.cpp
Go to the documentation of this file.
2 
4 #include <boost/test/unit_test.hpp>
5 
6 /**
7  * @test Verify that jb::itch5::make_socket_udp_recv compiles.
8  */
9 BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_compile) {
10  boost::asio::io_service io;
12  auto socket = jb::itch5::make_socket_udp_recv(io, cfg.address("127.0.0.1"));
13  BOOST_CHECK(socket.is_open());
14 }
15 
16 /**
17  * Types used in testing of jb::itch5::make_socket_udp_recv
18  */
19 namespace {} // anonymous namespace
20 
22 
23 BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_basic) {
24  // A simple unicast socket on the default interface ...
25  using namespace ::testing;
26  NiceMock<mock_udp_socket> socket;
27  EXPECT_CALL(socket, open(_)).Times(1);
28  EXPECT_CALL(socket, bind(_)).Times(1);
29  EXPECT_CALL(
30  socket, set_option(An<boost::asio::ip::multicast::join_group const&>()))
31  .Times(0);
32  EXPECT_CALL(
33  socket,
34  set_option(An<boost::asio::ip::multicast::enable_loopback const&>()))
35  .Times(0);
36 
38  socket, jb::itch5::udp_receiver_config().address("::1").port(50000));
39 }
40 
41 BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_multicast_ipv4) {
42  using namespace ::testing;
43  NiceMock<mock_udp_socket> socket;
44  EXPECT_CALL(socket, open(_)).Times(1);
45  EXPECT_CALL(
46  socket, bind(boost::asio::ip::udp::endpoint(
47  boost::asio::ip::address_v4(), 50000)))
48  .Times(1);
49  EXPECT_CALL(
50  socket, set_option(An<boost::asio::ip::multicast::join_group const&>()))
51  .Times(1);
52  EXPECT_CALL(
53  socket,
54  set_option(An<boost::asio::ip::multicast::enable_loopback const&>()))
55  .Times(1);
56 
57  // Create a IPv4 multicast socket on the default interface ...
59  socket,
60  jb::itch5::udp_receiver_config().address("239.128.1.1").port(50000));
61 }
62 
63 BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_multicast_ipv6) {
64  using namespace ::testing;
65  NiceMock<mock_udp_socket> socket;
66  EXPECT_CALL(socket, open(_)).Times(1);
67  EXPECT_CALL(
68  socket, bind(boost::asio::ip::udp::endpoint(
69  boost::asio::ip::address_v6(), 50000)))
70  .Times(1);
71  EXPECT_CALL(
72  socket, set_option(An<boost::asio::ip::multicast::join_group const&>()))
73  .Times(1);
74  EXPECT_CALL(
75  socket,
76  set_option(An<boost::asio::ip::multicast::enable_loopback const&>()))
77  .Times(1);
78 
79  // Create a IPv6 multicast socket on the default interface ...
81  socket, jb::itch5::udp_receiver_config().address("ff05::").port(50000));
82 }
83 
84 BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_listen_address) {
85  using namespace ::testing;
86  NiceMock<mock_udp_socket> socket;
87  char const* interface = "2001:db8:ca2:2::1";
88  EXPECT_CALL(socket, open(_)).Times(1);
89  EXPECT_CALL(
90  socket, bind(boost::asio::ip::udp::endpoint(
91  boost::asio::ip::address::from_string(interface), 50000)))
92  .Times(1);
93  EXPECT_CALL(
94  socket, set_option(An<boost::asio::ip::multicast::join_group const&>()))
95  .Times(1);
96  EXPECT_CALL(
97  socket,
98  set_option(An<boost::asio::ip::multicast::enable_loopback const&>()))
99  .Times(1);
100 
101  // Create a multicast socket on an specific interface ...
103  socket, jb::itch5::udp_receiver_config()
104  .address("ff05::")
105  .port(50000)
106  .local_address(interface));
107 }
A Mock Object for the socket class.
socket_t make_socket_udp_recv(boost::asio::io_service &io, udp_receiver_config const &cfg)
Create a socket given the configuration parameters.
jb::config_attribute< udp_receiver_config, std::string > address
BOOST_AUTO_TEST_CASE(itch5_make_socket_udp_recv_compile)
A configuration object for UDP receivers.
void setup_socket_udp_recv(socket_t &socket, udp_receiver_config const &cfg)
Configure a socket to receive UDP packets.