iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::bb::testing Namespace Reference

Namespaces

namespace  detail
 

Classes

class  ErrorHandlerSetup
 This class hooks into gTest to automatically resets the error handler on the start of a test. More...
 
class  LogPrinter
 This class hooks into gTest to automatically clear the log messages on the start of a test an print the cached log messages from failed tests. More...
 
class  TestingErrorHandler
 Defines the test reaction of dynamic error handling. More...
 
class  TestingLogger
 This logger is used for tests. It caches all the log messages and prints them to the console when a test fails. For debug purposes this behaviour can be overwritten with the 'IOX2_TESTING_ALLOW_LOG' environment variable, e.g. 'IOX2_TESTING_ALLOW_LOG=ON ./hoofs_moduletests –gtest_filter=SharedMemoryObject_Test*'. Furthermore, it can also be used to check for the occurrence on specific log messages, e.g. when a function is expected to log an error. More...
 

Typedefs

using ErrorHandler = legacy::StaticLifetimeGuard< TestingErrorHandler >
 

Functions

template<typename ErrorType , std::enable_if_t<!std::is_same< ErrorType, legacy::er::FatalKind >::value &&!std::is_same< ErrorType, legacy::er::EnforceViolationKind >::value &&!std::is_same< ErrorType, legacy::er::AssertViolationKind >::value, bool > = true>
auto expect_fatal_failure (const bb::StaticFunction< void()> &test_function, const ErrorType expected_error) -> bool
 This function is used in cases a fatal failure is expected. The function only works in combination with the iceoryx error handler. It is not recommended to use this function directly but the IOX2_TESTING_EXPECT_FATAL_FAILURE macro instead.
 
auto expect_no_fatal_failure (const bb::StaticFunction< void()> &test_function) -> bool
 This function is used in cases no fatal failure is expected but could potentially occur. The function only works in combination with the iceoryx error handler. It is not recommended to use this function directly but the IOX2_TESTING_EXPECT_NO_FATAL_FAILURE macro instead.
 
template<typename Code >
auto has_error (Code &&code) -> bool
 indicates whether the test error handler registered a specific error
 
auto has_panicked () -> bool
 indicates whether the test error handler invoked panic
 
auto has_error () -> bool
 indicates whether the test error handler registered any error
 
auto has_enforce_violation () -> bool
 indicates whether the test error handler registered an enforce violation
 
auto has_assert_violation () -> bool
 indicates whether the test error handler registered an assert violation
 
auto has_violation () -> bool
 indicates whether the test error handler registered violation (there are only two kinds).
 
auto is_in_normal_state () -> bool
 indicates there is no error, violation or panic.
 
auto run_in_test_thread (const bb::StaticFunction< void()> test_function) -> void
 runs test_function in a test context that can detect fatal failures; runs in a separate thread
 

Typedef Documentation

◆ ErrorHandler

Function Documentation

◆ expect_fatal_failure()

template<typename ErrorType , std::enable_if_t<!std::is_same< ErrorType, legacy::er::FatalKind >::value &&!std::is_same< ErrorType, legacy::er::EnforceViolationKind >::value &&!std::is_same< ErrorType, legacy::er::AssertViolationKind >::value, bool > = true>
auto iox2::bb::testing::expect_fatal_failure ( const bb::StaticFunction< void()> &  test_function,
const ErrorType expected_error  IOX2_MAYBE_UNUSED 
) -> bool
inline

This function is used in cases a fatal failure is expected. The function only works in combination with the iceoryx error handler. It is not recommended to use this function directly but the IOX2_TESTING_EXPECT_FATAL_FAILURE macro instead.

TEST(MyTest, valueOnNulloptIsFatal) {
}
#define IOX2_TESTING_EXPECT_FATAL_FAILURE(test_function, expected_error)
iox2::bb::variation::Optional< T > Optional
Definition optional.hpp:25
constexpr EnforceViolationKind ENFORCE_VIOLATION
Template Parameters

in] ErrorType The error type which is expected, e.g. 'iox2::legacy::HoofsError'

Parameters
[in]test_functionThis function will be executed as SUT and is expected to call the error handler
[in]expected_errorThe error value which triggered the fatal failure
Returns
true if a fatal failure occurs, false otherwise

