Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
constexpr_test.hpp File Reference

Go to the source code of this file.

Macro Definition Documentation

◆ CONDITIONAL_CONSTEXPR_TYPED_TEST

#define CONDITIONAL_CONSTEXPR_TYPED_TEST ( testsuite,
testcase,
... )
Value:
class TESTCASE_TYPE_NAME(testsuite, testcase); \
\
class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
\
template <class TypeParam> \
constexpr void maybe_do_test(TESTCASE_TAG_NAME(testsuite, testcase) tag, std::integral_constant<bool, true>) { \
\
/* do the test, we don't use @c static_assert due to some gcc8 issues */ \
static_cast<void>(std::integral_constant<bool, (test_impl<TypeParam>(tag), true)>{}); \
test_impl<TypeParam>(tag); \
} \
\
template <class TypeParam> \
constexpr void maybe_do_test(TESTCASE_TAG_NAME(testsuite, testcase), std::integral_constant<bool, false>) { \
GTEST_SKIP() << "Disabled by condition: " << ARENE_STRINGIZE(__VA_ARGS__); \
} \
\
TYPED_TEST(testsuite, testcase) { \
using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
maybe_do_test<TypeParam>(tag_type{}, std::integral_constant<bool, (__VA_ARGS__)>{}); \
} \
\
template <class TypeParam> \
constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
void test_impl()=delete
dummy function declaration to allow unqualified lookup
bool
Check if element Idx and all subsequent elements of the two tuples are equal.
Definition tuple.hpp:635
#define ARENE_STRINGIZE(...)
Definition stringize.hpp:31
#define TESTCASE_TAG_NAME(testsuite, testcase)
defines the name of a tag associated with a testcase
Definition constexpr_test.hpp:95
#define TESTCASE_TYPE_NAME(testsuite, testcase)
defines the name of a type associated with a testcase
Definition constexpr_test.hpp:89

defines a typed test case that is invoked at compile time which is conditionally run based on the third parameter

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name
ConditionA condition convertible to bool which depends on TypeParam

Defines a TYPED_TEST that invokes a constexpr test implementation function. The implementation function is invoked twice: once at compile-time to ensure it is in-fact compile-time invocable, and again at runtime in order to generate test coverage. If the Condition is false, then the implementation function is never instantiated.

The Condition parameter can be a type_trait depending on the TypeParam of the TYPED_TEST.

TestSuite,
TestCase,
my_metafunction<TypeParam>{})
{
...
}
#define CONDITIONAL_CONSTEXPR_TYPED_TEST(testsuite, testcase,...)
defines a typed test case that is invoked at compile time which is conditionally run based on the thi...
Definition constexpr_test.hpp:330

A test defined with this macro may not use *this or other non- constexpr members from the test fixture.

◆ CONDITIONALLY_CONSTEXPR_TEST

#define CONDITIONALLY_CONSTEXPR_TEST ( testsuite,
testcase,
... )
Value:
class TESTCASE_TYPE_NAME(testsuite, testcase); \
\
class TESTCASE_TAG_NAME(testsuite, testcase) { \
static ::testing::TestInfo const* const test_info_; \
}; \
\
/* NOLINTNEXTLINE(fuchsia-statically-constructed-objects) */ \
::testing::TestInfo const* const TESTCASE_TAG_NAME(testsuite, testcase)::test_info_ = ::testing::RegisterTest( \
ARENE_STRINGIZE(testsuite), \
ARENE_STRINGIZE(testcase), \
nullptr, \
nullptr, \
__FILE__, \
__LINE__, \
[] { \
return static_cast<::testing::Test*>( \
new ::arene::base::testing::internal:: \
conditionally_constexpr_test<TESTCASE_TAG_NAME(testsuite, testcase), (__VA_ARGS__)>{} \
); \
} \
); \
\
/* test_impl is a template so it is only analyzed at instantiation, which happens only from the true-branch \
* specialization of conditionally_constexpr_test. This avoids -Winvalid-constexpr on the false branch when \
* the user body calls non-constexpr functions. */ \
template <class> \
constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))

defines a test case that is conditionally invoked at compile-time

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name
ConditionA condition convertible to bool

Defines a TEST that conditionally invokes a constexpr test implementation function. The implementation function is invoked at least once at runtime, and possibly a second time at compile-time, depending on the Condition parameter.

TestSuite,
TestCase,
ARENE_HAS_BUILTIN(__some_builtin))
{
...
}
#define ARENE_HAS_BUILTIN(...)
A platform support query for testing if a supplied builtin is defined.
Definition has_builtin.hpp:29
#define CONDITIONALLY_CONSTEXPR_TEST(testsuite, testcase,...)
defines a test case that is conditionally invoked at compile-time
Definition constexpr_test.hpp:175

◆ CONDITIONALLY_CONSTEXPR_TYPED_TEST

#define CONDITIONALLY_CONSTEXPR_TYPED_TEST ( testsuite,
testcase,
... )
Value:
class TESTCASE_TYPE_NAME(testsuite, testcase); \
\
class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
\
template <class TypeParam> \
constexpr void \
maybe_do_test_in_constexpr(TESTCASE_TAG_NAME(testsuite, testcase) tag, std::integral_constant<bool, true>) { \
/* do the test, we don't use @c static_assert due to some gcc8 issues */ \
static_cast<void>(std::integral_constant<bool, (test_impl<TypeParam>(tag), true)>{}); \
} \
\
template <class TypeParam> \
constexpr void \
maybe_do_test_in_constexpr(TESTCASE_TAG_NAME(testsuite, testcase), std::integral_constant<bool, false>) {} \
\
TYPED_TEST(testsuite, testcase) { \
using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
/* The test_impl() function must be called at runtime before dispatching to maybe_do_test_in_constexpr(), \
* otherwise gcc8 will incorrectly think test_impl() is not invocable in a constant expression. */ \
test_impl<TypeParam>(tag_type{}); \
maybe_do_test_in_constexpr<TypeParam>(tag_type{}, std::integral_constant<bool, (__VA_ARGS__)>{}); \
} \
\
template <class TypeParam> \
constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))

