Debian Codegraph @

libstdc++-v3/testsuite/experimental/net/executor/1.cc

raw
1 // Copyright (C) 2020-2025 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 run { target c++14 } }
19
20 #include <experimental/executor>
21 #include <testsuite_hooks.h>
22
23 namespace net = std::experimental::net;
24
25 void
26 test01()
27 {
28 net::executor e;
29 VERIFY( !e );
30 VERIFY( e == nullptr );
31 VERIFY( nullptr == e );
32 VERIFY( e == e );
33 VERIFY( e == e );
34 net::executor e2;
35 VERIFY( e == e2 );
36 swap(e, e2);
37 VERIFY( e == e2 );
38 e = e2;
39 VERIFY( e == e2 );
40 }
41
42 void
43 test02()
44 {
45 struct E
46 {
47 void on_work_started() const noexcept { }
48 void on_work_finished() const noexcept { }
49 net::execution_context& context() const noexcept { return c; }
50 void dispatch(std::function<void()>, std::allocator<void>) const { }
51 void post(std::function<void()>, std::allocator<void>) const { }
52 void defer(std::function<void()>, std::allocator<void>) const { }
53
54 net::execution_context& c;
55
56 bool operator==(const E& rhs) const noexcept
57 { return &c == &rhs.c; }
58 };
59
60 net::execution_context c;
61 E d{c};
62 net::executor e(d);
63 VERIFY( e == e );
64 VERIFY( e != nullptr );
65 VERIFY( nullptr != e );
66
67 VERIFY( &e.context() == &c );
68 #if __cpp_rtti
69 VERIFY( e.target_type() == typeid(E) );
70 #endif
71 VERIFY( *e.target<E>() == d );
72 VERIFY( *e.target<const E>() == d );
73 VERIFY( *const_cast<const net::executor&>(e).target<E>() == d );
74 VERIFY( *const_cast<const net::executor&>(e).target<const E>() == d );
75
76 net::executor f = e;
77 VERIFY( f == e );
78 e = nullptr;
79 VERIFY( f != e );
80 swap(e, f);
81 VERIFY( f == nullptr );
82 VERIFY( nullptr != e );
83
84 net::executor g(E{c});
85 VERIFY( e == g );
86 }
87
88 void
89 test03()
90 {
91 static_assert( ! std::is_default_constructible<net::system_context>::value, "" );
92 }
93
94 int
95 main()
96 {
97 test01();
98 test02();
99 test03();
100 }