2 * Copyright (c) 2003-2007 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_gcpio_compat.c,v 1.2 2008/08/22 02:27:06 kientzle Exp $");
29 unpack_test(const char *from
, const char *options
, const char *se
)
33 /* Create a work dir named after the file we're unpacking. */
34 assertMakeDir(from
, 0775);
38 * Use cpio to unpack the sample archive
40 extract_reference_file(from
);
41 r
= systemf("%s -i %s < %s >unpack.out 2>unpack.err",
42 testprog
, options
, from
);
43 failure("Error invoking %s -i %s < %s",
44 testprog
, options
, from
);
47 /* Verify that nothing went to stderr. */
49 failure("Error invoking %s -i %s < %s",
50 testprog
, options
, from
);
51 assertTextFileContents(se
, "unpack.err");
55 * Verify unpacked files.
58 /* Regular file with 2 links. */
59 assertIsReg("file", 0644);
61 assertFileSize("file", 10);
62 assertFileSize("linkfile", 10);
64 assertFileNLinks("file", 2);
66 /* Another name for the same file. */
68 assertIsHardlink("linkfile", "file");
69 assertFileSize("file", 10);
70 assertFileSize("linkfile", 10);
74 assertIsSymlink("symlink", "file");
77 assertIsDir("dir", 0775);
82 DEFINE_TEST(test_gcpio_compat
)
86 /* Dearchive sample files with a variety of options. */
88 unpack_test("test_gcpio_compat_ref.bin",
89 "--no-preserve-owner", "1 block\n");
90 unpack_test("test_gcpio_compat_ref.crc",
91 "--no-preserve-owner", "2 blocks\n");
92 unpack_test("test_gcpio_compat_ref.newc",
93 "--no-preserve-owner", "2 blocks\n");
94 /* gcpio-2.9 only reads 6 blocks here */
95 unpack_test("test_gcpio_compat_ref.ustar",
96 "--no-preserve-owner", "7 blocks\n");
98 unpack_test("test_gcpio_compat_ref_nosym.bin",
99 "--no-preserve-owner", "1 block\n");
100 unpack_test("test_gcpio_compat_ref_nosym.crc",
101 "--no-preserve-owner", "2 blocks\n");
102 unpack_test("test_gcpio_compat_ref_nosym.newc",
103 "--no-preserve-owner", "2 blocks\n");
104 /* gcpio-2.9 only reads 6 blocks here */
105 unpack_test("test_gcpio_compat_ref_nosym.ustar",
106 "--no-preserve-owner", "7 blocks\n");