This source file includes following definitions.
- bad_input
- is_true
- is_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_false(crm_is_true(NULL));
21 }
22
23 static void
24 is_true(void **state) {
25 assert_true(crm_is_true("true"));
26 assert_true(crm_is_true("TrUe"));
27 assert_true(crm_is_true("on"));
28 assert_true(crm_is_true("ON"));
29 assert_true(crm_is_true("yes"));
30 assert_true(crm_is_true("yES"));
31 assert_true(crm_is_true("y"));
32 assert_true(crm_is_true("Y"));
33 assert_true(crm_is_true("1"));
34 }
35
36 static void
37 is_false(void **state) {
38 assert_false(crm_is_true("false"));
39 assert_false(crm_is_true("fAlSe"));
40 assert_false(crm_is_true("off"));
41 assert_false(crm_is_true("OFF"));
42 assert_false(crm_is_true("no"));
43 assert_false(crm_is_true("No"));
44 assert_false(crm_is_true("n"));
45 assert_false(crm_is_true("N"));
46 assert_false(crm_is_true("0"));
47
48 assert_false(crm_is_true(""));
49 assert_false(crm_is_true("blahblah"));
50
51 assert_false(crm_is_true("truedat"));
52 assert_false(crm_is_true("onnn"));
53 assert_false(crm_is_true("yep"));
54 assert_false(crm_is_true("Y!"));
55 assert_false(crm_is_true("100"));
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61 const struct CMUnitTest tests[] = {
62 cmocka_unit_test(bad_input),
63 cmocka_unit_test(is_true),
64 cmocka_unit_test(is_false),
65 };
66
67 cmocka_set_message_output(CM_OUTPUT_TAP);
68 return cmocka_run_group_tests(tests, NULL, NULL);
69 }