]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/test/ip/unicast.cpp
7e14b0dcc57707cd9e13cd13d04b219f06aeaffe
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 // Disable autolinking for unit tests.
12 #if !defined(BOOST_ALL_NO_LIB)
13 #define BOOST_ALL_NO_LIB 1
14 #endif // !defined(BOOST_ALL_NO_LIB)
16 // Test that header file is self-contained.
17 #include <boost/asio/ip/unicast.hpp>
19 #include <boost/asio/io_service.hpp>
20 #include <boost/asio/ip/udp.hpp>
21 #include "../unit_test.hpp"
23 //------------------------------------------------------------------------------
25 // ip_unicast_compile test
26 // ~~~~~~~~~~~~~~~~~~~~~~~
27 // The following test checks that all nested classes, enums and constants in
28 // ip::unicast compile and link correctly. Runtime failures are ignored.
30 namespace ip_unicast_compile
{
34 using namespace boost::asio
;
35 namespace ip
= boost::asio::ip
;
40 ip::udp::socket
sock(ios
);
44 ip::unicast::hops
hops1(1024);
45 sock
.set_option(hops1
);
46 ip::unicast::hops hops2
;
47 sock
.get_option(hops2
);
49 (void)static_cast<int>(hops1
.value());
51 catch (std::exception
&)
56 } // namespace ip_unicast_compile
58 //------------------------------------------------------------------------------
60 // ip_unicast_runtime test
61 // ~~~~~~~~~~~~~~~~~~~~~~~
62 // The following test checks the runtime operation of the socket options defined
63 // in the ip::unicast namespace.
65 namespace ip_unicast_runtime
{
69 using namespace boost::asio
;
70 namespace ip
= boost::asio::ip
;
73 boost::system::error_code ec
;
75 ip::udp::endpoint
ep_v4(ip::address_v4::loopback(), 0);
76 ip::udp::socket
sock_v4(ios
);
77 sock_v4
.open(ep_v4
.protocol(), ec
);
78 sock_v4
.bind(ep_v4
, ec
);
81 ip::udp::endpoint
ep_v6(ip::address_v6::loopback(), 0);
82 ip::udp::socket
sock_v6(ios
);
83 sock_v6
.open(ep_v6
.protocol(), ec
);
84 sock_v6
.bind(ep_v6
, ec
);
87 BOOST_ASIO_CHECK(have_v4
|| have_v6
);
93 ip::unicast::hops
hops1(1);
94 BOOST_ASIO_CHECK(hops1
.value() == 1);
95 sock_v4
.set_option(hops1
, ec
);
96 #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
97 // Option is not supported under Windows CE.
98 BOOST_ASIO_CHECK_MESSAGE(ec
== boost::asio::error::no_protocol_option
,
99 ec
.value() << ", " << ec
.message());
100 #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
101 BOOST_ASIO_CHECK(!ec
);
102 #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
104 ip::unicast::hops hops2
;
105 sock_v4
.get_option(hops2
, ec
);
106 #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
107 // Option is not supported under Windows CE.
108 BOOST_ASIO_CHECK_MESSAGE(ec
== boost::asio::error::no_protocol_option
,
109 ec
.value() << ", " << ec
.message());
110 #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
111 BOOST_ASIO_CHECK(!ec
);
112 BOOST_ASIO_CHECK(hops2
.value() == 1);
113 #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
115 ip::unicast::hops
hops3(255);
116 BOOST_ASIO_CHECK(hops3
.value() == 255);
117 sock_v4
.set_option(hops3
, ec
);
118 #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
119 // Option is not supported under Windows CE.
120 BOOST_ASIO_CHECK_MESSAGE(ec
== boost::asio::error::no_protocol_option
,
121 ec
.value() << ", " << ec
.message());
122 #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
123 BOOST_ASIO_CHECK(!ec
);
124 #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
126 ip::unicast::hops hops4
;
127 sock_v4
.get_option(hops4
, ec
);
128 #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
129 // Option is not supported under Windows CE.
130 BOOST_ASIO_CHECK_MESSAGE(ec
== boost::asio::error::no_protocol_option
,
131 ec
.value() << ", " << ec
.message());
132 #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
133 BOOST_ASIO_CHECK(!ec
);
134 BOOST_ASIO_CHECK(hops4
.value() == 255);
135 #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
140 ip::unicast::hops
hops1(1);
141 BOOST_ASIO_CHECK(hops1
.value() == 1);
142 sock_v6
.set_option(hops1
, ec
);
143 BOOST_ASIO_CHECK(!ec
);
145 ip::unicast::hops hops2
;
146 sock_v6
.get_option(hops2
, ec
);
147 BOOST_ASIO_CHECK(!ec
);
148 BOOST_ASIO_CHECK(hops2
.value() == 1);
150 ip::unicast::hops
hops3(255);
151 BOOST_ASIO_CHECK(hops3
.value() == 255);
152 sock_v6
.set_option(hops3
, ec
);
153 BOOST_ASIO_CHECK(!ec
);
155 ip::unicast::hops hops4
;
156 sock_v6
.get_option(hops4
, ec
);
157 BOOST_ASIO_CHECK(!ec
);
158 BOOST_ASIO_CHECK(hops4
.value() == 255);
162 } // namespace ip_unicast_runtime
164 //------------------------------------------------------------------------------
166 BOOST_ASIO_TEST_SUITE
169 BOOST_ASIO_TEST_CASE(ip_unicast_compile::test
)
170 BOOST_ASIO_TEST_CASE(ip_unicast_runtime::test
)