Sen API
Sen Libraries
Loading...
Searching...
No Matches
helpers.h
Go to the documentation of this file.
1// === helpers.h =======================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_LIBS_KERNEL_TEST_INTEGRATION_TRANSPORT_HELPERS_H
9#define SEN_LIBS_KERNEL_TEST_INTEGRATION_TRANSPORT_HELPERS_H
10
11// sen
14
15// generated code
16#include "test_helpers/tester.stl.h"
17
18// std
19#include <cmath>
20#include <future>
21#include <string>
22#include <type_traits>
23
24namespace sen::test
25{
26
27//--------------------------------------------------------------------------------------------------------------
28// Helpers
29//--------------------------------------------------------------------------------------------------------------
30
31template <typename T>
32[[nodiscard]] inline bool eq(T a, T b)
33{
34 // handle possible quantities of floating point types
35 if constexpr (!std::is_same_v<T, sen::TimeStamp> && sen::HasValueType<T>::value)
36 {
37 return eq(a.get(), b.get());
38 }
39
40 if constexpr (std::is_floating_point_v<T>)
41 {
42 constexpr T eps = 1e-3;
43 return std::fabs(a - b) < eps;
44 }
45
46 return a == b;
47}
48
49template <typename PropType>
50[[nodiscard]] inline bool checkProp(std::promise<TestResult>& promise,
51 const std::string& propName,
53 sen::MaybeRef<PropType> expectation)
54{
55 if (!eq(value, expectation))
56 {
57 std::string err;
58 err.append("Incorrect value of ");
59 err.append(propName);
60 promise.set_value(TestResult(err));
61 return false;
62 }
63
64 return true;
65}
66
67[[nodiscard]] inline bool checkMember(std::promise<TestResult>& promise, const std::string& memberName, bool isOk)
68{
69 if (isOk)
70 {
71 return true;
72 }
73
74 std::string err = "Member ";
75 err.append(memberName);
76 err.append(" adaptation failed.");
77 promise.set_value(TestResult(err));
78 return false;
79}
80
81} // namespace sen::test
82
83#endif // SEN_LIBS_KERNEL_TEST_INTEGRATION_TRANSPORT_HELPERS_H
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
std::conditional_t< std::is_arithmetic_v< T >||shouldBePassedByValueV< T >, T, AddConstRef< T > > MaybeRef
returns 'const T&' or 'T' depending on the type
Definition class_helpers.h:46
Definition reader_writer.h:19
bool eq(T a, T b)
Definition helpers.h:32
bool checkProp(std::promise< TestResult > &promise, const std::string &propName, sen::MaybeRef< PropType > value, sen::MaybeRef< PropType > expectation)
Definition helpers.h:50
bool checkMember(std::promise< TestResult > &promise, const std::string &memberName, bool isOk)
Definition helpers.h:67
return false if T has not an 'using ValueType' or a 'typedef ValueType'
Definition class_helpers.h:51