From: Michihiro NAKAJIMA Date: Wed, 3 Oct 2012 06:16:35 +0000 (+0900) Subject: Add extraction tests for compressed files to bsdtar_test. X-Git-Tag: v3.1.0~40^2~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c33eebf8986aee852b1829ed34280e7a0bfedde6;p=thirdparty%2Flibarchive.git Add extraction tests for compressed files to bsdtar_test. --- diff --git a/Makefile.am b/Makefile.am index 70d4ec28e..3e277aba5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -699,6 +699,12 @@ bsdtar_test_SOURCES= \ tar/test/test_basic.c \ tar/test/test_copy.c \ tar/test/test_empty_mtree.c \ + tar/test/test_extract_tar_bz2.c \ + tar/test/test_extract_tar_gz.c \ + tar/test/test_extract_tar_lrz.c \ + tar/test/test_extract_tar_lz.c \ + tar/test/test_extract_tar_lzma.c \ + tar/test/test_extract_tar_xz.c \ tar/test/test_format_newc.c \ tar/test/test_help.c \ tar/test/test_option_C_upper.c \ diff --git a/cpio/test/main.c b/cpio/test/main.c index a016bcc1b..d4cd865c5 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -1835,15 +1835,30 @@ canSymlink(void) return (value); } -/* - * Can this platform run the gzip program? - */ /* Platform-dependent options for hiding the output of a subcommand. */ #if defined(_WIN32) && !defined(__CYGWIN__) static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ #else static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ #endif +/* + * Can this platform run the bunzip2 program? + */ +int +canBunzip2(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("bunzip2 -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gzip program? + */ int canGzip(void) { @@ -1871,6 +1886,81 @@ canGunzip(void) return (value); } +/* + * Can this platform run the lrzip program? + */ +int +canLrzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lrzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the lrunzip program? + */ +int +canLrunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lrunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the lunzip program? + */ +int +canLunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unlzma program? + */ +int +canUnlzma(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unlzma -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unxz program? + */ +int +canUnxz(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unxz -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + /* * Can this filesystem handle nodump flags. */ diff --git a/cpio/test/test.h b/cpio/test/test.h index d57a861dc..88c7c2438 100644 --- a/cpio/test/test.h +++ b/cpio/test/test.h @@ -266,12 +266,30 @@ void sleepUntilAfter(time_t); /* Return true if this platform can create symlinks. */ int canSymlink(void); +/* Return true if this platform can run the "bunzip2" program. */ +int canBunzip2(void); + /* Return true if this platform can run the "gzip" program. */ int canGzip(void); /* Return true if this platform can run the "gunzip" program. */ int canGunzip(void); +/* Return true if this platform can run the "lrzip" program. */ +int canLrzip(void); + +/* Return true if this platform can run the "lrunzip" program. */ +int canLrunzip(void); + +/* Return true if this platform can run the "lunzip" program. */ +int canLunzip(void); + +/* Return true if this platform can run the "unlzma" program. */ +int canUnlzma(void); + +/* Return true if this platform can run the "unxz" program. */ +int canUnxz(void); + /* Return true if this filesystem can handle nodump flags. */ int canNodump(void); diff --git a/libarchive/test/main.c b/libarchive/test/main.c index db160ddb1..fd2e5dd93 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -1833,15 +1833,30 @@ canSymlink(void) return (value); } -/* - * Can this platform run the gzip program? - */ /* Platform-dependent options for hiding the output of a subcommand. */ #if defined(_WIN32) && !defined(__CYGWIN__) static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ #else static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ #endif +/* + * Can this platform run the bunzip2 program? + */ +int +canBunzip2(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("bunzip2 -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gzip program? + */ int canGzip(void) { @@ -1869,6 +1884,9 @@ canGunzip(void) return (value); } +/* + * Can this platform run the lrzip program? + */ int canLrzip(void) { @@ -1881,6 +1899,66 @@ canLrzip(void) return (value); } +/* + * Can this platform run the lrunzip program? + */ +int +canLrunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lrunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the lunzip program? + */ +int +canLunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unlzma program? + */ +int +canUnlzma(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unlzma -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unxz program? + */ +int +canUnxz(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unxz -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + /* * Can this filesystem handle nodump flags. */ diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 6c5de6a71..eee985df4 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -266,6 +266,9 @@ void sleepUntilAfter(time_t); /* Return true if this platform can create symlinks. */ int canSymlink(void); +/* Return true if this platform can run the "bunzip2" program. */ +int canBunzip2(void); + /* Return true if this platform can run the "gzip" program. */ int canGzip(void); @@ -275,6 +278,18 @@ int canGunzip(void); /* Return true if this platform can run the "lrzip" program. */ int canLrzip(void); +/* Return true if this platform can run the "lrunzip" program. */ +int canLrunzip(void); + +/* Return true if this platform can run the "lunzip" program. */ +int canLunzip(void); + +/* Return true if this platform can run the "unlzma" program. */ +int canUnlzma(void); + +/* Return true if this platform can run the "unxz" program. */ +int canUnxz(void); + /* Return true if this filesystem can handle nodump flags. */ int canNodump(void); diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 6d74530da..ffa8dcd11 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -12,6 +12,12 @@ IF(ENABLE_TAR AND ENABLE_TEST) test_basic.c test_copy.c test_empty_mtree.c + test_extract_tar_bz2.c + test_extract_tar_gz.c + test_extract_tar_lrz.c + test_extract_tar_lz.c + test_extract_tar_lzma.c + test_extract_tar_xz.c test_format_newc.c test_help.c test_option_C_upper.c diff --git a/tar/test/main.c b/tar/test/main.c index d9f12c1eb..26bab757c 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -1835,15 +1835,30 @@ canSymlink(void) return (value); } -/* - * Can this platform run the gzip program? - */ /* Platform-dependent options for hiding the output of a subcommand. */ #if defined(_WIN32) && !defined(__CYGWIN__) static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ #else static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ #endif +/* + * Can this platform run the bunzip2 program? + */ +int +canBunzip2(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("bunzip2 -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gzip program? + */ int canGzip(void) { @@ -1871,6 +1886,81 @@ canGunzip(void) return (value); } +/* + * Can this platform run the lrzip program? + */ +int +canLrzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lrzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the lrunzip program? + */ +int +canLrunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lrunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the lunzip program? + */ +int +canLunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("lunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unlzma program? + */ +int +canUnlzma(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unlzma -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the unxz program? + */ +int +canUnxz(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("unxz -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + /* * Can this filesystem handle nodump flags. */ diff --git a/tar/test/test.h b/tar/test/test.h index 46abb59ec..05d99c2a2 100644 --- a/tar/test/test.h +++ b/tar/test/test.h @@ -268,12 +268,30 @@ void sleepUntilAfter(time_t); /* Return true if this platform can create symlinks. */ int canSymlink(void); +/* Return true if this platform can run the "bunzip2" program. */ +int canBunzip2(void); + /* Return true if this platform can run the "gzip" program. */ int canGzip(void); /* Return true if this platform can run the "gunzip" program. */ int canGunzip(void); +/* Return true if this platform can run the "lrzip" program. */ +int canLrzip(void); + +/* Return true if this platform can run the "lrunzip" program. */ +int canLrunzip(void); + +/* Return true if this platform can run the "lunzip" program. */ +int canLunzip(void); + +/* Return true if this platform can run the "unlzma" program. */ +int canUnlzma(void); + +/* Return true if this platform can run the "unxz" program. */ +int canUnxz(void); + /* Return true if this filesystem can handle nodump flags. */ int canNodump(void); diff --git a/tar/test/test_extract.tar.bz2.uu b/tar/test/test_extract.tar.bz2.uu new file mode 100644 index 000000000..9a37413ad --- /dev/null +++ b/tar/test/test_extract.tar.bz2.uu @@ -0,0 +1,7 @@ +begin 664 test_extract.tar.bz2 +M0EIH.3%!629368N]6:```'U[D=(0`"!``7^```AK)9X`!```$0`(,`"X#&$Q +M,F`F``,83$R8"8``*J:")M0TCQ30-/%-3*]V3EE!&(DSM8?BJ4J)=TSJ4/"B +M,?#R_6>?9K=+H02NT0V040P3.SHF:(573*)M5&;!-%6RO=6F5":N"+,"YZ;L +AV+<]%F[GWYCR<%FRKAPR=7VY+'+1)_B[DBG"A(1=ZLT` +` +end diff --git a/tar/test/test_extract.tar.gz.uu b/tar/test/test_extract.tar.gz.uu new file mode 100644 index 000000000..19f8bc047 --- /dev/null +++ b/tar/test/test_extract.tar.gz.uu @@ -0,0 +1,7 @@ +begin 664 test_extract.tar.gz +M'XL(""S!:U```W1E26I>27%"OEI"FF@M*#'-=!.&@5T!*`X-Z*Q'23E?Q-3 +AP?_D@0*H:&)P-5? +MZX%NI60,IT@(N<,S%?7H2TLP5)FN#[-;&&[/2A#BNH4(7#C+*&ZP<>K&B)AG +M:Z(;Y=]3<5Q$)_[[5M\7=]N7A$%\ZF:H2/,Q%BK$JA4L!,K(-RZU2X[/`%69 +.9U@/B[!N",NH4]8F,M(` +` +end diff --git a/tar/test/test_extract.tar.lz.uu b/tar/test/test_extract.tar.lz.uu new file mode 100644 index 000000000..cb380e3a0 --- /dev/null +++ b/tar/test/test_extract.tar.lz.uu @@ -0,0 +1,7 @@ +begin 664 test_extract.tar.lz +M3%I)4`$,`#,:2=:X2EY2J/TZ6]L7]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FY +MV\,8BTS,N0/O2=#67;G5)%I'C,D.U?*T!NX("FYPYI9I40F>X))?^8\?E?#> +MOP";"GD#8(9*K;XP318HXZ\?_^SZ +6K-(!CH7```P```````"=```````````` +` +end diff --git a/tar/test/test_extract.tar.lzma.uu b/tar/test/test_extract.tar.lzma.uu new file mode 100644 index 000000000..581236ac3 --- /dev/null +++ b/tar/test/test_extract.tar.lzma.uu @@ -0,0 +1,7 @@ +begin 664 test_extract.tar.lzma +M70``@`#__________P`S&DG6N$I>4JC].EO;%_?;E*WZAH294@PH1Y0M$9<" +M[=1FR,$9N=O#&(M,Q24U'H+5Z^7^*J;G!)OU]O'2D;AZ&0^IO?>-YA]$:-X_ +MD^O)YVM(4`^-MT$X`.D(6)*$]3HNB9KJ_H=1$QKYZ:`:,H_L"H[#"?#Z5A<] +%O_OZW=D` +` +end diff --git a/tar/test/test_extract.tar.xz.uu b/tar/test/test_extract.tar.xz.uu new file mode 100644 index 000000000..24cac6cd9 --- /dev/null +++ b/tar/test/test_extract.tar.xz.uu @@ -0,0 +1,8 @@ +begin 664 test_extract.tar.xz +M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`O_`'E=`#,:2=:X2EY2J/TZ6]L7 +M]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FYV\,8BTS%)34>@M7KY?XJIN<$F_7V +M\=*1N'H9#ZF]]XWF'T1HWC^3Z\GG:TA0#XVW03@`Z0A8DH3U.BZ)FNK^AU$3 +M&OGIH!HRC^P*CL,)\/,MGP``````2IVA+$<(^YX``94!@!@``&X^\DRQQ&?[ +(`@`````$65H` +` +end diff --git a/tar/test/test_extract_tar_bz2.c b/tar/test/test_extract_tar_bz2.c new file mode 100644 index 000000000..e146d507c --- /dev/null +++ b/tar/test/test_extract_tar_bz2.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_bz2) +{ + const char *reffile = "test_extract.tar.bz2"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canBunzip2()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + } else { + skipping("It seems bzip2 is not supported on this platform"); + } +} diff --git a/tar/test/test_extract_tar_gz.c b/tar/test/test_extract_tar_gz.c new file mode 100644 index 000000000..ba5fdec66 --- /dev/null +++ b/tar/test/test_extract_tar_gz.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_gz) +{ + const char *reffile = "test_extract.tar.gz"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canGunzip()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + } else { + skipping("It seems gzip is not supported on this platform"); + } +} diff --git a/tar/test/test_extract_tar_lrz.c b/tar/test/test_extract_tar_lrz.c new file mode 100644 index 000000000..e08845f7f --- /dev/null +++ b/tar/test/test_extract_tar_lrz.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_lrz) +{ + const char *reffile = "test_extract.tar.lrz"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canLrunzip()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + /*assertEmptyFile("test.err");*/ + } else { + skipping("It seems lrzip is not supported on this platform"); + } +} diff --git a/tar/test/test_extract_tar_lz.c b/tar/test/test_extract_tar_lz.c new file mode 100644 index 000000000..f7ac3c352 --- /dev/null +++ b/tar/test/test_extract_tar_lz.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_lz) +{ + const char *reffile = "test_extract.tar.lz"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canLunzip()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + } else { + skipping("It seems lzma is not supported on this platform"); + } +} diff --git a/tar/test/test_extract_tar_lzma.c b/tar/test/test_extract_tar_lzma.c new file mode 100644 index 000000000..977f6d69e --- /dev/null +++ b/tar/test/test_extract_tar_lzma.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_lzma) +{ + const char *reffile = "test_extract.tar.lzma"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canUnlzma()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + } else { + skipping("It seems lzma is not supported on this platform"); + } +} diff --git a/tar/test/test_extract_tar_xz.c b/tar/test/test_extract_tar_xz.c new file mode 100644 index 000000000..2edaf3401 --- /dev/null +++ b/tar/test/test_extract_tar_xz.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2012 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_extract_tar_xz) +{ + const char *reffile = "test_extract.tar.xz"; + int f; + + extract_reference_file(reffile); + f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile); + if (f == 0 || canUnxz()) { + assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", + testprog, reffile)); + + assertFileExists("file1"); + assertTextFileContents("contents of file1.\n", "file1"); + assertFileExists("file2"); + assertTextFileContents("contents of file2.\n", "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + } else { + skipping("It seems xz is not supported on this platform"); + } +}