test_read_format_gtar_sparse_skip_entry.c revision 285972
155682Smarkm/*- 2233294Sstas * Copyright (c) 2014 Michihiro NAKAJIMA 3233294Sstas * All rights reserved. 4233294Sstas * 555682Smarkm * Redistribution and use in source and binary forms, with or without 6233294Sstas * modification, are permitted provided that the following conditions 7233294Sstas * are met: 8233294Sstas * 1. Redistributions of source code must retain the above copyright 955682Smarkm * notice, this list of conditions and the following disclaimer. 10233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer in the 1255682Smarkm * documentation and/or other materials provided with the distribution. 13233294Sstas * 14233294Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15233294Sstas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1655682Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17233294Sstas * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18233294Sstas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19233294Sstas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2055682Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21233294Sstas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22233294Sstas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23233294Sstas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24233294Sstas */ 25233294Sstas#include "test.h" 26233294Sstas__FBSDID("$FreeBSD"); 27233294Sstas 28233294Sstas/* 29233294Sstas * To test skip a sparse file entry, this test does not read file data. 30233294Sstas */ 31233294SstasDEFINE_TEST(test_read_format_gtar_sparse_skip_entry) 3255682Smarkm{ 3355682Smarkm#ifndef __FreeBSD__ /* Backport test. */ 3455682Smarkm const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z.uu"; 35178825Sdfr#else 3655682Smarkm const char *refname = "test_read_format_gtar_sparse_skip_entry.tar.Z"; 37233294Sstas#endif 3855682Smarkm struct archive *a; 3955682Smarkm struct archive_entry *ae; 40178825Sdfr const void *p; 4155682Smarkm size_t s; 42178825Sdfr int64_t o; 4355682Smarkm 4455682Smarkm#ifndef __FreeBSD__ /* Backport test. */ 45178825Sdfr copy_reference_file(refname); 4655682Smarkm#else 47178825Sdfr extract_reference_file(refname); 48178825Sdfr#endif 49178825Sdfr assert((a = archive_read_new()) != NULL); 50178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 51178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 52178825Sdfr assertEqualIntA(a, ARCHIVE_OK, 53178825Sdfr archive_read_open_filename(a, refname, 10240)); 54178825Sdfr 55178825Sdfr /* Verify regular first file. */ 56178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 5755682Smarkm assertEqualString("a", archive_entry_pathname(ae)); 5855682Smarkm assertEqualInt(10737418244, archive_entry_size(ae)); 5955682Smarkm#ifndef __FreeBSD__ /* Backport test. */ 60178825Sdfr assertEqualInt(archive_entry_is_encrypted(ae), 0); 61178825Sdfr assertEqualIntA(a, archive_read_has_encrypted_entries(a), 6255682Smarkm ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 6372445Sassar#endif 64178825Sdfr 65178825Sdfr /* Verify regular second file. */ 66178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 67178825Sdfr assertEqualString("b", archive_entry_pathname(ae)); 68178825Sdfr assertEqualInt(4, archive_entry_size(ae)); 69178825Sdfr#ifndef __FreeBSD__ /* Backport test. */ 70178825Sdfr assertEqualInt(archive_entry_is_encrypted(ae), 0); 71178825Sdfr assertEqualIntA(a, archive_read_has_encrypted_entries(a), 72178825Sdfr ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 73178825Sdfr#endif 74233294Sstas 75178825Sdfr 76178825Sdfr /* End of archive. */ 77178825Sdfr assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 78178825Sdfr 79178825Sdfr /* Verify archive format. */ 80178825Sdfr assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 81233294Sstas assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 82178825Sdfr archive_format(a)); 83178825Sdfr 84178825Sdfr /* Close the archive. */ 85178825Sdfr assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 86233294Sstas assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 87178825Sdfr 88178825Sdfr 89233294Sstas /* 90233294Sstas * Read just one block of a sparse file and skip it. 91233294Sstas */ 92233294Sstas assert((a = archive_read_new()) != NULL); 93233294Sstas assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 94178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 95178825Sdfr assertEqualIntA(a, ARCHIVE_OK, 96178825Sdfr archive_read_open_filename(a, refname, 10240)); 97178825Sdfr 98178825Sdfr /* Verify regular first file. */ 99178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 100178825Sdfr assertEqualString("a", archive_entry_pathname(ae)); 101233294Sstas assertEqualInt(10737418244, archive_entry_size(ae)); 102178825Sdfr#ifndef __FreeBSD__ /* Backport test. */ 103178825Sdfr assertEqualInt(archive_entry_is_encrypted(ae), 0); 104178825Sdfr assertEqualIntA(a, archive_read_has_encrypted_entries(a), 105178825Sdfr ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 106178825Sdfr#endif 107178825Sdfr assertEqualInt(0, archive_read_data_block(a, &p, &s, &o)); 108178825Sdfr assertEqualInt(4096, s); 109178825Sdfr assertEqualInt(0, o); 110178825Sdfr 111233294Sstas 112178825Sdfr /* Verify regular second file. */ 113178825Sdfr assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 114178825Sdfr assertEqualString("b", archive_entry_pathname(ae)); 115178825Sdfr assertEqualInt(4, archive_entry_size(ae)); 116233294Sstas#ifndef __FreeBSD__ /* Backport test. */ 117178825Sdfr assertEqualInt(archive_entry_is_encrypted(ae), 0); 118178825Sdfr assertEqualIntA(a, archive_read_has_encrypted_entries(a), 119178825Sdfr ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 120178825Sdfr#endif 121178825Sdfr 122178825Sdfr 123178825Sdfr /* End of archive. */ 124178825Sdfr assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 125178825Sdfr 126233294Sstas /* Verify archive format. */ 127178825Sdfr assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0)); 128178825Sdfr assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, 129178825Sdfr archive_format(a)); 130178825Sdfr 131178825Sdfr /* Close the archive. */ 132233294Sstas assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 133178825Sdfr assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 134178825Sdfr} 135178825Sdfr 136178825Sdfr