1 //
2 // address.cpp
3 // ~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 "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 
test()31 void test()
32 {
33   using namespace asio;
34   namespace ip = asio::ip;
35 
36   try
37   {
38     asio::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 creation functions.
102 
103     addr1 = ip::make_address("127.0.0.1");
104     addr1 = ip::make_address("127.0.0.1", ec);
105     addr1 = ip::make_address(string_value);
106     addr1 = ip::make_address(string_value, ec);
107 
108     // address I/O.
109 
110     std::ostringstream os;
111     os << addr1;
112 
113 #if !defined(BOOST_NO_STD_WSTREAMBUF)
114     std::wostringstream wos;
115     wos << addr1;
116 #endif // !defined(BOOST_NO_STD_WSTREAMBUF)
117   }
118   catch (std::exception&)
119   {
120   }
121 }
122 
123 } // namespace ip_address_compile
124 
125 //------------------------------------------------------------------------------
126 
127 ASIO_TEST_SUITE
128 (
129   "ip/address",
130   ASIO_TEST_CASE(ip_address_compile::test)
131 )
132