15 static int compare_name_handler(xmlNode *xml,
void *userdata) {
17 assert_string_equal((
char *) userdata, crm_element_name(xml));
23 " <!-- This is a level 1 node -->\n" 27 " <!-- This is a level 1 node -->\n" 31 " <!-- This is a level 1 node -->\n" 38 bad_input(
void **state) {
47 name_given_test(
void **state) {
51 expect_function_call(compare_name_handler);
52 expect_function_call(compare_name_handler);
53 expect_function_call(compare_name_handler);
60 no_name_given_test(
void **state) {
64 expect_function_call(compare_name_handler);
65 expect_function_call(compare_name_handler);
66 expect_function_call(compare_name_handler);
73 name_doesnt_exist_test(
void **state) {
82 " <!-- Inside a level 1 node -->\n" 84 " <!-- Inside a level 2 node -->\n" 88 " <!-- Inside a level 1 node -->\n" 90 " <!-- Inside a level 2 node -->\n" 92 " <!-- Inside a level 3 node -->\n" 96 " <!-- Inside a level 2 node -->\n" 102 multiple_levels_test(
void **state) {
106 expect_function_call(compare_name_handler);
107 expect_function_call(compare_name_handler);
114 multiple_levels_no_name_test(
void **state) {
118 expect_function_call(compare_name_handler);
119 expect_function_call(compare_name_handler);
127 " <!-- This is node #1 -->\n" 131 " <!-- This is node #2 -->\n" 135 " <!-- This is node #3 -->\n" 141 static int any_of_handler(xmlNode *xml,
void *userdata) {
143 assert_true(
pcmk__str_any_of(crm_element_name(xml),
"node1",
"node2",
"node3", NULL));
148 any_of_test(
void **state) {
152 expect_function_call(any_of_handler);
153 expect_function_call(any_of_handler);
154 expect_function_call(any_of_handler);
160 static int stops_on_first_handler(xmlNode *xml,
void *userdata) {
163 if (pcmk__str_eq(crm_element_name(xml),
"node1",
pcmk__str_none)) {
170 static int stops_on_second_handler(xmlNode *xml,
void *userdata) {
173 if (pcmk__str_eq(crm_element_name(xml),
"node2",
pcmk__str_none)) {
180 static int stops_on_third_handler(xmlNode *xml,
void *userdata) {
183 if (pcmk__str_eq(crm_element_name(xml),
"node3",
pcmk__str_none)) {
191 one_of_test(
void **state) {
195 expect_function_call(stops_on_first_handler);
198 expect_function_call(stops_on_second_handler);
201 expect_function_call(stops_on_third_handler);
208 cmocka_unit_test(bad_input),
209 cmocka_unit_test(name_given_test),
210 cmocka_unit_test(no_name_given_test),
211 cmocka_unit_test(name_doesnt_exist_test),
212 cmocka_unit_test(multiple_levels_test),
213 cmocka_unit_test(multiple_levels_no_name_test),
214 cmocka_unit_test(any_of_test),
215 cmocka_unit_test(one_of_test))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
xmlNode * string2xml(const char *input)
#define pcmk__assert_asserts(stmt)
void free_xml(xmlNode *child)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name, int(*handler)(xmlNode *xml, void *userdata), void *userdata)