Tests
Test framework
-
void utest_run(char const *name, ...)
Runs a test batch.
- Parameters:
name – Name of the test batch.
... – One or more
(void) -> voidtest 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.
-
ulib_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_ret(ulib_ret ret, ulib_ret val)
Asserts that the specified return code is equal to the expected value.
- Parameters:
ret – Return code.
val – Expected value.
-
void utest_assert_ok(ulib_ret ret)
Asserts that the specified return code is equal to
ULIB_OK.- Parameters:
ret – Return code.
-
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_fatalinstead.
- 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_enum(A, OP, B)
Assert that
A OP Bmust be true, whereAandBare enum values.- Parameters:
A –
intFirst enum value.OP – Comparison operator.
B –
intSecond enum value.
-
utest_assert_int(A, OP, B)
Assert that
A OP Bmust be true, whereAandBare integers.- Parameters:
A –
long longFirst integer.OP – Comparison operator.
B –
long longSecond integer.
-
utest_assert_uint(A, OP, B)
Assert that
A OP Bmust be true, whereAandBare unsigned integers.- Parameters:
A –
unsigned long longFirst integer.OP – Comparison operator.
B –
unsigned long longSecond integer.
-
utest_assert_float(A, OP, B)
Assert that
A OP Bmust be true, whereAandBare floating point numbers.- Parameters:
A –
doubleFirst float.OP – Comparison operator.
B –
doubleSecond float.
-
utest_assert_ptr(A, OP, B)
Assert that
A OP Bmust be true, whereAandBare 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 0must 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 0must be true.- Parameters:
A –
void *First buffer.OP – Comparison operator.
B –
void *Second buffer.SIZE –
size_tBuffer 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.