Home | History | Annotate | Line # | Download | only in test
      1      1.1     joerg /*-
      2  1.1.1.5  christos  * SPDX-License-Identifier: BSD-2-Clause
      3  1.1.1.5  christos  *
      4      1.1     joerg  * Copyright (c) 2003-2007 Tim Kientzle
      5      1.1     joerg  * All rights reserved.
      6      1.1     joerg  */
      7      1.1     joerg #include "test.h"
      8      1.1     joerg 
      9      1.1     joerg static void
     10      1.1     joerg unpack_test(const char *from, const char *options, const char *se)
     11      1.1     joerg {
     12      1.1     joerg 	int r;
     13      1.1     joerg 
     14      1.1     joerg 	/* Create a work dir named after the file we're unpacking. */
     15  1.1.1.2     joerg 	assertMakeDir(from, 0775);
     16  1.1.1.2     joerg 	assertChdir(from);
     17      1.1     joerg 
     18      1.1     joerg 	/*
     19      1.1     joerg 	 * Use cpio to unpack the sample archive
     20      1.1     joerg 	 */
     21      1.1     joerg 	extract_reference_file(from);
     22      1.1     joerg 	r = systemf("%s -i %s < %s >unpack.out 2>unpack.err",
     23      1.1     joerg 	    testprog, options, from);
     24      1.1     joerg 	failure("Error invoking %s -i %s < %s",
     25      1.1     joerg 	    testprog, options, from);
     26      1.1     joerg 	assertEqualInt(r, 0);
     27      1.1     joerg 
     28      1.1     joerg 	/* Verify that nothing went to stderr. */
     29  1.1.1.2     joerg 	if (canSymlink()) {
     30  1.1.1.2     joerg 		failure("Error invoking %s -i %s < %s",
     31  1.1.1.2     joerg 		    testprog, options, from);
     32  1.1.1.2     joerg 		assertTextFileContents(se, "unpack.err");
     33  1.1.1.2     joerg 	}
     34      1.1     joerg 
     35      1.1     joerg 	/*
     36      1.1     joerg 	 * Verify unpacked files.
     37      1.1     joerg 	 */
     38      1.1     joerg 
     39      1.1     joerg 	/* Regular file with 2 links. */
     40  1.1.1.2     joerg 	assertIsReg("file", 0644);
     41  1.1.1.2     joerg 	failure("%s", from);
     42  1.1.1.2     joerg 	assertFileSize("file", 10);
     43  1.1.1.2     joerg 	assertFileSize("linkfile", 10);
     44  1.1.1.2     joerg 	failure("%s", from);
     45  1.1.1.2     joerg 	assertFileNLinks("file", 2);
     46      1.1     joerg 
     47      1.1     joerg 	/* Another name for the same file. */
     48  1.1.1.2     joerg 	failure("%s", from);
     49  1.1.1.2     joerg 	assertIsHardlink("linkfile", "file");
     50  1.1.1.2     joerg 	assertFileSize("file", 10);
     51  1.1.1.2     joerg 	assertFileSize("linkfile", 10);
     52      1.1     joerg 
     53      1.1     joerg 	/* Symlink */
     54  1.1.1.2     joerg 	if (canSymlink())
     55  1.1.1.3     joerg 		assertIsSymlink("symlink", "file", 0);
     56      1.1     joerg 
     57      1.1     joerg 	/* dir */
     58  1.1.1.2     joerg 	assertIsDir("dir", 0775);
     59      1.1     joerg 
     60  1.1.1.2     joerg 	assertChdir("..");
     61      1.1     joerg }
     62      1.1     joerg 
     63      1.1     joerg DEFINE_TEST(test_gcpio_compat)
     64      1.1     joerg {
     65  1.1.1.2     joerg 	assertUmask(0);
     66      1.1     joerg 
     67      1.1     joerg 	/* Dearchive sample files with a variety of options. */
     68  1.1.1.2     joerg 	if (canSymlink()) {
     69  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref.bin",
     70  1.1.1.2     joerg 		    "--no-preserve-owner", "1 block\n");
     71  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref.crc",
     72  1.1.1.2     joerg 		    "--no-preserve-owner", "2 blocks\n");
     73  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref.newc",
     74  1.1.1.2     joerg 		    "--no-preserve-owner", "2 blocks\n");
     75  1.1.1.2     joerg 		/* gcpio-2.9 only reads 6 blocks here */
     76  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref.ustar",
     77  1.1.1.2     joerg 		    "--no-preserve-owner", "7 blocks\n");
     78  1.1.1.2     joerg 	} else {
     79  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref_nosym.bin",
     80  1.1.1.2     joerg 		    "--no-preserve-owner", "1 block\n");
     81  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref_nosym.crc",
     82  1.1.1.2     joerg 		    "--no-preserve-owner", "2 blocks\n");
     83  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref_nosym.newc",
     84  1.1.1.2     joerg 		    "--no-preserve-owner", "2 blocks\n");
     85  1.1.1.2     joerg 		/* gcpio-2.9 only reads 6 blocks here */
     86  1.1.1.2     joerg 		unpack_test("test_gcpio_compat_ref_nosym.ustar",
     87  1.1.1.2     joerg 		    "--no-preserve-owner", "7 blocks\n");
     88  1.1.1.2     joerg 	}
     89      1.1     joerg }
     90