• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // executor.cpp
3 // ~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 // Disable autolinking for unit tests.
12 #if !defined(BOOST_ALL_NO_LIB)
13 #define BOOST_ALL_NO_LIB 1
14 #endif // !defined(BOOST_ALL_NO_LIB)
15 
16 // Test that header file is self-contained.
17 #include <boost/asio/execution/executor.hpp>
18 
19 #include "../unit_test.hpp"
20 
21 struct not_an_executor
22 {
23 };
24 
25 struct executor
26 {
executorexecutor27   executor()
28   {
29   }
30 
executorexecutor31   executor(const executor&) BOOST_ASIO_NOEXCEPT
32   {
33   }
34 
35 #if defined(BOOST_ASIO_HAS_MOVE)
executorexecutor36   executor(executor&&) BOOST_ASIO_NOEXCEPT
37   {
38   }
39 #endif // defined(BOOST_ASIO_HAS_MOVE)
40 
41   template <typename F>
executeexecutor42   void execute(BOOST_ASIO_MOVE_ARG(F) f) const BOOST_ASIO_NOEXCEPT
43   {
44     (void)f;
45   }
46 
operator ==executor47   bool operator==(const executor&) const BOOST_ASIO_NOEXCEPT
48   {
49     return true;
50   }
51 
operator !=executor52   bool operator!=(const executor&) const BOOST_ASIO_NOEXCEPT
53   {
54     return false;
55   }
56 };
57 
58 namespace boost {
59 namespace asio {
60 namespace traits {
61 
62 #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
63 
64 template <typename F>
65 struct execute_member<executor, F>
66 {
67   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
68   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
69   typedef void result_type;
70 };
71 
72 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
73 #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
74 
75 template <>
76 struct equality_comparable<executor>
77 {
78   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
79   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
80 };
81 
82 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
83 
84 } // namespace traits
85 } // namespace asio
86 } // namespace boost
87 
is_executor_test()88 void is_executor_test()
89 {
90   BOOST_ASIO_CHECK((
91       !boost::asio::execution::is_executor<
92         void
93       >::value));
94 
95   BOOST_ASIO_CHECK((
96       !boost::asio::execution::is_executor<
97         not_an_executor
98       >::value));
99 
100   BOOST_ASIO_CHECK((
101       boost::asio::execution::is_executor<
102         executor
103       >::value));
104 }
105 
is_executor_of_test()106 void is_executor_of_test()
107 {
108   BOOST_ASIO_CHECK((
109       !boost::asio::execution::is_executor_of<
110         void,
111         void(*)()
112       >::value));
113 
114   BOOST_ASIO_CHECK((
115       !boost::asio::execution::is_executor_of<
116         not_an_executor,
117         void(*)()
118       >::value));
119 
120   BOOST_ASIO_CHECK((
121       boost::asio::execution::is_executor_of<
122         executor,
123         void(*)()
124       >::value));
125 }
126 
127 struct executor_with_other_shape_type
128 {
129   typedef double shape_type;
130 };
131 
executor_shape_test()132 void executor_shape_test()
133 {
134   BOOST_ASIO_CHECK((
135       boost::asio::is_same<
136         boost::asio::execution::executor_shape<executor>::type,
137         std::size_t
138       >::value));
139 
140   BOOST_ASIO_CHECK((
141       boost::asio::is_same<
142         boost::asio::execution::executor_shape<
143           executor_with_other_shape_type
144         >::type,
145         double
146       >::value));
147 }
148 
149 struct executor_with_other_index_type
150 {
151   typedef unsigned char index_type;
152 };
153 
executor_index_test()154 void executor_index_test()
155 {
156   BOOST_ASIO_CHECK((
157       boost::asio::is_same<
158         boost::asio::execution::executor_index<executor>::type,
159         std::size_t
160       >::value));
161 
162   BOOST_ASIO_CHECK((
163       boost::asio::is_same<
164         boost::asio::execution::executor_index<
165           executor_with_other_shape_type
166         >::type,
167         double
168       >::value));
169 
170   BOOST_ASIO_CHECK((
171       boost::asio::is_same<
172         boost::asio::execution::executor_index<
173           executor_with_other_index_type
174         >::type,
175         unsigned char
176       >::value));
177 }
178 
179 BOOST_ASIO_TEST_SUITE
180 (
181   "executor",
182   BOOST_ASIO_TEST_CASE(is_executor_test)
183   BOOST_ASIO_TEST_CASE(is_executor_of_test)
184   BOOST_ASIO_TEST_CASE(executor_shape_test)
185   BOOST_ASIO_TEST_CASE(executor_index_test)
186 )
187