CTEST. A lightweight test for C and C++  0.0.1
asserts.h File Reference
#include <stdint.h>

Go to the source code of this file.

Macros

#define C_TEST_TRUE   (int)(1==1)
 
#define C_TEST_FALSE   (int)(1!=1)
 
#define C_TEST_BEGIN_IGNORE   _c_test_ignore();
 
#define C_TEST_END_IGNORE   _c_test_ignore_end();
 
#define TITLE_MSG(msg)   write_title(msg, INITIAL_TITLE);
 
#define ERROR_MSG(msg)   write_title(msg, ERROR_CODE);
 
#define SUCCESS_MSG(msg)   write_title(msg, SUCCESS_CODE);
 
#define WARN_MSG(msg)   write_title(msg, WARNING_CODE);
 
#define INFO_MSG(msg)   write_title(msg, INFO_CODE);
 
#define TITLE_MSG_FMT(...)   write_title_fmt(INITIAL_TITLE, __VA_ARGS__);
 
#define ERROR_MSG_FMT(...)   write_title_fmt(ERROR_CODE, __VA_ARGS__);
 
#define WARN_MSG_FMT(...)   write_title_fmt(WARNING_CODE, __VA_ARGS__);
 
#define INFO_MSG_FMT(...)   write_title_fmt(INFO_CODE, __VA_ARGS__);
 
#define SUCCESS_MSG_FMT(...)   write_title_fmt(SUCCESS_CODE, __VA_ARGS__);
 
#define CTEST_SETTER(...)   vargs_setter(-1, __VA_ARGS__, NULL, VA_END_SIGNATURE)
 
#define CTEST_TITLE(...)   set_varg(C_TEST_VARGS_TITLE, __VA_ARGS__)
 
#define CTEST_INFO(...)   set_varg(C_TEST_VARGS_INFO, __VA_ARGS__)
 
#define CTEST_WARN(...)   set_varg(C_TEST_VARGS_WARNING, __VA_ARGS__)
 
#define CTEST_ON_ERROR(...)   set_varg(C_TEST_VARGS_ERROR, __VA_ARGS__)
 
#define CTEST_ON_SUCCESS(...)   set_varg(C_TEST_VARGS_SUCCESS, __VA_ARGS__)
 
#define CTEST_ON_SUCCESS_CB(...)   set_varg_callback(C_TEST_VARGS_ON_SUCCESS_CALLBACK, __VA_ARGS__, NULL, VAS_END_SIGNATURE)
 
#define CTEST_ON_ERROR_CB(...)   set_varg_callback(C_TEST_VARGS_ON_ERROR_CALLBACK, __VA_ARGS__, NULL, VAS_END_SIGNATURE)
 
#define C_ASSERT_FALSE(...)   assert_false(__VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_TRUE(...)   assert_true(__VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_INT(expected, ...)   assert_equal_int(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_INT(unexpected, ...)   assert_not_equal_int(unexpected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_LONG_INT(expected, ...)   assert_equal_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_LONG_INT(expected, ...)   assert_not_equal_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_UNSIGNED_LONG_INT(expected, ...)   assert_equal_unsigned_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_UNSIGNED_LONG_INT(expected, ...)   assert_not_equal_unsigned_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_DOUBLE(expected, result, ...)   assert_equal_double(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_DOUBLE(expected, result, ...)   assert_not_equal_double(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_BYTE(expected, result, ...)   assert_equal_byte(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_BYTE(unexpected, result, ...)   assert_not_equal_byte(unexpected, result, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NULL(...)   assert_null(__VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_NULL(...)   assert_not_null(__VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_STRING(expected, ...)   assert_equal_string(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_STRING(expected, ...)   assert_not_equal_string(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_STRING_IGNORE_CASE(expected, ...)   assert_equal_string_ignore_case(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_STRING_IGNORE_CASE(expected, ...)   assert_not_equal_string_ignore_case(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_U8(expected, ...)   assert_equal_u8(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_U8(expected, ...)   assert_not_equal_u8(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_S8(expected, ...)   assert_equal_s8(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_S8(expected, ...)   assert_not_equal_s8(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_U16(expected, ...)   assert_equal_u16(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_U16(expected, ...)   assert_not_equal_u16(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_S16(expected, ...)   assert_equal_s16(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_S16(expected, ...)   assert_not_equal_s16(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_U32(expected, ...)   assert_equal_u32(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_U32(expected, ...)   assert_not_equal_u32(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_S32(expected, ...)   assert_equal_s32(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_S32(expected, ...)   assert_not_equal_s32(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_U64(expected, ...)   assert_equal_u64(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_U64(expected, ...)   assert_not_equal_u64(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_EQUAL_S64(expected, ...)   assert_equal_s64(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_NOT_EQUAL_S64(expected, ...)   assert_not_equal_s64(expected, __VA_ARGS__, VAS_END_SIGNATURE);
 
