Kea 2.7.5
gtest_utils.h File Reference
#include <gtest/gtest.h>
+ Include dependency graph for gtest_utils.h:

Go to the source code of this file.

Namespaces

namespace  isc
 Defines the logger used by the top-level component of kea-lfc.
 
namespace  isc::test
 

Macros

#define ASSERT_NO_THROW_LOG(statement)
 Generates a fatal failure with exception info, if the given expression throws.
 
#define ASSERT_THROW_MSG(statement, etype, emsg)
 Verifies an expected exception type and message.
 
#define EXPECT_NO_THROW_LOG(statement)
 Adds a non-fatal failure with exception info, if the given expression throws.
 
#define EXPECT_THROW_MSG(statement, etype, emsg)
 Verifies an expected exception type and message.
 
#define SKIP_IF(expression)
 Skip a test without failure if the given expression is true.
 

Macro Definition Documentation

◆ ASSERT_NO_THROW_LOG

#define ASSERT_NO_THROW_LOG ( statement)
Value:
{ \
try { \
statement; \
} catch (const std::exception& ex) { \
GTEST_FAIL() << #statement << " threw type: " << typeid(ex).name() \
<< ", what: " << ex.what(); \
} catch (...) { \
GTEST_FAIL() << #statement << " threw non-std::exception"; \
} \
} \

Generates a fatal failure with exception info, if the given expression throws.

Note the type name emitted may be mangled.

Parameters
statement- statement block to execute

Definition at line 77 of file gtest_utils.h.

◆ ASSERT_THROW_MSG

#define ASSERT_THROW_MSG ( statement,
etype,
emsg )
Value:
{ \
try { \
statement; \
GTEST_FAIL() << "no exception, expected: " << #etype; \
} catch (const etype& ex) { \
ASSERT_EQ(std::string(ex.what()), emsg); \
} catch (...) { \
GTEST_FAIL() << "wrong exception type thrown, expected: " << #etype; \
} \
} \

Verifies an expected exception type and message.

If the statement does not generate the expected exception containing the expected message it will generate a fatal failure.

Parameters
statement- statement block to execute
etype- type of exception expected
emsg- exact content expected to be returned by ex.what()

Definition at line 45 of file gtest_utils.h.

◆ EXPECT_NO_THROW_LOG

#define EXPECT_NO_THROW_LOG ( statement)
Value:
{ \
try { \
statement; \
} catch (const std::exception& ex) { \
ADD_FAILURE() << #statement << " threw type: " << typeid(ex).name() \
<< ", what: " << ex.what(); \
} catch (...) { \
ADD_FAILURE() << #statement << "threw non-std::exception"; \
} \
} \

Adds a non-fatal failure with exception info, if the given expression throws.

Note the type name emitted may be mangled.

Parameters
statement- statement block to execute

Definition at line 61 of file gtest_utils.h.

◆ EXPECT_THROW_MSG

#define EXPECT_THROW_MSG ( statement,
etype,
emsg )
Value:
{ \
try { \
statement; \
ADD_FAILURE() << "no exception, expected: " << #etype; \
} catch (const etype& ex) { \
EXPECT_EQ(std::string(ex.what()), emsg); \
} catch (...) { \
ADD_FAILURE() << "wrong exception type thrown, expected: " << #etype; \
} \
} \

Verifies an expected exception type and message.

If the statement does not generate the expected exception containing the expected message it will generate a non-fatal failure.

Parameters
statement- statement block to execute
etype- type of exception expected
emsg- exact content expected to be returned by ex.what()

Definition at line 24 of file gtest_utils.h.

◆ SKIP_IF

#define SKIP_IF ( expression)
Value:
{ \
if (expression) { \
auto const info = ::testing::UnitTest::GetInstance()->current_test_info(); \
std::cerr << "SKIPPING: " << info->test_case_name() << ":" << info->name() \
<< ": '" << #expression << "' is true" << std::endl; \
return; \
} \
}

Skip a test without failure if the given expression is true.

SKIP_IF(exp) provides a means to exit a test without failing if the given expression is true. This works around the lack of GTEST_SKIP prior to googletest 1.10.

Note
This macro cannot be used in testing::Test::SetUp() to skip tests (unless running with googletest 1.10 or later). It must be used directly within the body of each unit test.
Parameters
expressionlogical expression to execute

Definition at line 101 of file gtest_utils.h.