@micro-os-plus/micro-test-plus 3.2.2 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cmake-format.yaml +11 -0
- package/CHANGELOG.md +352 -2
- package/CMakeLists.txt +32 -30
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/{xcdl.json → config/xcdl-build.json} +6 -6
- package/include/micro-os-plus/micro-test-plus/detail.h +1885 -0
- package/include/micro-os-plus/micro-test-plus/function-comparators.h +333 -0
- package/include/micro-os-plus/micro-test-plus/inlines/details-inlines.h +172 -0
- package/include/micro-os-plus/micro-test-plus/inlines/function-comparators-inlines.h +341 -0
- package/include/micro-os-plus/micro-test-plus/inlines/literals-inlines.h +604 -0
- package/include/micro-os-plus/micro-test-plus/inlines/math-inlines.h +315 -0
- package/include/micro-os-plus/micro-test-plus/inlines/micro-test-plus-inlines.h +313 -0
- package/include/micro-os-plus/micro-test-plus/inlines/reflection-inlines.h +170 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-reporter-inlines.h +471 -0
- package/include/micro-os-plus/micro-test-plus/inlines/test-suite-inlines.h +115 -0
- package/include/micro-os-plus/micro-test-plus/literals.h +912 -0
- package/include/micro-os-plus/micro-test-plus/math.h +217 -0
- package/include/micro-os-plus/micro-test-plus/operators.h +514 -0
- package/include/micro-os-plus/micro-test-plus/reflection.h +233 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +801 -0
- package/include/micro-os-plus/micro-test-plus/test-runner.h +241 -0
- package/include/micro-os-plus/micro-test-plus/test-suite.h +456 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
- package/include/micro-os-plus/micro-test-plus.h +169 -551
- package/meson.build +5 -5
- package/package.json +29 -34
- package/src/micro-test-plus.cpp +131 -35
- package/src/test-reporter.cpp +348 -6
- package/src/test-runner.cpp +69 -5
- package/src/test-suite.cpp +124 -5
- package/include/micro-os-plus/detail.h +0 -765
- package/include/micro-os-plus/inlines.h +0 -209
- package/include/micro-os-plus/literals.h +0 -512
- package/include/micro-os-plus/math.h +0 -204
- package/include/micro-os-plus/reflection.h +0 -139
- package/include/micro-os-plus/test-reporter-inlines.h +0 -230
- package/include/micro-os-plus/test-reporter.h +0 -356
- package/include/micro-os-plus/test-runner.h +0 -132
- package/include/micro-os-plus/test-suite.h +0 -306
- package/include/micro-os-plus/type-traits.h +0 -389
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
|
|
3
|
-
* Copyright (c) 2021 Liviu Ionescu. All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
-
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* If a copy of the license was not distributed with this file, it can
|
|
9
|
-
* be obtained from https://opensource.org/licenses/mit.
|
|
10
|
-
*
|
|
11
|
-
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
|
|
12
|
-
* released under the terms of the Boost Version 1.0 Software License,
|
|
13
|
-
* which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
#ifndef MICRO_TEST_PLUS_TEST_SUITE_H_
|
|
17
|
-
#define MICRO_TEST_PLUS_TEST_SUITE_H_
|
|
18
|
-
|
|
19
|
-
// ----------------------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
#ifdef __cplusplus
|
|
22
|
-
|
|
23
|
-
// ----------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
#include <functional>
|
|
26
|
-
|
|
27
|
-
// ----------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
#if defined(__GNUC__)
|
|
30
|
-
#pragma GCC diagnostic push
|
|
31
|
-
#pragma GCC diagnostic ignored "-Wpadded"
|
|
32
|
-
#if !defined(__clang__) // GCC only
|
|
33
|
-
#pragma GCC diagnostic ignored "-Wsuggest-final-types"
|
|
34
|
-
#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
|
|
35
|
-
#endif
|
|
36
|
-
#if defined(__clang__)
|
|
37
|
-
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
38
|
-
#endif
|
|
39
|
-
#endif
|
|
40
|
-
|
|
41
|
-
namespace micro_os_plus::micro_test_plus
|
|
42
|
-
{
|
|
43
|
-
// --------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @brief Base class for all test suites.
|
|
47
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
48
|
-
*/
|
|
49
|
-
class test_suite_base
|
|
50
|
-
{
|
|
51
|
-
public:
|
|
52
|
-
/**
|
|
53
|
-
* @brief Construct a test suite.
|
|
54
|
-
* @param [in] name The test suite name.
|
|
55
|
-
*/
|
|
56
|
-
test_suite_base (const char* name);
|
|
57
|
-
|
|
58
|
-
// The rule of five.
|
|
59
|
-
test_suite_base (const test_suite_base&) = delete;
|
|
60
|
-
test_suite_base (test_suite_base&&) = delete;
|
|
61
|
-
test_suite_base&
|
|
62
|
-
operator= (const test_suite_base&)
|
|
63
|
-
= delete;
|
|
64
|
-
test_suite_base&
|
|
65
|
-
operator= (test_suite_base&&)
|
|
66
|
-
= delete;
|
|
67
|
-
|
|
68
|
-
virtual ~test_suite_base ();
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @brief Run the sequence of test cases in the suite.
|
|
72
|
-
* @par Parameters
|
|
73
|
-
* None.
|
|
74
|
-
* @par Returns
|
|
75
|
-
* Nothing.
|
|
76
|
-
*/
|
|
77
|
-
virtual void
|
|
78
|
-
run (void);
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @brief Mark the beginning of a named test case.
|
|
82
|
-
* @param [in] name The test case name.
|
|
83
|
-
* @par Returns
|
|
84
|
-
* Nothing.
|
|
85
|
-
*/
|
|
86
|
-
void
|
|
87
|
-
begin_test_case (const char* name);
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @brief Mark the end of a test case.
|
|
91
|
-
* @par Parameters
|
|
92
|
-
* None.
|
|
93
|
-
* @par Returns
|
|
94
|
-
* Nothing.
|
|
95
|
-
*/
|
|
96
|
-
void
|
|
97
|
-
end_test_case (void);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @brief Get the suite name.
|
|
101
|
-
* @par Parameters
|
|
102
|
-
* None.
|
|
103
|
-
* @return A pointer to the null terminated test suite name.
|
|
104
|
-
*/
|
|
105
|
-
[[nodiscard]] constexpr const char*
|
|
106
|
-
name ()
|
|
107
|
-
{
|
|
108
|
-
return name_;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @brief Count one more passed test conditions.
|
|
113
|
-
* @par Parameters
|
|
114
|
-
* None.
|
|
115
|
-
* @par Returns
|
|
116
|
-
* Nothing.
|
|
117
|
-
*/
|
|
118
|
-
void
|
|
119
|
-
increment_successful (void);
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @brief Count one more failed test conditions.
|
|
123
|
-
* @par Parameters
|
|
124
|
-
* None.
|
|
125
|
-
* @par Returns
|
|
126
|
-
* Nothing.
|
|
127
|
-
*/
|
|
128
|
-
void
|
|
129
|
-
increment_failed (void);
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @brief Get the number of conditions that passed.
|
|
133
|
-
* @par Parameters
|
|
134
|
-
* None.
|
|
135
|
-
* @return An integer with the number checks that passed.
|
|
136
|
-
*/
|
|
137
|
-
[[nodiscard]] constexpr int
|
|
138
|
-
successful_checks (void)
|
|
139
|
-
{
|
|
140
|
-
return successful_checks_;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @brief Get the number of conditions that failed.
|
|
145
|
-
* @par Parameters
|
|
146
|
-
* None.
|
|
147
|
-
* @return An integer with the number checks that failed.
|
|
148
|
-
*/
|
|
149
|
-
[[nodiscard]] constexpr int
|
|
150
|
-
failed_checks (void)
|
|
151
|
-
{
|
|
152
|
-
return failed_checks_;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @brief Get the number of test cases.
|
|
157
|
-
* @par Parameters
|
|
158
|
-
* None.
|
|
159
|
-
* @return An integer with the number of test cases.
|
|
160
|
-
*/
|
|
161
|
-
[[nodiscard]] constexpr int
|
|
162
|
-
test_cases (void)
|
|
163
|
-
{
|
|
164
|
-
return test_cases_;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @brief Begin the execution of the test suite.
|
|
169
|
-
* @par Parameters
|
|
170
|
-
* None.
|
|
171
|
-
* @par Returns
|
|
172
|
-
* Nothing.
|
|
173
|
-
*/
|
|
174
|
-
void
|
|
175
|
-
begin_test_suite (void);
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* @brief Mark the end of the test suite.
|
|
179
|
-
* @par Parameters
|
|
180
|
-
* None.
|
|
181
|
-
* @par Returns
|
|
182
|
-
* Nothing.
|
|
183
|
-
*/
|
|
184
|
-
void
|
|
185
|
-
end_test_suite (void);
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @brief Get the test suite result.
|
|
189
|
-
* @par Parameters
|
|
190
|
-
* None.
|
|
191
|
-
* @return True if the test suite was successful.
|
|
192
|
-
*/
|
|
193
|
-
[[nodiscard]] constexpr bool
|
|
194
|
-
was_successful (void)
|
|
195
|
-
{
|
|
196
|
-
// Also fail if none passed.
|
|
197
|
-
return (failed_checks_ == 0 && successful_checks_ != 0);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* @brief If all counter are null, it is unused.
|
|
202
|
-
* @par Parameters
|
|
203
|
-
* None.
|
|
204
|
-
* @return True if the test suite is not used.
|
|
205
|
-
*/
|
|
206
|
-
[[nodiscard]] constexpr bool
|
|
207
|
-
unused (void)
|
|
208
|
-
{
|
|
209
|
-
return (failed_checks_ == 0 && successful_checks_ == 0
|
|
210
|
-
&& test_cases_ == 0);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
protected:
|
|
214
|
-
/**
|
|
215
|
-
* @brief The test suite name.
|
|
216
|
-
*/
|
|
217
|
-
const char* name_;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @brief The current test case name.
|
|
221
|
-
*/
|
|
222
|
-
const char* test_case_name_;
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @brief Count of test conditions that passed.
|
|
226
|
-
*/
|
|
227
|
-
int successful_checks_ = 0;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @brief Count of test conditions that failed.
|
|
231
|
-
*/
|
|
232
|
-
int failed_checks_ = 0;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* @brief Count of test cases in the test suite.
|
|
236
|
-
*/
|
|
237
|
-
int test_cases_ = 0;
|
|
238
|
-
|
|
239
|
-
public:
|
|
240
|
-
bool process_deferred_begin = true;
|
|
241
|
-
struct
|
|
242
|
-
{
|
|
243
|
-
int successful_checks;
|
|
244
|
-
int failed_checks;
|
|
245
|
-
} current_test_case{};
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @ingroup micro-test-plus-test-suites
|
|
250
|
-
* @brief Test suites are classes that represent a named group of
|
|
251
|
-
* test cases which self register to the runner.
|
|
252
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
253
|
-
*/
|
|
254
|
-
class test_suite : public test_suite_base
|
|
255
|
-
{
|
|
256
|
-
public:
|
|
257
|
-
/**
|
|
258
|
-
* @brief Construct a test suite.
|
|
259
|
-
* @tparam Callable_T The type of an object that can be called.
|
|
260
|
-
* @tparam Args_T The type of the callable arguments.
|
|
261
|
-
* @param [in] name The test case name or description.
|
|
262
|
-
* A short string used in the report.
|
|
263
|
-
* @param [in] callable A generic callable object,
|
|
264
|
-
* invoked to perform the test. Usually a lambda.
|
|
265
|
-
* @param [in] arguments A possibly empty list of arguments to be
|
|
266
|
-
* passed to the callable.
|
|
267
|
-
*/
|
|
268
|
-
template <typename Callable_T, typename... Args_T>
|
|
269
|
-
test_suite (const char* name, Callable_T&& callable,
|
|
270
|
-
Args_T&&... arguments);
|
|
271
|
-
|
|
272
|
-
// The rule of five.
|
|
273
|
-
test_suite (const test_suite&) = delete;
|
|
274
|
-
test_suite (test_suite&&) = delete;
|
|
275
|
-
test_suite&
|
|
276
|
-
operator= (const test_suite&)
|
|
277
|
-
= delete;
|
|
278
|
-
test_suite&
|
|
279
|
-
operator= (test_suite&&)
|
|
280
|
-
= delete;
|
|
281
|
-
|
|
282
|
-
virtual ~test_suite () override;
|
|
283
|
-
|
|
284
|
-
virtual void
|
|
285
|
-
run (void) override;
|
|
286
|
-
|
|
287
|
-
protected:
|
|
288
|
-
std::function<void (void)> callable_;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// --------------------------------------------------------------------------
|
|
292
|
-
} // namespace micro_os_plus::micro_test_plus
|
|
293
|
-
|
|
294
|
-
#if defined(__GNUC__)
|
|
295
|
-
#pragma GCC diagnostic pop
|
|
296
|
-
#endif
|
|
297
|
-
|
|
298
|
-
// ----------------------------------------------------------------------------
|
|
299
|
-
|
|
300
|
-
#endif // __cplusplus
|
|
301
|
-
|
|
302
|
-
// ----------------------------------------------------------------------------
|
|
303
|
-
|
|
304
|
-
#endif // MICRO_TEST_PLUS_TEST_SUITE_H_
|
|
305
|
-
|
|
306
|
-
// ----------------------------------------------------------------------------
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
|
|
3
|
-
* Copyright (c) 2021 Liviu Ionescu. All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
-
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* If a copy of the license was not distributed with this file, it can
|
|
9
|
-
* be obtained from https://opensource.org/licenses/mit.
|
|
10
|
-
*
|
|
11
|
-
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
|
|
12
|
-
* released under the terms of the Boost Version 1.0 Software License,
|
|
13
|
-
* which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
#ifndef MICRO_TEST_PLUS_TYPE_TRAITS_H_
|
|
17
|
-
#define MICRO_TEST_PLUS_TYPE_TRAITS_H_
|
|
18
|
-
|
|
19
|
-
// ----------------------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
#ifdef __cplusplus
|
|
22
|
-
|
|
23
|
-
// ----------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
#include "math.h"
|
|
26
|
-
|
|
27
|
-
// ----------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
#if defined(__GNUC__)
|
|
30
|
-
#pragma GCC diagnostic push
|
|
31
|
-
#if defined(__clang__)
|
|
32
|
-
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
33
|
-
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
|
34
|
-
#endif
|
|
35
|
-
#endif
|
|
36
|
-
|
|
37
|
-
namespace micro_os_plus::micro_test_plus
|
|
38
|
-
{
|
|
39
|
-
// --------------------------------------------------------------------------
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @brief Local type traits. Some may have standard equivalents, but
|
|
43
|
-
* better keep them locally.
|
|
44
|
-
*/
|
|
45
|
-
namespace type_traits
|
|
46
|
-
{
|
|
47
|
-
/**
|
|
48
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
49
|
-
*/
|
|
50
|
-
template <class...>
|
|
51
|
-
struct list
|
|
52
|
-
{
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
57
|
-
*/
|
|
58
|
-
template <class T, class...>
|
|
59
|
-
struct identity
|
|
60
|
-
{
|
|
61
|
-
using type = T;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
#if defined(__DOXYGEN__)
|
|
65
|
-
// error: Detected potential recursive class relation between class
|
|
66
|
-
// micro_os_plus::micro_test_plus::type_traits::function_traits and base
|
|
67
|
-
// class micro_os_plus::micro_test_plus::type_traits::function_traits<
|
|
68
|
-
// decltype(&T::operator())>!
|
|
69
|
-
// https://github.com/doxygen/doxygen/issues/9915
|
|
70
|
-
#else
|
|
71
|
-
template <class T>
|
|
72
|
-
struct function_traits : function_traits<decltype (&T::operator())>
|
|
73
|
-
{
|
|
74
|
-
};
|
|
75
|
-
#endif
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
79
|
-
*/
|
|
80
|
-
template <class R, class... Args_T>
|
|
81
|
-
struct function_traits<R (*) (Args_T...)>
|
|
82
|
-
{
|
|
83
|
-
using result_type = R;
|
|
84
|
-
using args = list<Args_T...>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
89
|
-
*/
|
|
90
|
-
template <class R, class... Args_T>
|
|
91
|
-
struct function_traits<R (Args_T...)>
|
|
92
|
-
{
|
|
93
|
-
using result_type = R;
|
|
94
|
-
using args = list<Args_T...>;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
99
|
-
*/
|
|
100
|
-
template <class R, class T, class... Args_T>
|
|
101
|
-
struct function_traits<R (T::*) (Args_T...)>
|
|
102
|
-
{
|
|
103
|
-
using result_type = R;
|
|
104
|
-
using args = list<Args_T...>;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
109
|
-
*/
|
|
110
|
-
template <class R, class T, class... Args_T>
|
|
111
|
-
struct function_traits<R (T::*) (Args_T...) const>
|
|
112
|
-
{
|
|
113
|
-
using result_type = R;
|
|
114
|
-
using args = list<Args_T...>;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
template <class T>
|
|
118
|
-
T&&
|
|
119
|
-
declval ();
|
|
120
|
-
template <class... Ts, class Expr_T>
|
|
121
|
-
constexpr auto
|
|
122
|
-
is_valid (Expr_T expr) -> decltype (expr (declval<Ts...> ()), bool ())
|
|
123
|
-
{
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
template <class...>
|
|
128
|
-
constexpr auto
|
|
129
|
-
is_valid (...) -> bool
|
|
130
|
-
{
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
template <class T>
|
|
135
|
-
static constexpr auto is_container_v = is_valid<T> (
|
|
136
|
-
[] (auto t) -> decltype (t.begin (), t.end (), void ()) {});
|
|
137
|
-
|
|
138
|
-
template <class T>
|
|
139
|
-
static constexpr auto has_npos_v
|
|
140
|
-
= is_valid<T> ([] (auto t) -> decltype (void (t.npos)) {});
|
|
141
|
-
|
|
142
|
-
template <class T>
|
|
143
|
-
static constexpr auto has_value_v
|
|
144
|
-
= is_valid<T> ([] (auto t) -> decltype (void (t.value)) {});
|
|
145
|
-
|
|
146
|
-
template <class T>
|
|
147
|
-
static constexpr auto has_epsilon_v
|
|
148
|
-
= is_valid<T> ([] (auto t) -> decltype (void (t.epsilon)) {});
|
|
149
|
-
|
|
150
|
-
template <class T>
|
|
151
|
-
inline constexpr auto is_floating_point_v = false;
|
|
152
|
-
template <>
|
|
153
|
-
inline constexpr auto is_floating_point_v<float> = true;
|
|
154
|
-
template <>
|
|
155
|
-
inline constexpr auto is_floating_point_v<double> = true;
|
|
156
|
-
template <>
|
|
157
|
-
inline constexpr auto is_floating_point_v<long double> = true;
|
|
158
|
-
|
|
159
|
-
#if defined(__clang__) or defined(_MSC_VER)
|
|
160
|
-
template <class From, class To>
|
|
161
|
-
static constexpr auto is_convertible_v = __is_convertible_to (From, To);
|
|
162
|
-
#else
|
|
163
|
-
template <class From, class To>
|
|
164
|
-
constexpr auto
|
|
165
|
-
is_convertible (int) -> decltype (bool (To (declval<From> ())))
|
|
166
|
-
{
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
template <class...>
|
|
170
|
-
constexpr auto
|
|
171
|
-
is_convertible (...)
|
|
172
|
-
{
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
template <class From, class To>
|
|
176
|
-
constexpr auto is_convertible_v = is_convertible<From, To> (0);
|
|
177
|
-
#endif
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
181
|
-
*/
|
|
182
|
-
template <bool>
|
|
183
|
-
struct requires_
|
|
184
|
-
{
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
189
|
-
*/
|
|
190
|
-
template <>
|
|
191
|
-
struct requires_<true>
|
|
192
|
-
{
|
|
193
|
-
using type = int;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
template <bool Cond>
|
|
197
|
-
using requires_t = typename requires_<Cond>::type;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @brief Empty base class of all operators.
|
|
201
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
202
|
-
*/
|
|
203
|
-
struct op
|
|
204
|
-
{
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @brief A generic integral constant.
|
|
209
|
-
* It has a getter and a '-' operator to return the negative value.
|
|
210
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
211
|
-
*/
|
|
212
|
-
template <auto N>
|
|
213
|
-
struct integral_constant : op
|
|
214
|
-
{
|
|
215
|
-
using value_type = decltype (N);
|
|
216
|
-
static constexpr auto value = N;
|
|
217
|
-
|
|
218
|
-
[[nodiscard]] constexpr auto
|
|
219
|
-
operator- () const
|
|
220
|
-
{
|
|
221
|
-
return integral_constant<-N>{};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
[[nodiscard]] constexpr explicit
|
|
225
|
-
operator value_type () const
|
|
226
|
-
{
|
|
227
|
-
return N;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
[[nodiscard]] constexpr auto
|
|
231
|
-
get () const
|
|
232
|
-
{
|
|
233
|
-
return N;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @brief A generic floating point constant, with custom size
|
|
239
|
-
* and precision.
|
|
240
|
-
* It has a getter and a '-' operator to return the negative value.
|
|
241
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
242
|
-
*/
|
|
243
|
-
template <class T, auto N, auto D, auto Size, auto P = 1>
|
|
244
|
-
struct floating_point_constant : op
|
|
245
|
-
{
|
|
246
|
-
using value_type = T;
|
|
247
|
-
|
|
248
|
-
static constexpr auto epsilon = T (1) / math::pow (T (10), Size - 1);
|
|
249
|
-
static constexpr auto value
|
|
250
|
-
= T (P) * (T (N) + (T (D) / math::pow (T (10), Size)));
|
|
251
|
-
|
|
252
|
-
[[nodiscard]] constexpr auto
|
|
253
|
-
operator- () const
|
|
254
|
-
{
|
|
255
|
-
return floating_point_constant<T, N, D, Size, -1>{};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
[[nodiscard]] constexpr explicit
|
|
259
|
-
operator value_type () const
|
|
260
|
-
{
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
[[nodiscard]] constexpr auto
|
|
265
|
-
get () const
|
|
266
|
-
{
|
|
267
|
-
return value;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
273
|
-
*/
|
|
274
|
-
template <class T>
|
|
275
|
-
struct genuine_integral_value : op
|
|
276
|
-
{
|
|
277
|
-
using value_type = T;
|
|
278
|
-
|
|
279
|
-
constexpr genuine_integral_value (const T& _value) : value_{ _value }
|
|
280
|
-
{
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
[[nodiscard]] constexpr explicit
|
|
284
|
-
operator T () const
|
|
285
|
-
{
|
|
286
|
-
return value_;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
[[nodiscard]] constexpr decltype (auto)
|
|
290
|
-
get () const
|
|
291
|
-
{
|
|
292
|
-
return value_;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
T value_{};
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
template <class T>
|
|
299
|
-
inline constexpr auto is_op_v = __is_base_of (type_traits::op, T);
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* @brief Class defining a generic value, accessible via a getter.
|
|
303
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
304
|
-
*/
|
|
305
|
-
template <class T, class = int>
|
|
306
|
-
struct value : type_traits::op
|
|
307
|
-
{
|
|
308
|
-
using value_type = T;
|
|
309
|
-
|
|
310
|
-
constexpr value (const T& _value) : value_{ _value }
|
|
311
|
-
{
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
[[nodiscard]] constexpr explicit
|
|
315
|
-
operator T () const
|
|
316
|
-
{
|
|
317
|
-
return value_;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
[[nodiscard]] constexpr decltype (auto)
|
|
321
|
-
get () const
|
|
322
|
-
{
|
|
323
|
-
return value_;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
T value_{};
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* @brief A generic value used to define floating points, which,
|
|
331
|
-
* in addition to the actual value, has an epsilon, to use the
|
|
332
|
-
* desired precision during comparisons.
|
|
333
|
-
* If missing, the default is 1 / (10^decimals).
|
|
334
|
-
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
335
|
-
*/
|
|
336
|
-
template <class T>
|
|
337
|
-
struct value<T,
|
|
338
|
-
type_traits::requires_t<type_traits::is_floating_point_v<T>>>
|
|
339
|
-
: type_traits::op
|
|
340
|
-
{
|
|
341
|
-
using value_type = T;
|
|
342
|
-
static inline auto epsilon = T{}; // Why static?
|
|
343
|
-
|
|
344
|
-
constexpr value (const T& _value, const T precision) : value_{ _value }
|
|
345
|
-
{
|
|
346
|
-
epsilon = precision;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
constexpr /*explicit(false)*/ value (const T& val)
|
|
350
|
-
: value{ val,
|
|
351
|
-
T (1)
|
|
352
|
-
/ math::pow (T (10),
|
|
353
|
-
math::den_size<unsigned long long> (val)) }
|
|
354
|
-
{
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
[[nodiscard]] constexpr explicit
|
|
358
|
-
operator T () const
|
|
359
|
-
{
|
|
360
|
-
return value_;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
[[nodiscard]] constexpr decltype (auto)
|
|
364
|
-
get () const
|
|
365
|
-
{
|
|
366
|
-
return value_;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
T value_{};
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
} // namespace type_traits
|
|
373
|
-
|
|
374
|
-
// --------------------------------------------------------------------------
|
|
375
|
-
} // namespace micro_os_plus::micro_test_plus
|
|
376
|
-
|
|
377
|
-
#if defined(__GNUC__)
|
|
378
|
-
#pragma GCC diagnostic pop
|
|
379
|
-
#endif
|
|
380
|
-
|
|
381
|
-
// ----------------------------------------------------------------------------
|
|
382
|
-
|
|
383
|
-
#endif // __cplusplus
|
|
384
|
-
|
|
385
|
-
// ----------------------------------------------------------------------------
|
|
386
|
-
|
|
387
|
-
#endif // MICRO_TEST_PLUS_TYPE_TRAITS_H_
|
|
388
|
-
|
|
389
|
-
// ----------------------------------------------------------------------------
|