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)
32 fd = open("foo", O_CREAT | O_WRONLY, 0644);
34 assertEqualInt(4, write(fd, "foo1", 4));
37 assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
39 fd = open("foo", O_TRUNC | O_WRONLY, 0644);
41 assertEqualInt(4, write(fd, "foo2", 4));
44 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
46 fd = open("bar", O_CREAT | O_WRONLY, 0644);
48 assertEqualInt(4, write(fd, "bar1", 4));
51 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
53 fd = open("foo", O_TRUNC | O_WRONLY, 0644);
55 assertEqualInt(4, write(fd, "foo3", 4));
58 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
60 fd = open("bar", O_TRUNC | O_WRONLY, 0644);
62 assertEqualInt(4, write(fd, "bar2", 4));
65 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
67 /* Test 1: -q foo should only extract the first foo. */
68 assertEqualInt(0, mkdir("test1", 0755));
69 assertEqualInt(0, chdir("test1"));
71 systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
73 assertFileContents("foo1", 4, "foo");
74 assertEmptyFile("test.out");
75 assertEmptyFile("test.err");
76 assertEqualInt(0, chdir(".."));
78 /* Test 2: -q foo bar should extract up to the first bar. */
79 assertEqualInt(0, mkdir("test2", 0755));
80 assertEqualInt(0, chdir("test2"));
82 systemf("%s -xf ../archive.tar -q foo bar", testprog));
83 assertFileContents("foo2", 4, "foo");
84 assertFileContents("bar1", 4, "bar");
85 assertEqualInt(0, chdir(".."));
87 /* Test 3: Same as test 2, but use --fast-read spelling. */
88 assertEqualInt(0, mkdir("test3", 0755));
89 assertEqualInt(0, chdir("test3"));
91 systemf("%s -xf ../archive.tar --fast-read foo bar", testprog));
92 assertFileContents("foo2", 4, "foo");
93 assertFileContents("bar1", 4, "bar");
94 assertEqualInt(0, chdir(".."));
96 /* Test 4: Without -q, should extract everything. */
97 assertEqualInt(0, mkdir("test4", 0755));
98 assertEqualInt(0, chdir("test4"));
100 systemf("%s -xf ../archive.tar foo bar", testprog));
101 assertFileContents("foo3", 4, "foo");
102 assertFileContents("bar2", 4, "bar");
103 assertEqualInt(0, chdir(".."));