tests: Add negative tests for assert_int_in_range()
This commit is contained in:
parent
e68a2333a3
commit
106c4fbce2
|
@ -28,6 +28,7 @@ set(CMOCKA_TESTS
|
|||
test_assert_u_int
|
||||
test_assert_u_int_fail
|
||||
test_assert_range
|
||||
test_assert_range_fail
|
||||
test_basics
|
||||
test_skip
|
||||
test_stop
|
||||
|
@ -83,6 +84,13 @@ set_tests_properties(
|
|||
"\\[ FAILED \\] integer_tests: 4 test"
|
||||
)
|
||||
|
||||
set_tests_properties(
|
||||
test_assert_range_fail
|
||||
PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION
|
||||
"\\[ FAILED \\] range_fail_tests: 4 test"
|
||||
)
|
||||
|
||||
# test_expect_check_fail
|
||||
set_tests_properties(
|
||||
test_expect_check_fail
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#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_int_in_range_fail_1(void **state)
|
||||
{
|
||||
(void)state; /* unused */
|
||||
assert_int_in_range(0, 1, 2);
|
||||
}
|
||||
|
||||
static void test_assert_int_in_range_fail_2(void **state)
|
||||
{
|
||||
(void)state; /* unused */
|
||||
assert_int_in_range(2, -1, 1);
|
||||
}
|
||||
|
||||
static void test_assert_int_in_range_fail_3(void **state)
|
||||
{
|
||||
(void)state; /* unused */
|
||||
assert_int_in_range(0, 1, INTMAX_MAX);
|
||||
}
|
||||
|
||||
static void test_assert_int_in_range_fail_4(void **state)
|
||||
{
|
||||
(void)state; /* unused */
|
||||
assert_int_in_range(0, INTMAX_MIN, -1);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const struct CMUnitTest range_fail_tests[] = {
|
||||
cmocka_unit_test(test_assert_int_in_range_fail_1),
|
||||
cmocka_unit_test(test_assert_int_in_range_fail_2),
|
||||
cmocka_unit_test(test_assert_int_in_range_fail_3),
|
||||
cmocka_unit_test(test_assert_int_in_range_fail_4),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(range_fail_tests, NULL, NULL);
|
||||
}
|
Loading…
Reference in New Issue