]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/execution_context/use_service.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / net / execution_context / use_service.cc
1 // Copyright (C) 2015-2022 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 // { dg-additional-options "-pthread" { target pthread } }
20
21 #include <experimental/executor>
22 #include <testsuite_hooks.h>
23
24 using std::experimental::net::execution_context;
25 using std::experimental::net::use_service;
26
27 struct service1 : execution_context::service
28 {
29 using key_type = service1;
30 service1(execution_context& c) : service(c) { }
31 void shutdown() noexcept { }
32 };
33
34 struct key2 : execution_context::service
35 {
36 key2(execution_context& c) : service(c) { }
37 };
38
39 struct service2 : key2
40 {
41 using key_type = key2;
42 service2(execution_context& c) : key2(c) { }
43 void shutdown() noexcept { }
44 };
45
46 struct service3 : service1
47 {
48 using service1::service1;
49 };
50
51 struct service4 : service2
52 {
53 using service2::service2;
54 };
55
56 void
57 test01()
58 {
59 execution_context ctx;
60 service1& svc1 = use_service<service1>(ctx);
61 service1& svc1a = use_service<service1>(ctx);
62 VERIFY( &svc1a == &svc1 );
63
64 key2& svc2 = use_service<service2>(ctx);
65 key2& svc2a = use_service<service2>(ctx);
66 VERIFY( &svc2a == &svc2 );
67
68 service1& svc3 = use_service<service3>(ctx);
69 VERIFY( &svc3 == &svc1 );
70
71 key2& svc4 = use_service<service4>(ctx);
72 VERIFY( &svc4 == &svc2 );
73
74 // TODO test02() function that puts derived types in first, then tests base comes out
75 }
76
77 int
78 main()
79 {
80 test01();
81 }