// SPDX-License-Identifier: GPL-2.0-only #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include "common/macros.h" #include "common/xml.h" struct test_case { const char *before, *after; } test_cases[] = {{ "", "" "" "ShowMenu" "root-menu" "" "1" "2" "" "" "" }, { "", "" "111" "222" "" }, { "", "" "111" "222" "333" "" }, { "", "" "111" "222" "333" "" }, { "", "" "111" "222" "" }, { "", "" "111" "222" "333" "", }, { "" "" "" "", "" "111" "111" "", }, { "" "222" "", "" "111" "222" "", }, { "" "111" "111" "", "" "111" "111" "", }, { "", "111" }}; static void test_lab_xml_expand_dotted_attributes(void **state) { (void)state; for (size_t i = 0; i < ARRAY_SIZE(test_cases); i++) { xmlDoc *doc = xmlReadDoc((xmlChar *)test_cases[i].before, NULL, NULL, 0); xmlNode *root = xmlDocGetRootElement(doc); lab_xml_expand_dotted_attributes(root); xmlBuffer *buf = xmlBufferCreate(); xmlNodeDump(buf, root->doc, root, 0, 0); assert_string_equal(test_cases[i].after, (char *)buf->content); xmlBufferFree(buf); xmlFreeDoc(doc); } } int main(int argc, char **argv) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_lab_xml_expand_dotted_attributes), }; return cmocka_run_group_tests(tests, NULL, NULL); }