xref: /freebsd/contrib/libarchive/tar/test/test_option_H_upper.c (revision 57718be8fa0bd5edc11ab9a72e68cc71982939a6)
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 DEFINE_TEST(test_option_H_upper)
29 {
30 
31 	if (!canSymlink()) {
32 		skipping("Can't test symlinks on this filesystem");
33 		return;
34 	}
35 
36 	/*
37 	 * Create a sample archive.
38 	 */
39 	assertMakeDir("in", 0755);
40 	assertChdir("in");
41 	assertMakeDir("d1", 0755);
42 	assertMakeSymlink("ld1", "d1");
43 	assertMakeFile("d1/file1", 0644, "d1/file1");
44 	assertMakeFile("d1/file2", 0644, "d1/file2");
45 	assertMakeSymlink("d1/link1", "file1");
46 	assertMakeSymlink("d1/linkX", "fileX");
47 	assertMakeSymlink("link2", "d1/file2");
48 	assertMakeSymlink("linkY", "d1/fileY");
49 	assertChdir("..");
50 
51 	/* Test 1: Without -H */
52 	assertMakeDir("test1", 0755);
53 	assertEqualInt(0,
54 	    systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
55 	assertChdir("test1");
56 	assertEqualInt(0,
57 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
58 	assertIsSymlink("ld1", "d1");
59 	assertIsSymlink("d1/link1", "file1");
60 	assertIsSymlink("d1/linkX", "fileX");
61 	assertIsSymlink("link2", "d1/file2");
62 	assertIsSymlink("linkY", "d1/fileY");
63 	assertChdir("..");
64 
65 	/* Test 2: With -H, no symlink on command line. */
66 	assertMakeDir("test2", 0755);
67 	assertEqualInt(0,
68 	    systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog));
69 	assertChdir("test2");
70 	assertEqualInt(0,
71 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
72 	assertIsSymlink("ld1", "d1");
73 	assertIsSymlink("d1/link1", "file1");
74 	assertIsSymlink("d1/linkX", "fileX");
75 	assertIsSymlink("link2", "d1/file2");
76 	assertIsSymlink("linkY", "d1/fileY");
77 	assertChdir("..");
78 
79 	/* Test 3: With -H, some symlinks on command line. */
80 	assertMakeDir("test3", 0755);
81 	assertEqualInt(0,
82 	    systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog));
83 	assertChdir("test3");
84 	assertEqualInt(0,
85 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
86 	assertIsDir("ld1", 0755);
87 	assertIsSymlink("d1/linkX", "fileX");
88 	assertIsSymlink("d1/link1", "file1");
89 	assertIsReg("link2", 0644);
90 	assertIsSymlink("linkY", "d1/fileY");
91 	assertChdir("..");
92 }
93