comparison libstdc++-v3/testsuite/experimental/net/socket/basic_socket.cc @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
comparison
equal deleted inserted replaced
18:1830386684a0 19:2b5abeee2509
1 // Copyright (C) 2020 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-do compile { target c++14 } }
19
20 #include <experimental/socket>
21
22 namespace net = std::experimental::net;
23 using namespace std;
24
25 namespace test
26 {
27 }
28
29 void
30 test01(net::io_context& io)
31 {
32 struct proto
33 {
34 struct endpoint
35 {
36 using protocol_type = proto;
37 protocol_type protocol() const { return {}; }
38
39 void* data() { return nullptr; }
40 const void* data() const { return nullptr; }
41 std::size_t size() const { return 0; }
42 void resize(std::size_t) { }
43 std::size_t capacity() const { return 0; }
44 };
45
46 int family() const { return 0; }
47 int type() const { return 0; }
48 int protocol() const { return 0; }
49 };
50
51 static_assert( ! is_default_constructible<net::basic_socket<proto>>::value,
52 "no default ctor" );
53 static_assert( ! is_copy_constructible<net::basic_socket<proto>>::value,
54 "copy ctor is deleted" );
55 static_assert( ! is_move_constructible<net::basic_socket<proto>>::value,
56 "move ctor is protected" );
57 static_assert( ! is_move_assignable<net::basic_socket<proto>>::value,
58 "move assignment op is protected" );
59
60 struct socket : net::basic_socket<proto>
61 {
62 explicit
63 socket(net::io_context& io)
64 : basic_socket(io) { }
65
66 socket(net::io_context& io, const proto& p)
67 : basic_socket(io, p) { }
68
69 socket(net::io_context& io, const proto::endpoint& e)
70 : basic_socket(io, e) { }
71
72 socket(net::io_context& io, const proto& p, int n)
73 : basic_socket(io, p, n) { }
74 };
75
76 static_assert( ! is_copy_constructible<socket>::value, "deleted" );
77 static_assert( is_move_constructible<socket>::value, "" );
78 static_assert( is_move_assignable<socket>::value, "" );
79
80 error_code ec;
81 proto p;
82 proto::endpoint e;
83
84 socket s(io);
85 s = socket(io, p);
86 s = socket(io, e);
87 s = socket(io, p, s.release());
88
89 static_assert( is_same<decltype(s.get_executor()),
90 net::io_context::executor_type>::value, "" );
91 static_assert( noexcept(s.get_executor()), "" );
92 static_assert( is_same<decltype(s.native_handle()),
93 socket::native_handle_type>::value, "" );
94 static_assert( noexcept(s.native_handle()), "GNU extension" );
95
96 s.open();
97 s.open(p);
98 s.open(p, ec);
99
100 s.assign(p, s.release());
101 s.assign(p, s.release(ec), ec);
102
103 static_assert( is_same<decltype(const_cast<const socket&>(s).is_open()),
104 bool>::value, "" );
105 static_assert( noexcept(const_cast<const socket&>(s).is_open()), "" );
106
107 s.close();
108 s.close(ec);
109
110 s.cancel();
111 s.cancel(ec);
112
113 s.bind(e);
114 s.bind(e, ec);
115
116 s.shutdown(net::socket_base::shutdown_both);
117 s.shutdown(net::socket_base::shutdown_both, ec);
118
119 e = s.local_endpoint();
120 e = s.local_endpoint(ec);
121 e = s.remote_endpoint();
122 e = s.remote_endpoint(ec);
123
124 s.connect(e);
125 s.connect(e, ec);
126
127 s.wait(net::socket_base::wait_read);
128 s.wait(net::socket_base::wait_read, ec);
129 }