#define C_ASSERT_FAIL(...)   assert_fail(__VA_ARGS__, VAS_END_SIGNATURE);
 

Functions

void on_add_test (header_on_cb)
 
void rm_on_add_test ()
 
void on_begin_test (header_on_cb)
 
void rm_begin_test ()
 
void on_test (header_on_cb)
 
void rm_on_test ()
 
void on_end_test (header_on_cb)
 
void rm_on_end_test ()
 
void on_abort (header_on_cb)
 
void rm_on_abort ()
 
void end_tests ()
 

Detailed Description

A simplest lightweight compatible C test suite for low level C and C++ applications.

Definition in file asserts.h.

Macro Definition Documentation

◆ C_ASSERT_EQUAL_BYTE

#define C_ASSERT_EQUAL_BYTE (   expected,
  result,
  ... 
)    assert_equal_byte(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);

Checks two memory pointers with same size are equals.

Parameters
expectedExpected value
resultResult value
sizeSize of expected and result pointers
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_BYTE

Definition at line 796 of file asserts.h.

◆ C_ASSERT_EQUAL_DOUBLE

#define C_ASSERT_EQUAL_DOUBLE (   expected,
  result,
  ... 
)    assert_equal_double(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedUnexpected value
resultResult value
deltaDelta double value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_DOUBLE

Definition at line 772 of file asserts.h.

◆ C_ASSERT_EQUAL_INT

#define C_ASSERT_EQUAL_INT (   expected,
  ... 
)    assert_equal_int(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_INT

Definition at line 705 of file asserts.h.

◆ C_ASSERT_EQUAL_LONG_INT

#define C_ASSERT_EQUAL_LONG_INT (   expected,
  ... 
)    assert_equal_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_LONG_INT

Definition at line 727 of file asserts.h.

◆ C_ASSERT_EQUAL_S16

