]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add a test for read_concatenated_archives 60/head
authorKevin Locke <kevin@kevinlocke.name>
Sat, 11 Jan 2014 23:40:16 +0000 (16:40 -0700)
committerKevin Locke <kevin@kevinlocke.name>
Sun, 12 Jan 2014 20:46:04 +0000 (13:46 -0700)
Make sure that we are reading the concatenated contents when requested
and only when requested.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_format_tar_concatenated.c [new file with mode: 0644]
libarchive/test/test_read_format_tar_concatenated.tar.uu [new file with mode: 0644]

index cdf34f2b6db6cc72ba10ddac44758a13b4fb02fb..54a99cac68da29f2992b1e1f0ea9051825d366aa 100644 (file)
@@ -423,6 +423,7 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_read_format_rar_encryption_header.c        \
        libarchive/test/test_read_format_raw.c                  \
        libarchive/test/test_read_format_tar.c                  \
+       libarchive/test/test_read_format_tar_concatenated.c     \
        libarchive/test/test_read_format_tar_empty_pax.c        \
        libarchive/test/test_read_format_tar_empty_filename.c   \
        libarchive/test/test_read_format_tar_filename.c         \
index 8c10c906f62c89bda938445346f2a2d69211f02f..8d1e1fe66efba0c17b180ec11da225971074a8c8 100644 (file)
@@ -135,6 +135,7 @@ IF(ENABLE_TEST)
     test_read_format_rar_encryption_header.c
     test_read_format_raw.c
     test_read_format_tar.c
+    test_read_format_tar_concatenated.c
     test_read_format_tar_empty_pax.c
     test_read_format_tar_empty_filename.c
     test_read_format_tar_filename.c
diff --git a/libarchive/test/test_read_format_tar_concatenated.c b/libarchive/test/test_read_format_tar_concatenated.c
new file mode 100644 (file)
index 0000000..d1f67e2
--- /dev/null
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 2014 Kevin Locke
+ * 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");
+
+/*
+ * The sample tar file is the result of concatenating two tar files,
+ * the first containing file1 the second containing file2.
+ *
+ * When the read_concatenated_archives option is specified, both files should
+ * be read.  Otherwise, only file1 should be read.
+ */
+DEFINE_TEST(test_read_format_tar_concatenated)
+{
+       char name[] = "test_read_format_tar_concatenated.tar";
+       struct archive_entry *ae;
+       struct archive *a;
+
+       /*
+        * First test that when read_concatenated_archives is not specified
+        * only file1 is present.
+        */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_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, 10240));
+
+       /* Read first entry. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("file1", archive_entry_pathname(ae));
+
+       /* Verify the end-of-archive. */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+
+       /*
+        * Next test that when read_concatenated_archives is specified both
+        * file1 and file2 are present.
+        */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "read_concatenated_archives"));
+       extract_reference_file(name);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
+
+       /* Read first entry. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("file1", archive_entry_pathname(ae));
+
+       /* Read second entry. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("file2", archive_entry_pathname(ae));
+
+       /* Verify the end-of-archive. */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_format_tar_concatenated.tar.uu b/libarchive/test/test_read_format_tar_concatenated.tar.uu
new file mode 100644 (file)
index 0000000..4354b56
--- /dev/null
@@ -0,0 +1,72 @@
+begin 644 test_read_format_tar_concatenated.tar
+M9FEL93$`````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@`#`P,#`P,#`P,#`P
+M(#$R,C8T,S0W-3$W(#`Q,C(W-``@,```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,&ME=FEN
+M````````````````````````````````````:V5V:6X`````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````9FEL93(`````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@`#`P,#`P
+M,#`P,#`P(#$R,C8T,S0W-3(Q(#`Q,C(W,``@,```````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,&ME=FEN````````````````````````````````````:V5V:6X`````````
+M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+,````````````````
+`
+end