This source file includes following definitions.
- bad_input
- is_true
- is_not_true
- is_false
- is_not_false
- main
1
2
3
4
5
6
7
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 bad_input(void **state) {
20 assert_int_equal(crm_str_to_boolean(NULL, NULL), -1);
21 assert_int_equal(crm_str_to_boolean("", NULL), -1);
22 assert_int_equal(crm_str_to_boolean("blahblah", NULL), -1);
23 }
24
25 static void
26 is_true(void **state) {
27 int ret;
28
29 assert_int_equal(crm_str_to_boolean("true", &ret), 1);
30 assert_true(ret);
31 assert_int_equal(crm_str_to_boolean("TrUe", &ret), 1);
32 assert_true(ret);
33 assert_int_equal(crm_str_to_boolean("on", &ret), 1);
34 assert_true(ret);
35 assert_int_equal(crm_str_to_boolean("ON", &ret), 1);
36 assert_true(ret);
37 assert_int_equal(crm_str_to_boolean("yes", &ret), 1);
38 assert_true(ret);
39 assert_int_equal(crm_str_to_boolean("yES", &ret), 1);
40 assert_true(ret);
41 assert_int_equal(crm_str_to_boolean("y", &ret), 1);
42 assert_true(ret);
43 assert_int_equal(crm_str_to_boolean("Y", &ret), 1);
44 assert_true(ret);
45 assert_int_equal(crm_str_to_boolean("1", &ret), 1);
46 assert_true(ret);
47 }
48
49 static void
50 is_not_true(void **state) {
51 assert_int_equal(crm_str_to_boolean("truedat", NULL), -1);
52 assert_int_equal(crm_str_to_boolean("onnn", NULL), -1);
53 assert_int_equal(crm_str_to_boolean("yep", NULL), -1);
54 assert_int_equal(crm_str_to_boolean("Y!", NULL), -1);
55 assert_int_equal(crm_str_to_boolean("100", NULL), -1);
56 }
57
58 static void
59 is_false(void **state) {
60 int ret;
61
62 assert_int_equal(crm_str_to_boolean("false", &ret), 1);
63 assert_false(ret);
64 assert_int_equal(crm_str_to_boolean("fAlSe", &ret), 1);
65 assert_false(ret);
66 assert_int_equal(crm_str_to_boolean("off", &ret), 1);
67 assert_false(ret);
68 assert_int_equal(crm_str_to_boolean("OFF", &ret), 1);
69 assert_false(ret);
70 assert_int_equal(crm_str_to_boolean("no", &ret), 1);
71 assert_false(ret);
72 assert_int_equal(crm_str_to_boolean("No", &ret), 1);
73 assert_false(ret);
74 assert_int_equal(crm_str_to_boolean("n", &ret), 1);
75 assert_false(ret);
76 assert_int_equal(crm_str_to_boolean("N", &ret), 1);
77 assert_false(ret);
78 assert_int_equal(crm_str_to_boolean("0", &ret), 1);
79 assert_false(ret);
80 }
81
82 static void
83 is_not_false(void **state) {
84 assert_int_equal(crm_str_to_boolean("falseee", NULL), -1);
85 assert_int_equal(crm_str_to_boolean("of", NULL), -1);
86 assert_int_equal(crm_str_to_boolean("nope", NULL), -1);
87 assert_int_equal(crm_str_to_boolean("N!", NULL), -1);
88 assert_int_equal(crm_str_to_boolean("000", NULL), -1);
89 }
90
91 int
92 main(int argc, char **argv)
93 {
94 const struct CMUnitTest tests[] = {
95 cmocka_unit_test(bad_input),
96 cmocka_unit_test(is_true),
97 cmocka_unit_test(is_not_true),
98 cmocka_unit_test(is_false),
99 cmocka_unit_test(is_not_false),
100 };
101
102 cmocka_set_message_output(CM_OUTPUT_TAP);
103 return cmocka_run_group_tests(tests, NULL, NULL);
104 }