pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__scan_min_int_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-2024 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_min_int("", &result, 1), EINVAL);
20  assert_int_equal(result, 1);
21 
22  assert_int_equal(pcmk__scan_min_int(NULL, &result, 1), pcmk_rc_ok);
23  assert_int_equal(result, 1);
24 }
25 
26 static void
27 input_below_minimum(void **state)
28 {
29  int result;
30 
31  assert_int_equal(pcmk__scan_min_int("100", &result, 1024), pcmk_rc_ok);
32  assert_int_equal(result, 1024);
33 }
34 
35 static void
36 input_above_maximum(void **state)
37 {
38  int result;
39 
40  assert_int_equal(pcmk__scan_min_int("20000000000000000", &result, 100), EOVERFLOW);
41  assert_int_equal(result, INT_MAX);
42 }
43 
44 static void
45 input_just_right(void **state)
46 {
47  int result;
48 
49  assert_int_equal(pcmk__scan_min_int("1024", &result, 1024), pcmk_rc_ok);
50  assert_int_equal(result, 1024);
51 
52  assert_int_equal(pcmk__scan_min_int("2048", &result, 1024), pcmk_rc_ok);
53  assert_int_equal(result, 2048);
54 }
55 
56 PCMK__UNIT_TEST(NULL, NULL,
57  cmocka_unit_test(empty_input_string),
58  cmocka_unit_test(input_below_minimum),
59  cmocka_unit_test(input_above_maximum),
60  cmocka_unit_test(input_just_right))
int pcmk__scan_min_int(const char *text, int *result, int minimum)
Definition: strings.c:126
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
pcmk__action_result_t result
Definition: pcmk_fence.c:35