]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc
Introduce dg-add-options net_ts
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / net / internet / address / v4 / members.cc
1 // Copyright (C) 2015-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-options "-std=gnu++14" }
19 // { dg-add-options net_ts }
20
21 #include <experimental/internet>
22 #include <testsuite_hooks.h>
23
24 using std::experimental::net::ip::address_v4;
25
26 void
27 test01()
28 {
29 bool test __attribute__((unused)) = false;
30
31 address_v4 a;
32 VERIFY( a.is_unspecified() );
33
34 a = address_v4::any();
35 VERIFY( a.is_unspecified() );
36
37 a = address_v4::loopback();
38 VERIFY( !a.is_unspecified() );
39
40 a = address_v4::broadcast();
41 VERIFY( !a.is_unspecified() );
42 }
43
44 void
45 test02()
46 {
47 bool test __attribute__((unused)) = false;
48
49 auto a = address_v4::loopback();
50 VERIFY( a.is_loopback() );
51
52 a = address_v4{0x7F000001};
53 VERIFY( a.is_loopback() );
54
55 a = address_v4{0x7F010203};
56 VERIFY( a.is_loopback() );
57
58 a = address_v4{0x7FFFFFFF};
59 VERIFY( a.is_loopback() );
60
61 a = address_v4::any();
62 VERIFY( !a.is_loopback() );
63
64 a = address_v4::broadcast();
65 VERIFY( !a.is_loopback() );
66 }
67
68 void
69 test03()
70 {
71 bool test __attribute__((unused)) = false;
72
73 auto a = address_v4{0xE0000001};
74 VERIFY( a.is_multicast() );
75
76 a = address_v4{0xE0010203};
77 VERIFY( a.is_multicast() );
78
79 a = address_v4{0xE0FFFFFF};
80 VERIFY( a.is_multicast() );
81
82 a = address_v4{0xF0000000};
83 VERIFY( !a.is_multicast() );
84
85 a = address_v4{0xDFFFFFFF};
86 VERIFY( !a.is_multicast() );
87 }
88
89 void
90 test04()
91 {
92 bool test __attribute__((unused)) = false;
93
94 VERIFY( address_v4::any().to_string() == "0.0.0.0" );
95 VERIFY( address_v4::loopback().to_string() == "127.0.0.1" );
96 VERIFY( address_v4::broadcast().to_string() == "255.255.255.255" );
97 }
98
99 void
100 test05()
101 {
102 bool test __attribute__((unused)) = false;
103
104 std::ostringstream ss;
105 ss << address_v4::any() << ' ' << address_v4::loopback() << ' '
106 << address_v4::broadcast();
107 VERIFY( ss.str() == "0.0.0.0 127.0.0.1 255.255.255.255" );
108 }
109
110
111 int
112 main()
113 {
114 test01();
115 test02();
116 test03();
117 test04();
118 test05();
119 }