This source file includes following definitions.
- empty_input_string
- bad_input_string
- out_of_range
- typical_case
- 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_port("", &result), EINVAL);
24 assert_int_equal(result, -1);
25 }
26
27 static void
28 bad_input_string(void **state)
29 {
30 int result;
31
32 assert_int_equal(pcmk__scan_port("abc", &result), EINVAL);
33 assert_int_equal(result, -1);
34 }
35
36 static void
37 out_of_range(void **state)
38 {
39 int result;
40
41 assert_int_equal(pcmk__scan_port("-1", &result), pcmk_rc_before_range);
42 assert_int_equal(result, -1);
43 assert_int_equal(pcmk__scan_port("65536", &result), pcmk_rc_after_range);
44 assert_int_equal(result, -1);
45 }
46
47 static void
48 typical_case(void **state)
49 {
50 int result;
51
52 assert_int_equal(pcmk__scan_port("0", &result), pcmk_rc_ok);
53 assert_int_equal(result, 0);
54
55 assert_int_equal(pcmk__scan_port("80", &result), pcmk_rc_ok);
56 assert_int_equal(result, 80);
57 }
58
59 int main(int argc, char **argv)
60 {
61 const struct CMUnitTest tests[] = {
62 cmocka_unit_test(empty_input_string),
63 cmocka_unit_test(bad_input_string),
64 cmocka_unit_test(out_of_range),
65 cmocka_unit_test(typical_case),
66 };
67
68 cmocka_set_message_output(CM_OUTPUT_TAP);
69 return cmocka_run_group_tests(tests, NULL, NULL);
70 }
71