diff options
Diffstat (limited to 'contrib/libarchive/tar/test')
| -rw-r--r-- | contrib/libarchive/tar/test/test_crlf_mtree.c | 74 | ||||
| -rw-r--r-- | contrib/libarchive/tar/test/test_option_safe_writes.c | 5 | 
2 files changed, 78 insertions, 1 deletions
diff --git a/contrib/libarchive/tar/test/test_crlf_mtree.c b/contrib/libarchive/tar/test/test_crlf_mtree.c new file mode 100644 index 000000000000..5ef8811369c1 --- /dev/null +++ b/contrib/libarchive/tar/test/test_crlf_mtree.c @@ -0,0 +1,74 @@ +/*- + * 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" +		"f type=file uname=\\\r\n" +		"root gname=root mode=0755 content=bar/foo\r\n" +		"g type=file uname=root gname=root mode=0755 content=bar/goo\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"); +	assertMakeFile("bar/goo", 0777, "abc"); + +#if defined(_WIN32) && !defined(__CYGWIN__) +	p = absolute_path; +	while(*p != '\0') { +		if (*p == '/') +			*p = '\\'; +		p++; +	} + +	r = systemf("%s -cf %s @%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 \"@%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, "f", 2); +	assertEqualMem(p0 + 512, "abc", 4); +	assertEqualMem(p0 + 1024, "g", 2); +	assertEqualMem(p0 + 1536, "abc", 4); +done: +	free(p0); +	free(absolute_path); +} + + diff --git a/contrib/libarchive/tar/test/test_option_safe_writes.c b/contrib/libarchive/tar/test/test_option_safe_writes.c index b88479bc5f35..d30b9a745927 100644 --- a/contrib/libarchive/tar/test/test_option_safe_writes.c +++ b/contrib/libarchive/tar/test/test_option_safe_writes.c @@ -16,11 +16,12 @@ DEFINE_TEST(test_option_safe_writes)  	assertMakeFile("d", 0644, "c");  	assertMakeFile("fs", 0644, "d");  	assertMakeFile("ds", 0644, "e"); +	assertMakeDir("fd", 0755);  	assertEqualInt(0, chdir(".."));  	/* Tar files up */  	assertEqualInt(0, -	    systemf("%s -c -C in -f t.tar f fh d fs ds " +	    systemf("%s -c -C in -f t.tar f fh d fs ds fd "  	    ">pack.out 2>pack.err", testprog));          /* Verify that nothing went to stdout or stderr. */ @@ -32,6 +33,7 @@ DEFINE_TEST(test_option_safe_writes)  	assertEqualInt(0, chdir("out"));  	assertMakeFile("f", 0644, "a");  	assertMakeHardlink("fh", "f"); +	assertMakeFile("fd", 0644, "b");  	assertMakeDir("d", 0755);  	if (canSymlink()) {  		assertMakeSymlink("fs", "f", 0); @@ -55,4 +57,5 @@ DEFINE_TEST(test_option_safe_writes)  	assertTextFileContents("c","d");  	assertTextFileContents("d","fs");  	assertTextFileContents("e","ds"); +	assertIsDir("fd", 0755);  }  | 
