pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14static void
15empty_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
23static void
24bad_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
34static void
35trailing_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
43static void
44no_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
50static void
51typical_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
59PCMK__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__action_result_t result
Definition pcmk_fence.c:35
@ pcmk_rc_ok
Definition results.h:162
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
Definition strings.c:97
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)