test_read_format_gtar_sparse_skip_entry.c revision 299529
159766Sjlemon/*- 238451Smsmith * Copyright (c) 2014 Michihiro NAKAJIMA 338451Smsmith * All rights reserved. 438451Smsmith * 538451Smsmith * Redistribution and use in source and binary forms, with or without 638451Smsmith * modification, are permitted provided that the following conditions 738451Smsmith * are met: 838451Smsmith * 1. Redistributions of source code must retain the above copyright 938451Smsmith * notice, this list of conditions and the following disclaimer. 1038451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138451Smsmith * notice, this list of conditions and the following disclaimer in the 1238451Smsmith * documentation and/or other materials provided with the distribution. 1338451Smsmith * 1438451Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1538451Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1638451Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1738451Smsmith * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1838451Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1938451Smsmith * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2038451Smsmith * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2138451Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2238451Smsmith * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2338451Smsmith * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2438451Smsmith */ 2538451Smsmith#include "test.h" 2638451Smsmith__FBSDID("$FreeBSD"); 2738451Smsmith 2838451Smsmith#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) 2938451Smsmith# define LITERAL_LL(x) x##i64 3038451Smsmith#else 3138451Smsmith# define LITERAL_LL(x) x##ll 3238451Smsmith#endif 3338451Smsmith/* 3438451Smsmith * To test skip a sparse file entry, this test does not read file data. 3538451Smsmith */ 3638451SmsmithDEFINE_TEST(test_read_format_gtar_sparse_skip_entry) 3738451Smsmith{ 3838451Smsmith#ifndef __FreeBSD__ /* Backport test. */ 3938451Smsmith const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z.uu"; 4038451Smsmith#else 4138451Smsmith const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z"; 4238451Smsmith#endif 4338451Smsmith struct archive *a; 4438451Smsmith struct archive_entry *ae; 4538451Smsmith const void *p; 4638451Smsmith size_t s; 4738451Smsmith int64_t o; 4838451Smsmith 4938451Smsmith#ifndef __FreeBSD__ /* Backport test. */ 5038451Smsmith copy_reference_file(refname); 5138451Smsmith#else 5238451Smsmith extract_reference_file(refname); 5338451Smsmith#endif 5438451Smsmith assert((a = archive_read_new()) != NULL); 5538451Smsmith assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 5638451Smsmith assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 5738451Smsmith assertEqualIntA(a, ARCHIVE_OK, 5838451Smsmith archive_read_open_filename(a, refname, 10240)); 5938451Smsmith 6038451Smsmith /* Verify regular first file. */ 6138451Smsmith assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 6238451Smsmith assertEqualString("a", archive_entry_pathname(ae)); 6338451Smsmith assertEqualInt(LITERAL_LL(10737418244), archive_entry_size(ae)); 6438451Smsmith#ifndef __FreeBSD__ /* Backport test. */ 6538451Smsmith assertEqualInt(archive_entry_is_encrypted(ae), 0); 6638451Smsmith assertEqualIntA(a, archive_read_has_encrypted_entries(a), 6738451Smsmith ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 6838451Smsmith#endif 6938451Smsmith 7038451Smsmith /* Verify regular second file. */ 7138451Smsmith assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 7238451Smsmith assertEqualString("b", archive_entry_pathname(ae)); 7338451Smsmith assertEqualInt(4, archive_entry_size(ae)); 7438451Smsmith#ifndef __FreeBSD__ /* Backport test. */ 7538451Smsmith assertEqualInt(archive_entry_is_encrypted(ae), 0); 7638451Smsmith assertEqualIntA(a, archive_read_has_encrypted_entries(a), 7738451Smsmith ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 7838451Smsmith#endif 7938451Smsmith 8038451Smsmith 8138451Smsmith /* End of archive. */ 8238451Smsmith assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 8338451Smsmith 8438451Smsmith /* Verify archive format. */ 8538451Smsmith assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 8638451Smsmith assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 8738451Smsmith archive_format(a)); 8838451Smsmith 8938451Smsmith /* Close the archive. */ 9038451Smsmith assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 9138451Smsmith assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 9238451Smsmith 9338451Smsmith 9459853Sps /* 9559853Sps * Read just one block of a sparse file and skip it. 9659853Sps */ 9759853Sps assert((a = archive_read_new()) != NULL); 9859853Sps assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 9959853Sps assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 10059853Sps assertEqualIntA(a, ARCHIVE_OK, 10159853Sps archive_read_open_filename(a, refname, 10240)); 10259853Sps 10359853Sps /* Verify regular first file. */ 10459853Sps assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 10559853Sps assertEqualString("a", archive_entry_pathname(ae)); 10659853Sps assertEqualInt(LITERAL_LL(10737418244), archive_entry_size(ae)); 10759853Sps#ifndef __FreeBSD__ /* Backport test. */ 10859853Sps assertEqualInt(archive_entry_is_encrypted(ae), 0); 10959853Sps assertEqualIntA(a, archive_read_has_encrypted_entries(a), 11059853Sps ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 11138451Smsmith#endif 11238451Smsmith assertEqualInt(0, archive_read_data_block(a, &p, &s, &o)); 11338451Smsmith assertEqualInt(4096, s); 11438451Smsmith assertEqualInt(0, o); 11538451Smsmith 11638451Smsmith 11738451Smsmith /* Verify regular second file. */ 11838451Smsmith assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 11938451Smsmith assertEqualString("b", archive_entry_pathname(ae)); 12038451Smsmith assertEqualInt(4, archive_entry_size(ae)); 12138451Smsmith#ifndef __FreeBSD__ /* Backport test. */ 12239468Smsmith assertEqualInt(archive_entry_is_encrypted(ae), 0); 12338451Smsmith assertEqualIntA(a, archive_read_has_encrypted_entries(a), 12438451Smsmith ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 12538451Smsmith#endif 12638451Smsmith 12738451Smsmith 12859853Sps /* End of archive. */ 12938451Smsmith assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 13059824Sps 13159824Sps /* Verify archive format. */ 13238451Smsmith assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 13359766Sjlemon assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 13459766Sjlemon archive_format(a)); 13559766Sjlemon 13659766Sjlemon /* Close the archive. */ 13759766Sjlemon assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 13859766Sjlemon assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 13959766Sjlemon} 14059853Sps 14138451Smsmith