Path: blob/main/contrib/libarchive/tar/test/test_option_C_mtree.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2018 The FreeBSD Foundation4* All rights reserved.5*6* This software was developed by Arshan Khanifar <[email protected]>7* under sponsorship from the FreeBSD Foundation.8*/9#include "test.h"1011DEFINE_TEST(test_option_C_mtree)12{13char *p0;14size_t s;15int r;16p0 = NULL;17char *content = "./foo type=file uname=root gname=root mode=0755\n";18char *filename = "output.tar";19#if defined(_WIN32) && !defined(__CYGWIN__)20char *p;21#endif2223/* an absolute path to mtree file */24char *mtree_file = "/METALOG.mtree";25char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);26strcpy(absolute_path, testworkdir);27strcat(absolute_path, mtree_file );2829/* Create an archive using an mtree file. */30assertMakeFile(absolute_path, 0777, content);31assertMakeDir("bar", 0775);32assertMakeFile("bar/foo", 0777, "abc");3334#if defined(_WIN32) && !defined(__CYGWIN__)35p = absolute_path;36while(*p != '\0') {37if (*p == '/')38*p = '\\';39p++;40}4142r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path);43failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);44#else45r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);46failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path);47#endif4849assertEqualInt(r, 0);50assertEmptyFile("step1.out");51assertEmptyFile("step1.err");5253/* Do validation of the constructed archive. */5455p0 = slurpfile(&s, "output.tar");56if (!assert(p0 != NULL))57goto done;58if (!assert(s >= 2048))59goto done;60assertEqualMem(p0 + 0, "./foo", 5);61assertEqualMem(p0 + 512, "abc", 3);62assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);63assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);64done:65free(p0);66free(absolute_path);67}6869707172