pacemaker  2.1.7-0f7f88312f
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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 static void
15 empty_input_string(void **state)
16 {
17  int result;
18 
19  assert_int_equal(pcmk__scan_port("", &result), EINVAL);
20  assert_int_equal(result, -1);
21 }
22 
23 static void
24 bad_input_string(void **state)
25 {
26  int result;
27 
28  assert_int_equal(pcmk__scan_port("abc", &result), EINVAL);
29  assert_int_equal(result, -1);
30 }
31 
32 static void
33 out_of_range(void **state)
34 {
35  int result;
36 
37  assert_int_equal(pcmk__scan_port("-1", &result), pcmk_rc_before_range);
38  assert_int_equal(result, -1);
39  assert_int_equal(pcmk__scan_port("65536", &result), pcmk_rc_after_range);
40  assert_int_equal(result, -1);
41 }
42 
43 static void
44 typical_case(void **state)
45 {
46  int result;
47 
48  assert_int_equal(pcmk__scan_port("0", &result), pcmk_rc_ok);
49  assert_int_equal(result, 0);
50 
51  assert_int_equal(pcmk__scan_port("80", &result), pcmk_rc_ok);
52  assert_int_equal(result, 80);
53 }
54 
55 PCMK__UNIT_TEST(NULL, NULL,
56  cmocka_unit_test(empty_input_string),
57  cmocka_unit_test(bad_input_string),
58  cmocka_unit_test(out_of_range),
59  cmocka_unit_test(typical_case))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
int pcmk__scan_port(const char *text, int *port)
Definition: strings.c:161
pcmk__action_result_t result
Definition: pcmk_fence.c:35