]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
add test
authorChris Brown <77508021+peakschris@users.noreply.github.com>
Sat, 9 Aug 2025 00:15:35 +0000 (20:15 -0400)
committerChris Brown <77508021+peakschris@users.noreply.github.com>
Sat, 9 Aug 2025 00:15:35 +0000 (20:15 -0400)
tar/test/CMakeLists.txt
tar/test/test_crlf_mtree.c [new file with mode: 0644]
test_utils/test_main.c

index 7a3803bdcb66cefa0d99f357ef7c958b6d9a2c1f..d3c0bd22af9aabac0a664d6f2cdbbce36133a526 100644 (file)
@@ -14,6 +14,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
     test_0.c
     test_basic.c
     test_copy.c
+    test_crlf_mtree.c
     test_empty_mtree.c
     test_extract_tar_Z.c
     test_extract_tar_bz2.c
diff --git a/tar/test/test_crlf_mtree.c b/tar/test/test_crlf_mtree.c
new file mode 100644 (file)
index 0000000..75669c2
--- /dev/null
@@ -0,0 +1,70 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_crlf_mtree)
+{
+       char *p0;
+       size_t s;
+       int r;
+       p0 = NULL;
+       char *content = "#mtree\r\n./foo type=file uname=\\\r\nroot gname=root mode=0755\r\n";
+       char *filename = "output.tar";
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       char *p;
+#endif
+
+       /* an absolute path to mtree file */
+       char *mtree_file = "/METALOG.mtree";
+       char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
+       strcpy(absolute_path, testworkdir);
+       strcat(absolute_path, mtree_file );
+
+       /* Create an archive using an mtree file. */
+       assertMakeFile(absolute_path, 0777, content);
+       assertMakeDir("bar", 0775);
+       assertMakeFile("bar/foo", 0777, "abc");
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       p = absolute_path;
+       while(*p != '\0') {
+               if (*p == '/')
+                       *p = '\\';
+               p++;
+       }
+
+       r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path);
+       failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
+#else
+       r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
+       failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path);
+#endif
+
+       assertEqualInt(r, 0);
+       assertEmptyFile("step1.out");
+       assertEmptyFile("step1.err");
+
+       /* Do validation of the constructed archive. */
+
+       p0 = slurpfile(&s, "output.tar");
+       if (!assert(p0 != NULL))
+               goto done;
+       if (!assert(s >= 2048))
+               goto done;
+       assertEqualMem(p0 + 0, "./foo", 5);
+       assertEqualMem(p0 + 512, "abc", 3);
+       assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
+       assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
+done:
+       free(p0);
+       free(absolute_path);
+}
+
+
index c4244e9c6bcaa8ab4cf9641f8b3bb2c7188d6d5c..48698535526a062d1ac4a10a4c8c3a12f2e8bb15 100644 (file)
@@ -4094,6 +4094,9 @@ main(int argc, char **argv)
        if (testprogfile == NULL)
        {
                tmp2_len = strlen(testprogdir) + 1 + strlen(PROGRAM) + 1;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+               tmp2_len += 4;
+#endif
                if ((tmp2 = malloc(tmp2_len)) == NULL)
                {
                        fprintf(stderr, "ERROR: Out of memory.");
@@ -4102,6 +4105,9 @@ main(int argc, char **argv)
                strncpy(tmp2, testprogdir, tmp2_len);
                strncat(tmp2, "/", tmp2_len);
                strncat(tmp2, PROGRAM, tmp2_len);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+               strncat(tmp2, ".exe", tmp2_len);
+#endif
                testprogfile = tmp2;
        }