pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__scan_ll_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2023 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  long long result;
18 
19  assert_int_equal(pcmk__scan_ll(NULL, &result, 47), pcmk_rc_ok);
20  assert_int_equal(result, 47);
21 }
22 
23 static void
24 bad_input_string(void **state)
25 {
26  long long result;
27 
28  assert_int_equal(pcmk__scan_ll("asdf", &result, 47), EINVAL);
29  assert_int_equal(result, 47);
30  assert_int_equal(pcmk__scan_ll("as12", &result, 47), EINVAL);
31  assert_int_equal(result, 47);
32 }
33 
34 static void
35 trailing_chars(void **state)
36 {
37  long long result;
38 
39  assert_int_equal(pcmk__scan_ll("12as", &result, 47), pcmk_rc_ok);
40  assert_int_equal(result, 12);
41 }
42 
43 static void
44 no_result_variable(void **state)
45 {
46  assert_int_equal(pcmk__scan_ll("1234", NULL, 47), pcmk_rc_ok);
47  assert_int_equal(pcmk__scan_ll("asdf", NULL, 47), EINVAL);
48 }
49 
50 static void
51 typical_case(void **state)
52 {
53  long long result;
54 
55  assert_int_equal(pcmk__scan_ll("1234", &result, 47), pcmk_rc_ok);
56  assert_int_equal(result, 1234);
57 }
58 
59 PCMK__UNIT_TEST(NULL, NULL,
60  cmocka_unit_test(empty_input_string),
61  cmocka_unit_test(bad_input_string),
62  cmocka_unit_test(trailing_chars),
63  cmocka_unit_test(no_result_variable),
64  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_ll(const char *text, long long *result, long long default_value)
Definition: strings.c:97
pcmk__action_result_t result
Definition: pcmk_fence.c:35