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$");
28 DEFINE_TEST(test_option_q)
33 * Create an archive with several different versions of the
34 * same files. By default, the last version will overwrite
35 * any earlier versions. The -q/--fast-read option will
36 * stop early, so we can verify -q/--fast-read by seeing
37 * which version of each file actually ended up being
38 * extracted. This also exercises -r mode, since that's
39 * what we use to build up the test archive.
42 assertMakeFile("foo", 0644, "foo1");
44 assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
46 assertMakeFile("foo", 0644, "foo2");
48 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
50 assertMakeFile("bar", 0644, "bar1");
52 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
54 assertMakeFile("foo", 0644, "foo3");
56 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
58 assertMakeFile("bar", 0644, "bar2");
60 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
63 * Now, try extracting from the test archive with various
67 /* Test 1: -q foo should only extract the first foo. */
68 assertMakeDir("test1", 0755);
70 r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
72 failure("Fatal error trying to use -q option");
73 if (!assertEqualInt(0, r))
76 assertFileContents("foo1", 4, "foo");
77 assertEmptyFile("test.out");
78 assertEmptyFile("test.err");
81 /* Test 2: -q foo bar should extract up to the first bar. */
82 assertMakeDir("test2", 0755);
85 systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog));
86 assertFileContents("foo2", 4, "foo");
87 assertFileContents("bar1", 4, "bar");
88 assertEmptyFile("test.out");
89 assertEmptyFile("test.err");
92 /* Test 3: Same as test 2, but use --fast-read spelling. */
93 assertMakeDir("test3", 0755);
96 systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog));
97 assertFileContents("foo2", 4, "foo");
98 assertFileContents("bar1", 4, "bar");
99 assertEmptyFile("test.out");
100 assertEmptyFile("test.err");
103 /* Test 4: Without -q, should extract everything. */
104 assertMakeDir("test4", 0755);
105 assertChdir("test4");
107 systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog));
108 assertFileContents("foo3", 4, "foo");
109 assertFileContents("bar2", 4, "bar");
110 assertEmptyFile("test.out");
111 assertEmptyFile("test.err");