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, whereA
andB
are integers.- Parameters:
A –
long long
First integer.OP – Comparison operator.
B –
long long
Second integer.
-
utest_assert_uint(A, OP, B)
Assert that
A OP B
must be true, whereA
andB
are unsigned integers.- Parameters:
A –
unsigned long long
First integer.OP – Comparison operator.
B –
unsigned long long
Second integer.
-
utest_assert_float(A, OP, B)
Assert that
A OP B
must be true, whereA
andB
are floating point numbers.- Parameters:
A –
double
First float.OP – Comparison operator.
B –
double
Second float.
-
utest_assert_ptr(A, OP, B)
Assert that
A OP B
must be true, whereA
andB
are pointers.- Parameters:
A –
void *
First pointer.OP – Comparison operator.
B –
void *
Second pointer.
-
utest_assert_string(A, OP, B)
Assert that
strcmp(A, B) OP 0
must be true.- Parameters:
A –
char const *
First string.OP – Comparison operator.
B –
char const *
Second string.
-
utest_assert_buf(A, OP, B, SIZE)
Assert that
memcmp(A, B, SIZE) OP 0
must be true.- Parameters:
A –
void *
First buffer.OP – Comparison operator.
B –
void *
Second buffer.SIZE –
size_t
Buffer size.
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.