1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2018 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com> 8 * under sponsorship from the FreeBSD Foundation. 9 */ 10 #include "test.h" 11 12 DEFINE_TEST(test_option_C_mtree) 13 { 14 char *p0; 15 size_t s; 16 int r; 17 p0 = NULL; 18 char *content = "./foo type=file uname=root gname=root mode=0755\n"; 19 char *filename = "output.tar"; 20 #if defined(_WIN32) && !defined(CYGWIN) 21 char *p; 22 #endif 23 24 /* an absolute path to mtree file */ 25 char *mtree_file = "/METALOG.mtree"; 26 char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1); 27 strcpy(absolute_path, testworkdir); 28 strcat(absolute_path, mtree_file ); 29 30 /* Create an archive using an mtree file. */ 31 assertMakeFile(absolute_path, 0777, content); 32 assertMakeDir("bar", 0775); 33 assertMakeFile("bar/foo", 0777, "abc"); 34 35 #if defined(_WIN32) && !defined(CYGWIN) 36 p = absolute_path; 37 while(*p != '\0') { 38 if (*p == '/') 39 *p = '\\'; 40 p++; 41 } 42 43 r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path); 44 failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path); 45 #else 46 r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path); 47 failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path); 48 #endif 49 50 assertEqualInt(r, 0); 51 assertEmptyFile("step1.out"); 52 assertEmptyFile("step1.err"); 53 54 /* Do validation of the constructed archive. */ 55 56 p0 = slurpfile(&s, "output.tar"); 57 if (!assert(p0 != NULL)) 58 goto done; 59 if (!assert(s >= 2048)) 60 goto done; 61 assertEqualMem(p0 + 0, "./foo", 5); 62 assertEqualMem(p0 + 512, "abc", 3); 63 assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); 64 assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); 65 done: 66 free(p0); 67 free(absolute_path); 68 } 69 70 71