This source file includes following definitions.
- empty_input
- attr_missing
- attr_present
- main
1
2
3
4
5
6
7
8
9
10 #include "crm/common/results.h"
11 #include <crm_internal.h>
12 #include <crm/common/xml_internal.h>
13
14 #include <stdarg.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <setjmp.h>
20 #include <cmocka.h>
21
22 static void
23 empty_input(void **state)
24 {
25 xmlNode *node = string2xml("<node/>");
26 bool value;
27
28 assert_int_equal(pcmk__xe_get_bool_attr(NULL, NULL, &value), ENODATA);
29 assert_int_equal(pcmk__xe_get_bool_attr(NULL, "whatever", &value), ENODATA);
30 assert_int_equal(pcmk__xe_get_bool_attr(node, NULL, &value), EINVAL);
31 assert_int_equal(pcmk__xe_get_bool_attr(node, "whatever", NULL), EINVAL);
32
33 free_xml(node);
34 }
35
36 static void
37 attr_missing(void **state)
38 {
39 xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
40 bool value;
41
42 assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), ENODATA);
43 free_xml(node);
44 }
45
46 static void
47 attr_present(void **state)
48 {
49 xmlNode *node = string2xml("<node a=\"true\" b=\"false\" c=\"blah\"/>");
50 bool value;
51
52 value = false;
53 assert_int_equal(pcmk__xe_get_bool_attr(node, "a", &value), pcmk_rc_ok);
54 assert_true(value);
55 value = true;
56 assert_int_equal(pcmk__xe_get_bool_attr(node, "b", &value), pcmk_rc_ok);
57 assert_false(value);
58 assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), pcmk_rc_unknown_format);
59
60 free_xml(node);
61 }
62
63 int
64 main(int argc, char **argv)
65 {
66 const struct CMUnitTest tests[] = {
67 cmocka_unit_test(empty_input),
68 cmocka_unit_test(attr_missing),
69 cmocka_unit_test(attr_present),
70 };
71
72 cmocka_set_message_output(CM_OUTPUT_TAP);
73 return cmocka_run_group_tests(tests, NULL, NULL);
74 }