1299425Smm/*- 2299425Smm * Copyright (c) 2014 Kevin Locke 3299425Smm * All rights reserved. 4299425Smm * 5299425Smm * Redistribution and use in source and binary forms, with or without 6299425Smm * modification, are permitted provided that the following conditions 7299425Smm * are met: 8299425Smm * 1. Redistributions of source code must retain the above copyright 9299425Smm * notice, this list of conditions and the following disclaimer. 10299425Smm * 2. Redistributions in binary form must reproduce the above copyright 11299425Smm * notice, this list of conditions and the following disclaimer in the 12299425Smm * documentation and/or other materials provided with the distribution. 13299425Smm * 14299425Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15299425Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16299425Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17299425Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18299425Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19299425Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20299425Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21299425Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22299425Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23299425Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24299425Smm */ 25299425Smm#include "test.h" 26299425Smm__FBSDID("$FreeBSD"); 27299425Smm 28299425Smm/* 29299425Smm * The sample tar file is the result of concatenating two tar files, 30299425Smm * the first containing file1 the second containing file2. 31299425Smm * 32299425Smm * When the read_concatenated_archives option is specified, both files should 33299425Smm * be read. Otherwise, only file1 should be read. 34299425Smm */ 35299425SmmDEFINE_TEST(test_read_format_tar_concatenated) 36299425Smm{ 37299425Smm char name[] = "test_read_format_tar_concatenated.tar"; 38299425Smm struct archive_entry *ae; 39299425Smm struct archive *a; 40299425Smm 41299425Smm /* 42299425Smm * First test that when read_concatenated_archives is not specified 43299425Smm * only file1 is present. 44299425Smm */ 45299425Smm assert((a = archive_read_new()) != NULL); 46299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 47299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 48299425Smm extract_reference_file(name); 49299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); 50299425Smm 51299425Smm /* Read first entry. */ 52299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 53299425Smm assertEqualString("file1", archive_entry_pathname(ae)); 54299425Smm 55299425Smm /* Verify the end-of-archive. */ 56299425Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 57299425Smm 58299425Smm assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 59299425Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 60299425Smm 61299425Smm 62299425Smm /* 63299425Smm * Next test that when read_concatenated_archives is specified both 64299425Smm * file1 and file2 are present. 65299425Smm */ 66299425Smm assert((a = archive_read_new()) != NULL); 67299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 68299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 69299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "read_concatenated_archives")); 70299425Smm extract_reference_file(name); 71299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); 72299425Smm 73299425Smm /* Read first entry. */ 74299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 75299425Smm assertEqualString("file1", archive_entry_pathname(ae)); 76299425Smm 77299425Smm /* Read second entry. */ 78299425Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 79299425Smm assertEqualString("file2", archive_entry_pathname(ae)); 80299425Smm 81299425Smm /* Verify the end-of-archive. */ 82299425Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 83299425Smm 84299425Smm assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 85299425Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 86299425Smm} 87