pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__scan_port_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
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 
int main(int argc, char **argv)
int pcmk__scan_port(const char *text, int *port)
Definition: strings.c:161
pcmk__action_result_t result
Definition: pcmk_fence.c:34