#define C_ASSERT_EQUAL_S16 (   expected,
  ... 
)    assert_equal_s16(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_S16

Definition at line 949 of file asserts.h.

◆ C_ASSERT_EQUAL_S32

#define C_ASSERT_EQUAL_S32 (   expected,
  ... 
)    assert_equal_s32(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_S32

Definition at line 993 of file asserts.h.

◆ C_ASSERT_EQUAL_S64

#define C_ASSERT_EQUAL_S64 (   expected,
  ... 
)    assert_equal_s64(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_S64

Definition at line 1037 of file asserts.h.

◆ C_ASSERT_EQUAL_S8

#define C_ASSERT_EQUAL_S8 (   expected,
  ... 
)    assert_equal_s8(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_S8

Definition at line 905 of file asserts.h.

◆ C_ASSERT_EQUAL_STRING

#define C_ASSERT_EQUAL_STRING (   expected,
  ... 
)    assert_equal_string(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if two strings are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_STRING

Definition at line 839 of file asserts.h.

◆ C_ASSERT_EQUAL_STRING_IGNORE_CASE

#define C_ASSERT_EQUAL_STRING_IGNORE_CASE (   expected,
  ... 
)    assert_equal_string_ignore_case(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if two strings are equal ignoring case.

Parameters
ExpectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_STRING_IGNORE_CASE

Definition at line 861 of file asserts.h.

◆ C_ASSERT_EQUAL_U16

#define C_ASSERT_EQUAL_U16 (   expected,
  ... 
)    assert_equal_u16(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_U16

Definition at line 927 of file asserts.h.

◆ C_ASSERT_EQUAL_U32

#define C_ASSERT_EQUAL_U32 (   expected,
  ... 
)    assert_equal_u32(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_U32

Definition at line 971 of file asserts.h.

◆ C_ASSERT_EQUAL_U64

#define C_ASSERT_EQUAL_U64 (   expected,
  ... 
)    assert_equal_u64(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_U64

Definition at line 1015 of file asserts.h.

◆ C_ASSERT_EQUAL_U8

#define C_ASSERT_EQUAL_U8 (   expected,
  ... 
)    assert_equal_u8(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_U8

Definition at line 883 of file asserts.h.

◆ C_ASSERT_EQUAL_UNSIGNED_LONG_INT

#define C_ASSERT_EQUAL_UNSIGNED_LONG_INT (   expected,
  ... 
)    assert_equal_unsigned_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are equal.

Parameters
expectedExpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_EQUAL_UNSIGNED_LONG_INT

Definition at line 749 of file asserts.h.

◆ C_ASSERT_FAIL

#define C_ASSERT_FAIL (   ...)    assert_fail(__VA_ARGS__, VAS_END_SIGNATURE);

Fails on execution.

Parameters
...Optional. See CTEST_SETTER() for details
  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
int main(int argc, char **argv)
{
CTEST_INFO("Information fail"),
CTEST_WARN("Warning: This should fail")
)
)
printf("Never reaches here");
return 0;
}

Definition at line 1078 of file asserts.h.

◆ C_ASSERT_FALSE

#define C_ASSERT_FALSE (   ...)    assert_false(__VA_ARGS__, VAS_END_SIGNATURE);

Checks if result is FALSE

Parameters
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_TRUE

Definition at line 684 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_BYTE

#define C_ASSERT_NOT_EQUAL_BYTE (   unexpected,
  result,
  ... 
)    assert_not_equal_byte(unexpected, result, __VA_ARGS__, VAS_END_SIGNATURE);

Checks two memory pointers with same size are not equals.

Parameters
unexpectedUnexpected value
resultResult value
sizeSize of unexpected and result pointers
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_BYTE

Definition at line 808 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_DOUBLE

#define C_ASSERT_NOT_EQUAL_DOUBLE (   expected,
  result,
  ... 
)    assert_not_equal_double(expected, result, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedExpected value
resultResult value
deltaDelta double value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_DOUBLE

Definition at line 784 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_INT

#define C_ASSERT_NOT_EQUAL_INT (   unexpected,
  ... 
)    assert_not_equal_int(unexpected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_INT

Definition at line 716 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_LONG_INT

#define C_ASSERT_NOT_EQUAL_LONG_INT (   expected,
  ... 
)    assert_not_equal_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_LONG_INT

Definition at line 738 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_S16

