Initial commit of Networking TS implementation
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / net / execution_context / use_service.cc
blobd8fb6404b3cde9a3293502edc76efe1b50ad8f30
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.
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.
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/>.
18 // { dg-options "-std=gnu++14" }
20 #include <experimental/executor>
21 #include <testsuite_hooks.h>
23 using std::experimental::net::execution_context;
24 using std::experimental::net::use_service;
26 struct service1 : execution_context::service
28 using key_type = service1;
29 service1(execution_context& c) : service(c) { }
30 void shutdown() noexcept { }
33 struct key2 : execution_context::service
35 key2(execution_context& c) : service(c) { }
38 struct service2 : key2
40 using key_type = key2;
41 service2(execution_context& c) : key2(c) { }
42 void shutdown() noexcept { }
45 struct service3 : service1
47 using service1::service1;
50 struct service4 : service2
52 using service2::service2;
55 void
56 test01()
58 execution_context ctx;
59 service1& svc1 = use_service<service1>(ctx);
60 service1& svc1a = use_service<service1>(ctx);
61 VERIFY( &svc1a == &svc1 );
63 key2& svc2 = use_service<service2>(ctx);
64 key2& svc2a = use_service<service2>(ctx);
65 VERIFY( &svc2a == &svc2 );
67 service1& svc3 = use_service<service3>(ctx);
68 VERIFY( &svc3 == &svc1 );
70 key2& svc4 = use_service<service4>(ctx);
71 VERIFY( &svc4 == &svc2 );
73 // TODO test02() function that puts derived types in first, then tests base comes out
76 int
77 main()
79 test01();