1231200Smm/*- 2231200Smm * Copyright (c) 2010 Tim Kientzle 3231200Smm * All rights reserved. 4231200Smm * 5231200Smm * Redistribution and use in source and binary forms, with or without 6231200Smm * modification, are permitted provided that the following conditions 7231200Smm * are met: 8231200Smm * 1. Redistributions of source code must retain the above copyright 9231200Smm * notice, this list of conditions and the following disclaimer. 10231200Smm * 2. Redistributions in binary form must reproduce the above copyright 11231200Smm * notice, this list of conditions and the following disclaimer in the 12231200Smm * documentation and/or other materials provided with the distribution. 13231200Smm * 14231200Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15231200Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16231200Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17231200Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18231200Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19231200Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20231200Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21231200Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22231200Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23231200Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24231200Smm */ 25231200Smm#include "test.h" 26231200Smm__FBSDID("$FreeBSD$"); 27231200Smm 28231200SmmDEFINE_TEST(test_option_exclude) 29231200Smm{ 30231200Smm int r; 31231200Smm 32231200Smm assertMakeFile("file1", 0644, "file1"); 33231200Smm assertMakeFile("file2", 0644, "file2"); 34231200Smm assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); 35231200Smm 36231200Smm /* 37231200Smm * Now, try extracting from the test archive with various --exclude options. 38231200Smm */ 39231200Smm 40231200Smm /* Test 1: Without --exclude */ 41231200Smm assertMakeDir("test1", 0755); 42231200Smm assertChdir("test1"); 43231200Smm assertEqualInt(0, 44231200Smm systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); 45231200Smm assertFileContents("file1", 5, "file1"); 46231200Smm assertFileContents("file2", 5, "file2"); 47231200Smm assertEmptyFile("test.out"); 48231200Smm assertEmptyFile("test.err"); 49231200Smm assertChdir(".."); 50231200Smm 51231200Smm /* Test 2: Selecting just one file */ 52231200Smm assertMakeDir("test2", 0755); 53231200Smm assertChdir("test2"); 54231200Smm assertEqualInt(0, 55231200Smm systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog)); 56231200Smm assertFileContents("file1", 5, "file1"); 57231200Smm assertFileNotExists("file2"); 58231200Smm assertEmptyFile("test.out"); 59231200Smm assertEmptyFile("test.err"); 60231200Smm assertChdir(".."); 61231200Smm 62231200Smm /* Test 3: Use --exclude to skip one file */ 63231200Smm assertMakeDir("test3", 0755); 64231200Smm assertChdir("test3"); 65231200Smm assertEqualInt(0, 66231200Smm systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog)); 67231200Smm assertFileNotExists("file1"); 68231200Smm assertFileContents("file2", 5, "file2"); 69231200Smm assertEmptyFile("test.out"); 70231200Smm assertEmptyFile("test.err"); 71231200Smm assertChdir(".."); 72231200Smm 73231200Smm /* Test 4: Selecting one valid and one invalid file */ 74231200Smm assertMakeDir("test4", 0755); 75231200Smm assertChdir("test4"); 76231200Smm r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog); 77231200Smm assert(r != 0); 78231200Smm assertFileContents("file1", 5, "file1"); 79231200Smm assertFileNotExists("file2"); 80231200Smm assertFileNotExists("file3"); 81231200Smm assertEmptyFile("test.out"); 82231200Smm assertNonEmptyFile("test.err"); 83231200Smm assertChdir(".."); 84231200Smm 85231200Smm /* Test 5: Selecting one valid file twice */ 86231200Smm assertMakeDir("test5", 0755); 87231200Smm assertChdir("test5"); 88231200Smm assertEqualInt(0, 89231200Smm systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog)); 90231200Smm assertFileContents("file1", 5, "file1"); 91231200Smm assertFileNotExists("file2"); 92231200Smm assertEmptyFile("test.out"); 93231200Smm assertEmptyFile("test.err"); 94231200Smm assertChdir(".."); 95231200Smm 96231200Smm /* Test 6: Include and exclude the same file */ 97231200Smm assertMakeDir("test6", 0755); 98231200Smm assertChdir("test6"); 99231200Smm assertEqualInt(0, 100231200Smm systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog)); 101231200Smm assertFileNotExists("file1"); 102231200Smm assertFileNotExists("file2"); 103231200Smm assertEmptyFile("test.out"); 104231200Smm assertEmptyFile("test.err"); 105231200Smm assertChdir(".."); 106231200Smm 107231200Smm /* Test 7: Exclude a non-existent file */ 108231200Smm assertMakeDir("test7", 0755); 109231200Smm assertChdir("test7"); 110231200Smm assertEqualInt(0, 111231200Smm systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog)); 112231200Smm assertFileContents("file1", 5, "file1"); 113231200Smm assertFileNotExists("file2"); 114231200Smm assertFileNotExists("file3"); 115231200Smm assertEmptyFile("test.out"); 116231200Smm assertEmptyFile("test.err"); 117231200Smm assertChdir(".."); 118231200Smm 119231200Smm /* Test 8: Include a non-existent file */ 120231200Smm assertMakeDir("test8", 0755); 121231200Smm assertChdir("test8"); 122231200Smm r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog); 123231200Smm assert(r != 0); 124231200Smm assertFileNotExists("file1"); 125231200Smm assertFileNotExists("file2"); 126231200Smm assertFileNotExists("file3"); 127231200Smm assertEmptyFile("test.out"); 128231200Smm assertNonEmptyFile("test.err"); 129231200Smm assertChdir(".."); 130231200Smm 131231200Smm /* Test 9: Include a non-existent file plus an exclusion */ 132231200Smm assertMakeDir("test9", 0755); 133231200Smm assertChdir("test9"); 134231200Smm r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog); 135231200Smm assert(r != 0); 136231200Smm assertFileNotExists("file1"); 137231200Smm assertFileNotExists("file2"); 138231200Smm assertFileNotExists("file3"); 139231200Smm assertEmptyFile("test.out"); 140231200Smm assertNonEmptyFile("test.err"); 141231200Smm assertChdir(".."); 142231200Smm} 143