#define C_ASSERT_NOT_EQUAL_S16 (   expected,
  ... 
)    assert_not_equal_s16(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_S16

Definition at line 960 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_S32

#define C_ASSERT_NOT_EQUAL_S32 (   expected,
  ... 
)    assert_not_equal_s32(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_S32

Definition at line 1004 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_S64

#define C_ASSERT_NOT_EQUAL_S64 (   expected,
  ... 
)    assert_not_equal_s64(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_S64

Definition at line 1048 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_S8

#define C_ASSERT_NOT_EQUAL_S8 (   expected,
  ... 
)    assert_not_equal_s8(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_S8

Definition at line 916 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_STRING

#define C_ASSERT_NOT_EQUAL_STRING (   expected,
  ... 
)    assert_not_equal_string(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if two strings are not equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_STRING

Definition at line 850 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_STRING_IGNORE_CASE

#define C_ASSERT_NOT_EQUAL_STRING_IGNORE_CASE (   expected,
  ... 
)    assert_not_equal_string_ignore_case(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if two strings are NOT equal ignoring case.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_STRING_IGNORE_CASE

Definition at line 872 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_U16

#define C_ASSERT_NOT_EQUAL_U16 (   expected,
  ... 
)    assert_not_equal_u16(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_U16

Definition at line 938 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_U32

#define C_ASSERT_NOT_EQUAL_U32 (   expected,
  ... 
)    assert_not_equal_u32(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_U32

Definition at line 982 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_U64

#define C_ASSERT_NOT_EQUAL_U64 (   expected,
  ... 
)    assert_not_equal_u64(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_U64

Definition at line 1026 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_U8

#define C_ASSERT_NOT_EQUAL_U8 (   expected,
  ... 
)    assert_not_equal_u8(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_U8

Definition at line 894 of file asserts.h.

◆ C_ASSERT_NOT_EQUAL_UNSIGNED_LONG_INT

#define C_ASSERT_NOT_EQUAL_UNSIGNED_LONG_INT (   expected,
  ... 
)    assert_not_equal_unsigned_longint(expected, __VA_ARGS__, VAS_END_SIGNATURE);

Checks if expected and result value are NOT equal.

Parameters
unexpectedUnexpected value
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_EQUAL_UNSIGNED_LONG_INT

Definition at line 760 of file asserts.h.

◆ C_ASSERT_NOT_NULL

#define C_ASSERT_NOT_NULL (   ...)    assert_not_null(__VA_ARGS__, VAS_END_SIGNATURE);

Checks if pointer is not NULL

Parameters
resultResult pointer
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NULL

Definition at line 828 of file asserts.h.

◆ C_ASSERT_NULL

#define C_ASSERT_NULL (   ...)    assert_null(__VA_ARGS__, VAS_END_SIGNATURE);

Checks if pointer is NULL

Parameters
resultResult pointer
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_NOT_NULL

Definition at line 818 of file asserts.h.

◆ C_ASSERT_TRUE

#define C_ASSERT_TRUE (   ...)    assert_true(__VA_ARGS__, VAS_END_SIGNATURE);

Checks if result is TRUE

Parameters
resultResult value
...Optional. See CTEST_SETTER() for details
See also
C_ASSERT_FALSE

Definition at line 694 of file asserts.h.

◆ C_TEST_BEGIN_IGNORE

#define C_TEST_BEGIN_IGNORE   _c_test_ignore();

Begin ignoring tests.

Definition at line 65 of file asserts.h.

◆ C_TEST_END_IGNORE

#define C_TEST_END_IGNORE   _c_test_ignore_end();

End ignoring tests.

Definition at line 71 of file asserts.h.

◆ C_TEST_FALSE

#define C_TEST_FALSE   (int)(1!=1)

FALSE value for CTEST

Definition at line 54 of file asserts.h.

◆ C_TEST_TRUE

#define C_TEST_TRUE   (int)(1==1)

TRUE value for CTEST

Definition at line 48 of file asserts.h.

◆ CTEST_INFO

#define CTEST_INFO (   ...)    set_varg(C_TEST_VARGS_INFO, __VA_ARGS__)

Set a info message to test.

It is only used with CTEST_SETTER macro

Example:

...
C_ASSERT_EQUAL_BYTE(vec1, vec3, sizeof(vec1),
CTEST_INFO("Checking if vec1 at (%p) has equal bytes with vec2 at (%p)", vec1, vec2,
)
)
...

Definition at line 651 of file asserts.h.

