28assert_deref(
const char *xml_string,
const char *element_name, ...)
32 GHashTable *table = NULL;
36 if (xml_string != NULL) {
42 va_start(ap, element_name);
43 for (
const char *value = va_arg(ap,
const char *);
44 value != NULL; value = va_arg(ap,
const char *)) {
48 g_hash_table_add(table, (gpointer) value);
61 while (list != NULL) {
65 assert_true(g_hash_table_remove(table, value));
68 assert_int_equal(g_hash_table_size(table), 0);
73 g_hash_table_destroy(table);
79null_for_null(
void **state)
81 assert_deref(NULL, NULL, NULL);
82 assert_deref(NULL,
"test", NULL);
85#define XML_NO_CHILDREN "<xml><test/></xml>"
86#define XML_NO_ELEMENT_CHILDREN "<xml><test><!-- comment -->text</test></xml>"
89null_for_no_children(
void **state)
100 " <!-- comment -->\n" \
101 " <other id='other1' testattr='othervalue1' />\n" \
102 " <child id='child1' testattr='childvalue1' />\n" \
103 " <other id='other2' testattr='othervalue2' />\n" \
104 " <child id='child2' testattr='childvalue2' />\n" \
105 " <child id='child3' testattr='childvalue3' />\n" \
106 " <other id='other3' testattr='othervalue3' />\n" \
111without_idref(
void **state)
114 "othervalue1",
"othervalue2",
"othervalue3",
115 "childvalue1",
"childvalue2",
"childvalue3", NULL);
118 "othervalue1",
"othervalue2",
"othervalue3", NULL);
121 "childvalue1",
"childvalue2",
"childvalue3", NULL);
126#define XML_WITH_IDREF \
128 " <other id='other1' testattr='othervalue1' />\n" \
129 " <child id='child2' testattr='childvalue2' />\n" \
131 " <!-- comment -->\n" \
132 " <other id-ref='other1'/>\n" \
133 " <child id='child1' testattr='childvalue1' />\n" \
134 " <other id='other2' testattr='othervalue2' />\n" \
135 " <child id-ref='child2' />\n" \
136 " <child id='child3' testattr='childvalue3' />\n" \
137 " <other id='other3' testattr='othervalue3' />\n" \
142with_idref(
void **state)
145 "othervalue1",
"othervalue2",
"othervalue3",
146 "childvalue1",
"childvalue2",
"childvalue3", NULL);
149 "othervalue1",
"othervalue2",
"othervalue3", NULL);
152 "childvalue1",
"childvalue2",
"childvalue3", NULL);
157#define XML_WITH_BROKEN_IDREF \
160 " <!-- comment -->\n" \
161 " <other id-ref='other1'/>\n" \
162 " <child id='child1' testattr='childvalue1' />\n" \
163 " <other id='other2' testattr='othervalue2' />\n" \
164 " <child id-ref='child2' />\n" \
165 " <child id='child3' testattr='childvalue3' />\n" \
166 " <other id='other3' testattr='othervalue3' />\n" \
171with_broken_idref(
void **state)
174 "othervalue2",
"othervalue3",
175 "childvalue1",
"childvalue3", NULL);
178 "othervalue2",
"othervalue3", NULL);
181 "childvalue1",
"childvalue3", NULL);
187 cmocka_unit_test(null_for_null),
188 cmocka_unit_test(null_for_no_children),
189 cmocka_unit_test(without_idref),
190 cmocka_unit_test(with_idref),
191 cmocka_unit_test(with_broken_idref))
#define XML_NO_ELEMENT_CHILDREN
#define XML_WITH_BROKEN_IDREF
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
int pcmk__xml_test_teardown_group(void **state)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk__xml_test_setup_group(void **state)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
GList * pcmk__xe_dereference_children(const xmlNode *xml, const char *element_name)
void pcmk__xml_free(xmlNode *xml)
xmlNode * pcmk__xml_parse(const char *input)