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 27 DEFINE_TEST(test_option_exclude) 28 { 29 int r; 30 31 assertMakeFile("file1", 0644, "file1"); 32 assertMakeFile("file2", 0644, "file2"); 33 assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); 34 35 /* 36 * Now, try extracting from the test archive with various --exclude options. 37 */ 38 39 /* Test 1: Without --exclude */ 40 assertMakeDir("test1", 0755); 41 assertChdir("test1"); 42 assertEqualInt(0, 43 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); 44 assertFileContents("file1", 5, "file1"); 45 assertFileContents("file2", 5, "file2"); 46 assertEmptyFile("test.out"); 47 assertEmptyFile("test.err"); 48 assertChdir(".."); 49 50 /* Test 2: Selecting just one file */ 51 assertMakeDir("test2", 0755); 52 assertChdir("test2"); 53 assertEqualInt(0, 54 systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog)); 55 assertFileContents("file1", 5, "file1"); 56 assertFileNotExists("file2"); 57 assertEmptyFile("test.out"); 58 assertEmptyFile("test.err"); 59 assertChdir(".."); 60 61 /* Test 3: Use --exclude to skip one file */ 62 assertMakeDir("test3", 0755); 63 assertChdir("test3"); 64 assertEqualInt(0, 65 systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog)); 66 assertFileNotExists("file1"); 67 assertFileContents("file2", 5, "file2"); 68 assertEmptyFile("test.out"); 69 assertEmptyFile("test.err"); 70 assertChdir(".."); 71 72 /* Test 4: Selecting one valid and one invalid file */ 73 assertMakeDir("test4", 0755); 74 assertChdir("test4"); 75 r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog); 76 assert(r != 0); 77 assertFileContents("file1", 5, "file1"); 78 assertFileNotExists("file2"); 79 assertFileNotExists("file3"); 80 assertEmptyFile("test.out"); 81 assertNonEmptyFile("test.err"); 82 assertChdir(".."); 83 84 /* Test 5: Selecting one valid file twice */ 85 assertMakeDir("test5", 0755); 86 assertChdir("test5"); 87 assertEqualInt(0, 88 systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog)); 89 assertFileContents("file1", 5, "file1"); 90 assertFileNotExists("file2"); 91 assertEmptyFile("test.out"); 92 assertEmptyFile("test.err"); 93 assertChdir(".."); 94 95 /* Test 6: Include and exclude the same file */ 96 assertMakeDir("test6", 0755); 97 assertChdir("test6"); 98 assertEqualInt(0, 99 systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog)); 100 assertFileNotExists("file1"); 101 assertFileNotExists("file2"); 102 assertEmptyFile("test.out"); 103 assertEmptyFile("test.err"); 104 assertChdir(".."); 105 106 /* Test 7: Exclude a non-existent file */ 107 assertMakeDir("test7", 0755); 108 assertChdir("test7"); 109 assertEqualInt(0, 110 systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog)); 111 assertFileContents("file1", 5, "file1"); 112 assertFileNotExists("file2"); 113 assertFileNotExists("file3"); 114 assertEmptyFile("test.out"); 115 assertEmptyFile("test.err"); 116 assertChdir(".."); 117 118 /* Test 8: Include a non-existent file */ 119 assertMakeDir("test8", 0755); 120 assertChdir("test8"); 121 r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog); 122 assert(r != 0); 123 assertFileNotExists("file1"); 124 assertFileNotExists("file2"); 125 assertFileNotExists("file3"); 126 assertEmptyFile("test.out"); 127 assertNonEmptyFile("test.err"); 128 assertChdir(".."); 129 130 /* Test 9: Include a non-existent file plus an exclusion */ 131 assertMakeDir("test9", 0755); 132 assertChdir("test9"); 133 r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog); 134 assert(r != 0); 135 assertFileNotExists("file1"); 136 assertFileNotExists("file2"); 137 assertFileNotExists("file3"); 138 assertEmptyFile("test.out"); 139 assertNonEmptyFile("test.err"); 140 assertChdir(".."); 141 } 142