@@ -40,46 +40,9 @@ namespace detail
4040// / @param[in] onNonFatalFailurePath This function will be executed on the non-failure path if no failure was detected
4141// / @return true if a fatal failure occurs, false otherwise
4242template <typename ErrorType>
43- bool FATAL_FAILURE_TEST (const std::function<void ()>& testFunction,
44- const std::function<void(const ErrorType, const iox::ErrorLevel)>& onFatalFailurePath,
45- const std::function<void()>& onNonFatalFailurePath)
46- {
47- std::atomic<bool > hasFatalFailure{false };
48- auto th = std::thread ([&] {
49- constexpr int JMP_VALUE{1 };
50- std::jmp_buf jmpBuffer;
51-
52- optional<ErrorType> detectedError;
53- optional<iox::ErrorLevel> detectedErrorLevel;
54-
55- auto errorHandlerGuard =
56- iox::ErrorHandlerMock::setTemporaryErrorHandler<ErrorType>([&](const auto error, const auto errorLevel) {
57- detectedError.emplace (error);
58- detectedErrorLevel.emplace (errorLevel);
59-
60- // NOLINTNEXTLINE(cert-err52-cpp) exception cannot be used and longjmp/setjmp is a working fallback
61- std::longjmp (&jmpBuffer[0 ], JMP_VALUE);
62- });
63-
64- // NOLINTNEXTLINE(cert-err52-cpp) exception cannot be used and longjmp/setjmp is a working fallback
65- if (setjmp (&jmpBuffer[0 ]) == JMP_VALUE)
66- {
67- hasFatalFailure = true ;
68- // using value directly is save since this path is only executed if the error handler was called and the
69- // respective values were set
70- onFatalFailurePath (detectedError.value (), detectedErrorLevel.value ());
71- return ;
72- }
73-
74- testFunction ();
75-
76- onNonFatalFailurePath ();
77- });
78-
79- th.join ();
80-
81- return hasFatalFailure.load (std::memory_order_relaxed);
82- }
43+ bool IOX_FATAL_FAILURE_TEST (const std::function<void ()>& testFunction,
44+ const std::function<void(const ErrorType, const iox::ErrorLevel)>& onFatalFailurePath,
45+ const std::function<void()>& onNonFatalFailurePath);
8346} // namespace detail
8447
8548// / @brief This function is used in cases a fatal failure is expected. The function only works in combination with the
@@ -95,16 +58,7 @@ bool FATAL_FAILURE_TEST(const std::function<void()>& testFunction,
9558// / @param[in] expectedError The error value which triggered the fatal failure
9659// / @return true if a fatal failure occurs, false otherwise
9760template <typename ErrorType>
98- bool IOX_EXPECT_FATAL_FAILURE (const std::function<void ()>& testFunction, const ErrorType expectedError)
99- {
100- return detail::FATAL_FAILURE_TEST<ErrorType>(
101- testFunction,
102- [&](const auto error, const auto errorLevel) {
103- EXPECT_THAT (error, ::testing::Eq (expectedError));
104- EXPECT_THAT (errorLevel, ::testing::Eq (iox::ErrorLevel::FATAL));
105- },
106- [&] { GTEST_FAIL () << " Expected fatal failure but execution continued!" ; });
107- }
61+ bool IOX_EXPECT_FATAL_FAILURE (const std::function<void ()>& testFunction, const ErrorType expectedError);
10862
10963// / @brief This function is used in cases no fatal failure is expected but could potentially occur. The function only
11064// / works in combination with the iceoryx error handler.
@@ -118,19 +72,12 @@ bool IOX_EXPECT_FATAL_FAILURE(const std::function<void()>& testFunction, const E
11872// / @param[in] testFunction This function will be executed as SUT and is not expected to call the error handler
11973// / @return true if no fatal failure occurs, false otherwise
12074template <typename ErrorType>
121- bool IOX_EXPECT_NO_FATAL_FAILURE (const std::function<void ()>& testFunction)
122- {
123- return !detail::FATAL_FAILURE_TEST<ErrorType>(
124- testFunction,
125- [&](const auto error, const auto errorLevel) {
126- GTEST_FAIL () << " Expected no fatal failure but execution failed! Error code: "
127- << static_cast <uint64_t >(error) << " ; Error level: " << static_cast <uint64_t >(errorLevel);
128- },
129- [&] {});
130- return false ;
131- }
75+ bool IOX_EXPECT_NO_FATAL_FAILURE (const std::function<void ()>& testFunction);
13276
13377} // namespace testing
13478} // namespace iox
13579
80+
81+ #include " iceoryx_hoofs/testing/fatal_failure.inl"
82+
13683#endif // IOX_HOOFS_TESTING_FATAL_FAILURE_HPP
0 commit comments