]> git.llucax.com Git - software/posixx.git/blob - test/socket/inet/sockaddr.cpp
Add SUB_CANCEL to tipc::subscr_t
[software/posixx.git] / test / socket / inet / sockaddr.cpp
1
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
5
6 namespace inet = posixx::socket::inet;
7
8 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_test )
9 {
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);
13 }
14
15 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_default )
16 {
17         inet::sockaddr addr;
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);
22 }
23
24 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast )
25 {
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);
31 }
32
33 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast_port )
34 {
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);
39 }
40
41 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_1_1_1_1_8080 )
42 {
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);
48 }
49
50 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_16_16_16_16_12345 )
51 {
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);
57 }
58
59 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_broadcast_port )
60 {
61         inet::sockaddr addr;
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);
66 }
67
68 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_16_16_16_16_12345 )
69 {
70         inet::sockaddr addr;
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);
76 }
77
78 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_broadcast )
79 {
80         inet::sockaddr addr(inet::broadcast);
81         addr.port(12345);
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);
85 }
86
87 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_16_16_16_16_12345 )
88 {
89         inet::sockaddr addr("16.16.16.16", 0);
90         addr.port(12345);
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);
95 }
96
97 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_broadcast )
98 {
99         inet::sockaddr addr;
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);
104 }
105
106 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_16_16_16_16 )
107 {
108         inet::sockaddr addr;
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);
114 }
115