// SPDX-License-Identifier: GPL-2.0-only #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include #include "common/buf.h" #include "common/macros.h" #include "common/yaml2xml.h" struct test_set { const char *name, *yaml, *xml; }; const struct test_set test_sets[] = { { .name = "key-scalar", .yaml = "xxx: yyy", .xml = "yyy", }, { .name = "key-sequence", .yaml = "xxx: [yyy, zzz]", .xml = "yyyzzz", }, { .name = "key-mapping", .yaml = "xxx: {yyy: zzz}", .xml = "zzz", }, { .name = "window-switcher-fields", .yaml = "windowSwitcher: {fields: [xxx, yyy]}", .xml = "" "xxx" "yyy" "", }, { .name = "theme-fonts", .yaml = "theme: {fonts: [xxx, yyy]}", .xml = "" "xxx" "yyy" "", }, { .name = "mousebinds", .yaml = "mousebinds:\n" " - { button: W-Left, action: Press, actions: [ { name: Raise }, { name: Move } ] }\n" " - { button: W-Right, action: Drag, action: { name: Resize} }\n", .xml = "" "" "" "Press" "Raise" "Move" "" "" "" "Drag" "Resize" "" "", }, }; static void test_yaml_to_xml(void **state) { (void)state; for (int i = 0; i < (int)ARRAY_SIZE(test_sets); i++) { const struct test_set *set = &test_sets[i]; char buf[1024]; FILE *stream = fmemopen(buf, sizeof(buf), "w+"); fwrite(set->yaml, strlen(set->yaml), 1, stream); fseek(stream, 0, SEEK_SET); struct buf b = yaml_to_xml(stream, "test"); fclose(stream); assert_string_equal(b.data, set->xml); } } int main(int argc, char **argv) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_yaml_to_xml), }; return cmocka_run_group_tests(tests, NULL, NULL); }