80 lines
No EOL
2.5 KiB
C
80 lines
No EOL
2.5 KiB
C
#ifndef UAF_gtest_h__
|
|
#define UAF_gtest_h__
|
|
|
|
// Misc macros for unit tests with gtest in UAF
|
|
|
|
#include "core/debug/assert/AssertManager.h" // for macros {ASSERT|EXPECT}_ITF_ASSERT()
|
|
|
|
//
|
|
// Some new assertions to simplify things
|
|
//
|
|
|
|
// Managing pointers
|
|
//
|
|
// * {ASSERT|EXPECT}_NULL(pointer):
|
|
// Tests that the pointer is null.
|
|
// * {ASSERT|EXPECT}_NOT_NULL(pointer):
|
|
// Tests that the pointer is not null.
|
|
|
|
#define EXPECT_NULL(ptr) EXPECT_EQ((void*)0, ptr)
|
|
#define ASSERT_NULL(ptr) ASSERT_EQ((void*)0, ptr)
|
|
|
|
#define EXPECT_NOT_NULL(ptr) \
|
|
GTEST_TEST_BOOLEAN_(ptr != (void*)0, #ptr, NULL, !NULL, \
|
|
GTEST_NONFATAL_FAILURE_)
|
|
|
|
#define ASSERT_NOT_NULL(ptr) \
|
|
GTEST_TEST_BOOLEAN_(ptr != (void*)0, #ptr, NULL, !NULL, \
|
|
GTEST_FATAL_FAILURE_)
|
|
|
|
// Managing bbool
|
|
//
|
|
// * {ASSERT|EXPECT}_BTRUE(expr):
|
|
// Tests that expr is equal to btrue.
|
|
// * {ASSERT|EXPECT}_BFALSE(expr):
|
|
// Tests that expr is equal to bfalse.
|
|
|
|
#define EXPECT_BTRUE(condition) \
|
|
GTEST_TEST_BOOLEAN_((condition) == btrue, #condition, bfalse, btrue, \
|
|
GTEST_NONFATAL_FAILURE_)
|
|
|
|
#define ASSERT_BTRUE(condition) \
|
|
GTEST_TEST_BOOLEAN_((condition) == btrue, #condition, bfalse, btrue, \
|
|
GTEST_FATAL_FAILURE_)
|
|
|
|
#define EXPECT_BFALSE(condition) \
|
|
GTEST_TEST_BOOLEAN_((condition) == bfalse, #condition, btrue, bfalse, \
|
|
GTEST_NONFATAL_FAILURE_)
|
|
|
|
#define ASSERT_BFALSE(condition) \
|
|
GTEST_TEST_BOOLEAN_((condition) == bfalse, #condition, btrue, bfalse, \
|
|
GTEST_FATAL_FAILURE_)
|
|
|
|
//
|
|
// Catching ITF assertions
|
|
//
|
|
// * {ASSERT|EXPECT}_ITF_ASSERT(statement):
|
|
// Tests that statement generates an assert (ITF_ASSERT).
|
|
|
|
#define EXPECT_ITF_ASSERT(statement) \
|
|
ITF::AssertManager::startCatchingAssertForUnitTests(); \
|
|
EXPECT_DEATH_IF_SUPPORTED(statement, ""); \
|
|
ITF::AssertManager::stopCatchingAssertForUnitTests()
|
|
|
|
#define ASSERT_ITF_ASSERT(statement) \
|
|
ITF::AssertManager::startCatchingAssertForUnitTests(); \
|
|
ASSERT_DEATH_IF_SUPPORTED(statments, ""); \
|
|
ITF::AssertManager::stopCatchingAssertForUnitTests()
|
|
|
|
#define EXPECT_ITF_ASSERT_AND_IGNORE(statement) \
|
|
ITF::AssertManager::startDetectAssertAndIgnoreForUnitTests(); \
|
|
statement; \
|
|
EXPECT_BTRUE(ITF::AssertManager::getAssertDetectedAndReset());\
|
|
ITF::AssertManager::stopDetectAssertAndIgnoreForUnitTests()
|
|
|
|
#define ASSERT_ITF_ASSERT_AND_IGNORE(statement) \
|
|
ITF::AssertManager::startDetectAssertAndIgnoreForUnitTests(); \
|
|
statments; \
|
|
ASSERT_BTRUE(ITF::AssertManager::getAssertDetectedAndReset()); \
|
|
ITF::AssertManager::stopDetectAssertAndIgnoreForUnitTests()
|
|
#endif // UAF_gtest_h__
|