pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__scan_min_int_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_min_int("", &result, 1), EINVAL);
24  assert_int_equal(result, 1);
25 
26  assert_int_equal(pcmk__scan_min_int(NULL, &result, 1), pcmk_rc_ok);
27  assert_int_equal(result, 1);
28 }
29 
30 static void
31 input_below_minimum(void **state)
32 {
33  int result;
34 
35  assert_int_equal(pcmk__scan_min_int("100", &result, 1024), pcmk_rc_ok);
36  assert_int_equal(result, 1024);
37 }
38 
39 static void
40 input_above_maximum(void **state)
41 {
42  int result;
43 
44  assert_int_equal(pcmk__scan_min_int("20000000000000000", &result, 100), EOVERFLOW);
45  assert_int_equal(result, INT_MAX);
46 }
47 
48 static void
49 input_just_right(void **state)
50 {
51  int result;
52 
53  assert_int_equal(pcmk__scan_min_int("1024", &result, 1024), pcmk_rc_ok);
54  assert_int_equal(result, 1024);
55 
56  assert_int_equal(pcmk__scan_min_int("2048", &result, 1024), pcmk_rc_ok);
57  assert_int_equal(result, 2048);
58 }
59 
60 int main(int argc, char **argv)
61 {
62  const struct CMUnitTest tests[] = {
63  cmocka_unit_test(empty_input_string),
64  cmocka_unit_test(input_below_minimum),
65  cmocka_unit_test(input_above_maximum),
66  cmocka_unit_test(input_just_right),
67  };
68 
69  cmocka_set_message_output(CM_OUTPUT_TAP);
70  return cmocka_run_group_tests(tests, NULL, NULL);
71 }
72 
int main(int argc, char **argv)
int pcmk__scan_min_int(const char *text, int *result, int minimum)
Definition: strings.c:127
pcmk__action_result_t result
Definition: pcmk_fence.c:34