]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/test/ip/address.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / asio / test / ip / address.cpp
1 //
2 // address.cpp
3 // ~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10
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)
15
16 // Test that header file is self-contained.
17 #include <boost/asio/ip/address.hpp>
18
19 #include "../unit_test.hpp"
20 #include <sstream>
21
22 //------------------------------------------------------------------------------
23
24 // ip_address_compile test
25 // ~~~~~~~~~~~~~~~~~~~~~~~
26 // The following test checks that all public member functions on the class
27 // ip::address compile and link correctly. Runtime failures are ignored.
28
29 namespace ip_address_compile {
30
31 void test()
32 {
33 using namespace boost::asio;
34 namespace ip = boost::asio::ip;
35
36 try
37 {
38 boost::system::error_code ec;
39
40 // address constructors.
41
42 ip::address addr1;
43 const ip::address_v4 const_addr_v4;
44 ip::address addr2(const_addr_v4);
45 const ip::address_v6 const_addr_v6;
46 ip::address addr3(const_addr_v6);
47
48 // address functions.
49
50 bool b = addr1.is_v4();
51 (void)b;
52
53 b = addr1.is_v6();
54 (void)b;
55
56 b = addr1.is_loopback();
57 (void)b;
58
59 b = addr1.is_unspecified();
60 (void)b;
61
62 b = addr1.is_multicast();
63 (void)b;
64
65 ip::address_v4 addr_v4_value = addr1.to_v4();
66 (void)addr_v4_value;
67
68 ip::address_v6 addr_v6_value = addr1.to_v6();
69 (void)addr_v6_value;
70
71 std::string string_value = addr1.to_string();
72 string_value = addr1.to_string(ec);
73
74 // address static functions.
75
76 addr1 = ip::address::from_string("127.0.0.1");
77 addr1 = ip::address::from_string("127.0.0.1", ec);
78 addr1 = ip::address::from_string(string_value);
79 addr1 = ip::address::from_string(string_value, ec);
80
81 // address comparisons.
82
83 b = (addr1 == addr2);
84 (void)b;
85
86 b = (addr1 != addr2);
87 (void)b;
88
89 b = (addr1 < addr2);
90 (void)b;
91
92 b = (addr1 > addr2);
93 (void)b;
94
95 b = (addr1 <= addr2);
96 (void)b;
97
98 b = (addr1 >= addr2);
99 (void)b;
100
101 // address I/O.
102
103 std::ostringstream os;
104 os << addr1;
105
106 #if !defined(BOOST_NO_STD_WSTREAMBUF)
107 std::wostringstream wos;
108 wos << addr1;
109 #endif // !defined(BOOST_NO_STD_WSTREAMBUF)
110 }
111 catch (std::exception&)
112 {
113 }
114 }
115
116 } // namespace ip_address_compile
117
118 //------------------------------------------------------------------------------
119
120 BOOST_ASIO_TEST_SUITE
121 (
122 "ip/address",
123 BOOST_ASIO_TEST_CASE(ip_address_compile::test)
124 )