@micro-os-plus/micro-test-plus 3.2.2 → 3.3.0
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 +417 -2
- package/CMakeLists.txt +33 -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 +1908 -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 +476 -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-basic.h +289 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter-tap.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-reporter.h +846 -0
- package/include/micro-os-plus/micro-test-plus/test-runner.h +281 -0
- package/include/micro-os-plus/micro-test-plus/test-suite.h +492 -0
- package/include/micro-os-plus/micro-test-plus/type-traits.h +1148 -0
- package/include/micro-os-plus/micro-test-plus.h +172 -552
- package/meson.build +7 -5
- package/package.json +29 -34
- package/src/micro-test-plus.cpp +134 -37
- package/src/test-reporter-basic.cpp +466 -0
- package/src/test-reporter-tap.cpp +530 -0
- package/src/test-reporter.cpp +207 -240
- package/src/test-runner.cpp +135 -23
- package/src/test-suite.cpp +182 -10
- 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
|
@@ -0,0 +1,1908 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* 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 be
|
|
9
|
+
* 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
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
* @brief C++ header file with declarations for the µTest++ internals.
|
|
21
|
+
*
|
|
22
|
+
* @details
|
|
23
|
+
* This header provides the declarations for the internal components of the
|
|
24
|
+
* µTest++ framework, encapsulated within the
|
|
25
|
+
* `micro_os_plus::micro_test_plus::detail` namespace. It defines the core
|
|
26
|
+
* mechanisms, helper structures, and utility templates that underpin the
|
|
27
|
+
* framework's assertion handling, value retrieval, comparator logic, deferred
|
|
28
|
+
* reporting, and exception checking facilities.
|
|
29
|
+
*
|
|
30
|
+
* All definitions reside within the `micro_os_plus::micro_test_plus::detail`
|
|
31
|
+
* namespace, ensuring clear separation from user code and minimising the risk
|
|
32
|
+
* of naming conflicts.
|
|
33
|
+
*
|
|
34
|
+
* The header files are organised within the
|
|
35
|
+
* `include/micro-os-plus/micro-test-plus` folder to maintain a structured and
|
|
36
|
+
* modular codebase.
|
|
37
|
+
*
|
|
38
|
+
* This file is intended solely for internal use within the framework and
|
|
39
|
+
* should not be included directly by user code.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
#ifndef MICRO_TEST_PLUS_DETAIL_H_
|
|
43
|
+
#define MICRO_TEST_PLUS_DETAIL_H_
|
|
44
|
+
|
|
45
|
+
// ----------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
#ifdef __cplusplus
|
|
48
|
+
|
|
49
|
+
// ----------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
#include <stdio.h>
|
|
52
|
+
#include <string>
|
|
53
|
+
|
|
54
|
+
// ----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
#if defined(__GNUC__)
|
|
57
|
+
#pragma GCC diagnostic push
|
|
58
|
+
#pragma GCC diagnostic ignored "-Wpadded"
|
|
59
|
+
#pragma GCC diagnostic ignored "-Waggregate-return"
|
|
60
|
+
#if defined(__clang__)
|
|
61
|
+
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
62
|
+
#endif
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
namespace micro_os_plus::micro_test_plus
|
|
66
|
+
{
|
|
67
|
+
// --------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @namespace micro_os_plus::micro_test_plus::detail
|
|
71
|
+
* @brief Internal implementation details for the µTest++ framework.
|
|
72
|
+
*
|
|
73
|
+
* @details
|
|
74
|
+
* The `detail` namespace encapsulates the internal mechanisms, helper
|
|
75
|
+
* structures, and implementation utilities employed by the µTest++ testing
|
|
76
|
+
* framework. These components do not form part of the public API and may be
|
|
77
|
+
* modified without prior notice.
|
|
78
|
+
*
|
|
79
|
+
* Within this namespace, one will find assertion handling, generic getter
|
|
80
|
+
* utilities, comparator structures for logical and relational operations,
|
|
81
|
+
* mechanisms for exception checking, and base classes for deferred reporting
|
|
82
|
+
* of test results.
|
|
83
|
+
*
|
|
84
|
+
* All definitions within `detail` are intended exclusively for internal use,
|
|
85
|
+
* ensuring a clear distinction between user-facing and internal components.
|
|
86
|
+
* This approach enhances maintainability, mitigates the risk of naming
|
|
87
|
+
* conflicts, and keeps the public API succinct.
|
|
88
|
+
*
|
|
89
|
+
* The relevant header files are organised within the `include/micro-os-plus`
|
|
90
|
+
* folder to maintain a structured and modular codebase.
|
|
91
|
+
*/
|
|
92
|
+
namespace detail
|
|
93
|
+
{
|
|
94
|
+
/**
|
|
95
|
+
* @brief Assertion struct template for parameter passing to the evaluator.
|
|
96
|
+
*
|
|
97
|
+
* @tparam Expr_T The type of the expression being asserted.
|
|
98
|
+
*
|
|
99
|
+
* @details
|
|
100
|
+
* The `assertion` struct template is used to encapsulate assertion
|
|
101
|
+
* parameters, including the expression under evaluation and its associated
|
|
102
|
+
* source location. This design enables precise reporting and diagnostics
|
|
103
|
+
* within the framework.
|
|
104
|
+
*
|
|
105
|
+
* The structure is intended exclusively for internal use and is
|
|
106
|
+
* implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
107
|
+
* maintain a structured and modular codebase.
|
|
108
|
+
*
|
|
109
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
110
|
+
*/
|
|
111
|
+
template <class Expr_T>
|
|
112
|
+
struct assertion
|
|
113
|
+
{
|
|
114
|
+
/**
|
|
115
|
+
* @brief The expression under evaluation.
|
|
116
|
+
*/
|
|
117
|
+
Expr_T expr{};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @brief The source location associated with the assertion.
|
|
121
|
+
*/
|
|
122
|
+
reflection::source_location location{};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// ------------------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
// in C++14/17/20, a function template with a deduced return type
|
|
128
|
+
// (auto) cannot be used before its definition is visible.
|
|
129
|
+
// Therefore it is not possible to split definitions.
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @brief Generic getter function template for value retrieval.
|
|
133
|
+
*
|
|
134
|
+
* @tparam T The type from which the value is to be retrieved.
|
|
135
|
+
*
|
|
136
|
+
* @param t The object or value to be accessed.
|
|
137
|
+
* @return The value obtained via the relevant getter implementation.
|
|
138
|
+
*
|
|
139
|
+
* @details
|
|
140
|
+
* The `get` function template invokes the appropriate getter
|
|
141
|
+
* implementation to retrieve the value from the provided object or type.
|
|
142
|
+
* This function ensures consistent access to values for both custom and
|
|
143
|
+
* standard types within the framework.
|
|
144
|
+
*
|
|
145
|
+
* The primary implementation attempts to invoke a `get()` method if it
|
|
146
|
+
* exists, which is recommended for user-defined types to ensure consistent
|
|
147
|
+
* value access. If the type does not provide a `get()` method, the
|
|
148
|
+
* fallback variadic implementation simply returns the original argument.
|
|
149
|
+
*
|
|
150
|
+
* The `get` function template delegates to these implementations, enabling
|
|
151
|
+
* seamless support for a wide range of types in test expressions and
|
|
152
|
+
* comparators.
|
|
153
|
+
*
|
|
154
|
+
* All definitions are intended for internal use within the framework and
|
|
155
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
156
|
+
* maintain a structured and modular codebase.
|
|
157
|
+
*/
|
|
158
|
+
template <class T>
|
|
159
|
+
[[nodiscard]] constexpr auto
|
|
160
|
+
get_impl (const T& t, int) -> decltype (t.get ())
|
|
161
|
+
{
|
|
162
|
+
return t.get ();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @brief Fallback variadic getter function template.
|
|
167
|
+
*
|
|
168
|
+
* @tparam T The type from which the value is to be retrieved.
|
|
169
|
+
*
|
|
170
|
+
* @param t The object or value to be accessed.
|
|
171
|
+
* @return The original argument `t`.
|
|
172
|
+
*
|
|
173
|
+
* @details
|
|
174
|
+
* The `get_impl` function template serves as a fallback mechanism for
|
|
175
|
+
* value retrieval when the provided type does not implement a `get()`
|
|
176
|
+
* member function. It simply returns the first argument, discarding any
|
|
177
|
+
* additional parameters.
|
|
178
|
+
*
|
|
179
|
+
* This approach ensures that both custom types (with a `get()` method) and
|
|
180
|
+
* standard types (without a `get()` method) are supported seamlessly
|
|
181
|
+
* within the framework's generic getter utilities.
|
|
182
|
+
*
|
|
183
|
+
* All definitions are intended for internal use within the framework and
|
|
184
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
185
|
+
* maintain a structured and modular codebase.
|
|
186
|
+
*/
|
|
187
|
+
template <class T>
|
|
188
|
+
[[nodiscard]] constexpr auto
|
|
189
|
+
get_impl (const T& t, ...) -> decltype (auto)
|
|
190
|
+
{
|
|
191
|
+
return t;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @brief Generic getter function template for value retrieval.
|
|
196
|
+
*
|
|
197
|
+
* @tparam T The type from which the value is to be retrieved.
|
|
198
|
+
*
|
|
199
|
+
* @param t The object or value to be accessed.
|
|
200
|
+
* @return The value obtained via the relevant getter implementation.
|
|
201
|
+
*
|
|
202
|
+
* @details
|
|
203
|
+
* The `get` function template invokes the appropriate getter
|
|
204
|
+
* implementation to retrieve the value from the provided object or type.
|
|
205
|
+
* This function ensures consistent access to values for both custom and
|
|
206
|
+
* standard types within the framework.
|
|
207
|
+
*
|
|
208
|
+
* The primary implementation attempts to invoke a `get()` method if it
|
|
209
|
+
* exists, which is recommended for user-defined types to ensure consistent
|
|
210
|
+
* value access. If the type does not provide a `get()` method, the
|
|
211
|
+
* fallback variadic implementation simply returns the original argument.
|
|
212
|
+
*
|
|
213
|
+
* The `get` function template delegates to these implementations, enabling
|
|
214
|
+
* seamless support for a wide range of types in test expressions and
|
|
215
|
+
* comparators.
|
|
216
|
+
*
|
|
217
|
+
* All definitions are intended for internal use within the framework and
|
|
218
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
219
|
+
* maintain a structured and modular codebase.
|
|
220
|
+
*/
|
|
221
|
+
template <class T>
|
|
222
|
+
[[nodiscard]] constexpr auto
|
|
223
|
+
get (const T& t)
|
|
224
|
+
{
|
|
225
|
+
// Call the variadic function, basically to force it return `t`.
|
|
226
|
+
return get_impl<T> (t, 0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ------------------------------------------------------------------------
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @brief Equality comparator struct template.
|
|
233
|
+
*
|
|
234
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
235
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
236
|
+
*
|
|
237
|
+
* @details
|
|
238
|
+
* The `eq_` struct template provides a type-safe mechanism for evaluating
|
|
239
|
+
* equality between two operands within the framework.
|
|
240
|
+
*
|
|
241
|
+
* This comparator supports a variety of operand types, including those
|
|
242
|
+
* with static values, types with precision (epsilon), and generic types.
|
|
243
|
+
* For types with static values, the comparison is performed directly. For
|
|
244
|
+
* types supporting precision, the comparison accounts for the smallest
|
|
245
|
+
* epsilon to ensure accuracy, particularly for floating-point types. For
|
|
246
|
+
* all other types, the generic getter is used to retrieve and compare the
|
|
247
|
+
* values.
|
|
248
|
+
*
|
|
249
|
+
* The implementation is optimised for use in embedded environments and
|
|
250
|
+
* supports both compile-time and run-time evaluation.
|
|
251
|
+
*
|
|
252
|
+
* All definitions are intended for internal use within the framework and
|
|
253
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
254
|
+
* maintain a structured and modular codebase.
|
|
255
|
+
*
|
|
256
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
257
|
+
*/
|
|
258
|
+
template <class Lhs_T, class Rhs_T>
|
|
259
|
+
struct eq_ : type_traits::op
|
|
260
|
+
{
|
|
261
|
+
/**
|
|
262
|
+
* @brief Constructs an equality comparator for the given operands.
|
|
263
|
+
*
|
|
264
|
+
* @param lhs The left-hand operand.
|
|
265
|
+
* @param rhs The right-hand operand.
|
|
266
|
+
*
|
|
267
|
+
* @details
|
|
268
|
+
* Evaluates the equality of the provided operands at construction,
|
|
269
|
+
* supporting static values, types with precision, and generic types. The
|
|
270
|
+
* result is stored in the `value_` member for efficient access.
|
|
271
|
+
*/
|
|
272
|
+
constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
273
|
+
: lhs_{ lhs }, rhs_{ rhs }, value_{
|
|
274
|
+
[&]
|
|
275
|
+
{
|
|
276
|
+
// This lambda is called in the constructor to
|
|
277
|
+
// evaluate the comparison.
|
|
278
|
+
using std::operator==;
|
|
279
|
+
using std::operator<;
|
|
280
|
+
|
|
281
|
+
#if defined(__GNUC__)
|
|
282
|
+
#pragma GCC diagnostic push
|
|
283
|
+
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
|
284
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
285
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
286
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
287
|
+
#if defined(__clang__)
|
|
288
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
289
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
290
|
+
#endif
|
|
291
|
+
#endif
|
|
292
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
293
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
294
|
+
{
|
|
295
|
+
// If both types have values (like numeric constants),
|
|
296
|
+
// compare them directly.
|
|
297
|
+
return Lhs_T::value == Rhs_T::value;
|
|
298
|
+
}
|
|
299
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>
|
|
300
|
+
and type_traits::has_epsilon_v<Rhs_T>)
|
|
301
|
+
{
|
|
302
|
+
// If both values have precision, compare them using
|
|
303
|
+
// the smalles precision.
|
|
304
|
+
return math::abs (get (lhs) - get (rhs))
|
|
305
|
+
< math::min_value (Lhs_T::epsilon,
|
|
306
|
+
Rhs_T::epsilon);
|
|
307
|
+
}
|
|
308
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
|
|
309
|
+
{
|
|
310
|
+
// If only the left operand has precision, use it.
|
|
311
|
+
return math::abs (get (lhs) - get (rhs))
|
|
312
|
+
< Lhs_T::epsilon;
|
|
313
|
+
}
|
|
314
|
+
else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
|
|
315
|
+
{
|
|
316
|
+
// If only the right operand has precision, use it.
|
|
317
|
+
return math::abs (get (lhs) - get (rhs))
|
|
318
|
+
< Rhs_T::epsilon;
|
|
319
|
+
}
|
|
320
|
+
else
|
|
321
|
+
{
|
|
322
|
+
// Call the generic getters, which might
|
|
323
|
+
// either call the type get() or return the value.
|
|
324
|
+
return get (lhs) == get (rhs);
|
|
325
|
+
}
|
|
326
|
+
#if defined(__GNUC__)
|
|
327
|
+
#pragma GCC diagnostic pop
|
|
328
|
+
#endif
|
|
329
|
+
}()
|
|
330
|
+
}
|
|
331
|
+
{
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @brief Conversion operator to boolean.
|
|
336
|
+
*
|
|
337
|
+
* @par Parameters
|
|
338
|
+
* None.
|
|
339
|
+
* @retval true The operands are considered equal.
|
|
340
|
+
* @retval false The operands are not equal.
|
|
341
|
+
*
|
|
342
|
+
* @details
|
|
343
|
+
* Returns the result of the equality comparison.
|
|
344
|
+
*/
|
|
345
|
+
[[nodiscard]] constexpr
|
|
346
|
+
operator bool () const
|
|
347
|
+
{
|
|
348
|
+
return value_;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @brief Retrieves the left-hand operand.
|
|
353
|
+
*
|
|
354
|
+
* @par Parameters
|
|
355
|
+
* None.
|
|
356
|
+
* @return The extracted left-hand operand.
|
|
357
|
+
*
|
|
358
|
+
* @details
|
|
359
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
360
|
+
* getter to ensure correct extraction for both custom and standard
|
|
361
|
+
* types.
|
|
362
|
+
*/
|
|
363
|
+
[[nodiscard]] constexpr auto
|
|
364
|
+
lhs (void) const
|
|
365
|
+
{
|
|
366
|
+
return get (lhs_);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @brief Retrieves the right-hand operand.
|
|
371
|
+
*
|
|
372
|
+
* @par Parameters
|
|
373
|
+
* None.
|
|
374
|
+
* @return The extracted right-hand operand.
|
|
375
|
+
*
|
|
376
|
+
* @details
|
|
377
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
378
|
+
* getter to ensure correct extraction for both custom and standard
|
|
379
|
+
* types.
|
|
380
|
+
*/
|
|
381
|
+
[[nodiscard]] constexpr auto
|
|
382
|
+
rhs (void) const
|
|
383
|
+
{
|
|
384
|
+
return get (rhs_);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @brief Stores the left-hand operand.
|
|
389
|
+
*/
|
|
390
|
+
const Lhs_T lhs_{};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @brief Stores the right-hand operand.
|
|
394
|
+
*/
|
|
395
|
+
const Rhs_T rhs_{};
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @brief Stores the result of the equality comparison.
|
|
399
|
+
*/
|
|
400
|
+
const bool value_{};
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// Deduction guide.
|
|
404
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
405
|
+
eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
|
|
406
|
+
|
|
407
|
+
// ------------------------------------------------------------------------
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @brief Non-equality comparator struct template.
|
|
411
|
+
*
|
|
412
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
413
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
414
|
+
*
|
|
415
|
+
* @details
|
|
416
|
+
* The `ne_` struct template provides a type-safe mechanism for evaluating
|
|
417
|
+
* non-equality between two operands within the framework.
|
|
418
|
+
*
|
|
419
|
+
* This comparator supports a variety of operand types, including those
|
|
420
|
+
* with static values, types with precision (epsilon), and generic types.
|
|
421
|
+
* For types with static values, the comparison is performed directly. For
|
|
422
|
+
* types supporting precision, the comparison accounts for the smallest
|
|
423
|
+
* epsilon to ensure accuracy, particularly for floating-point types. For
|
|
424
|
+
* all other types, the generic getter is used to retrieve and compare the
|
|
425
|
+
* values.
|
|
426
|
+
*
|
|
427
|
+
* The implementation is optimised for use in embedded environments and
|
|
428
|
+
* supports both compile-time and run-time evaluation.
|
|
429
|
+
*
|
|
430
|
+
* All definitions are intended for internal use within the framework and
|
|
431
|
+
* are implemented in the `include/micro-os-plus` folder to maintain a
|
|
432
|
+
* structured and modular codebase.
|
|
433
|
+
*
|
|
434
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
435
|
+
*/
|
|
436
|
+
template <class Lhs_T, class Rhs_T>
|
|
437
|
+
struct ne_ : type_traits::op
|
|
438
|
+
{
|
|
439
|
+
/**
|
|
440
|
+
* @brief Constructs a non-equality comparator for the given operands.
|
|
441
|
+
*
|
|
442
|
+
* @param lhs The left-hand operand.
|
|
443
|
+
* @param rhs The right-hand operand.
|
|
444
|
+
*
|
|
445
|
+
* @details
|
|
446
|
+
* Evaluates the non-equality of the provided operands at construction,
|
|
447
|
+
* supporting static values, types with precision, and generic types. The
|
|
448
|
+
* result is stored in the `value_` member for efficient access.
|
|
449
|
+
*/
|
|
450
|
+
constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
451
|
+
: lhs_{ lhs }, rhs_{ rhs }, value_{
|
|
452
|
+
[&]
|
|
453
|
+
{
|
|
454
|
+
using std::operator==;
|
|
455
|
+
using std::operator!=;
|
|
456
|
+
using std::operator>;
|
|
457
|
+
|
|
458
|
+
#if defined(__GNUC__)
|
|
459
|
+
#pragma GCC diagnostic push
|
|
460
|
+
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
|
461
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
462
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
463
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
464
|
+
#if defined(__clang__)
|
|
465
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
466
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
467
|
+
#endif
|
|
468
|
+
#endif
|
|
469
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
470
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
471
|
+
{
|
|
472
|
+
return Lhs_T::value != Rhs_T::value;
|
|
473
|
+
}
|
|
474
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>
|
|
475
|
+
and type_traits::has_epsilon_v<Rhs_T>)
|
|
476
|
+
{
|
|
477
|
+
return math::abs (get (lhs_) - get (rhs_))
|
|
478
|
+
> math::min_value (Lhs_T::epsilon,
|
|
479
|
+
Rhs_T::epsilon);
|
|
480
|
+
}
|
|
481
|
+
else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
|
|
482
|
+
{
|
|
483
|
+
return math::abs (get (lhs_) - get (rhs_))
|
|
484
|
+
> Lhs_T::epsilon;
|
|
485
|
+
}
|
|
486
|
+
else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
|
|
487
|
+
{
|
|
488
|
+
return math::abs (get (lhs_) - get (rhs_))
|
|
489
|
+
> Rhs_T::epsilon;
|
|
490
|
+
}
|
|
491
|
+
else
|
|
492
|
+
{
|
|
493
|
+
return get (lhs_) != get (rhs_);
|
|
494
|
+
}
|
|
495
|
+
#if defined(__GNUC__)
|
|
496
|
+
#pragma GCC diagnostic pop
|
|
497
|
+
#endif
|
|
498
|
+
}()
|
|
499
|
+
}
|
|
500
|
+
{
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* @brief Conversion operator to boolean.
|
|
505
|
+
*
|
|
506
|
+
* @par Parameters
|
|
507
|
+
* None.
|
|
508
|
+
* @retval true The operands are considered not equal.
|
|
509
|
+
* @retval false The operands are considered equal.
|
|
510
|
+
*
|
|
511
|
+
* @details
|
|
512
|
+
* Returns the result of the non-equality comparison.
|
|
513
|
+
*/
|
|
514
|
+
[[nodiscard]] constexpr
|
|
515
|
+
operator bool () const
|
|
516
|
+
{
|
|
517
|
+
return value_;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @brief Retrieves the left-hand operand.
|
|
522
|
+
*
|
|
523
|
+
* @par Parameters
|
|
524
|
+
* None.
|
|
525
|
+
* @return The extracted left-hand operand.
|
|
526
|
+
*
|
|
527
|
+
* @details
|
|
528
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
529
|
+
* getter to ensure correct extraction for both custom and standard
|
|
530
|
+
* types.
|
|
531
|
+
*/
|
|
532
|
+
[[nodiscard]] constexpr auto
|
|
533
|
+
lhs (void) const
|
|
534
|
+
{
|
|
535
|
+
return get (lhs_);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @brief Retrieves the right-hand operand.
|
|
540
|
+
*
|
|
541
|
+
* @par Parameters
|
|
542
|
+
* None.
|
|
543
|
+
* @return The extracted right-hand operand.
|
|
544
|
+
*
|
|
545
|
+
* @details
|
|
546
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
547
|
+
* getter to ensure correct extraction for both custom and standard
|
|
548
|
+
* types.
|
|
549
|
+
*/
|
|
550
|
+
[[nodiscard]] constexpr auto
|
|
551
|
+
rhs (void) const
|
|
552
|
+
{
|
|
553
|
+
return get (rhs_);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* @brief Stores the left-hand operand.
|
|
558
|
+
*/
|
|
559
|
+
const Lhs_T lhs_{};
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* @brief Stores the right-hand operand.
|
|
563
|
+
*/
|
|
564
|
+
const Rhs_T rhs_{};
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* @brief Stores the result of the non-equality comparison.
|
|
568
|
+
*/
|
|
569
|
+
const bool value_{};
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// Deduction guide.
|
|
573
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
574
|
+
ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
|
|
575
|
+
|
|
576
|
+
// ------------------------------------------------------------------------
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @brief Greater than comparator struct template.
|
|
580
|
+
*
|
|
581
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
582
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
583
|
+
*
|
|
584
|
+
* @details
|
|
585
|
+
* The `gt_` struct template provides a type-safe mechanism for evaluating
|
|
586
|
+
* whether the left-hand operand is greater than the right-hand operand
|
|
587
|
+
* within the framework.
|
|
588
|
+
*
|
|
589
|
+
* This comparator supports a variety of operand types, including those
|
|
590
|
+
* with static values and generic types. For types with static values, the
|
|
591
|
+
* comparison is performed directly. For all other types, the generic
|
|
592
|
+
* getter is used to retrieve and compare the values.
|
|
593
|
+
*
|
|
594
|
+
* The implementation is optimised for use in embedded environments and
|
|
595
|
+
* supports both compile-time and run-time evaluation.
|
|
596
|
+
*
|
|
597
|
+
* All definitions are intended for internal use within the framework and
|
|
598
|
+
* are implemented in the `include/micro-os-plus` folder to maintain a
|
|
599
|
+
* structured and modular codebase.
|
|
600
|
+
*
|
|
601
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
602
|
+
*/
|
|
603
|
+
template <class Lhs_T, class Rhs_T>
|
|
604
|
+
struct gt_ : type_traits::op
|
|
605
|
+
{
|
|
606
|
+
/**
|
|
607
|
+
* @brief Constructs a greater than comparator for the given operands.
|
|
608
|
+
*
|
|
609
|
+
* @param lhs The left-hand operand.
|
|
610
|
+
* @param rhs The right-hand operand.
|
|
611
|
+
*
|
|
612
|
+
* @details
|
|
613
|
+
* Evaluates whether the left-hand operand is greater than the right-hand
|
|
614
|
+
* operand at construction, supporting static values and generic types.
|
|
615
|
+
* The result is stored in the `value_` member for efficient access.
|
|
616
|
+
*/
|
|
617
|
+
constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
618
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
619
|
+
value_{ [&]
|
|
620
|
+
{
|
|
621
|
+
using std::operator>;
|
|
622
|
+
|
|
623
|
+
#if defined(__GNUC__)
|
|
624
|
+
#pragma GCC diagnostic push
|
|
625
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
626
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
627
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
628
|
+
#if defined(__clang__)
|
|
629
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
630
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
631
|
+
#endif
|
|
632
|
+
#endif
|
|
633
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
634
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
635
|
+
{
|
|
636
|
+
return Lhs_T::value > Rhs_T::value;
|
|
637
|
+
}
|
|
638
|
+
else
|
|
639
|
+
{
|
|
640
|
+
return get (lhs_) > get (rhs_);
|
|
641
|
+
}
|
|
642
|
+
#if defined(__GNUC__)
|
|
643
|
+
#pragma GCC diagnostic pop
|
|
644
|
+
#endif
|
|
645
|
+
}() }
|
|
646
|
+
{
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* @brief Conversion operator to boolean.
|
|
651
|
+
*
|
|
652
|
+
* @par Parameters
|
|
653
|
+
* None.
|
|
654
|
+
* @retval true The left-hand operand is greater than the right-hand
|
|
655
|
+
* operand.
|
|
656
|
+
* @retval false Otherwise.
|
|
657
|
+
*
|
|
658
|
+
* @details
|
|
659
|
+
* Returns the result of the greater than comparison.
|
|
660
|
+
*/
|
|
661
|
+
[[nodiscard]] constexpr
|
|
662
|
+
operator bool () const
|
|
663
|
+
{
|
|
664
|
+
return value_;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* @brief Retrieves the left-hand operand.
|
|
669
|
+
*
|
|
670
|
+
* @par Parameters
|
|
671
|
+
* None.
|
|
672
|
+
* @return The extracted left-hand operand.
|
|
673
|
+
*
|
|
674
|
+
* @details
|
|
675
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
676
|
+
* getter to ensure correct extraction for both custom and standard
|
|
677
|
+
* types.
|
|
678
|
+
*/
|
|
679
|
+
[[nodiscard]] constexpr auto
|
|
680
|
+
lhs (void) const
|
|
681
|
+
{
|
|
682
|
+
return get (lhs_);
|
|
683
|
+
}
|
|
684
|
+
[[nodiscard]] constexpr auto
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* @brief Retrieves the right-hand operand.
|
|
688
|
+
*
|
|
689
|
+
* @par Parameters
|
|
690
|
+
* None.
|
|
691
|
+
* @return The extracted right-hand operand.
|
|
692
|
+
*
|
|
693
|
+
* @details
|
|
694
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
695
|
+
* getter to ensure correct extraction for both custom and standard
|
|
696
|
+
* types.
|
|
697
|
+
*/
|
|
698
|
+
rhs (void) const
|
|
699
|
+
{
|
|
700
|
+
return get (rhs_);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @brief Stores the left-hand operand.
|
|
705
|
+
*/
|
|
706
|
+
const Lhs_T lhs_{};
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* @brief Stores the right-hand operand.
|
|
710
|
+
*/
|
|
711
|
+
const Rhs_T rhs_{};
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* @brief Stores the result of the greater than comparison.
|
|
715
|
+
*/
|
|
716
|
+
const bool value_{};
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// Deduction guide.
|
|
720
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
721
|
+
gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
|
|
722
|
+
|
|
723
|
+
// ------------------------------------------------------------------------
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* @brief Greater than or equal comparator struct template.
|
|
727
|
+
*
|
|
728
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
729
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
730
|
+
*
|
|
731
|
+
* @details
|
|
732
|
+
* The `ge_` struct template provides a type-safe mechanism for evaluating
|
|
733
|
+
* whether the left-hand operand is greater than or equal to the right-hand
|
|
734
|
+
* operand within the framework.
|
|
735
|
+
*
|
|
736
|
+
* This comparator supports a variety of operand types, including those
|
|
737
|
+
* with static values and generic types. For types with static values, the
|
|
738
|
+
* comparison is performed directly. For all other types, the generic
|
|
739
|
+
* getter is used to retrieve and compare the values.
|
|
740
|
+
*
|
|
741
|
+
* The implementation is optimised for use in embedded environments and
|
|
742
|
+
* supports both compile-time and run-time evaluation.
|
|
743
|
+
*
|
|
744
|
+
* All definitions are intended for internal use within the framework and
|
|
745
|
+
* are implemented in the `include/micro-os-plus` folder to maintain a
|
|
746
|
+
* structured and modular codebase.
|
|
747
|
+
*
|
|
748
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
749
|
+
*/
|
|
750
|
+
template <class Lhs_T, class Rhs_T>
|
|
751
|
+
struct ge_ : type_traits::op
|
|
752
|
+
{
|
|
753
|
+
/**
|
|
754
|
+
* @brief Constructs a greater than or equal comparator for the given
|
|
755
|
+
* operands.
|
|
756
|
+
*
|
|
757
|
+
* @param lhs The left-hand operand.
|
|
758
|
+
* @param rhs The right-hand operand.
|
|
759
|
+
*
|
|
760
|
+
* @details
|
|
761
|
+
* Evaluates whether the left-hand operand is greater than or equal to
|
|
762
|
+
* the right-hand operand at construction, supporting static values and
|
|
763
|
+
* generic types. The result is stored in the `value_` member for
|
|
764
|
+
* efficient access.
|
|
765
|
+
*/
|
|
766
|
+
constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
767
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
768
|
+
value_{ [&]
|
|
769
|
+
{
|
|
770
|
+
using std::operator>=;
|
|
771
|
+
|
|
772
|
+
#if defined(__GNUC__)
|
|
773
|
+
#pragma GCC diagnostic push
|
|
774
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
775
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
776
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
777
|
+
#if defined(__clang__)
|
|
778
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
779
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
780
|
+
#endif
|
|
781
|
+
#endif
|
|
782
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
783
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
784
|
+
{
|
|
785
|
+
return Lhs_T::value >= Rhs_T::value;
|
|
786
|
+
}
|
|
787
|
+
else
|
|
788
|
+
{
|
|
789
|
+
return get (lhs_) >= get (rhs_);
|
|
790
|
+
}
|
|
791
|
+
#if defined(__GNUC__)
|
|
792
|
+
#pragma GCC diagnostic pop
|
|
793
|
+
#endif
|
|
794
|
+
}() }
|
|
795
|
+
{
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* @brief Conversion operator to boolean.
|
|
800
|
+
*
|
|
801
|
+
* @par Parameters
|
|
802
|
+
* None.
|
|
803
|
+
* @retval true The left-hand operand is greater than or equal to the
|
|
804
|
+
* right-hand operand.
|
|
805
|
+
* @retval false Otherwise.
|
|
806
|
+
*
|
|
807
|
+
* @details
|
|
808
|
+
* Returns the result of the greater than or equal comparison.
|
|
809
|
+
*/
|
|
810
|
+
[[nodiscard]] constexpr
|
|
811
|
+
operator bool () const
|
|
812
|
+
{
|
|
813
|
+
return value_;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* @brief Retrieves the left-hand operand.
|
|
818
|
+
*
|
|
819
|
+
* @par Parameters
|
|
820
|
+
* None.
|
|
821
|
+
* @return The extracted left-hand operand.
|
|
822
|
+
*
|
|
823
|
+
* @details
|
|
824
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
825
|
+
* getter to ensure correct extraction for both custom and standard
|
|
826
|
+
* types.
|
|
827
|
+
*/
|
|
828
|
+
[[nodiscard]] constexpr auto
|
|
829
|
+
lhs (void) const
|
|
830
|
+
{
|
|
831
|
+
return get (lhs_);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* @brief Retrieves the right-hand operand.
|
|
836
|
+
*
|
|
837
|
+
* @par Parameters
|
|
838
|
+
* None.
|
|
839
|
+
* @return The extracted right-hand operand.
|
|
840
|
+
*
|
|
841
|
+
* @details
|
|
842
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
843
|
+
* getter to ensure correct extraction for both custom and standard
|
|
844
|
+
* types.
|
|
845
|
+
*/
|
|
846
|
+
[[nodiscard]] constexpr auto
|
|
847
|
+
rhs (void) const
|
|
848
|
+
{
|
|
849
|
+
return get (rhs_);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @brief Stores the left-hand operand.
|
|
854
|
+
*/
|
|
855
|
+
const Lhs_T lhs_{};
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* @brief Stores the right-hand operand.
|
|
859
|
+
*/
|
|
860
|
+
const Rhs_T rhs_{};
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @brief Stores the result of the greater than or equal comparison.
|
|
864
|
+
*/
|
|
865
|
+
const bool value_{};
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// Deduction guide.
|
|
869
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
870
|
+
ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
|
|
871
|
+
|
|
872
|
+
// ------------------------------------------------------------------------
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* @brief Less than comparator struct template.
|
|
876
|
+
*
|
|
877
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
878
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
879
|
+
*
|
|
880
|
+
* @details
|
|
881
|
+
* The `lt_` struct template provides a type-safe mechanism for evaluating
|
|
882
|
+
* whether the left-hand operand is less than the right-hand operand within
|
|
883
|
+
* the framework.
|
|
884
|
+
*
|
|
885
|
+
* This comparator supports a variety of operand types, including those
|
|
886
|
+
* with static values and generic types. For types with static values, the
|
|
887
|
+
* comparison is performed directly. For all other types, the generic
|
|
888
|
+
* getter is used to retrieve and compare the values.
|
|
889
|
+
*
|
|
890
|
+
* The implementation is optimised for use in embedded environments and
|
|
891
|
+
* supports both compile-time and run-time evaluation.
|
|
892
|
+
*
|
|
893
|
+
* All definitions are intended for internal use within the framework and
|
|
894
|
+
* are implemented in the `include/micro-os-plus` folder to maintain a
|
|
895
|
+
* structured and modular codebase.
|
|
896
|
+
*
|
|
897
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
898
|
+
*/
|
|
899
|
+
template <class Lhs_T, class Rhs_T>
|
|
900
|
+
struct lt_ : type_traits::op
|
|
901
|
+
{
|
|
902
|
+
/**
|
|
903
|
+
* @brief Constructs a less than comparator for the given operands.
|
|
904
|
+
*
|
|
905
|
+
* @param lhs The left-hand operand.
|
|
906
|
+
* @param rhs The right-hand operand.
|
|
907
|
+
*
|
|
908
|
+
* @details
|
|
909
|
+
* Evaluates whether the left-hand operand is less than the right-hand
|
|
910
|
+
* operand at construction, supporting static values and generic types.
|
|
911
|
+
* The result is stored in the `value_` member for efficient access.
|
|
912
|
+
*/
|
|
913
|
+
constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
914
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
915
|
+
value_{ [&]
|
|
916
|
+
{
|
|
917
|
+
using std::operator<;
|
|
918
|
+
|
|
919
|
+
#if defined(__GNUC__)
|
|
920
|
+
#pragma GCC diagnostic push
|
|
921
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
922
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
923
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
924
|
+
#if defined(__clang__)
|
|
925
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
926
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
927
|
+
#endif
|
|
928
|
+
#endif
|
|
929
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
930
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
931
|
+
{
|
|
932
|
+
return Lhs_T::value < Rhs_T::value;
|
|
933
|
+
}
|
|
934
|
+
else
|
|
935
|
+
{
|
|
936
|
+
return get (lhs_) < get (rhs_);
|
|
937
|
+
}
|
|
938
|
+
#if defined(__GNUC__)
|
|
939
|
+
#pragma GCC diagnostic pop
|
|
940
|
+
#endif
|
|
941
|
+
}() }
|
|
942
|
+
{
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* @brief Conversion operator to boolean.
|
|
947
|
+
*
|
|
948
|
+
* @par Parameters
|
|
949
|
+
* None.
|
|
950
|
+
* @retval true The left-hand operand is less than the right-hand
|
|
951
|
+
* operand.
|
|
952
|
+
* @retval false Otherwise.
|
|
953
|
+
*
|
|
954
|
+
* @details
|
|
955
|
+
* Returns the result of the less than comparison.
|
|
956
|
+
*/
|
|
957
|
+
[[nodiscard]] constexpr
|
|
958
|
+
operator bool () const
|
|
959
|
+
{
|
|
960
|
+
return value_;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* @brief Retrieves the left-hand operand.
|
|
965
|
+
*
|
|
966
|
+
* @par Parameters
|
|
967
|
+
* None.
|
|
968
|
+
* @return The extracted left-hand operand.
|
|
969
|
+
*
|
|
970
|
+
* @details
|
|
971
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
972
|
+
* getter to ensure correct extraction for both custom and standard
|
|
973
|
+
* types.
|
|
974
|
+
*/
|
|
975
|
+
[[nodiscard]] constexpr auto
|
|
976
|
+
lhs (void) const
|
|
977
|
+
{
|
|
978
|
+
return get (lhs_);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* @brief Retrieves the right-hand operand.
|
|
983
|
+
*
|
|
984
|
+
* @par Parameters
|
|
985
|
+
* None.
|
|
986
|
+
* @return The extracted right-hand operand.
|
|
987
|
+
*
|
|
988
|
+
* @details
|
|
989
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
990
|
+
* getter to ensure correct extraction for both custom and standard
|
|
991
|
+
* types.
|
|
992
|
+
*/
|
|
993
|
+
[[nodiscard]] constexpr auto
|
|
994
|
+
rhs (void) const
|
|
995
|
+
{
|
|
996
|
+
return get (rhs_);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
private:
|
|
1000
|
+
/**
|
|
1001
|
+
* @brief Stores the left-hand operand.
|
|
1002
|
+
*/
|
|
1003
|
+
const Lhs_T lhs_{};
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* @brief Stores the right-hand operand.
|
|
1007
|
+
*/
|
|
1008
|
+
const Rhs_T rhs_{};
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* @brief Stores the result of the less than comparison.
|
|
1012
|
+
*/
|
|
1013
|
+
const bool value_{};
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
// Deduction guide.
|
|
1017
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
1018
|
+
lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
|
|
1019
|
+
|
|
1020
|
+
// ------------------------------------------------------------------------
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* @brief Less than or equal comparator struct template.
|
|
1024
|
+
*
|
|
1025
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
1026
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
1027
|
+
*
|
|
1028
|
+
* @details
|
|
1029
|
+
* The `le_` struct template provides a type-safe mechanism for evaluating
|
|
1030
|
+
* whether the left-hand operand is less than or equal to the right-hand
|
|
1031
|
+
* operand within the framework.
|
|
1032
|
+
*
|
|
1033
|
+
* This comparator supports a variety of operand types, including those
|
|
1034
|
+
* with static values and generic types. For types with static values, the
|
|
1035
|
+
* comparison is performed directly. For all other types, the generic
|
|
1036
|
+
* getter is used to retrieve and compare the values.
|
|
1037
|
+
*
|
|
1038
|
+
* The implementation is optimised for use in embedded environments and
|
|
1039
|
+
* supports both compile-time and run-time evaluation.
|
|
1040
|
+
*
|
|
1041
|
+
* All definitions are intended for internal use within the framework and
|
|
1042
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1043
|
+
* maintain a structured and modular codebase.
|
|
1044
|
+
*
|
|
1045
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1046
|
+
*/
|
|
1047
|
+
template <class Lhs_T, class Rhs_T>
|
|
1048
|
+
struct le_ : type_traits::op
|
|
1049
|
+
{
|
|
1050
|
+
/**
|
|
1051
|
+
* @brief Constructs a less than or equal comparator for the given
|
|
1052
|
+
* operands.
|
|
1053
|
+
*
|
|
1054
|
+
* @param lhs The left-hand operand.
|
|
1055
|
+
* @param rhs The right-hand operand.
|
|
1056
|
+
*
|
|
1057
|
+
* @details
|
|
1058
|
+
* Evaluates whether the left-hand operand is less than or equal to the
|
|
1059
|
+
* right-hand operand at construction, supporting static values and
|
|
1060
|
+
* generic types. The result is stored in the `value_` member for
|
|
1061
|
+
* efficient access.
|
|
1062
|
+
*/
|
|
1063
|
+
constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
1064
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
1065
|
+
value_{ [&]
|
|
1066
|
+
{
|
|
1067
|
+
using std::operator<=;
|
|
1068
|
+
|
|
1069
|
+
#if defined(__GNUC__)
|
|
1070
|
+
#pragma GCC diagnostic push
|
|
1071
|
+
#pragma GCC diagnostic ignored "-Wconversion"
|
|
1072
|
+
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
|
1073
|
+
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
1074
|
+
#if defined(__clang__)
|
|
1075
|
+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
|
|
1076
|
+
#pragma clang diagnostic ignored "-Wpedantic"
|
|
1077
|
+
#endif
|
|
1078
|
+
#endif
|
|
1079
|
+
if constexpr (type_traits::has_value_v<Lhs_T>
|
|
1080
|
+
and type_traits::has_value_v<Rhs_T>)
|
|
1081
|
+
{
|
|
1082
|
+
return Lhs_T::value <= Rhs_T::value;
|
|
1083
|
+
}
|
|
1084
|
+
else
|
|
1085
|
+
{
|
|
1086
|
+
return get (lhs_) <= get (rhs_);
|
|
1087
|
+
}
|
|
1088
|
+
#if defined(__GNUC__)
|
|
1089
|
+
#pragma GCC diagnostic pop
|
|
1090
|
+
#endif
|
|
1091
|
+
}() }
|
|
1092
|
+
{
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* @brief Conversion operator to boolean.
|
|
1097
|
+
*
|
|
1098
|
+
* @par Parameters
|
|
1099
|
+
* None.
|
|
1100
|
+
* @retval true The left-hand operand is less than or equal to the
|
|
1101
|
+
* right-hand operand.
|
|
1102
|
+
* @retval false Otherwise.
|
|
1103
|
+
*
|
|
1104
|
+
* @details
|
|
1105
|
+
* Returns the result of the less than or equal comparison.
|
|
1106
|
+
*/
|
|
1107
|
+
[[nodiscard]] constexpr
|
|
1108
|
+
operator bool () const
|
|
1109
|
+
{
|
|
1110
|
+
return value_;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* @brief Retrieves the left-hand operand.
|
|
1115
|
+
*
|
|
1116
|
+
* @par Parameters
|
|
1117
|
+
* None.
|
|
1118
|
+
* @return The extracted left-hand operand.
|
|
1119
|
+
*
|
|
1120
|
+
* @details
|
|
1121
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
1122
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1123
|
+
* types.
|
|
1124
|
+
*/
|
|
1125
|
+
|
|
1126
|
+
[[nodiscard]] constexpr auto
|
|
1127
|
+
lhs (void) const
|
|
1128
|
+
{
|
|
1129
|
+
return get (lhs_);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* @brief Retrieves the right-hand operand.
|
|
1134
|
+
*
|
|
1135
|
+
* @par Parameters
|
|
1136
|
+
* None.
|
|
1137
|
+
* @return The extracted right-hand operand.
|
|
1138
|
+
*
|
|
1139
|
+
* @details
|
|
1140
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
1141
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1142
|
+
* types.
|
|
1143
|
+
*/
|
|
1144
|
+
[[nodiscard]] constexpr auto
|
|
1145
|
+
rhs (void) const
|
|
1146
|
+
{
|
|
1147
|
+
return get (rhs_);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* @brief Stores the left-hand operand.
|
|
1152
|
+
*/
|
|
1153
|
+
const Lhs_T lhs_{};
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* @brief Stores the right-hand operand.
|
|
1157
|
+
*/
|
|
1158
|
+
const Rhs_T rhs_{};
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* @brief Stores the result of the less than or equal comparison.
|
|
1162
|
+
*/
|
|
1163
|
+
const bool value_{};
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
// Deduction guide.
|
|
1167
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
1168
|
+
le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
|
|
1169
|
+
|
|
1170
|
+
// ------------------------------------------------------------------------
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* @brief Logical AND comparator struct template.
|
|
1174
|
+
*
|
|
1175
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
1176
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
1177
|
+
*
|
|
1178
|
+
* @details
|
|
1179
|
+
* The `and_` struct template provides a type-safe mechanism for evaluating
|
|
1180
|
+
* the logical conjunction (AND) of two operands within the framework.
|
|
1181
|
+
*
|
|
1182
|
+
* This comparator supports a wide range of operand types, applying the
|
|
1183
|
+
* generic getter to ensure correct value extraction for both custom and
|
|
1184
|
+
* standard types. The result of the logical AND operation is stored in the
|
|
1185
|
+
* `value_` member for efficient access.
|
|
1186
|
+
*
|
|
1187
|
+
* The implementation is optimised for use in embedded environments and
|
|
1188
|
+
* supports both compile-time and run-time evaluation.
|
|
1189
|
+
*
|
|
1190
|
+
* All definitions are intended for internal use within the framework and
|
|
1191
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1192
|
+
* maintain a structured and modular codebase.
|
|
1193
|
+
*
|
|
1194
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1195
|
+
*/
|
|
1196
|
+
template <class Lhs_T, class Rhs_T>
|
|
1197
|
+
struct and_ : type_traits::op
|
|
1198
|
+
{
|
|
1199
|
+
/**
|
|
1200
|
+
* @brief Constructs a logical AND comparator for the given operands.
|
|
1201
|
+
*
|
|
1202
|
+
* @param lhs The left-hand operand.
|
|
1203
|
+
* @param rhs The right-hand operand.
|
|
1204
|
+
*
|
|
1205
|
+
* @details
|
|
1206
|
+
* Evaluates the logical conjunction of the provided operands at
|
|
1207
|
+
* construction, supporting both custom and standard types. The result is
|
|
1208
|
+
* stored in the `value_` member for efficient access.
|
|
1209
|
+
*/
|
|
1210
|
+
constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
1211
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
1212
|
+
value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
|
|
1213
|
+
{
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* @brief Conversion operator to boolean.
|
|
1218
|
+
*
|
|
1219
|
+
* @par Parameters
|
|
1220
|
+
* None.
|
|
1221
|
+
* @retval true Both operands evaluate to true.
|
|
1222
|
+
* @retval false At least one operand evaluates to false.
|
|
1223
|
+
*
|
|
1224
|
+
* @details
|
|
1225
|
+
* Returns the result of the logical AND operation.
|
|
1226
|
+
*/
|
|
1227
|
+
[[nodiscard]] constexpr
|
|
1228
|
+
operator bool () const
|
|
1229
|
+
{
|
|
1230
|
+
return value_;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* @brief Retrieves the left-hand operand.
|
|
1235
|
+
*
|
|
1236
|
+
* @par Parameters
|
|
1237
|
+
* None.
|
|
1238
|
+
* @return The extracted left-hand operand.
|
|
1239
|
+
*
|
|
1240
|
+
* @details
|
|
1241
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
1242
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1243
|
+
* types.
|
|
1244
|
+
*/
|
|
1245
|
+
[[nodiscard]] constexpr auto
|
|
1246
|
+
lhs (void) const
|
|
1247
|
+
{
|
|
1248
|
+
return get (lhs_);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* @brief Retrieves the right-hand operand.
|
|
1253
|
+
*
|
|
1254
|
+
* @par Parameters
|
|
1255
|
+
* None.
|
|
1256
|
+
* @return The extracted right-hand operand.
|
|
1257
|
+
*
|
|
1258
|
+
* @details
|
|
1259
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
1260
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1261
|
+
* types.
|
|
1262
|
+
*/
|
|
1263
|
+
[[nodiscard]] constexpr auto
|
|
1264
|
+
rhs (void) const
|
|
1265
|
+
{
|
|
1266
|
+
return get (rhs_);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* @brief Stores the left-hand operand.
|
|
1271
|
+
*/
|
|
1272
|
+
const Lhs_T lhs_{};
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* @brief Stores the right-hand operand.
|
|
1276
|
+
*/
|
|
1277
|
+
const Rhs_T rhs_{};
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* @brief Stores the result of the logical AND operation.
|
|
1281
|
+
*/
|
|
1282
|
+
const bool value_{};
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
// Deduction guide.
|
|
1286
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
1287
|
+
and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
|
|
1288
|
+
|
|
1289
|
+
// ------------------------------------------------------------------------
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* @brief Logical OR comparator struct template.
|
|
1293
|
+
*
|
|
1294
|
+
* @tparam Lhs_T The type of the left-hand operand.
|
|
1295
|
+
* @tparam Rhs_T The type of the right-hand operand.
|
|
1296
|
+
*
|
|
1297
|
+
* @details
|
|
1298
|
+
* The `or_` struct template provides a type-safe mechanism for evaluating
|
|
1299
|
+
* the logical disjunction (OR) of two operands within the framework.
|
|
1300
|
+
*
|
|
1301
|
+
* This comparator supports a wide range of operand types, applying the
|
|
1302
|
+
* generic getter to ensure correct value extraction for both custom and
|
|
1303
|
+
* standard types. The result of the logical OR operation is stored in the
|
|
1304
|
+
* `value_` member for efficient access.
|
|
1305
|
+
*
|
|
1306
|
+
* The implementation is optimised for use in embedded environments and
|
|
1307
|
+
* supports both compile-time and run-time evaluation.
|
|
1308
|
+
*
|
|
1309
|
+
* All definitions are intended for internal use within the framework and
|
|
1310
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1311
|
+
* maintain a structured and modular codebase.
|
|
1312
|
+
*
|
|
1313
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1314
|
+
*/
|
|
1315
|
+
template <class Lhs_T, class Rhs_T>
|
|
1316
|
+
struct or_ : type_traits::op
|
|
1317
|
+
{
|
|
1318
|
+
/**
|
|
1319
|
+
* @brief Constructs a logical OR comparator for the given operands.
|
|
1320
|
+
*
|
|
1321
|
+
* @details
|
|
1322
|
+
* Evaluates the logical disjunction of the provided operands at
|
|
1323
|
+
* construction, supporting both custom and standard types. The result is
|
|
1324
|
+
* stored in the `value_` member for efficient access.
|
|
1325
|
+
*
|
|
1326
|
+
* @param lhs The left-hand operand.
|
|
1327
|
+
* @param rhs The right-hand operand.
|
|
1328
|
+
*/
|
|
1329
|
+
constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
|
|
1330
|
+
: lhs_{ lhs }, rhs_{ rhs },
|
|
1331
|
+
value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
|
|
1332
|
+
{
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* @brief Conversion operator to boolean.
|
|
1337
|
+
*
|
|
1338
|
+
* @par Parameters
|
|
1339
|
+
* None.
|
|
1340
|
+
* @retval true At least one operand evaluates to true.
|
|
1341
|
+
* @retval false Both operands evaluate to false.
|
|
1342
|
+
*
|
|
1343
|
+
* @details
|
|
1344
|
+
* Returns the result of the logical OR operation.
|
|
1345
|
+
*/
|
|
1346
|
+
[[nodiscard]] constexpr
|
|
1347
|
+
operator bool () const
|
|
1348
|
+
{
|
|
1349
|
+
return value_;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* @brief Retrieves the left-hand operand.
|
|
1354
|
+
*
|
|
1355
|
+
* @par Parameters
|
|
1356
|
+
* None.
|
|
1357
|
+
* @return The extracted left-hand operand.
|
|
1358
|
+
*
|
|
1359
|
+
* @details
|
|
1360
|
+
* Returns the value of the left-hand operand, applying the generic
|
|
1361
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1362
|
+
* types.
|
|
1363
|
+
*/
|
|
1364
|
+
[[nodiscard]] constexpr auto
|
|
1365
|
+
lhs (void) const
|
|
1366
|
+
{
|
|
1367
|
+
return get (lhs_);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* @brief Retrieves the right-hand operand.
|
|
1372
|
+
*
|
|
1373
|
+
* @par Parameters
|
|
1374
|
+
* None.
|
|
1375
|
+
* @return The extracted right-hand operand.
|
|
1376
|
+
*
|
|
1377
|
+
* @details
|
|
1378
|
+
* Returns the value of the right-hand operand, applying the generic
|
|
1379
|
+
* getter to ensure correct extraction for both custom and standard
|
|
1380
|
+
* types.
|
|
1381
|
+
*/
|
|
1382
|
+
[[nodiscard]] constexpr auto
|
|
1383
|
+
rhs (void) const
|
|
1384
|
+
{
|
|
1385
|
+
return get (rhs_);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* @brief Stores the left-hand operand.
|
|
1390
|
+
*/
|
|
1391
|
+
const Lhs_T lhs_{};
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* @brief Stores the right-hand operand.
|
|
1395
|
+
*/
|
|
1396
|
+
const Rhs_T rhs_{};
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* @brief Stores the result of the logical OR operation.
|
|
1400
|
+
*/
|
|
1401
|
+
const bool value_{};
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// Deduction guide.
|
|
1405
|
+
template <typename Lhs_T, typename Rhs_T>
|
|
1406
|
+
or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
|
|
1407
|
+
|
|
1408
|
+
// ------------------------------------------------------------------------
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* @brief Logical NOT comparator struct template.
|
|
1412
|
+
*
|
|
1413
|
+
* @tparam T The type of the operand.
|
|
1414
|
+
*
|
|
1415
|
+
* @details
|
|
1416
|
+
* The `not_` struct template provides a type-safe mechanism for evaluating
|
|
1417
|
+
* the logical negation (NOT) of an operand within the framework.
|
|
1418
|
+
*
|
|
1419
|
+
* This comparator supports a wide range of operand types, applying the
|
|
1420
|
+
* generic getter to ensure correct value extraction for both custom and
|
|
1421
|
+
* standard types. The result of the logical NOT operation is stored in the
|
|
1422
|
+
* `value_` member for efficient access.
|
|
1423
|
+
*
|
|
1424
|
+
* The implementation is optimised for use in embedded environments and
|
|
1425
|
+
* supports both compile-time and run-time evaluation.
|
|
1426
|
+
*
|
|
1427
|
+
* All definitions are intended for internal use within the framework and
|
|
1428
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1429
|
+
* maintain a structured and modular codebase.
|
|
1430
|
+
*
|
|
1431
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1432
|
+
*/
|
|
1433
|
+
template <class T>
|
|
1434
|
+
struct not_ : type_traits::op
|
|
1435
|
+
{
|
|
1436
|
+
/**
|
|
1437
|
+
* @brief Constructs a logical NOT comparator for the given operand.
|
|
1438
|
+
*
|
|
1439
|
+
* @param t The operand to be negated.
|
|
1440
|
+
*
|
|
1441
|
+
* @details
|
|
1442
|
+
* Evaluates the logical negation of the provided operand at
|
|
1443
|
+
* construction, supporting both custom and standard types. The result is
|
|
1444
|
+
* stored in the `value_` member for efficient access.
|
|
1445
|
+
*/
|
|
1446
|
+
explicit constexpr not_ (const T& t = {})
|
|
1447
|
+
: t_{ t }, value_{ not static_cast<bool> (t) }
|
|
1448
|
+
{
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* @brief Conversion operator to boolean.
|
|
1453
|
+
*
|
|
1454
|
+
* @par Parameters
|
|
1455
|
+
* None.
|
|
1456
|
+
* @retval true The operand evaluates to false.
|
|
1457
|
+
* @retval false The operand evaluates to true.
|
|
1458
|
+
*
|
|
1459
|
+
* @details
|
|
1460
|
+
* Returns the result of the logical NOT operation.
|
|
1461
|
+
*/
|
|
1462
|
+
[[nodiscard]] constexpr
|
|
1463
|
+
operator bool () const
|
|
1464
|
+
{
|
|
1465
|
+
return value_;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* @brief Retrieves the value of the operand.
|
|
1470
|
+
*
|
|
1471
|
+
* @par Parameters
|
|
1472
|
+
* None.
|
|
1473
|
+
* @return The extracted operand value.
|
|
1474
|
+
*
|
|
1475
|
+
* @details
|
|
1476
|
+
* Returns the value of the operand, applying the generic getter to
|
|
1477
|
+
* ensure correct extraction for both custom and standard types.
|
|
1478
|
+
*/
|
|
1479
|
+
[[nodiscard]] constexpr auto
|
|
1480
|
+
value () const
|
|
1481
|
+
{
|
|
1482
|
+
return get (t_);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
* @brief Stores the operand.
|
|
1487
|
+
*/
|
|
1488
|
+
const T t_{};
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
1491
|
+
* @brief Stores the result of the logical NOT operation.
|
|
1492
|
+
*/
|
|
1493
|
+
const bool value_{};
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
// Deduction guide.
|
|
1497
|
+
template <typename T>
|
|
1498
|
+
not_ (const T&) -> not_<T>;
|
|
1499
|
+
|
|
1500
|
+
// ------------------------------------------------------------------------
|
|
1501
|
+
|
|
1502
|
+
#if defined(__cpp_exceptions)
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* @brief Operator struct template to check if an expression throws a
|
|
1506
|
+
* specific exception.
|
|
1507
|
+
*
|
|
1508
|
+
* @tparam Callable_T The type of the callable object to be invoked.
|
|
1509
|
+
* @tparam Exception_T The type of the exception to check for (defaults to
|
|
1510
|
+
* `void` for any exception).
|
|
1511
|
+
*
|
|
1512
|
+
* @details
|
|
1513
|
+
* The `throws_` struct template provides a type-safe mechanism for
|
|
1514
|
+
* verifying whether a callable expression throws a specified exception
|
|
1515
|
+
* type during its execution within the framework.
|
|
1516
|
+
*
|
|
1517
|
+
* This comparator is designed to support both custom and standard callable
|
|
1518
|
+
* types. The result of the exception check is stored in the `value_`
|
|
1519
|
+
* member for efficient access.
|
|
1520
|
+
*
|
|
1521
|
+
* The implementation is optimised for use in embedded environments and
|
|
1522
|
+
* supports both compile-time and run-time evaluation.
|
|
1523
|
+
*
|
|
1524
|
+
* All definitions are intended for internal use within the framework and
|
|
1525
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1526
|
+
* maintain a structured and modular codebase.
|
|
1527
|
+
*
|
|
1528
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1529
|
+
*/
|
|
1530
|
+
template <class Callable_T, class Exception_T = void>
|
|
1531
|
+
struct throws_ : type_traits::op
|
|
1532
|
+
{
|
|
1533
|
+
/**
|
|
1534
|
+
* @brief Constructs an exception checking operator for the given
|
|
1535
|
+
* callable.
|
|
1536
|
+
*
|
|
1537
|
+
* @param func The callable object to be invoked.
|
|
1538
|
+
*
|
|
1539
|
+
* @details
|
|
1540
|
+
* Invokes the provided callable and determines whether it throws an
|
|
1541
|
+
* exception of the specified type. The result is stored in the `value_`
|
|
1542
|
+
* member for efficient access.
|
|
1543
|
+
*/
|
|
1544
|
+
constexpr explicit throws_ (const Callable_T& func)
|
|
1545
|
+
: value_{ [&func]
|
|
1546
|
+
{
|
|
1547
|
+
try
|
|
1548
|
+
{
|
|
1549
|
+
func ();
|
|
1550
|
+
}
|
|
1551
|
+
catch (const Exception_T&)
|
|
1552
|
+
{
|
|
1553
|
+
return true;
|
|
1554
|
+
}
|
|
1555
|
+
catch (...)
|
|
1556
|
+
{
|
|
1557
|
+
return false;
|
|
1558
|
+
}
|
|
1559
|
+
return false;
|
|
1560
|
+
}() }
|
|
1561
|
+
{
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* @brief Conversion operator to boolean.
|
|
1566
|
+
*
|
|
1567
|
+
* @par Parameters
|
|
1568
|
+
* None.
|
|
1569
|
+
* @retval true The callable throws the specified exception type.
|
|
1570
|
+
* @retval false The callable does not throw the specified exception
|
|
1571
|
+
* type.
|
|
1572
|
+
*
|
|
1573
|
+
* @details
|
|
1574
|
+
* Returns the result of the exception check.
|
|
1575
|
+
*/
|
|
1576
|
+
[[nodiscard]] constexpr
|
|
1577
|
+
operator bool () const
|
|
1578
|
+
{
|
|
1579
|
+
return value_;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* @brief Stores the result of the exception check.
|
|
1584
|
+
*/
|
|
1585
|
+
const bool value_{};
|
|
1586
|
+
};
|
|
1587
|
+
|
|
1588
|
+
// ------------------------------------------------------------------------
|
|
1589
|
+
|
|
1590
|
+
/**
|
|
1591
|
+
* @brief Operator struct template to check if an expression throws any
|
|
1592
|
+
* exception.
|
|
1593
|
+
*
|
|
1594
|
+
* @tparam Callable_T The type of the callable object to be invoked.
|
|
1595
|
+
*
|
|
1596
|
+
* @details
|
|
1597
|
+
* The `throws_` struct template provides a type-safe mechanism for
|
|
1598
|
+
* verifying whether a callable expression throws any exception during its
|
|
1599
|
+
* execution within the framework.
|
|
1600
|
+
*
|
|
1601
|
+
* This comparator is designed to support both custom and standard callable
|
|
1602
|
+
* types. The result of the exception check is stored in the `value_`
|
|
1603
|
+
* member for efficient access.
|
|
1604
|
+
*
|
|
1605
|
+
* The implementation is optimised for use in embedded environments and
|
|
1606
|
+
* supports both compile-time and run-time evaluation.
|
|
1607
|
+
*
|
|
1608
|
+
* All definitions are intended for internal use within the framework and
|
|
1609
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1610
|
+
* maintain a structured and modular codebase.
|
|
1611
|
+
*
|
|
1612
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1613
|
+
*/
|
|
1614
|
+
template <class Callable_T>
|
|
1615
|
+
struct throws_<Callable_T, void> : type_traits::op
|
|
1616
|
+
{
|
|
1617
|
+
/**
|
|
1618
|
+
* @brief Constructs an exception checking operator for the given
|
|
1619
|
+
* callable.
|
|
1620
|
+
*
|
|
1621
|
+
* @details
|
|
1622
|
+
* Invokes the provided callable and determines whether it throws any
|
|
1623
|
+
* exception. The result is stored in the `value_` member for efficient
|
|
1624
|
+
* access.
|
|
1625
|
+
*
|
|
1626
|
+
* @param func The callable object to be invoked.
|
|
1627
|
+
*/
|
|
1628
|
+
constexpr explicit throws_ (const Callable_T& func)
|
|
1629
|
+
: value_{ [&func]
|
|
1630
|
+
{
|
|
1631
|
+
try
|
|
1632
|
+
{
|
|
1633
|
+
func ();
|
|
1634
|
+
}
|
|
1635
|
+
catch (...)
|
|
1636
|
+
{
|
|
1637
|
+
return true;
|
|
1638
|
+
}
|
|
1639
|
+
return false;
|
|
1640
|
+
}() }
|
|
1641
|
+
{
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
/**
|
|
1645
|
+
* @brief Conversion operator to boolean.
|
|
1646
|
+
*
|
|
1647
|
+
* @par Parameters
|
|
1648
|
+
* None.
|
|
1649
|
+
* @retval true The callable throws an exception.
|
|
1650
|
+
*
|
|
1651
|
+
* @details
|
|
1652
|
+
* Returns the result of the exception check.
|
|
1653
|
+
* @retval false The callable does not throw any exception.
|
|
1654
|
+
*/
|
|
1655
|
+
[[nodiscard]] constexpr
|
|
1656
|
+
operator bool () const
|
|
1657
|
+
{
|
|
1658
|
+
return value_;
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* @brief Stores the result of the exception check.
|
|
1663
|
+
*/
|
|
1664
|
+
const bool value_{};
|
|
1665
|
+
};
|
|
1666
|
+
|
|
1667
|
+
// ------------------------------------------------------------------------
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* @brief Operator struct template to check if an expression does not throw
|
|
1671
|
+
* any exception.
|
|
1672
|
+
*
|
|
1673
|
+
* @tparam Callable_T The type of the callable object to be invoked.
|
|
1674
|
+
*
|
|
1675
|
+
* @details
|
|
1676
|
+
* The `nothrow_` struct template provides a type-safe mechanism for
|
|
1677
|
+
* verifying whether a callable expression completes without throwing any
|
|
1678
|
+
* exception during its execution within the framework.
|
|
1679
|
+
*
|
|
1680
|
+
* This comparator is designed to support both custom and standard callable
|
|
1681
|
+
* types. The result of the exception check is stored in the `value_`
|
|
1682
|
+
* member for efficient access.
|
|
1683
|
+
*
|
|
1684
|
+
* The implementation is optimised for use in embedded environments and
|
|
1685
|
+
* supports both compile-time and run-time evaluation.
|
|
1686
|
+
*
|
|
1687
|
+
* All definitions are intended for internal use within the framework and
|
|
1688
|
+
* are implemented in the `include/micro-os-plus/micro-test-plus` folder to
|
|
1689
|
+
* maintain a structured and modular codebase.
|
|
1690
|
+
*
|
|
1691
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1692
|
+
*/
|
|
1693
|
+
template <class Callable_T>
|
|
1694
|
+
struct nothrow_ : type_traits::op
|
|
1695
|
+
{
|
|
1696
|
+
/**
|
|
1697
|
+
* @brief Constructs a nothrow checking operator for the given callable.
|
|
1698
|
+
*
|
|
1699
|
+
* @param func The callable object to be invoked.
|
|
1700
|
+
*
|
|
1701
|
+
* @details
|
|
1702
|
+
* Invokes the provided callable and determines whether it completes
|
|
1703
|
+
* without throwing any exception. The result is stored in the `value_`
|
|
1704
|
+
* member for efficient access.
|
|
1705
|
+
*/
|
|
1706
|
+
constexpr explicit nothrow_ (const Callable_T& func)
|
|
1707
|
+
: value_{ [&func]
|
|
1708
|
+
{
|
|
1709
|
+
try
|
|
1710
|
+
{
|
|
1711
|
+
func ();
|
|
1712
|
+
}
|
|
1713
|
+
catch (...)
|
|
1714
|
+
{
|
|
1715
|
+
return false;
|
|
1716
|
+
}
|
|
1717
|
+
return true;
|
|
1718
|
+
}() }
|
|
1719
|
+
{
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* @brief Conversion operator to boolean.
|
|
1724
|
+
*
|
|
1725
|
+
* @par Parameters
|
|
1726
|
+
* None.
|
|
1727
|
+
* @retval true The callable does not throw any exception.
|
|
1728
|
+
* @retval false The callable throws an exception.
|
|
1729
|
+
*
|
|
1730
|
+
* @details
|
|
1731
|
+
* Returns the result of the nothrow check.
|
|
1732
|
+
*/
|
|
1733
|
+
[[nodiscard]] constexpr
|
|
1734
|
+
operator bool () const
|
|
1735
|
+
{
|
|
1736
|
+
return value_;
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
/**
|
|
1740
|
+
* @brief Stores the result of the nothrow check.
|
|
1741
|
+
*/
|
|
1742
|
+
const bool value_{};
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
#endif
|
|
1746
|
+
|
|
1747
|
+
// ------------------------------------------------------------------------
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* @brief Base class for a deferred reporter that collects messages into a
|
|
1751
|
+
* string.
|
|
1752
|
+
*
|
|
1753
|
+
* @details
|
|
1754
|
+
* The `deferred_reporter_base` class serves as the foundational component
|
|
1755
|
+
* for deferred reporting within the framework. It is responsible for
|
|
1756
|
+
* collecting expectation messages, typically passed via the
|
|
1757
|
+
* `operator<<()`, into a string for later reporting.
|
|
1758
|
+
*
|
|
1759
|
+
* This class maintains the result value, abort status, and the source
|
|
1760
|
+
* location associated with the report. It is intended exclusively for
|
|
1761
|
+
* internal use and is implemented in the
|
|
1762
|
+
* `include/micro-os-plus/micro-test-plus` folder to ensure a structured
|
|
1763
|
+
* and modular codebase.
|
|
1764
|
+
*
|
|
1765
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1766
|
+
*/
|
|
1767
|
+
class deferred_reporter_base
|
|
1768
|
+
{
|
|
1769
|
+
public:
|
|
1770
|
+
/**
|
|
1771
|
+
* @brief Constructs a deferred reporter base.
|
|
1772
|
+
*
|
|
1773
|
+
* @param value The result value associated with the report.
|
|
1774
|
+
* @param location The source location relevant to the report.
|
|
1775
|
+
*/
|
|
1776
|
+
deferred_reporter_base (bool value,
|
|
1777
|
+
const reflection::source_location location);
|
|
1778
|
+
|
|
1779
|
+
/**
|
|
1780
|
+
* @brief Destructor for the deferred reporter base.
|
|
1781
|
+
*/
|
|
1782
|
+
~deferred_reporter_base ();
|
|
1783
|
+
|
|
1784
|
+
/**
|
|
1785
|
+
* @brief Appends a message to the reporter.
|
|
1786
|
+
*
|
|
1787
|
+
* @tparam T The type of the message to append.
|
|
1788
|
+
*
|
|
1789
|
+
* @param msg The message to append.
|
|
1790
|
+
* @return Reference to the current reporter instance.
|
|
1791
|
+
*/
|
|
1792
|
+
template <class T>
|
|
1793
|
+
auto&
|
|
1794
|
+
operator<< (const T& msg);
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* @brief Retrieves the result value.
|
|
1798
|
+
*
|
|
1799
|
+
*
|
|
1800
|
+
* @par Parameters
|
|
1801
|
+
* None.
|
|
1802
|
+
* @retval true The reported condition was met.
|
|
1803
|
+
* @retval false The reported condition was not met.
|
|
1804
|
+
*
|
|
1805
|
+
* @details
|
|
1806
|
+
* Returns the result value associated with the report.
|
|
1807
|
+
*/
|
|
1808
|
+
[[nodiscard]] constexpr bool
|
|
1809
|
+
value () const
|
|
1810
|
+
{
|
|
1811
|
+
return value_;
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
protected:
|
|
1815
|
+
/**
|
|
1816
|
+
* @brief Stores the result value of the report.
|
|
1817
|
+
*/
|
|
1818
|
+
bool value_{};
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* @brief Indicates whether the reporting should abort further
|
|
1822
|
+
* processing.
|
|
1823
|
+
*/
|
|
1824
|
+
bool abort_ = false;
|
|
1825
|
+
|
|
1826
|
+
/**
|
|
1827
|
+
* @brief Stores the source location associated with the report.
|
|
1828
|
+
*/
|
|
1829
|
+
const reflection::source_location location_{};
|
|
1830
|
+
|
|
1831
|
+
/**
|
|
1832
|
+
* @brief String to collect the expectation message passed via
|
|
1833
|
+
* `operator<<()`.
|
|
1834
|
+
*/
|
|
1835
|
+
std::string message_{};
|
|
1836
|
+
};
|
|
1837
|
+
|
|
1838
|
+
// ------------------------------------------------------------------------
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* @brief Deferred reporter class template for a specific expression.
|
|
1842
|
+
*
|
|
1843
|
+
* @tparam Expr_T The type of the expression being reported.
|
|
1844
|
+
*
|
|
1845
|
+
* @details
|
|
1846
|
+
* The `deferred_reporter` class template extends `deferred_reporter_base`
|
|
1847
|
+
* to provide deferred reporting functionality for a specific test
|
|
1848
|
+
* expression within the framework.
|
|
1849
|
+
*
|
|
1850
|
+
* This class template is responsible for capturing the expression under
|
|
1851
|
+
* evaluation, the abort status, and the source location. It is intended
|
|
1852
|
+
* exclusively for internal use and is implemented in the
|
|
1853
|
+
* `include/micro-os-plus/micro-test-plus` folder to ensure a structured
|
|
1854
|
+
* and modular codebase.
|
|
1855
|
+
*
|
|
1856
|
+
* @headerfile micro-test-plus.h <micro-os-plus/micro-test-plus.h>
|
|
1857
|
+
*/
|
|
1858
|
+
template <class Expr_T>
|
|
1859
|
+
class deferred_reporter : public deferred_reporter_base
|
|
1860
|
+
{
|
|
1861
|
+
public:
|
|
1862
|
+
/**
|
|
1863
|
+
* @brief Constructs a deferred reporter for a specific expression.
|
|
1864
|
+
*
|
|
1865
|
+
* @param expr The expression under evaluation.
|
|
1866
|
+
* @param abort Indicates whether reporting should abort further
|
|
1867
|
+
* processing.
|
|
1868
|
+
* @param location The source location relevant to the report.
|
|
1869
|
+
*
|
|
1870
|
+
* @details
|
|
1871
|
+
* Initialises the reporter with the given expression, abort status, and
|
|
1872
|
+
* source location.
|
|
1873
|
+
*/
|
|
1874
|
+
constexpr explicit deferred_reporter (
|
|
1875
|
+
const Expr_T& expr, bool abort,
|
|
1876
|
+
const reflection::source_location& location);
|
|
1877
|
+
|
|
1878
|
+
/**
|
|
1879
|
+
* @brief Destructor for the deferred reporter.
|
|
1880
|
+
*/
|
|
1881
|
+
~deferred_reporter ();
|
|
1882
|
+
|
|
1883
|
+
protected:
|
|
1884
|
+
/**
|
|
1885
|
+
* @brief Stores the expression under evaluation.
|
|
1886
|
+
*/
|
|
1887
|
+
const Expr_T expr_{};
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
// ------------------------------------------------------------------------
|
|
1891
|
+
} // namespace detail
|
|
1892
|
+
|
|
1893
|
+
// --------------------------------------------------------------------------
|
|
1894
|
+
} // namespace micro_os_plus::micro_test_plus
|
|
1895
|
+
|
|
1896
|
+
#if defined(__GNUC__)
|
|
1897
|
+
#pragma GCC diagnostic pop
|
|
1898
|
+
#endif
|
|
1899
|
+
|
|
1900
|
+
// ----------------------------------------------------------------------------
|
|
1901
|
+
|
|
1902
|
+
#endif // __cplusplus
|
|
1903
|
+
|
|
1904
|
+
// ----------------------------------------------------------------------------
|
|
1905
|
+
|
|
1906
|
+
#endif // MICRO_TEST_PLUS_DETAIL_H_
|
|
1907
|
+
|
|
1908
|
+
// ----------------------------------------------------------------------------
|