2 #include "common.hpp" // IP, PORT{1,2}, test_address{1,2}
3 #include <posixx/socket/inet.hpp> // posixx::socket::inet
4 #include <boost/test/unit_test.hpp> // unit testing stuff
6 namespace inet = posixx::socket::inet;
8 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_test )
10 BOOST_CHECK_EQUAL(test_address1.sin_family, AF_INET);
11 BOOST_CHECK_EQUAL(test_address1.addr(), IP);
12 BOOST_CHECK_EQUAL(test_address1.port(), PORT1);
15 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_default )
18 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
19 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::any);
20 BOOST_CHECK_EQUAL(addr.sin_port, 0);
21 BOOST_CHECK_EQUAL(addr.port(), 0);
24 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast )
26 inet::sockaddr addr(inet::broadcast);
27 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
28 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
29 BOOST_CHECK_EQUAL(addr.sin_port, 0);
30 BOOST_CHECK_EQUAL(addr.port(), 0);
33 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast_port )
35 inet::sockaddr addr(inet::broadcast, 12345);
36 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
37 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
38 BOOST_CHECK_EQUAL(addr.port(), 12345);
41 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_1_1_1_1_8080 )
43 inet::sockaddr addr("1.1.1.1", 8080);
44 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
45 BOOST_CHECK_EQUAL(addr.addr(), "1.1.1.1");
46 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x01010101);
47 BOOST_CHECK_EQUAL(addr.port(), 8080);
50 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_16_16_16_16_12345 )
52 inet::sockaddr addr("16.16.16.16", 12345);
53 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
54 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
55 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
56 BOOST_CHECK_EQUAL(addr.port(), 12345);
59 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_broadcast_port )
62 addr.set(inet::broadcast, 12345);
63 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
64 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
65 BOOST_CHECK_EQUAL(addr.port(), 12345);
68 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_16_16_16_16_12345 )
71 addr.set("16.16.16.16", 12345);
72 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
73 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
74 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
75 BOOST_CHECK_EQUAL(addr.port(), 12345);
78 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_broadcast )
80 inet::sockaddr addr(inet::broadcast);
82 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
83 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
84 BOOST_CHECK_EQUAL(addr.port(), 12345);
87 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_16_16_16_16_12345 )
89 inet::sockaddr addr("16.16.16.16", 0);
91 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
92 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
93 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
94 BOOST_CHECK_EQUAL(addr.port(), 12345);
97 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_broadcast )
100 addr.addr(inet::broadcast);
101 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
102 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
103 BOOST_CHECK_EQUAL(addr.port(), 0);
106 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_16_16_16_16 )
109 addr.addr("16.16.16.16");
110 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
111 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
112 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
113 BOOST_CHECK_EQUAL(addr.port(), 0);