12f6e434mm/*-
22f6e434mm * Copyright (c) 2010 Tim Kientzle
32f6e434mm * All rights reserved.
42f6e434mm *
52f6e434mm * Redistribution and use in source and binary forms, with or without
62f6e434mm * modification, are permitted provided that the following conditions
72f6e434mm * are met:
82f6e434mm * 1. Redistributions of source code must retain the above copyright
92f6e434mm *    notice, this list of conditions and the following disclaimer.
102f6e434mm * 2. Redistributions in binary form must reproduce the above copyright
112f6e434mm *    notice, this list of conditions and the following disclaimer in the
122f6e434mm *    documentation and/or other materials provided with the distribution.
132f6e434mm *
142f6e434mm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
152f6e434mm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
162f6e434mm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
172f6e434mm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
182f6e434mm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
192f6e434mm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
202f6e434mm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
212f6e434mm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
222f6e434mm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
232f6e434mm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242f6e434mm */
252f6e434mm#include "test.h"
262f6e434mm__FBSDID("$FreeBSD$");
272f6e434mm
283404e2cmm#define USTAR_OPT " --format=ustar"
293404e2cmm
302f6e434mmDEFINE_TEST(test_option_b)
312f6e434mm{
323404e2cmm	char *testprog_ustar;
333404e2cmm
342f6e434mm	assertMakeFile("file1", 0644, "file1");
352f6e434mm	if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) {
367fe6ca6mm		skipping("This test requires a `cat` program");
372f6e434mm		return;
382f6e434mm	}
393404e2cmm	testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
403404e2cmm	strcpy(testprog_ustar, testprog);
413404e2cmm	strcat(testprog_ustar, USTAR_OPT);
422f6e434mm
432f6e434mm	/*
442f6e434mm	 * Bsdtar does not pad if the output is going directly to a disk file.
452f6e434mm	 */
463404e2cmm	assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog_ustar));
472f6e434mm	failure("bsdtar does not pad archives written directly to regular files");
482f6e434mm	assertFileSize("archive1.tar", 2048);
492f6e434mm	assertEmptyFile("test1.out");
502f6e434mm	assertEmptyFile("test1.err");
512f6e434mm
522f6e434mm	/*
532f6e434mm	 * Bsdtar does pad to the block size if the output is going to a socket.
542f6e434mm	 */
552f6e434mm	/* Default is -b 20 */
563404e2cmm	assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog_ustar));
572f6e434mm	failure("bsdtar does pad archives written to pipes");
582f6e434mm	assertFileSize("archive2.tar", 10240);
592f6e434mm	assertEmptyFile("test2.err");
602f6e434mm
613404e2cmm	assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog_ustar));
622f6e434mm	assertFileSize("archive3.tar", 10240);
632f6e434mm	assertEmptyFile("test3.err");
642f6e434mm
653404e2cmm	assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog_ustar));
662f6e434mm	assertFileSize("archive4.tar", 5120);
672f6e434mm	assertEmptyFile("test4.err");
682f6e434mm
693404e2cmm	assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog_ustar));
702f6e434mm	assertFileSize("archive5.tar", 2048);
712f6e434mm	assertEmptyFile("test5.err");
722f6e434mm
733404e2cmm	assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog_ustar));
742f6e434mm	assertFileSize("archive6.tar", 4194304);
752f6e434mm	assertEmptyFile("test6.err");
762f6e434mm
772f6e434mm	/*
782f6e434mm	 * Note: It's not possible to verify at this level that blocks
792f6e434mm	 * are getting written with the
802f6e434mm	 */
81d68a983ngie
82d68a983ngie	free(testprog_ustar);
832f6e434mm}
84