Skip to content

Latest commit

 

History

History
250 lines (173 loc) · 6.88 KB

asserts.md

File metadata and controls

250 lines (173 loc) · 6.88 KB

EzTest documentation - asserts

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.


Assert NULL

Tests whether the provided pointer is NULL. This test uses NULL as defined by stddef.h.

Declaration
ASSERT_IS_NULL(const void *value);
Parameters

value The pointer to test for NULL.


Assert not NULL

Tests whether the provided pointer is non-NULL. This test uses NULL as defined by stddef.h.

Declaration
ASSERT_IS_NOT_NULL(const void *value);
Parameters

value The pointer to test for NULL.


Assert true

Tests whether the passed condition is true. This test uses the boolean definitions in stdbool.h.

Declaration
ASSERT_IS_TRUE(const bool condition);
Parameters

condition The boolean condition to test.


Assert false

Tests whether the passed condition is false. This test uses the boolean definitions in stdbool.h.

Declaration
ASSERT_IS_FALSE(const bool condition);
Parameters

condition The boolean condition to test.


Assert same

Tests whether the two pointers refer to the same memory location.

Declaration
ASSERT_ARE_SAME(const void *expected, const void *actual);
Parameters

expected This is the value the tests expects.

actual This is the value produced by the code under test.


Assert not same

Tests whether the two pointers refer to different memory locations.

Declaration
ASSERT_ARE_NOT_SAME(const void *unexpected, const void *actual);
Parameters

unexpected This is the value that should not occur.

actual This is the value produced by the code under test.


Assert NaN

Tests whether the passed value is NaN.

Declaration
ASSERT_IS_NAN(float value);
Parameters

value The floating point value to check.


Assert equal

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).

Declaration
ASSERT_ARE_EQUAL(T expected, T actual);

ASSERT_EQ(T expected, T actual);
Parameters

expected This is the value that should occur.

actual This is the value produced by the code under test.


Assert equal precision

Tests whether two floating point numbers are equal using a user provided epsilon.

Declaration
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);
Parameters

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.


Assert equal memory

Tests whether the two values are equal by comparing each byte at the given memory locations.

Declaration
ASSERT_EQUAL_MEM(const void *expected, const void *actual, size_t size);

ASSERT_EQ_MEM(const void *expected, const void *actual, size_t size);
Parameters

expected A pointer to the expected value.

actual A pointer to the actual value.

size The size of the passed types.


Assert equal cmp

Tests whether the two values are equal by using the passed comparator function.

Declaration
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));
Parameters

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.


Assert not equal

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).

Declaration
ASSERT_ARE_NOT_EQUAL(T unexpected, T actual);

ASSERT_NE(T unexpected, T actual);
Parameters

unexpected This is the value that should not occur.

actual This is the value produced by the code under test.


Assert not equal precision

Tests whether two floating point numbers are different using a user provided epsilon.

Declaration
ASSERT_ARE_NOT_EQUAL_PRECISION(long double unexpected, long double actual, long double epsilon);

ASSERT_NE_PRECISION(T unexpected, T actual);
Parameters

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.


Assert not equal mem

Tests whether the two values are different by comparing each byte at the given memory locations.

Declaration
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);
Parameters

unexpected A pointer to the unexpected value.

actual A pointer to the actual value.

size The size of the passed types.


Assert not equal cmp

Tests whether the two values are different by using the passed comparator function.

Declaration
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));
Parameters

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.