test_read_format_isorr_new_bz2.c revision 228759
159769Sgrog/*- 259769Sgrog * Copyright (c) 2003-2007 Tim Kientzle 324424Swosch * All rights reserved. 424424Swosch * 524424Swosch * Redistribution and use in source and binary forms, with or without 624424Swosch * modification, are permitted provided that the following conditions 724424Swosch * are met: 824424Swosch * 1. Redistributions of source code must retain the above copyright 924424Swosch * notice, this list of conditions and the following disclaimer. 1024424Swosch * 2. Redistributions in binary form must reproduce the above copyright 1124424Swosch * notice, this list of conditions and the following disclaimer in the 1224424Swosch * documentation and/or other materials provided with the distribution. 1324424Swosch * 1424424Swosch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1542704Swosch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1642704Swosch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1742704Swosch * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1824424Swosch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1942704Swosch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2042704Swosch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2142704Swosch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2242704Swosch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2342704Swosch * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2442704Swosch */ 2542704Swosch#include "test.h" 2642704Swosch__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_new_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); 2742704Swosch 2842704Swosch 2942704Swosch/* 3059769SgrogPLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. 3159769SgrogOld version mkisofs made wrong "SL" System Use Entry of RRIP. 3259769Sgrog 3359769SgrogExecute the following command to rebuild the data for this program: 3459769Sgrog tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh 3559769Sgrog 3659769Sgrogrm -rf /tmp/iso 3759769Sgrogmkdir /tmp/iso 3859769Sgrogmkdir /tmp/iso/dir 3924424Swoschecho "hello" >/tmp/iso/file 4042704Swoschdd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 4124424Swoschln /tmp/iso/file /tmp/iso/hardlink 4242704Swosch(cd /tmp/iso; ln -s file symlink) 4324424Swosch(cd /tmp/iso; ln -s /tmp/ symlink2) 4442704Swosch(cd /tmp/iso; ln -s /tmp/../ symlink3) 4524424Swosch(cd /tmp/iso; ln -s .././../tmp/ symlink4) 4624424Swosch(cd /tmp/iso; ln -s .///file symlink5) 4724424Swosch(cd /tmp/iso; ln -s /tmp//../ symlink6) 4842704SwoschTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 4925031SwoschTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 5059156SwoschF=test_read_format_iso_rockridge_new.iso.Z 5125031Swoschmkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 5225031Swoschuuencode $F $F > $F.uu 5324424Swoschexit 1 5424424Swosch */ 5524424Swosch 5624424SwoschDEFINE_TEST(test_read_format_isorr_new_bz2) 5771231Sitojun{ 5824424Swosch const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; 5971231Sitojun struct archive_entry *ae; 6025031Swosch struct archive *a; 6171231Sitojun const void *p; 6224424Swosch size_t size; 6325031Swosch off_t offset; 6425031Swosch int i; 6571231Sitojun 6625031Swosch extract_reference_file(refname); 6771231Sitojun assert((a = archive_read_new()) != NULL); 6870110Swosch assertEqualInt(0, archive_read_support_compression_all(a)); 6970110Swosch assertEqualInt(0, archive_read_support_format_all(a)); 7070110Swosch assertEqualInt(ARCHIVE_OK, 7170110Swosch archive_read_open_filename(a, refname, 10240)); 7270110Swosch 7370110Swosch /* Retrieve each of the 8 files on the ISO image and 7470110Swosch * verify that each one is what we expect. */ 7570110Swosch for (i = 0; i < 10; ++i) { 7670110Swosch assertEqualInt(0, archive_read_next_header(a, &ae)); 7770110Swosch 7870110Swosch if (strcmp(".", archive_entry_pathname(ae)) == 0) { 7980675Sasmodai /* '.' root directory. */ 8080675Sasmodai assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 8180675Sasmodai assertEqualInt(2048, archive_entry_size(ae)); 8280675Sasmodai /* Now, we read timestamp recorded by RRIP "TF". */ 8380675Sasmodai assertEqualInt(86401, archive_entry_mtime(ae)); 8480675Sasmodai assertEqualInt(0, archive_entry_mtime_nsec(ae)); 8580675Sasmodai /* Now, we read links recorded by RRIP "PX". */ 8680675Sasmodai assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 8780675Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 8880675Sasmodai assertEqualIntA(a, ARCHIVE_EOF, 8980675Sasmodai archive_read_data_block(a, &p, &size, &offset)); 9080675Sasmodai assertEqualInt((int)size, 0); 9180675Sasmodai } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 9280675Sasmodai /* A directory. */ 9380675Sasmodai assertEqualString("dir", archive_entry_pathname(ae)); 9480675Sasmodai assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 9580675Sasmodai assertEqualInt(2048, archive_entry_size(ae)); 9680675Sasmodai assertEqualInt(86401, archive_entry_mtime(ae)); 9780675Sasmodai assertEqualInt(86401, archive_entry_atime(ae)); 9880675Sasmodai assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 9980675Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 10080675Sasmodai assertEqualInt(2, archive_entry_gid(ae)); 10180675Sasmodai } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 10280675Sasmodai /* A regular file. */ 10380675Sasmodai assertEqualString("file", archive_entry_pathname(ae)); 10480675Sasmodai assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 10580675Sasmodai assertEqualInt(12345684, archive_entry_size(ae)); 10680675Sasmodai assertEqualInt(0, 10780675Sasmodai archive_read_data_block(a, &p, &size, &offset)); 10880675Sasmodai assertEqualInt(0, offset); 10980675Sasmodai assertEqualMem(p, "hello\n", 6); 11080675Sasmodai assertEqualInt(86401, archive_entry_mtime(ae)); 11180675Sasmodai assertEqualInt(86401, archive_entry_atime(ae)); 11280675Sasmodai assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 11380675Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 11480675Sasmodai assertEqualInt(2, archive_entry_gid(ae)); 11580675Sasmodai } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 11680675Sasmodai /* A hardlink to the regular file. */ 11780675Sasmodai /* Note: If "hardlink" gets returned before "file", 11880675Sasmodai * then "hardlink" will get returned as a regular file 11980675Sasmodai * and "file" will get returned as the hardlink. 12080675Sasmodai * This test should tolerate that, since it's a 12180675Sasmodai * perfectly permissible thing for libarchive to do. */ 12280675Sasmodai assertEqualString("hardlink", archive_entry_pathname(ae)); 12380675Sasmodai assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 12480675Sasmodai assertEqualString("file", archive_entry_hardlink(ae)); 12580675Sasmodai assertEqualInt(0, archive_entry_size_is_set(ae)); 12680675Sasmodai assertEqualInt(0, archive_entry_size(ae)); 12780675Sasmodai assertEqualInt(86401, archive_entry_mtime(ae)); 12880675Sasmodai assertEqualInt(86401, archive_entry_atime(ae)); 12980675Sasmodai assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 13080675Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 13180675Sasmodai assertEqualInt(2, archive_entry_gid(ae)); 13280675Sasmodai } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 13380675Sasmodai /* A symlink to the regular file. */ 13480675Sasmodai assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 13580675Sasmodai assertEqualString("file", archive_entry_symlink(ae)); 13680675Sasmodai assertEqualInt(0, archive_entry_size(ae)); 13780675Sasmodai assertEqualInt(172802, archive_entry_mtime(ae)); 13880675Sasmodai assertEqualInt(172802, archive_entry_atime(ae)); 13980675Sasmodai assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 14087200Swosch assertEqualInt(1, archive_entry_uid(ae)); 14187200Swosch assertEqualInt(2, archive_entry_gid(ae)); 14287200Swosch } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 14380675Sasmodai /* A symlink to /tmp/ (an absolute path) */ 14480675Sasmodai assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 14580675Sasmodai assertEqualString("/tmp/", archive_entry_symlink(ae)); 14680675Sasmodai assertEqualInt(0, archive_entry_size(ae)); 14784087Swosch assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 14884087Swosch assertEqualInt(1, archive_entry_uid(ae)); 14987200Swosch assertEqualInt(2, archive_entry_gid(ae)); 15088698Swosch } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 15188698Swosch /* A symlink to /tmp/../ (with a ".." component) */ 15288698Swosch assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 15388698Swosch assertEqualString("/tmp/../", archive_entry_symlink(ae)); 15480675Sasmodai assertEqualInt(0, archive_entry_size(ae)); 15580675Sasmodai assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 15680675Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 15780675Sasmodai assertEqualInt(2, archive_entry_gid(ae)); 15880675Sasmodai } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 15980675Sasmodai /* A symlink to a path with ".." and "." components */ 16024424Swosch assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 16124424Swosch assertEqualString(".././../tmp/", 16224424Swosch archive_entry_symlink(ae)); 16324424Swosch assertEqualInt(0, archive_entry_size(ae)); 16469277Sasmodai assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 16569277Sasmodai assertEqualInt(1, archive_entry_uid(ae)); 16624424Swosch assertEqualInt(2, archive_entry_gid(ae)); 16725031Swosch } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 16825031Swosch /* A symlink to the regular file with "/" components. */ 16925031Swosch assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 17080675Sasmodai assertEqualString(".///file", archive_entry_symlink(ae)); 17125031Swosch assertEqualInt(0, archive_entry_size(ae)); 17225031Swosch assertEqualInt(172802, archive_entry_mtime(ae)); 17325031Swosch assertEqualInt(172802, archive_entry_atime(ae)); 17425031Swosch assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 17525031Swosch assertEqualInt(1, archive_entry_uid(ae)); 17625031Swosch assertEqualInt(2, archive_entry_gid(ae)); 17725031Swosch } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 17825031Swosch /* A symlink to /tmp//../ 17925031Swosch * (with "/" and ".." components) */ 18025031Swosch assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 18125031Swosch assertEqualString("/tmp//../", archive_entry_symlink(ae)); 18225031Swosch assertEqualInt(0, archive_entry_size(ae)); 18338440Sjkh assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 18445349Swosch assertEqualInt(1, archive_entry_uid(ae)); 18545349Swosch assertEqualInt(2, archive_entry_gid(ae)); 18642704Swosch } else { 18770110Swosch failure("Saw a file that shouldn't have been there"); 18825031Swosch assertEqualString(archive_entry_pathname(ae), ""); 18924424Swosch } 19059769Sgrog } 19125031Swosch 19225031Swosch /* End of archive. */ 19325031Swosch assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 19425031Swosch 19559769Sgrog /* Verify archive format. */ 19625031Swosch assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); 19725031Swosch assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 19825031Swosch 19925031Swosch /* Close the archive. */ 20024424Swosch assertEqualInt(0, archive_read_close(a)); 20125031Swosch assertEqualInt(0, archive_read_finish(a)); 20225031Swosch} 20325031Swosch 20425031Swosch 20525031Swosch