◆ CTEST_ON_ERROR

#define CTEST_ON_ERROR (   ...)    set_varg(C_TEST_VARGS_ERROR, __VA_ARGS__)

Definition at line 671 of file asserts.h.

◆ CTEST_ON_ERROR_CB

#define CTEST_ON_ERROR_CB (   ...)    set_varg_callback(C_TEST_VARGS_ON_ERROR_CALLBACK, __VA_ARGS__, NULL, VAS_END_SIGNATURE)

Definition at line 674 of file asserts.h.

◆ CTEST_ON_SUCCESS

#define CTEST_ON_SUCCESS (   ...)    set_varg(C_TEST_VARGS_SUCCESS, __VA_ARGS__)

Definition at line 672 of file asserts.h.

◆ CTEST_ON_SUCCESS_CB

#define CTEST_ON_SUCCESS_CB (   ...)    set_varg_callback(C_TEST_VARGS_ON_SUCCESS_CALLBACK, __VA_ARGS__, NULL, VAS_END_SIGNATURE)

Definition at line 673 of file asserts.h.

◆ CTEST_SETTER

#define CTEST_SETTER (   ...)    vargs_setter(-1, __VA_ARGS__, NULL, VA_END_SIGNATURE)

Setter for CTEST.

This setter allows callback function such on_error and on_success and add custom message, warn, error, info and title

Example:

const char *message = "This is a text";
...
C_ASSERT_TRUE(a > b,
CTEST_TITLE("This is a title with message %s", message),
CTEST_INFO("This is an INFO title"),
CTEST_WARN("This is a WARN message"),
CTEST_ON_ERROR("This is a message when error occurs"),
CTEST_ON_SUCCESS("This is a message when SUCCESS occurs"),
CTEST_ON_ERROR_CB(cb_func_on_error, "This function is called on error"),
CTEST_ON_SUCCESS_CB(cb_func_on_success, "This function is callend on success")
))
...

Definition at line 613 of file asserts.h.

◆ CTEST_TITLE

#define CTEST_TITLE (   ...)    set_varg(C_TEST_VARGS_TITLE, __VA_ARGS__)

Set a title message to test.

It is only used with CTEST_SETTER macro

Example:

...
C_ASSERT_EQUAL_BYTE(vec1, vec3, sizeof(vec1),
CTEST_TITLE("Checking if vec1 at (%p) has equal bytes with vec2 at (%p)", vec1, vec2,
)
)
...

Definition at line 632 of file asserts.h.

◆ CTEST_WARN

#define CTEST_WARN (   ...)    set_varg(C_TEST_VARGS_WARNING, __VA_ARGS__)

Set a warn message to test.

It is only used with CTEST_SETTER macro

Example:

...
C_ASSERT_EQUAL_BYTE(vec1, vec3, sizeof(vec1),
CTEST_WARN("Checking if vec1 at (%p) has equal bytes with vec2 at (%p)", vec1, vec2,
)
)
...

Definition at line 670 of file asserts.h.

◆ ERROR_MSG

#define ERROR_MSG (   msg)    write_title(msg, ERROR_CODE);

Add error text message.

Example:

...
ERROR_MSG("This is a text error message")
...
See also
ERROR_MSG_FMT

Definition at line 115 of file asserts.h.

◆ ERROR_MSG_FMT

#define ERROR_MSG_FMT (   ...)    write_title_fmt(ERROR_CODE, __VA_ARGS__);

Add error text message with formatted string.

Example:

int a=5, b=10;
...
ERROR_MSG_FMT("This is a %s and a + b = %d", "text", a+b)
...
See also
ERROR_MSG

Definition at line 201 of file asserts.h.

◆ INFO_MSG

#define INFO_MSG (   msg)    write_title(msg, INFO_CODE);

Add info text message.

Example:

...
WARN_MSG("This is a text info message")
...
See also
INFO_MSG_FMT

Definition at line 163 of file asserts.h.

