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 28231200Smmstatic const char *test4out[] = {"file1", "file2", NULL}; 29231200Smmstatic const char *test5err[] = {"file1", "file2", NULL}; 30231200Smm 31231200SmmDEFINE_TEST(test_option_O_upper) 32231200Smm{ 33231200Smm assertMakeFile("file1", 0644, "file1"); 34231200Smm assertMakeFile("file2", 0644, "file2"); 35231200Smm assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); 36231200Smm 37231200Smm /* Test 1: -x without -O */ 38231200Smm assertMakeDir("test1", 0755); 39231200Smm assertChdir("test1"); 40231200Smm assertEqualInt(0, 41231200Smm systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); 42231200Smm assertFileContents("file1", 5, "file1"); 43231200Smm assertFileContents("file2", 5, "file2"); 44231200Smm assertEmptyFile("test.out"); 45231200Smm assertEmptyFile("test.err"); 46231200Smm assertChdir(".."); 47231200Smm 48231200Smm /* Test 2: -x with -O */ 49231200Smm assertMakeDir("test2", 0755); 50231200Smm assertChdir("test2"); 51231200Smm assertEqualInt(0, 52231200Smm systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog)); 53231200Smm assertFileNotExists("file1"); 54231200Smm assertFileNotExists("file2"); 55231200Smm assertFileContents("file1", 5, "test.out"); 56231200Smm assertEmptyFile("test.err"); 57231200Smm assertChdir(".."); 58231200Smm 59231200Smm /* Test 3: -x with -O and multiple files */ 60231200Smm assertMakeDir("test3", 0755); 61231200Smm assertChdir("test3"); 62231200Smm assertEqualInt(0, 63231200Smm systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog)); 64231200Smm assertFileNotExists("file1"); 65231200Smm assertFileNotExists("file2"); 66231200Smm assertFileContents("file1file2", 10, "test.out"); 67231200Smm assertEmptyFile("test.err"); 68231200Smm assertChdir(".."); 69231200Smm 70231200Smm /* Test 4: -t without -O */ 71231200Smm assertMakeDir("test4", 0755); 72231200Smm assertChdir("test4"); 73231200Smm assertEqualInt(0, 74231200Smm systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog)); 75231200Smm assertFileContainsLinesAnyOrder("test.out", test4out); 76231200Smm assertEmptyFile("test.err"); 77231200Smm assertChdir(".."); 78231200Smm 79231200Smm /* Test 5: -t with -O */ 80231200Smm assertMakeDir("test5", 0755); 81231200Smm assertChdir("test5"); 82231200Smm assertEqualInt(0, 83231200Smm systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog)); 84231200Smm assertEmptyFile("test.out"); 85231200Smm assertFileContainsLinesAnyOrder("test.err", test5err); 86231200Smm assertChdir(".."); 87231200Smm} 88