]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add xz compatibly test.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 17 Feb 2009 23:31:22 +0000 (18:31 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 17 Feb 2009 23:31:22 +0000 (18:31 -0500)
SVN-Revision: 655

Makefile.am
libarchive/test/test_compat_xz.c [new file with mode: 0644]
libarchive/test/test_compat_xz_1.txz.uu [new file with mode: 0644]

index adb629e83c6ef27f8d878624e31af4a91018334a..da7f37ded23abaa1f55c7c727420399457a4b598 100644 (file)
@@ -198,6 +198,7 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_compat_gtar.c                      \
        libarchive/test/test_compat_gzip.c                      \
        libarchive/test/test_compat_tar_hardlink.c              \
+       libarchive/test/test_compat_xz.c                        \
        libarchive/test/test_compat_zip.c                       \
        libarchive/test/test_empty_write.c                      \
        libarchive/test/test_entry.c                            \
@@ -281,6 +282,7 @@ libarchive_test_EXTRA_DIST=\
        libarchive/test/test_compat_gzip_1.tgz.uu                       \
        libarchive/test/test_compat_gzip_2.tgz.uu                       \
        libarchive/test/test_compat_tar_hardlink_1.tar.uu               \
+       libarchive/test/test_compat_xz_1.txz.uu                         \
        libarchive/test/test_compat_zip_1.zip.uu                        \
        libarchive/test/test_fuzz_1.iso.uu                              \
        libarchive/test/test_pax_filename_encoding.tar.uu               \
diff --git a/libarchive/test/test_compat_xz.c b/libarchive/test/test_compat_xz.c
new file mode 100644 (file)
index 0000000..838f068
--- /dev/null
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2009 Michihiro NAKAJIMA
+ * Copyright (c) 2003-2008 Tim Kientzle
+ * 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$");
+
+/*
+ * Verify our ability to read sample files compatibly with unxz.
+ *
+ * In particular:
+ *  * unxz will read multiple xz streams, concatenating the output
+ */
+
+/*
+ * All of the sample files have the same contents; they're just
+ * compressed in different ways.
+ */
+static void
+compat_xz(const char *name)
+{
+       const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL };
+       struct archive_entry *ae;
+       struct archive *a;
+       int i,r;
+
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       extract_reference_file(name);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
+
+       /* Read entries, match up names with list above. */
+       for (i = 0; i < 6; ++i) {
+               r = archive_read_next_header(a, &ae);
+               if (r != ARCHIVE_OK) {
+                       if (strcmp(archive_error_string(a),
+                           "Unrecognized archive format") == 0) {
+                               skipping("Skipping XZ compression check: "
+                                       "This version of libarchive was compiled "
+                                   "without xz support");
+                               goto finish;
+                       }
+               }
+               failure("Could not read file %d (%s) from %s", i, n[i], name);
+               assertEqualIntA(a, ARCHIVE_OK, r);
+               if (r != ARCHIVE_OK) {
+                       archive_read_finish(a);
+                       return;
+               }
+               assertEqualString(n[i], archive_entry_pathname(ae));
+       }
+
+       /* Verify the end-of-archive. */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+       /* Verify that the format detection worked. */
+       assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ);
+       assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+finish:
+#if ARCHIVE_VERSION_NUMBER < 2000000
+       archive_read_finish(a);
+#else
+       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+#endif
+}
+
+
+DEFINE_TEST(test_compat_xz)
+{
+       compat_xz("test_compat_xz_1.txz");
+}
diff --git a/libarchive/test/test_compat_xz_1.txz.uu b/libarchive/test/test_compat_xz_1.txz.uu
new file mode 100644 (file)
index 0000000..ea5d1e5
--- /dev/null
@@ -0,0 +1,12 @@
+begin 644 test_compat_gzip_1.txz
+M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2
+M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B
+MHS@=K]7@K1-9FOIP#PU!I<PUHW+W#<F(6FSL/<?5:4*>?E5&IHH&Q=N>_C&G
+M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P``
+MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I
+M70``;IBIKOMK%/A?-<U3^2)5\V,DQ(:ZUH:[B'3>TZV0266G?2,[/?\,JE6`
+M__C/SA[W1?*2<Y3NQ'DCK4JEJYHQU`Q\N=H9LL3KRAH,VQQ2OD*@?1NLV]<E
+MF&X."!L\R:Z]=*TJPT/BJ^``````R[PG*'(H!W,``84!X!@``/;+`G2QQ&?[
+(`@`````$65H`
+`
+end