Add unit tests for assert_false()

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 11:07:02 +05:30 committed by Andreas Schneider
parent 5740aff1a1
commit a5cb5c3354
3 changed files with 70 additions and 0 deletions

View File

@ -28,6 +28,8 @@ set(CMOCKA_TESTS
test_double_macros
test_assert_true
test_assert_true_fail
test_assert_false
test_assert_false_fail
test_assert_macros
test_assert_macros_fail
test_assert_ptr
@ -94,6 +96,22 @@ set_tests_properties(
"x != 10 is not true"
)
# test_assert_false
set_tests_properties(
test_assert_false
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
# test_assert_false_fail
set_tests_properties(
test_assert_false_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"x == 10 is not false"
)
# test_assert_macros_fail
set_tests_properties(
test_assert_macros_fail

26
tests/test_assert_false.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_false(void **state)
{
int x = 10;
(void)state; /* unused */
assert_false(x != 10);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_assert_false),
};
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_false_fail(void **state)
{
int x = 10;
(void)state; /* unused */
assert_false(x == 10);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_assert_false_fail),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}