1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
24 */
25#include "test.h"
26
27/*
28 * Unpack the archive in a new dir.
29 */
30static void
31unpack(const char *dirname, const char *option)
32{
33	int r;
34
35	assertMakeDir(dirname, 0755);
36	assertChdir(dirname);
37	extract_reference_file("test_option_f.cpio");
38	r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option);
39	assertEqualInt(0, r);
40	assertChdir("..");
41}
42
43DEFINE_TEST(test_option_f)
44{
45	/* Calibrate:  No -f option, so everything should be extracted. */
46	unpack("t0", "--no-preserve-owner");
47	assertFileExists("t0/a123");
48	assertFileExists("t0/a234");
49	assertFileExists("t0/b123");
50	assertFileExists("t0/b234");
51
52	/* Don't extract 'a*' files. */
53#if defined(_WIN32) && !defined(__CYGWIN__)
54	/* Single quotes isn't used by command.exe. */
55	unpack("t1", "--no-preserve-owner -f a*");
56#else
57	unpack("t1", "--no-preserve-owner -f 'a*'");
58#endif
59	assertFileNotExists("t1/a123");
60	assertFileNotExists("t1/a234");
61	assertFileExists("t1/b123");
62	assertFileExists("t1/b234");
63
64	/* Don't extract 'b*' files. */
65#if defined(_WIN32) && !defined(__CYGWIN__)
66	/* Single quotes isn't used by command.exe. */
67	unpack("t2", "--no-preserve-owner -f b*");
68#else
69	unpack("t2", "--no-preserve-owner -f 'b*'");
70#endif
71	assertFileExists("t2/a123");
72	assertFileExists("t2/a234");
73	assertFileNotExists("t2/b123");
74	assertFileNotExists("t2/b234");
75}
76