31 assert_order(xmlNode *test_xml,
const xmlNode *reference_xml)
34 xmlAttr *test_attr = NULL;
35 xmlAttr *ref_attr = NULL;
38 for (xmlAttr *attr = pcmk__xe_first_attr(test_xml); attr != NULL;
44 g_hash_table_insert(attr_flags,
46 GUINT_TO_POINTER((guint)
flags));
51 test_attr = pcmk__xe_first_attr(test_xml);
52 ref_attr = pcmk__xe_first_attr(reference_xml);
54 for (; (test_attr != NULL) && (ref_attr != NULL);
55 test_attr = test_attr->next, ref_attr = ref_attr->next) {
57 const char *test_name = (
const char *) test_attr->name;
61 gpointer old_flags_ptr = g_hash_table_lookup(attr_flags, test_name);
64 if (old_flags_ptr != NULL) {
65 old_flags = GPOINTER_TO_UINT(old_flags_ptr);
69 assert_true(
flags == old_flags);
72 assert_string_equal(test_name, (
const char *) ref_attr->name);
73 assert_string_equal(pcmk__xml_attr_value(test_attr),
74 pcmk__xml_attr_value(ref_attr));
78 assert_null(test_attr);
79 assert_null(ref_attr);
81 g_hash_table_destroy(attr_flags);
85 null_arg(
void **state)
92 nothing_to_sort(
void **state)
95 xmlNode *reference_xml = NULL;
99 assert_order(test_xml, reference_xml);
105 assert_order(test_xml, reference_xml);
112 already_sorted(
void **state)
117 xmlAttr *attr = NULL;
124 attr = xmlHasProp(test_xml, (
pcmkXmlStr)
"admin");
128 if (nodepriv != NULL) {
133 attr = xmlHasProp(test_xml, (
pcmkXmlStr)
"location");
137 if (nodepriv != NULL) {
148 assert_order(test_xml, reference_xml);
155 need_sort(
void **state)
160 xmlAttr *attr = NULL;
167 attr = xmlHasProp(test_xml, (
pcmkXmlStr)
"location");
171 if (nodepriv != NULL) {
176 attr = xmlHasProp(test_xml, (
pcmkXmlStr)
"admin");
180 if (nodepriv != NULL) {
191 assert_order(test_xml, reference_xml);
198 cmocka_unit_test(null_arg),
199 cmocka_unit_test(nothing_to_sort),
200 cmocka_unit_test(already_sorted),
201 cmocka_unit_test(need_sort))
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
void pcmk__xe_sort_attrs(xmlNode *xml)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
void pcmk__xml_free(xmlNode *xml)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int pcmk__xml_test_setup_group(void **state)
#define pcmk__str_copy(str)
int pcmk__xml_test_teardown_group(void **state)
const xmlChar * pcmkXmlStr
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
#define pcmk__set_xml_flags(xml_priv, flags_to_set)
#define pcmk__clear_xml_flags(xml_priv, flags_to_clear)