1/*-
2 * Copyright (c) 2010 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
27static const char *test4out[] = {"file1", "file2", NULL};
28static const char *test5err[] = {"file1", "file2", NULL};
29
30DEFINE_TEST(test_option_O_upper)
31{
32	assertMakeFile("file1", 0644, "file1");
33	assertMakeFile("file2", 0644, "file2");
34	assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));
35
36	/* Test 1: -x without -O */
37	assertMakeDir("test1", 0755);
38	assertChdir("test1");
39	assertEqualInt(0,
40	    systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
41	assertFileContents("file1", 5, "file1");
42	assertFileContents("file2", 5, "file2");
43	assertEmptyFile("test.out");
44	assertEmptyFile("test.err");
45	assertChdir("..");
46
47	/* Test 2: -x with -O */
48	assertMakeDir("test2", 0755);
49	assertChdir("test2");
50	assertEqualInt(0,
51	    systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog));
52	assertFileNotExists("file1");
53	assertFileNotExists("file2");
54	assertFileContents("file1", 5, "test.out");
55	assertEmptyFile("test.err");
56	assertChdir("..");
57
58	/* Test 3: -x with -O and multiple files */
59	assertMakeDir("test3", 0755);
60	assertChdir("test3");
61	assertEqualInt(0,
62	    systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog));
63	assertFileNotExists("file1");
64	assertFileNotExists("file2");
65	assertFileContents("file1file2", 10, "test.out");
66	assertEmptyFile("test.err");
67	assertChdir("..");
68
69	/* Test 4: -t without -O */
70	assertMakeDir("test4", 0755);
71	assertChdir("test4");
72	assertEqualInt(0,
73	    systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog));
74	assertFileContainsLinesAnyOrder("test.out", test4out);
75	assertEmptyFile("test.err");
76	assertChdir("..");
77
78	/* Test 5: -t with -O */
79	assertMakeDir("test5", 0755);
80	assertChdir("test5");
81	assertEqualInt(0,
82	    systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog));
83	assertEmptyFile("test.out");
84	assertFileContainsLinesAnyOrder("test.err", test5err);
85	assertChdir("..");
86}
87