C/C++ API Reference
Loading...
Searching...
No Matches
Constexpr tests

Overview

Macros

#define PW_CONSTEXPR_TEST(test_suite, test_name, ...)
 
#define PW_TEST_EXPECT_TRUE(expr)   _PW_CEXPECT(TRUE, expr)
 
#define PW_TEST_EXPECT_FALSE(expr)   _PW_CEXPECT(FALSE, expr)
 
#define PW_TEST_EXPECT_EQ(lhs, rhs)   _PW_CEXPECT(EQ, lhs, rhs)
 
#define PW_TEST_EXPECT_NE(lhs, rhs)   _PW_CEXPECT(NE, lhs, rhs)
 
#define PW_TEST_EXPECT_GT(lhs, rhs)   _PW_CEXPECT(GT, lhs, rhs)
 
#define PW_TEST_EXPECT_GE(lhs, rhs)   _PW_CEXPECT(GE, lhs, rhs)
 
#define PW_TEST_EXPECT_LT(lhs, rhs)   _PW_CEXPECT(LT, lhs, rhs)
 
#define PW_TEST_EXPECT_LE(lhs, rhs)   _PW_CEXPECT(LE, lhs, rhs)
 
#define PW_TEST_EXPECT_NEAR(lhs, rhs, error)   _PW_CEXPECT(NEAR, lhs, rhs, error)
 
#define PW_TEST_EXPECT_FLOAT_EQ(lhs, rhs)   _PW_CEXPECT(FLOAT_EQ, lhs, rhs)
 
#define PW_TEST_EXPECT_DOUBLE_EQ(lhs, rhs)   _PW_CEXPECT(DOUBLE_EQ, lhs, rhs)
 
#define PW_TEST_EXPECT_STREQ(lhs, rhs)   _PW_CEXPECT(STREQ, lhs, rhs)
 
#define PW_TEST_EXPECT_STRNE(lhs, rhs)   _PW_CEXPECT(STRNE, lhs, rhs)
 
#define PW_TEST_ASSERT_TRUE(expr)   _PW_CASSERT(TRUE, expr)
 
#define PW_TEST_ASSERT_FALSE(expr)   _PW_CASSERT(FALSE, expr)
 
#define PW_TEST_ASSERT_EQ(lhs, rhs)   _PW_CASSERT(EQ, lhs, rhs)
 
#define PW_TEST_ASSERT_NE(lhs, rhs)   _PW_CASSERT(NE, lhs, rhs)
 
#define PW_TEST_ASSERT_GT(lhs, rhs)   _PW_CASSERT(GT, lhs, rhs)
 
#define PW_TEST_ASSERT_GE(lhs, rhs)   _PW_CASSERT(GE, lhs, rhs)
 
#define PW_TEST_ASSERT_LT(lhs, rhs)   _PW_CASSERT(LT, lhs, rhs)
 
#define PW_TEST_ASSERT_LE(lhs, rhs)   _PW_CASSERT(LE, lhs, rhs)
 
#define PW_TEST_ASSERT_NEAR(lhs, rhs, error)   _PW_CASSERT(NEAR, lhs, rhs, error)
 
#define PW_TEST_ASSERT_FLOAT_EQ(lhs, rhs)   _PW_CASSERT(FLOAT_EQ, lhs, rhs)
 
#define PW_TEST_ASSERT_DOUBLE_EQ(lhs, rhs)   _PW_CASSERT(DOUBLE_EQ, lhs, rhs)
 
#define PW_TEST_ASSERT_STREQ(lhs, rhs)   _PW_CASSERT(STREQ, lhs, rhs)
 
#define PW_TEST_ASSERT_STRNE(lhs, rhs)   _PW_CASSERT(STRNE, lhs, rhs)
 

Macro Definition Documentation

◆ PW_CONSTEXPR_TEST

#define PW_CONSTEXPR_TEST (   test_suite,
  test_name,
  ... 
)
Value:
_PW_IF_CONSTEXPR_TEST(constexpr) \
void PwConstexprTest_##test_suite##_##test_name() __VA_ARGS__ \
\
TEST(test_suite, test_name) { \
PwConstexprTest_##test_suite##_##test_name(); \
} \
\
static_assert([] { \
_PW_IF_CONSTEXPR_TEST(PwConstexprTest_##test_suite##_##test_name();) \
return true; \
}())
#define TEST(test_suite_name, test_name)
Definition: framework_backend.h:58

Defines a test that is executed both at compile time in a static_assert and as a regular GoogleTest-style TEST().

PW_CONSTEXPR_TEST works similarly to the GoogleTest TEST() macro, but has some differences.

  • All tested code must be constexpr.
  • Requires the PW_TEST_* prefixed versions of GoogleTest's EXPECT_* and ASSERT_* macros.
  • The function body is a macro argument. This has two implications:
    • The function body cannot contain preprocessor directives, such as #define. If these are needed, move them to a separate function that is called from the test.
    • The PW_CONSTEXPR_TEST macro must be terminated with ); after the test body argument.
Parameters
test_suiteGoogleTest test suite name
test_nameGoogleTest test name
...test function body surrounded by { }.