This source file includes following definitions.
- empty_input_string
- input_below_minimum
- input_above_maximum
- input_just_right
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 static void
19 empty_input_string(void **state)
20 {
21 int result;
22
23 assert_int_equal(pcmk__scan_min_int("", &result, 1), EINVAL);
24 assert_int_equal(result, 1);
25
26 assert_int_equal(pcmk__scan_min_int(NULL, &result, 1), pcmk_rc_ok);
27 assert_int_equal(result, 1);
28 }
29
30 static void
31 input_below_minimum(void **state)
32 {
33 int result;
34
35 assert_int_equal(pcmk__scan_min_int("100", &result, 1024), pcmk_rc_ok);
36 assert_int_equal(result, 1024);
37 }
38
39 static void
40 input_above_maximum(void **state)
41 {
42 int result;
43
44 assert_int_equal(pcmk__scan_min_int("20000000000000000", &result, 100), EOVERFLOW);
45 assert_int_equal(result, INT_MAX);
46 }
47
48 static void
49 input_just_right(void **state)
50 {
51 int result;
52
53 assert_int_equal(pcmk__scan_min_int("1024", &result, 1024), pcmk_rc_ok);
54 assert_int_equal(result, 1024);
55
56 assert_int_equal(pcmk__scan_min_int("2048", &result, 1024), pcmk_rc_ok);
57 assert_int_equal(result, 2048);
58 }
59
60 int main(int argc, char **argv)
61 {
62 const struct CMUnitTest tests[] = {
63 cmocka_unit_test(empty_input_string),
64 cmocka_unit_test(input_below_minimum),
65 cmocka_unit_test(input_above_maximum),
66 cmocka_unit_test(input_just_right),
67 };
68
69 cmocka_set_message_output(CM_OUTPUT_TAP);
70 return cmocka_run_group_tests(tests, NULL, NULL);
71 }
72