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 28299529Smm#define USTAR_OPT " --format=ustar" 29299529Smm 30231200SmmDEFINE_TEST(test_option_b) 31231200Smm{ 32299529Smm char *testprog_ustar; 33299529Smm 34231200Smm assertMakeFile("file1", 0644, "file1"); 35231200Smm if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) { 36231200Smm skipping("Platform doesn't have cat"); 37231200Smm return; 38231200Smm } 39299529Smm testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1); 40299529Smm strcpy(testprog_ustar, testprog); 41299529Smm strcat(testprog_ustar, USTAR_OPT); 42231200Smm 43231200Smm /* 44231200Smm * Bsdtar does not pad if the output is going directly to a disk file. 45231200Smm */ 46299529Smm assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog_ustar)); 47231200Smm failure("bsdtar does not pad archives written directly to regular files"); 48231200Smm assertFileSize("archive1.tar", 2048); 49231200Smm assertEmptyFile("test1.out"); 50231200Smm assertEmptyFile("test1.err"); 51231200Smm 52231200Smm /* 53231200Smm * Bsdtar does pad to the block size if the output is going to a socket. 54231200Smm */ 55231200Smm /* Default is -b 20 */ 56299529Smm assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog_ustar)); 57231200Smm failure("bsdtar does pad archives written to pipes"); 58231200Smm assertFileSize("archive2.tar", 10240); 59231200Smm assertEmptyFile("test2.err"); 60231200Smm 61299529Smm assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog_ustar)); 62231200Smm assertFileSize("archive3.tar", 10240); 63231200Smm assertEmptyFile("test3.err"); 64231200Smm 65299529Smm assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog_ustar)); 66231200Smm assertFileSize("archive4.tar", 5120); 67231200Smm assertEmptyFile("test4.err"); 68231200Smm 69299529Smm assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog_ustar)); 70231200Smm assertFileSize("archive5.tar", 2048); 71231200Smm assertEmptyFile("test5.err"); 72231200Smm 73299529Smm assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog_ustar)); 74231200Smm assertFileSize("archive6.tar", 4194304); 75231200Smm assertEmptyFile("test6.err"); 76231200Smm 77231200Smm /* 78231200Smm * Note: It's not possible to verify at this level that blocks 79231200Smm * are getting written with the 80231200Smm */ 81231200Smm} 82