Debian Codegraph @

libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc

raw
1 // { dg-do run { target c++14 } }
2 // { dg-require-effective-target net_ts_ip }
3 // { dg-add-options net_ts }
4
5 #include <experimental/internet>
6 #include <testsuite_hooks.h>
7
8 using namespace std::experimental::net;
9
10 #if __cplusplus >= 202002
11 constexpr
12 #endif
13 void
14 test_default()
15 {
16 ip::tcp::endpoint t1;
17 VERIFY( t1.protocol() == ip::tcp::v4() );
18 VERIFY( t1.address() == ip::address() );
19 VERIFY( t1.port() == 0 );
20
21 ip::udp::endpoint t2;
22 VERIFY( t2.protocol() == ip::udp::v4() );
23 VERIFY( t2.address() == ip::address() );
24 VERIFY( t2.port() == 0 );
25 }
26
27 #if __cplusplus >= 202002
28 constexpr
29 #endif
30 void
31 test_proto()
32 {
33 ip::tcp::endpoint t1(ip::tcp::v4(), 22);
34 VERIFY( t1.protocol() == ip::tcp::v4() );
35 VERIFY( t1.address() == ip::address_v4() );
36 VERIFY( t1.port() == 22 );
37
38 ip::tcp::endpoint t2(ip::tcp::v6(), 80);
39 VERIFY( t2.protocol() == ip::tcp::v6() );
40 VERIFY( t2.address() == ip::address_v6() );
41 VERIFY( t2.port() == 80 );
42 }
43
44 #if __cplusplus >= 202002
45 constexpr
46 #endif
47 void
48 test_addr()
49 {
50 ip::address_v4 a1(ip::address_v4::bytes_type(1, 2, 3, 4));
51 ip::tcp::endpoint t1(a1, 22);
52 VERIFY( t1.protocol() == ip::tcp::v4() );
53 VERIFY( t1.address() == a1 );
54 VERIFY( t1.port() == 22 );
55
56 ip::address_v6 a2(ip::address_v6::bytes_type(21,22,23,24,25,26,27,28,29));
57 ip::tcp::endpoint t2(a2, 80);
58 VERIFY( t2.protocol() == ip::tcp::v6() );
59 VERIFY( t2.address() == a2 );
60 VERIFY( t2.port() == 80 );
61 }
62
63 int main()
64 {
65 test_default();
66 test_proto();
67 test_addr();
68
69 #if __cplusplus >= 202002
70 // basic_endpoint constructors are only constexpr in C++20.
71 constexpr bool b = []{
72 test_default();
73 test_proto();
74 test_addr();
75 return true;
76 }();
77 #endif
78 }