◆ INFO_MSG_FMT

#define INFO_MSG_FMT (   ...)    write_title_fmt(INFO_CODE, __VA_ARGS__);

Add info text message with formatted string.

Example:

int a=5, b=10;
...
INFO_MSG_FMT("This is a %s and a + b = %d", "text", a+b)
...
See also
INFO_MSG

Definition at line 239 of file asserts.h.

◆ SUCCESS_MSG

#define SUCCESS_MSG (   msg)    write_title(msg, SUCCESS_CODE);

Add success text message.

Example:

...
SUCCESS_MSG("This is a text success message")
...
See also
SUCCESS_MSG_FMT

Definition at line 131 of file asserts.h.

◆ SUCCESS_MSG_FMT

#define SUCCESS_MSG_FMT (   ...)    write_title_fmt(SUCCESS_CODE, __VA_ARGS__);

Add success text message with formatted string.

Example:

int a=5, b=10;
...
SUCCESS_MSG_FMT("This is a %s and a + b = %d", "text", a+b)
...
See also
SUCCESS_MSG

Definition at line 258 of file asserts.h.

◆ TITLE_MSG

#define TITLE_MSG (   msg)    write_title(msg, INITIAL_TITLE);

Add title text message.

Example:

...
TITLE_MSG("This is a text title message")
...
See also
TITLE_MSG_FMT

Definition at line 99 of file asserts.h.

◆ TITLE_MSG_FMT

#define TITLE_MSG_FMT (   ...)    write_title_fmt(INITIAL_TITLE, __VA_ARGS__);

Add title text message with formatted string.

Example:

int a=5, b=10;
...
TITLE_MSG_FMT("This is a %s and a + b = %d", "text", a+b)
...
See also
TITLE_MSG

Definition at line 182 of file asserts.h.

◆ WARN_MSG

#define WARN_MSG (   msg)    write_title(msg, WARNING_CODE);

Add warning text message.

Example:

...
WARN_MSG("This is a text warning message")
...
See also
WARN_MSG_FMT

Definition at line 147 of file asserts.h.

◆ WARN_MSG_FMT

#define WARN_MSG_FMT (   ...)    write_title_fmt(WARNING_CODE, __VA_ARGS__);

Add warning text message with formatted string.

Example:

int a=5, b=10;
...
WARN_MSG_FMT("This is a %s and a + b = %d", "text", a+b)
...
See also
WARN_MSG

Definition at line 220 of file asserts.h.

Function Documentation

◆ end_tests()

void end_tests ( )

This function is called in every tests.

It shows statistics of the tests

◆ on_abort()

void on_abort ( header_on_cb  callback)

Call function callback if any test fails.

  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
uint8_t *vec2;
void on_abort_fn(void *context)
{
// context is not used.
if (vec2)
free(vec2);
}
int main(int argc, char **argv)
{
uint8_t vec1[] = "This is a simple text";
vec2 = malloc(sizeof(vec1));
memcpy(vec2, vec1, sizeof(vec1));
on_abort(on_abort_fn); // If error occurs, on abort will call on_abort_fn() function for any assert function
C_ASSERT_NOT_EQUAL_BYTE(vec1, vec2, sizeof(vec1),
CTEST_INFO("Testing if \"vec1\" (%p) is different from \"vec2\" (%p) of size %u", vec1, vec2, sizeof(vec1)),
CTEST_WARN("Warning: This should be different")
)
)
rm_on_abort(); // Release on_abort_fn() from lines below
return 0;
}
See also
rm_on_abort

◆ on_add_test()

void on_add_test ( header_on_cb  callback)

Call function callback on adding test event.

  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
