diff options
Diffstat (limited to 'tests/libutil')
-rw-r--r-- | tests/libutil/Makemodule.am | 5 | ||||
-rw-r--r-- | tests/libutil/fix_win32_filename.c | 55 |
2 files changed, 59 insertions, 1 deletions
diff --git a/tests/libutil/Makemodule.am b/tests/libutil/Makemodule.am index e039282..c783853 100644 --- a/tests/libutil/Makemodule.am +++ b/tests/libutil/Makemodule.am @@ -36,9 +36,12 @@ test_hex_decode_LDADD = libutil.a libcompat.a test_base64_decode_SOURCES = tests/libutil/base64_decode.c test_base64_decode_LDADD = libutil.a libcompat.a +test_fix_win32_filename_SOURCES = tests/libutil/fix_win32_filename.c +test_fix_win32_filename_LDADD = libutil.a libcompat.a + LIBUTIL_TESTS = \ test_str_table test_rbtree test_xxhash test_threadpool test_ismemzero \ - test_canonicalize_name test_filename_sane \ + test_canonicalize_name test_filename_sane test_fix_win32_filename \ test_sdate_epoch test_hex_decode test_base64_decode check_PROGRAMS += $(LIBUTIL_TESTS) diff --git a/tests/libutil/fix_win32_filename.c b/tests/libutil/fix_win32_filename.c new file mode 100644 index 0000000..a4f71e8 --- /dev/null +++ b/tests/libutil/fix_win32_filename.c @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fix_win32_filename.c + * + * Copyright (C) 2024 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" + +#include "util/test.h" +#include "util/util.h" + +static const struct { + const char *path; + const char *result; +} test_data[] = { + { "foo", "foo" }, + { "foo/bar", "foo/bar" }, + { "foo/bar.txt", "foo/bar.txt" }, + { "COM1", "COM1_" }, + { "COM1.txt", "COM1_.txt" }, + { "foo.aux", "foo.aux_" }, + { "foo/bar/test.LPT1/bla", "foo/bar/test.LPT1_/bla" }, + { "C:\\/foo/COM1.bla/bar", + "C\xEF\x80\xBA\xEF\x81\x9c/foo/COM1_.bla/bar" }, +}; + +int main(int argc, char **argv) +{ + (void)argc; (void)argv; + + for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i) { + char *result = fix_win32_filename(test_data[i].path); + size_t out_len = strlen(test_data[i].result); + + if (result == NULL) { + fprintf(stderr, "OOM for test case %u (%s)?\n", + (unsigned int)i, test_data[i].path); + return EXIT_FAILURE; + } + + if (out_len != strlen(result) || + memcmp(result, test_data[i].result, out_len) != 0) { + fprintf(stderr, + "Mismatch for %s -> %s, got %s instead!\n", + test_data[i].path, test_data[i].result, + result); + free(result); + return EXIT_FAILURE; + } + + free(result); + } + + return EXIT_SUCCESS; +} |