This source file includes following definitions.
- empty_input_string
- input_below_minimum
- input_above_maximum
- input_just_right
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
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))