test_read_format_isorr_new_bz2.c revision 248616
11541Srgrimes/*- 211150Swollman * Copyright (c) 2003-2007 Tim Kientzle 31541Srgrimes * All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 141541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 151541Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 161541Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 171541Srgrimes * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 181541Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 191541Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 201541Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 211541Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 221541Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 231541Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 241541Srgrimes */ 251541Srgrimes#include "test.h" 261541Srgrimes__FBSDID("$FreeBSD: head/contrib/libarchive/libarchive/test/test_read_format_isorr_new_bz2.c 248616 2013-03-22 13:36:03Z mm $"); 271541Srgrimes 281541Srgrimes 291541Srgrimes/* 301541SrgrimesPLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. 311541SrgrimesOld version mkisofs made wrong "SL" System Use Entry of RRIP. 321541Srgrimes 3311150SwollmanExecute the following command to rebuild the data for this program: 3443576Smsmith tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh 351541Srgrimes 361541Srgrimesrm -rf /tmp/iso 3732752Seivindmkdir /tmp/iso 3829514Sjoergmkdir /tmp/iso/dir 3929514Sjoergecho "hello" >/tmp/iso/file 401541Srgrimesdd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 411541Srgrimesln /tmp/iso/file /tmp/iso/hardlink 4212172Sphk(cd /tmp/iso; ln -s file symlink) 4312172Sphk(cd /tmp/iso; ln -s /tmp/ symlink2) 441541Srgrimes(cd /tmp/iso; ln -s /tmp/../ symlink3) 451541Srgrimes(cd /tmp/iso; ln -s .././../tmp/ symlink4) 461541Srgrimes(cd /tmp/iso; ln -s .///file symlink5) 471541Srgrimes(cd /tmp/iso; ln -s /tmp//../ symlink6) 481541SrgrimesTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 4934923SbdeTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 5034881SwollmanF=test_read_format_iso_rockridge_new.iso.Z 511541Srgrimesmkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 521541Srgrimesuuencode $F $F > $F.uu 531541Srgrimesexit 1 541541Srgrimes */ 5517269Swollman 561541SrgrimesDEFINE_TEST(test_read_format_isorr_new_bz2) 571541Srgrimes{ 581541Srgrimes const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; 591541Srgrimes struct archive_entry *ae; 607090Sbde struct archive *a; 611541Srgrimes const void *p; 621541Srgrimes size_t size; 631541Srgrimes int64_t offset; 641541Srgrimes int i; 651541Srgrimes 661541Srgrimes extract_reference_file(refname); 671541Srgrimes assert((a = archive_read_new()) != NULL); 686283Swollman assertEqualInt(0, archive_read_support_filter_all(a)); 696283Swollman assertEqualInt(0, archive_read_support_format_all(a)); 706283Swollman assertEqualInt(ARCHIVE_OK, 711541Srgrimes archive_read_open_filename(a, refname, 10240)); 721541Srgrimes 7312172Sphk /* Retrieve each of the 8 files on the ISO image and 7412172Sphk * verify that each one is what we expect. */ 7512296Sphk for (i = 0; i < 10; ++i) { 7612296Sphk assertEqualInt(0, archive_read_next_header(a, &ae)); 7712172Sphk 7812172Sphk if (strcmp(".", archive_entry_pathname(ae)) == 0) { 7912296Sphk /* '.' root directory. */ 8012296Sphk assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 8112172Sphk assertEqualInt(2048, archive_entry_size(ae)); 8212172Sphk /* Now, we read timestamp recorded by RRIP "TF". */ 8312296Sphk assertEqualInt(86401, archive_entry_mtime(ae)); 8438875Sphk assertEqualInt(0, archive_entry_mtime_nsec(ae)); 8512172Sphk /* Now, we read links recorded by RRIP "PX". */ 8612172Sphk assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 871541Srgrimes assertEqualInt(1, archive_entry_uid(ae)); 8836079Swollman assertEqualIntA(a, ARCHIVE_EOF, 8936079Swollman archive_read_data_block(a, &p, &size, &offset)); 9036079Swollman assertEqualInt((int)size, 0); 9129506Sbde } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 9212296Sphk /* A directory. */ 9312296Sphk assertEqualString("dir", archive_entry_pathname(ae)); 947684Sdg assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 9532821Sdg assertEqualInt(2048, archive_entry_size(ae)); 9643562Smsmith assertEqualInt(86401, archive_entry_mtime(ae)); 9743562Smsmith assertEqualInt(86401, archive_entry_atime(ae)); 9843562Smsmith assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 997684Sdg assertEqualInt(1, archive_entry_uid(ae)); 1007684Sdg assertEqualInt(2, archive_entry_gid(ae)); 10132821Sdg } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 1027684Sdg /* A regular file. */ 1031541Srgrimes assertEqualString("file", archive_entry_pathname(ae)); 1041541Srgrimes assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 10534881Swollman assertEqualInt(12345684, archive_entry_size(ae)); 10634881Swollman assertEqualInt(0, 10734881Swollman archive_read_data_block(a, &p, &size, &offset)); 10834881Swollman assertEqualInt(0, offset); 10934881Swollman assertEqualMem(p, "hello\n", 6); 11034881Swollman assertEqualInt(86401, archive_entry_mtime(ae)); 11134881Swollman assertEqualInt(86401, archive_entry_atime(ae)); 11234923Sbde assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 11334923Sbde assertEqualInt(1, archive_entry_uid(ae)); 11434881Swollman assertEqualInt(2, archive_entry_gid(ae)); 11534881Swollman } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 11634881Swollman /* A hardlink to the regular file. */ 11734881Swollman /* Note: If "hardlink" gets returned before "file", 11834881Swollman * then "hardlink" will get returned as a regular file 11934881Swollman * and "file" will get returned as the hardlink. 12034881Swollman * This test should tolerate that, since it's a 12134881Swollman * perfectly permissible thing for libarchive to do. */ 12234881Swollman assertEqualString("hardlink", archive_entry_pathname(ae)); 12334881Swollman assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 12434881Swollman assertEqualString("file", archive_entry_hardlink(ae)); 1251541Srgrimes assertEqualInt(0, archive_entry_size_is_set(ae)); 1261541Srgrimes assertEqualInt(0, archive_entry_size(ae)); 1271541Srgrimes assertEqualInt(86401, archive_entry_mtime(ae)); 1281541Srgrimes assertEqualInt(86401, archive_entry_atime(ae)); 1291541Srgrimes assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 13043562Smsmith assertEqualInt(1, archive_entry_uid(ae)); 13143562Smsmith assertEqualInt(2, archive_entry_gid(ae)); 13211150Swollman } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 1336283Swollman /* A symlink to the regular file. */ 1346283Swollman assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 1357684Sdg assertEqualString("file", archive_entry_symlink(ae)); 1367684Sdg assertEqualInt(0, archive_entry_size(ae)); 13743562Smsmith assertEqualInt(172802, archive_entry_mtime(ae)); 13843562Smsmith assertEqualInt(172802, archive_entry_atime(ae)); 13943576Smsmith assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 14043562Smsmith assertEqualInt(1, archive_entry_uid(ae)); 14143562Smsmith assertEqualInt(2, archive_entry_gid(ae)); 14243562Smsmith } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 14343562Smsmith /* A symlink to /tmp/ (an absolute path) */ 14443562Smsmith assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 14534923Sbde assertEqualString("/tmp/", archive_entry_symlink(ae)); 14636079Swollman assertEqualInt(0, archive_entry_size(ae)); 14734881Swollman assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 1481541Srgrimes assertEqualInt(1, archive_entry_uid(ae)); 1491541Srgrimes assertEqualInt(2, archive_entry_gid(ae)); 1501541Srgrimes } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 1511541Srgrimes /* A symlink to /tmp/../ (with a ".." component) */ 1521541Srgrimes assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 1531541Srgrimes assertEqualString("/tmp/../", archive_entry_symlink(ae)); 1541541Srgrimes assertEqualInt(0, archive_entry_size(ae)); 1551541Srgrimes assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 1561541Srgrimes assertEqualInt(1, archive_entry_uid(ae)); 1571541Srgrimes assertEqualInt(2, archive_entry_gid(ae)); 1581541Srgrimes } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 1591541Srgrimes /* A symlink to a path with ".." and "." components */ 1601541Srgrimes assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 1611541Srgrimes assertEqualString(".././../tmp/", 1621541Srgrimes archive_entry_symlink(ae)); 1631541Srgrimes assertEqualInt(0, archive_entry_size(ae)); 1641541Srgrimes assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 1651541Srgrimes assertEqualInt(1, archive_entry_uid(ae)); 1661541Srgrimes assertEqualInt(2, archive_entry_gid(ae)); 1671541Srgrimes } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 1681541Srgrimes /* A symlink to the regular file with "/" components. */ 1691541Srgrimes assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 1701541Srgrimes assertEqualString(".///file", archive_entry_symlink(ae)); 1711541Srgrimes assertEqualInt(0, archive_entry_size(ae)); 1721541Srgrimes assertEqualInt(172802, archive_entry_mtime(ae)); 1731541Srgrimes assertEqualInt(172802, archive_entry_atime(ae)); 1741541Srgrimes assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 17538513Sdfr assertEqualInt(1, archive_entry_uid(ae)); 1761541Srgrimes assertEqualInt(2, archive_entry_gid(ae)); 1771541Srgrimes } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 1781541Srgrimes /* A symlink to /tmp//../ 1791541Srgrimes * (with "/" and ".." components) */ 1801541Srgrimes assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 1811541Srgrimes assertEqualString("/tmp//../", archive_entry_symlink(ae)); 1821541Srgrimes assertEqualInt(0, archive_entry_size(ae)); 1831541Srgrimes assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 1841541Srgrimes assertEqualInt(1, archive_entry_uid(ae)); 1851541Srgrimes assertEqualInt(2, archive_entry_gid(ae)); 1861541Srgrimes } else { 1871541Srgrimes failure("Saw a file that shouldn't have been there"); 1881541Srgrimes assertEqualString(archive_entry_pathname(ae), ""); 1891541Srgrimes } 1901541Srgrimes } 1911541Srgrimes 1921541Srgrimes /* End of archive. */ 1931541Srgrimes assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 1941541Srgrimes 1951541Srgrimes /* Verify archive format. */ 1961541Srgrimes assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 1971541Srgrimes assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 1981541Srgrimes 1991541Srgrimes /* Close the archive. */ 2001541Srgrimes assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 2011541Srgrimes assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 2021541Srgrimes} 2031541Srgrimes 2041541Srgrimes 20531848Sjulian