From 8aab65b47c3b6c905f17dc71e966cdbf72cc0608 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Sat, 11 Jan 2014 16:40:16 -0700 Subject: [PATCH] Add a test for read_concatenated_archives Make sure that we are reading the concatenated contents when requested and only when requested. Signed-off-by: Kevin Locke --- Makefile.am | 1 + libarchive/test/CMakeLists.txt | 1 + .../test/test_read_format_tar_concatenated.c | 86 +++++++++++++++++++ .../test_read_format_tar_concatenated.tar.uu | 72 ++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 libarchive/test/test_read_format_tar_concatenated.c create mode 100644 libarchive/test/test_read_format_tar_concatenated.tar.uu diff --git a/Makefile.am b/Makefile.am index cdf34f2b6..54a99cac6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 8c10c906f..8d1e1fe66 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -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 index 000000000..d1f67e20f --- /dev/null +++ b/libarchive/test/test_read_format_tar_concatenated.c @@ -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 index 000000000..4354b56dc --- /dev/null +++ b/libarchive/test/test_read_format_tar_concatenated.tar.uu @@ -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