From 72c8155d9fc0eaeac72c053f46ebb7b231d4596a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 31 Jan 2023 11:30:46 +0100 Subject: Reintegrate test code with library code Signed-off-by: David Oberhollenzer --- tests/libutil/canonicalize_name.c | 78 --------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 tests/libutil/canonicalize_name.c (limited to 'tests/libutil/canonicalize_name.c') diff --git a/tests/libutil/canonicalize_name.c b/tests/libutil/canonicalize_name.c deleted file mode 100644 index 9f81b04..0000000 --- a/tests/libutil/canonicalize_name.c +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * canonicalize_name.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "util/util.h" -#include "util/test.h" - -static const struct { - const char *in; - const char *out; -} must_work[] = { - { "", "" }, - { "/", "" }, - { "\\", "\\" }, - { "///", "" }, - { "\\\\\\", "\\\\\\" }, - { "/\\//\\\\/", "\\/\\\\" }, - { "foo/bar/test", "foo/bar/test" }, - { "foo\\bar\\test", "foo\\bar\\test" }, - { "/foo/bar/test/", "foo/bar/test" }, - { "\\foo\\bar\\test\\", "\\foo\\bar\\test\\" }, - { "///foo//bar//test///", "foo/bar/test" }, - { "./foo/././bar/test/./.", "foo/bar/test" }, - { "./foo/././", "foo" }, - { ".", "" }, - { "./", "" }, - { "./.", "" }, - { "foo/.../bar", "foo/.../bar" }, - { "foo/.test/bar", "foo/.test/bar" }, -}; - -static const char *must_not_work[] = { - "..", - "foo/../bar", - "../foo/bar", - "foo/bar/..", - "foo/bar/../", -}; - -int main(int argc, char **argv) -{ - char buffer[512]; - size_t i; - (void)argc; (void)argv; - - for (i = 0; i < sizeof(must_work) / sizeof(must_work[0]); ++i) { - strcpy(buffer, must_work[i].in); - - if (canonicalize_name(buffer)) { - fprintf(stderr, "Test case rejected: '%s'\n", - must_work[i].in); - return EXIT_FAILURE; - } - - if (strcmp(buffer, must_work[i].out) != 0) { - fprintf(stderr, "Expected result: %s\n", - must_work[i].out); - fprintf(stderr, "Actual result: %s\n", buffer); - return EXIT_FAILURE; - } - } - - for (i = 0; i < sizeof(must_not_work) / sizeof(must_not_work[0]); ++i) { - strcpy(buffer, must_not_work[i]); - - if (canonicalize_name(buffer) == 0) { - fprintf(stderr, "Test case accepted: '%s'\n", - must_not_work[i]); - fprintf(stderr, "Transformed into: '%s'\n", buffer); - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -} -- cgit v1.2.3