1 // Copyright Leandro Lucarella 2008 - 2010.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file COPYING or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
8 #include "common.hpp" // IP, PORT{1,2}, test_address{1,2}
9 #include <posixx/socket/inet.hpp> // posixx::socket::inet
10 #include <boost/test/unit_test.hpp> // unit testing stuff
12 namespace inet = posixx::socket::inet;
14 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_test )
16 BOOST_CHECK_EQUAL(test_address1.sin_family, AF_INET);
17 BOOST_CHECK_EQUAL(test_address1.addr(), IP);
18 BOOST_CHECK_EQUAL(test_address1.port(), PORT1);
21 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_default )
24 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
25 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::any);
26 BOOST_CHECK_EQUAL(addr.sin_port, 0);
27 BOOST_CHECK_EQUAL(addr.port(), 0);
30 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast )
32 inet::sockaddr addr(inet::broadcast);
33 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
34 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
35 BOOST_CHECK_EQUAL(addr.sin_port, 0);
36 BOOST_CHECK_EQUAL(addr.port(), 0);
39 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast_port )
41 inet::sockaddr addr(inet::broadcast, 12345);
42 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
43 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
44 BOOST_CHECK_EQUAL(addr.port(), 12345);
47 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_1_1_1_1_8080 )
49 inet::sockaddr addr("1.1.1.1", 8080);
50 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
51 BOOST_CHECK_EQUAL(addr.addr(), "1.1.1.1");
52 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x01010101);
53 BOOST_CHECK_EQUAL(addr.port(), 8080);
56 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_16_16_16_16_12345 )
58 inet::sockaddr addr("16.16.16.16", 12345);
59 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
60 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
61 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
62 BOOST_CHECK_EQUAL(addr.port(), 12345);
65 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_broadcast_port )
68 addr.set(inet::broadcast, 12345);
69 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
70 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
71 BOOST_CHECK_EQUAL(addr.port(), 12345);
74 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_16_16_16_16_12345 )
77 addr.set("16.16.16.16", 12345);
78 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
79 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
80 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
81 BOOST_CHECK_EQUAL(addr.port(), 12345);
84 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_broadcast )
86 inet::sockaddr addr(inet::broadcast);
88 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
89 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
90 BOOST_CHECK_EQUAL(addr.port(), 12345);
93 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_16_16_16_16_12345 )
95 inet::sockaddr addr("16.16.16.16", 0);
97 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
98 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
99 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
100 BOOST_CHECK_EQUAL(addr.port(), 12345);
103 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_broadcast )
106 addr.addr(inet::broadcast);
107 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
108 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, inet::broadcast);
109 BOOST_CHECK_EQUAL(addr.port(), 0);
112 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_16_16_16_16 )
115 addr.addr("16.16.16.16");
116 BOOST_CHECK_EQUAL(addr.sin_family, AF_INET);
117 BOOST_CHECK_EQUAL(addr.addr(), "16.16.16.16");
118 BOOST_CHECK_EQUAL(addr.sin_addr.s_addr, 0x10101010);
119 BOOST_CHECK_EQUAL(addr.port(), 0);