]> git.llucax.com Git - software/posixx.git/blob - test/socket/inet/sockaddr.cpp
Add Boost License
[software/posixx.git] / test / socket / inet / sockaddr.cpp
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)
5
6
7
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
11
12 namespace inet = posixx::socket::inet;
13
14 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_test )
15 {
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);
19 }
20
21 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_default )
22 {
23         inet::sockaddr addr;
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);
28 }
29
30 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast )
31 {
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);
37 }
38
39 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_broadcast_port )
40 {
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);
45 }
46
47 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_1_1_1_1_8080 )
48 {
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);
54 }
55
56 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_16_16_16_16_12345 )
57 {
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);
63 }
64
65 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_broadcast_port )
66 {
67         inet::sockaddr addr;
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);
72 }
73
74 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_16_16_16_16_12345 )
75 {
76         inet::sockaddr addr;
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);
82 }
83
84 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_broadcast )
85 {
86         inet::sockaddr addr(inet::broadcast);
87         addr.port(12345);
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);
91 }
92
93 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_port_16_16_16_16_12345 )
94 {
95         inet::sockaddr addr("16.16.16.16", 0);
96         addr.port(12345);
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);
101 }
102
103 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_broadcast )
104 {
105         inet::sockaddr addr;
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);
110 }
111
112 BOOST_AUTO_TEST_CASE( socket_inet_sockaddr_set_addr_16_16_16_16 )
113 {
114         inet::sockaddr addr;
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);
120 }
121