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