Definition at line 48 of file fatal_failure.hpp.

References iox2::Error, has_error(), has_panicked(), iox2::legacy::StaticLifetimeGuard< T >::instance(), IOX2_LOG, IOX2_TESTING_EXPECT_PANIC, and run_in_test_thread().

◆ expect_no_fatal_failure()

auto iox2::bb::testing::expect_no_fatal_failure ( const bb::StaticFunction< void()> &  test_function) -> bool
inline

This function is used in cases no fatal failure is expected but could potentially occur. The function only works in combination with the iceoryx error handler. It is not recommended to use this function directly but the IOX2_TESTING_EXPECT_NO_FATAL_FAILURE macro instead.

TEST(MyTest, valueIsNotFatal) {
IOX2_TESTING_EXPECT_NO_FATAL_FAILURE([&] { sut.value(); });
}
#define IOX2_TESTING_EXPECT_NO_FATAL_FAILURE(test_function)
Parameters
[in]test_functionThis function will be executed as SUT and is not expected to call the error handler
Returns
true if no fatal failure occurs, false otherwise

Definition at line 128 of file fatal_failure.hpp.

References has_panicked(), and run_in_test_thread().

◆ has_assert_violation()

auto iox2::bb::testing::has_assert_violation ( ) -> bool
inline

indicates whether the test error handler registered an assert violation

Definition at line 53 of file testing_support.hpp.

References iox2::legacy::er::ASSERT_VIOLATION, iox2::legacy::er::Violation::code(), and iox2::legacy::StaticLifetimeGuard< T >::instance().

Referenced by has_violation().

◆ has_enforce_violation()

auto iox2::bb::testing::has_enforce_violation ( ) -> bool
inline

indicates whether the test error handler registered an enforce violation

Definition at line 47 of file testing_support.hpp.

References iox2::legacy::er::Violation::code(), iox2::legacy::er::ENFORCE_VIOLATION, and iox2::legacy::StaticLifetimeGuard< T >::instance().

Referenced by has_violation().

◆ has_error() [1/2]

auto iox2::bb::testing::has_error ( ) -> bool
inline

indicates whether the test error handler registered any error

Definition at line 42 of file testing_support.hpp.

References iox2::legacy::StaticLifetimeGuard< T >::instance().

Referenced by expect_fatal_failure(), and is_in_normal_state().

◆ has_error() [2/2]

template<typename Code >
auto iox2::bb::testing::has_error ( Code &&  code) -> bool
inline

indicates whether the test error handler registered a specific error

Definition at line 31 of file testing_support.hpp.

References iox2::bb::err(), iox2::legacy::StaticLifetimeGuard< T >::instance(), and iox2::legacy::er::toError().

◆ has_panicked()

auto iox2::bb::testing::has_panicked ( ) -> bool
inline

indicates whether the test error handler invoked panic

Definition at line 37 of file testing_support.hpp.

References iox2::legacy::StaticLifetimeGuard< T >::instance().

Referenced by expect_fatal_failure(), expect_no_fatal_failure(), and is_in_normal_state().

◆ has_violation()

auto iox2::bb::testing::has_violation ( ) -> bool
inline

indicates whether the test error handler registered violation (there are only two kinds).

Definition at line 59 of file testing_support.hpp.

References has_assert_violation(), and has_enforce_violation().

Referenced by is_in_normal_state().

◆ is_in_normal_state()

auto iox2::bb::testing::is_in_normal_state ( ) -> bool
inline

indicates there is no error, violation or panic.

Definition at line 64 of file testing_support.hpp.

References has_error(), has_panicked(), and has_violation().

◆ run_in_test_thread()

auto iox2::bb::testing::run_in_test_thread ( const bb::StaticFunction< void()>  test_function) -> void
inline

runs test_function in a test context that can detect fatal failures; runs in a separate thread

Note
uses a longjump inside the thread it runs the function in

Definition at line 71 of file testing_support.hpp.

References iox2::legacy::StaticLifetimeGuard< T >::instance().

Referenced by expect_fatal_failure(), and expect_no_fatal_failure().