Each assert is a macro prefixed with ASSERT_
. Some of the macros also have a short-hand version. The short-hand
version has the same underlying functionality.
Tests whether the provided pointer is NULL
. This test uses NULL
as defined by stddef.h
.
ASSERT_IS_NULL(const void *value);
value The pointer to test for NULL.
Tests whether the provided pointer is non-NULL
. This test uses NULL
as defined by stddef.h
.
ASSERT_IS_NOT_NULL(const void *value);
value The pointer to test for NULL.
Tests whether the passed condition is true
. This test uses the boolean definitions in stdbool.h
.
ASSERT_IS_TRUE(const bool condition);
condition The boolean condition to test.
Tests whether the passed condition is false
. This test uses the boolean definitions in stdbool.h
.
ASSERT_IS_FALSE(const bool condition);
condition The boolean condition to test.
Tests whether the two pointers refer to the same memory location.
ASSERT_ARE_SAME(const void *expected, const void *actual);
expected This is the value the tests expects.
actual This is the value produced by the code under test.
Tests whether the two pointers refer to different memory locations.
ASSERT_ARE_NOT_SAME(const void *unexpected, const void *actual);
unexpected This is the value that should not occur.
actual This is the value produced by the code under test.
Tests whether the passed value is NaN.
ASSERT_IS_NAN(float value);
value The floating point value to check.
Tests whether the two values are equal.
The equality function for floating point numbers uses the epsilon macro from
float.h
in its equality test. It is therefore often better to use ASSERT EQUAL PRECISION when comparing floating point numbers (allowing application specific epsilon).
ASSERT_ARE_EQUAL(T expected, T actual);
ASSERT_EQ(T expected, T actual);
expected This is the value that should occur.
actual This is the value produced by the code under test.
Tests whether two floating point numbers are equal using a user provided epsilon.
ASSERT_ARE_EQUAL_PRECISION(long double expected, long double actual, long double epsilon);
ASSERT_EQ_PRECISION(long double expected, long double actual, long double epsilon);
expected This is the value that is expected to be generated by the code under test.
actual This is the value generated by the code under test.
epsilon A floating point representing the precision required when testing for equality.
Tests whether the two values are equal by comparing each byte at the given memory locations.
ASSERT_EQUAL_MEM(const void *expected, const void *actual, size_t size);
ASSERT_EQ_MEM(const void *expected, const void *actual, size_t size);
expected A pointer to the expected value.
actual A pointer to the actual value.
size The size of the passed types.
Tests whether the two values are equal by using the passed comparator function.
ASSERT_ARE_EQUAL_CMP(const void *expected,
const void *actual,
int(*cmp_fn)(const void *ptr1, const void *ptr2));
ASSERT_ARE_EQ_CMP(const void *expected,
const void *actual,
int(*cmp_fn)(const void *ptr1, const void *ptr2));
expected A pointer to the expected value.
actual A pointer to the actual value.
cmp_fn The comparator to use. This should return a negative value if the first parameter is less than the second parameter, 0 (zero) if the values are equal and a positive value if the first value is greater than the second value.
Tests whether the two values are different.
The equality function for floating point numbers uses the epsilon macro from
float.h
in its equality test. It is therefore often better to use ASSERT NOT EQUAL PRECISION when comparing floating point numbers (allowing application specific epsilon).
ASSERT_ARE_NOT_EQUAL(T unexpected, T actual);
ASSERT_NE(T unexpected, T actual);
unexpected This is the value that should not occur.
actual This is the value produced by the code under test.
Tests whether two floating point numbers are different using a user provided epsilon.
ASSERT_ARE_NOT_EQUAL_PRECISION(long double unexpected, long double actual, long double epsilon);
ASSERT_NE_PRECISION(T unexpected, T actual);
unexpected This is the value that should not occur.
actual This is the value produced by the code under test.
epsilon A floating point representing the precision required when testing for equality.
Tests whether the two values are different by comparing each byte at the given memory locations.
ASSERT_NOT_EQUAL_MEM(const void *unexpected, const void *actual, size_t size);
ASSERT_NE_MEM(const void *unexpected, const void *actual, size_t size);
unexpected A pointer to the unexpected value.
actual A pointer to the actual value.
size The size of the passed types.
Tests whether the two values are different by using the passed comparator function.
ASSERT_NOT_EQUAL_CMP(const void *unexpected,
const void *actual,
int(*cmp_fn)(const void *ptr1, const void *ptr2));
ASSERT_NE_CMP(const void *unexpected,
const void *actual,
int(*cmp_fn)(const void *ptr1, const void *ptr2));
unexpected The first value to compare. This is the value that should not occur.
actual The second value to compare. This is the value that is generated by the code under test.
cmp_fn The comparator to use. This should return a negative value if the first parameter is less than the second parameter, 0 (zero) if the values are equal and a positive value if the first value is greater than the second value.