void on_add_test_fn(void *context)
{
// context is not used.
printf("\nOn add test event ...\n\n");
}
int main(int argc, char **argv)
{
uint8_t vec1[] = "This is a simple text";
uint8_t *vec2 = malloc(sizeof(vec1));
memcpy(vec2, vec1, sizeof(vec1));
on_add_test(on_add_test_fn); // It will be called every add test event
C_ASSERT_NOT_EQUAL_BYTE(vec1, vec2, sizeof(vec1),
CTEST_INFO("Testing if \"vec1\" (%p) is different from \"vec2\" (%p) of size %u", vec1, vec2, sizeof(vec1)),
CTEST_WARN("Warning: This should be different")
)
)
return 0;
}
See also
rm_on_add_test

◆ on_begin_test()

void on_begin_test ( header_on_cb  callback)

Call function callback on each beginning test event.

  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
void on_begin_test_fn(void *context)
{
// context is not used.
printf("\nOn begin test event ...\n\n");
}
int main(int argc, char **argv)
{
uint8_t vec1[] = "This is a simple text";
uint8_t *vec2 = malloc(sizeof(vec1));
memcpy(vec2, vec1, sizeof(vec1));
on_begin_test(on_begin_test_fn); // It will be called every begin test event
C_ASSERT_NOT_EQUAL_BYTE(vec1, vec2, sizeof(vec1),
CTEST_INFO("Testing if \"vec1\" (%p) is different from \"vec2\" (%p) of size %u", vec1, vec2, sizeof(vec1)),
CTEST_WARN("Warning: This should be different")
)
)
return 0;
}
See also
rm_begin_test

◆ on_end_test()

void on_end_test ( header_on_cb  callback)

Call function callback if at the end of all tests (if success)

  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
void on_end_test_fn(void *context)
{
// context is not used.
printf("\nEnding tests ...\nExtra summary goes here ...\n\n");
}
int main(int argc, char **argv)
{
uint8_t vec1[] = "This is a simple text";
uint8_t *vec2 = malloc(sizeof(vec1));
memcpy(vec2, vec1, sizeof(vec1));
on_end_test(on_end_test_fn); // It will be called if all tests finishes successfully
C_ASSERT_NOT_EQUAL_BYTE(vec1, vec2, sizeof(vec1),
CTEST_INFO("Testing if \"vec1\" (%p) is different from \"vec2\" (%p) of size %u", vec1, vec2, sizeof(vec1)),
CTEST_WARN("Warning: This should be different")
)
)
end_tests(); // Function on_end_test_fn will be called here
return 0;
}
See also
rm_on_end_test

◆ on_test()

void on_test ( header_on_cb  callback)

Call function callback on each test event.

  • Example:
#include <stdio.h>
#include <asserts.h>
#include <string.h>
void on_test_fn(void *context)
{
// context is not used.
printf("\nOn test event ...\n\n");
}
int main(int argc, char **argv)
{
uint8_t vec1[] = "This is a simple text";
uint8_t *vec2 = malloc(sizeof(vec1));
memcpy(vec2, vec1, sizeof(vec1));
on_test(on_test_fn); // It will be called every test event
C_ASSERT_NOT_EQUAL_BYTE(vec1, vec2, sizeof(vec1),
CTEST_INFO("Testing if \"vec1\" (%p) is different from \"vec2\" (%p) of size %u", vec1, vec2, sizeof(vec1)),
CTEST_WARN("Warning: This should be different")
)
)
return 0;
}
See also
rm_on_test

◆ rm_begin_test()

void rm_begin_test ( )

Removes callback pointer from global on_begin_test context.

See also
on_test

◆ rm_on_abort()

void rm_on_abort ( )

Removes callback pointer from global on_abort context.

See also
on_abort

◆ rm_on_add_test()

void rm_on_add_test ( )

Removes callback pointer from global rm_on_add_test context.

See also
on_add_test

◆ rm_on_end_test()

void rm_on_end_test ( )

Removes callback pointer from global rm_on_end_test context.

See also
on_end_test

◆ rm_on_test()

void rm_on_test ( )

Removes callback pointer from global on_test context.

See also
on_test