defines a typed test case that is conditionally invoked at compile-time

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name
ConditionA condition convertible to bool which depends on TypeParam

Defines a TYPED_TEST that conditionally invokes a constexpr test implementation function. The implementation function is invoked at least once at runtime, and possibly a second time at compile-time, depending on the CheckIfShouldRunInConstexpr parameter.

The CheckIfShouldRunInConstexpr parameter can be a type_trait depending on the TypeParam of the TYPED_TEST.

TestSuite,
TestCase,
my_metafunction<TypeParam>{})
{
...
}
#define CONDITIONALLY_CONSTEXPR_TYPED_TEST(testsuite, testcase,...)
defines a typed test case that is conditionally invoked at compile-time
Definition constexpr_test.hpp:276

A test defined with this macro may not use *this or other non- constexpr members from the test fixture.

◆ CONSTEXPR_ASSERT

#define CONSTEXPR_ASSERT ( ...)
Value:
if (not(__VA_ARGS__)) { \
FAIL(); \
}

asserts that the argument is true

Replacement assertion macro for use in CONSTEXPR_TEST and CONSTEXPR_TYPED_TEST. No GoogleTest assertion macro can be used at compile-time due to all implementations invoking functionality that cannot be used at compile-time (e.g. malloc).

◆ CONSTEXPR_ASSERT_EQ

#define CONSTEXPR_ASSERT_EQ ( lhs,
rhs )
Value:
CONSTEXPR_ASSERT(((lhs) == (rhs)))
#define CONSTEXPR_ASSERT(...)
asserts that the argument is true
Definition constexpr_test.hpp:370

asserts that the arguments are equal

Replacement assertion macro for use in CONSTEXPR_TEST and CONSTEXPR_TYPED_TEST. No GoogleTest assertion macro can be used at compile-time due to all implementations invoking functionality that cannot be used at compile-time (e.g. malloc).

◆ CONSTEXPR_ASSERT_FALSE

#define CONSTEXPR_ASSERT_FALSE ( ...)
Value:
CONSTEXPR_ASSERT(!(__VA_ARGS__))

asserts that the argument is false

Replacement assertion macro for use in CONSTEXPR_TEST and CONSTEXPR_TYPED_TEST. No GoogleTest assertion macro can be used at compile-time due to all implementations invoking functionality that cannot be used at compile-time (e.g. malloc).

◆ CONSTEXPR_TEST

#define CONSTEXPR_TEST ( testsuite,
testcase )
Value:
class TESTCASE_TYPE_NAME(testsuite, testcase); \
\
class TESTCASE_TAG_NAME(testsuite, testcase) { \
static ::testing::TestInfo const* const test_info_; \
}; \
\
/* NOLINTNEXTLINE(fuchsia-statically-constructed-objects) */ \
::testing::TestInfo const* const TESTCASE_TAG_NAME(testsuite, testcase)::test_info_ = ::testing::RegisterTest( \
ARENE_STRINGIZE(testsuite), \
ARENE_STRINGIZE(testcase), \
nullptr, \
nullptr, \
__FILE__, \
__LINE__, \
[] { \
return static_cast<::testing::Test*>( \
new ::arene::base::testing::internal::constexpr_test<TESTCASE_TAG_NAME(testsuite, testcase)>{} \
); \
} \
); \
\
constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))

defines a test case that is invoked at compile-time

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name

Performs custom test registration for testsuite testsuite and testcase @testcase that invokes a constexpr test implementation function. The implementation function is invoked twice: once at compile-time to ensure it is in-fact compile-time invocable, and again at runtime in order to generate test coverage.

◆ CONSTEXPR_TYPED_TEST

#define CONSTEXPR_TYPED_TEST ( testsuite,
testcase )
Value:
class TESTCASE_TYPE_NAME(testsuite, testcase); \
\
class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
\
TYPED_TEST(testsuite, testcase) { \
using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
static_assert((test_impl<TypeParam>(tag_type{}), true), "test body not invocable in a constant expression"); \
test_impl<TypeParam>(tag_type{}); \
} \
\
template <class TypeParam> \
constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))

defines a typed test case that is invoked at compile-time

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name

Defines a TYPED_TEST that invokes a constexpr test implementation function. The implementation function is invoked twice: once at compile-time to ensure it is in-fact compile-time invocable, and again at runtime in order to generate test coverage.

A test defined with this macro may not use *this or other non- constexpr members from the test fixture.

◆ TESTCASE_TAG_NAME

#define TESTCASE_TAG_NAME ( testsuite,
testcase )
Value:
testsuite##_##testcase##_tag

defines the name of a tag associated with a testcase

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name

◆ TESTCASE_TYPE_NAME

#define TESTCASE_TYPE_NAME ( testsuite,
testcase )
Value:
testsuite##_##testcase

defines the name of a type associated with a testcase

Parameters
testsuiteThe GoogleTest testsuite name
testcaseThe GoogleTest testcase name