Tests

Test framework

void utest_run(char const *name, ...)

Runs a test batch.

Parameters:
  • name – Name of the test batch.

  • ... – One or more (void) -> void test functions.

bool utest_all_passed(void)

Whether all tests that have been run so far passed.

Returns:

True if all tests passed, false otherwise.

bool utest_batch_all_passed(void)

Whether all tests in the current batch passed.

Returns:

True if all tests in the batch passed, false otherwise.

bool utest_passed(void)

Whether the current test passed.

Returns:

True if the current test passed, false otherwise.

ustream_ret utest_log_failure_reason(char const *fmt, ...)

Logs a test failure message.

Parameters:
  • fmt – Format string.

  • ... – Format arguments.

Returns:

Return code.

void utest_fail(void)

Causes the test function to fail.

void utest_assert_msg(bool exp, char const *fmt, ...)

Asserts that the specified expression is true.

If it is not, logs a failure message and returns from the test function.

Parameters:
  • exp – Assertion condition.

  • fmt – Format string.

  • ... – Format arguments.

void utest_assert(bool exp)

Asserts that the specified expression is true.

Parameters:
  • exp – Assertion condition.

void utest_assert_false(bool exp)

Asserts that the specified expression is false.

Parameters:
  • exp – Assertion condition.

void utest_assert_not_null(void *ptr)

Assert that the specified pointer must not be NULL.

Parameters:
  • ptr – Pointer.

void utest_assert_fatal(bool exp)

Assert that the specified expression must be true.

Abort the tests if it is false.

Parameters:
  • exp – Assertion condition.

void utest_assert_critical(bool exp)

Assert that the specified expression must be true.

Abort the tests if it is false.

Deprecated:

Use utest_assert_fatal instead.

Parameters:
  • exp – Boolean expression.

utest_main(CODE)

Defines the test driver function.

Parameters:
  • CODE – Code to execute, generally a sequence of utest_run statements.

utest_sub(CODE)

Runs a test subroutine.

If the test subroutine fails, the test function will return.

Parameters:
  • CODE – Code to execute, typically a call to a function containing assertions.

utest_assert_int(A, OP, B)

Assert that A OP B must be true, where A and B are integers.

Parameters:
  • Along long First integer.

  • OP – Comparison operator.

  • Blong long Second integer.

utest_assert_uint(A, OP, B)

Assert that A OP B must be true, where A and B are unsigned integers.

Parameters:
  • Aunsigned long long First integer.

  • OP – Comparison operator.

  • Bunsigned long long Second integer.

utest_assert_float(A, OP, B)

Assert that A OP B must be true, where A and B are floating point numbers.

Parameters:
  • Adouble First float.

  • OP – Comparison operator.

  • Bdouble Second float.

utest_assert_ptr(A, OP, B)

Assert that A OP B must be true, where A and B are pointers.

Parameters:
  • Avoid * First pointer.

  • OP – Comparison operator.

  • Bvoid * Second pointer.

utest_assert_string(A, OP, B)

Assert that strcmp(A, B) OP 0 must be true.

Parameters:
  • Achar const * First string.

  • OP – Comparison operator.

  • Bchar const * Second string.

utest_assert_buf(A, OP, B, SIZE)

Assert that memcmp(A, B, SIZE) OP 0 must be true.

Parameters:
  • Avoid * First buffer.

  • OP – Comparison operator.

  • Bvoid * Second buffer.

  • SIZEsize_t Buffer size.

utest_assert_ustring(A, OP, B)

Assert that #ustring_compare(A, B) OP 0 must be true.

Parameters:
  • AUString First string.

  • OP – Comparison operator.

  • BUString Second string.

Memory leak detection

bool uleak_detect_start(void)

Starts detection of memory leaks.

Returns:

True if detection started successfully, false otherwise.

bool uleak_detect_end(void)

Ends detection of memory leaks and logs detected leaks.

Returns:

True if no leaks were detected, false otherwise.