1 /*- 2 * Copyright (c) 2014 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 #include "test.h" 26 27 #if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) 28 # define LITERAL_LL(x) x##i64 29 #else 30 # define LITERAL_LL(x) x##ll 31 #endif 32 /* 33 * To test skip a sparse file entry, this test does not read file data. 34 */ 35 DEFINE_TEST(test_read_format_gtar_sparse_skip_entry) 36 { 37 #ifndef __FreeBSD__ /* Backport test. */ 38 const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z.uu"; 39 #else 40 const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z"; 41 #endif 42 struct archive *a; 43 struct archive_entry *ae; 44 const void *p; 45 size_t s; 46 int64_t o; 47 48 #ifndef __FreeBSD__ /* Backport test. */ 49 copy_reference_file(refname); 50 #else 51 extract_reference_file(refname); 52 #endif 53 assert((a = archive_read_new()) != NULL); 54 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 55 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 56 assertEqualIntA(a, ARCHIVE_OK, 57 archive_read_open_filename(a, refname, 10240)); 58 59 /* Verify regular first file. */ 60 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 61 assertEqualString("a", archive_entry_pathname(ae)); 62 assertEqualInt(LITERAL_LL(10737418244), archive_entry_size(ae)); 63 #ifndef __FreeBSD__ /* Backport test. */ 64 assertEqualInt(archive_entry_is_encrypted(ae), 0); 65 assertEqualIntA(a, archive_read_has_encrypted_entries(a), 66 ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 67 #endif 68 69 /* Verify regular second file. */ 70 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 71 assertEqualString("b", archive_entry_pathname(ae)); 72 assertEqualInt(4, archive_entry_size(ae)); 73 #ifndef __FreeBSD__ /* Backport test. */ 74 assertEqualInt(archive_entry_is_encrypted(ae), 0); 75 assertEqualIntA(a, archive_read_has_encrypted_entries(a), 76 ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 77 #endif 78 79 80 /* End of archive. */ 81 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 82 83 /* Verify archive format. */ 84 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 85 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 86 archive_format(a)); 87 88 /* Close the archive. */ 89 assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 90 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 91 92 93 /* 94 * Read just one block of a sparse file and skip it. 95 */ 96 assert((a = archive_read_new()) != NULL); 97 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 98 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 99 assertEqualIntA(a, ARCHIVE_OK, 100 archive_read_open_filename(a, refname, 10240)); 101 102 /* Verify regular first file. */ 103 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 104 assertEqualString("a", archive_entry_pathname(ae)); 105 assertEqualInt(LITERAL_LL(10737418244), archive_entry_size(ae)); 106 #ifndef __FreeBSD__ /* Backport test. */ 107 assertEqualInt(archive_entry_is_encrypted(ae), 0); 108 assertEqualIntA(a, archive_read_has_encrypted_entries(a), 109 ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 110 #endif 111 assertEqualInt(0, archive_read_data_block(a, &p, &s, &o)); 112 assertEqualInt(4096, s); 113 assertEqualInt(0, o); 114 115 116 /* Verify regular second file. */ 117 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 118 assertEqualString("b", archive_entry_pathname(ae)); 119 assertEqualInt(4, archive_entry_size(ae)); 120 #ifndef __FreeBSD__ /* Backport test. */ 121 assertEqualInt(archive_entry_is_encrypted(ae), 0); 122 assertEqualIntA(a, archive_read_has_encrypted_entries(a), 123 ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 124 #endif 125 126 127 /* End of archive. */ 128 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 129 130 /* Verify archive format. */ 131 assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 132 assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 133 archive_format(a)); 134 135 /* Close the archive. */ 136 assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 137 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 138 } 139 140