Add unit tests for assert_true()

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Eshan Kelkar 2023-12-23 10:48:15 +05:30 committed by Andreas Schneider
parent ad567f8d85
commit 5740aff1a1
3 changed files with 70 additions and 0 deletions

View File

@ -26,6 +26,8 @@ set(CMOCKA_TESTS
test_groups
test_float_macros
test_double_macros
test_assert_true
test_assert_true_fail
test_assert_macros
test_assert_macros_fail
test_assert_ptr
@ -76,6 +78,22 @@ set_tests_properties(
"\\[ SKIPPED \\] test_check_skip"
)
# test_assert_true
set_tests_properties(
test_assert_true
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
# test_assert_true_fail
set_tests_properties(
test_assert_true_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"x != 10 is not true"
)
# test_assert_macros_fail
set_tests_properties(
test_assert_macros_fail

26
tests/test_assert_true.c Normal file
View File

@ -0,0 +1,26 @@
#include "config.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#include <cmocka_private.h>
static void test_assert_true(void **state)
{
int x = 10;
(void)state; /* unused */
assert_true(x == 10);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_assert_true),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}

View File

@ -0,0 +1,26 @@
#include "config.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#include <cmocka_private.h>
static void test_assert_true_fail(void **state)
{
int x = 10;
(void)state; /* unused */
assert_true(x != 10);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_assert_true_fail),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}