This source file includes following definitions.
- setup
- teardown
- invalid_name
- single_schema
- multiple_schemas
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/xml.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/lists_internal.h>
15
16 #include <glib.h>
17
18 const char *rngs1[] = { "pacemaker-3.0.rng", "status-1.0.rng", "alerts-2.10.rng",
19 "nvset-2.9.rng", "score.rng", "rule-2.9.rng",
20 "tags-1.3.rng", "acls-2.0.rng", "fencing-2.4.rng",
21 "constraints-3.0.rng", "resources-3.0.rng", "nvset-3.0.rng",
22 "nodes-3.0.rng", "options-3.0.rng", NULL };
23
24 const char *rngs2[] = { "pacemaker-2.0.rng", "status-1.0.rng", "tags-1.3.rng",
25 "acls-2.0.rng", "fencing-1.2.rng", "constraints-1.2.rng",
26 "rule.rng", "score.rng", "resources-1.3.rng",
27 "nvset-1.3.rng", "nodes-1.3.rng", "options-1.0.rng",
28 "nvset.rng", "cib-1.2.rng", NULL };
29
30 const char *rngs3[] = { "pacemaker-2.1.rng", "constraints-2.1.rng", NULL };
31
32 static int
33 setup(void **state)
34 {
35 setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1);
36 crm_schema_init();
37 pcmk__xml_test_setup_group(state);
38 return 0;
39 }
40
41 static int
42 teardown(void **state)
43 {
44 pcmk__xml_test_teardown_group(state);
45 crm_schema_cleanup();
46 unsetenv("PCMK_schema_directory");
47 return 0;
48 }
49
50 static void
51 invalid_name(void **state)
52 {
53 GList *already_included = NULL;
54 xmlNode *parent = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
55
56 pcmk__build_schema_xml_node(parent, "pacemaker-9.0", &already_included);
57 assert_null(parent->children);
58 assert_null(already_included);
59 free_xml(parent);
60 }
61
62 static void
63 single_schema(void **state)
64 {
65 GList *already_included = NULL;
66 xmlNode *parent = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
67 xmlNode *schema_node = NULL;
68 xmlNode *file_node = NULL;
69 int i = 0;
70
71 pcmk__build_schema_xml_node(parent, "pacemaker-3.0", &already_included);
72
73 assert_non_null(already_included);
74 assert_non_null(parent->children);
75
76
77
78
79
80
81
82
83
84
85
86 schema_node = pcmk__xe_first_child(parent, NULL, NULL, NULL);
87 assert_string_equal("pacemaker-3.0",
88 crm_element_value(schema_node, PCMK_XA_VERSION));
89
90 file_node = pcmk__xe_first_child(schema_node, NULL, NULL, NULL);
91 while (file_node != NULL && rngs1[i] != NULL) {
92 assert_string_equal(rngs1[i],
93 crm_element_value(file_node, PCMK_XA_PATH));
94 assert_int_equal(pcmk__xml_first_child(file_node)->type, XML_CDATA_SECTION_NODE);
95
96 file_node = pcmk__xe_next(file_node);
97 i++;
98 }
99
100 g_list_free_full(already_included, free);
101 free_xml(parent);
102 }
103
104 static void
105 multiple_schemas(void **state)
106 {
107 GList *already_included = NULL;
108 xmlNode *parent = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
109 xmlNode *schema_node = NULL;
110 xmlNode *file_node = NULL;
111 int i = 0;
112
113 pcmk__build_schema_xml_node(parent, "pacemaker-2.0", &already_included);
114 pcmk__build_schema_xml_node(parent, "pacemaker-2.1", &already_included);
115
116 assert_non_null(already_included);
117 assert_non_null(parent->children);
118
119
120
121
122 schema_node = pcmk__xe_first_child(parent, NULL, NULL, NULL);
123 assert_string_equal("pacemaker-2.0",
124 crm_element_value(schema_node, PCMK_XA_VERSION));
125
126 file_node = pcmk__xe_first_child(schema_node, NULL, NULL, NULL);
127 while (file_node != NULL && rngs2[i] != NULL) {
128 assert_string_equal(rngs2[i],
129 crm_element_value(file_node, PCMK_XA_PATH));
130 assert_int_equal(pcmk__xml_first_child(file_node)->type, XML_CDATA_SECTION_NODE);
131
132 file_node = pcmk__xe_next(file_node);
133 i++;
134 }
135
136 schema_node = pcmk__xe_next(schema_node);
137 assert_string_equal("pacemaker-2.1",
138 crm_element_value(schema_node, PCMK_XA_VERSION));
139
140 file_node = pcmk__xe_first_child(schema_node, NULL, NULL, NULL);
141 i = 0;
142
143 while (file_node != NULL && rngs3[i] != NULL) {
144 assert_string_equal(rngs3[i],
145 crm_element_value(file_node, PCMK_XA_PATH));
146 assert_int_equal(pcmk__xml_first_child(file_node)->type, XML_CDATA_SECTION_NODE);
147
148 file_node = pcmk__xe_next(file_node);
149 i++;
150 }
151
152 g_list_free_full(already_included, free);
153 free_xml(parent);
154 }
155
156 PCMK__UNIT_TEST(setup, teardown,
157 cmocka_unit_test(invalid_name),
158 cmocka_unit_test(single_schema),
159 cmocka_unit_test(multiple_schemas))