1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Based on libarchive/test/test_read_format_isorr_bz2.c with 6228753Smm * bugs introduced by Andreas Henriksson <andreas@fatal.se> for 7228753Smm * testing ISO9660 image with Joliet extension. 8228753Smm * 9228753Smm * Redistribution and use in source and binary forms, with or without 10228753Smm * modification, are permitted provided that the following conditions 11228753Smm * are met: 12228753Smm * 1. Redistributions of source code must retain the above copyright 13228753Smm * notice, this list of conditions and the following disclaimer. 14228753Smm * 2. Redistributions in binary form must reproduce the above copyright 15228753Smm * notice, this list of conditions and the following disclaimer in the 16228753Smm * documentation and/or other materials provided with the distribution. 17228753Smm * 18228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 19228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 22228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28228753Smm */ 29228753Smm#include "test.h" 30228763Smm__FBSDID("$FreeBSD$"); 31228753Smm 32228753Smm/* 33228753SmmExecute the following to rebuild the data for this program: 34228753Smm tail -n +35 test_read_format_isojoliet_bz2.c | /bin/sh 35228753Smm 36228753Smmrm -rf /tmp/iso 37228753Smmmkdir /tmp/iso 38228753Smmmkdir /tmp/iso/dir 39228753Smmecho "hello" >/tmp/iso/long-joliet-file-name.textfile 40228753Smmln /tmp/iso/long-joliet-file-name.textfile /tmp/iso/hardlink 41228753Smm(cd /tmp/iso; ln -s long-joliet-file-name.textfile symlink) 42228753Smmif [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h 43228753SmmTZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir 44228753SmmTZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink 45228753Smmelse 46228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir 47228753SmmTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 48228753Smmfi 49228753SmmF=test_read_format_iso_joliet.iso.Z 50228753Smmmkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F 51228753Smmuuencode $F $F > $F.uu 52228753Smmexit 1 53228753Smm */ 54228753Smm 55228753SmmDEFINE_TEST(test_read_format_isojoliet_bz2) 56228753Smm{ 57228753Smm const char *refname = "test_read_format_iso_joliet.iso.Z"; 58228753Smm struct archive_entry *ae; 59228753Smm struct archive *a; 60228753Smm const void *p; 61228753Smm size_t size; 62232153Smm int64_t offset; 63228753Smm 64228753Smm extract_reference_file(refname); 65228753Smm assert((a = archive_read_new()) != NULL); 66232153Smm assertEqualInt(0, archive_read_support_filter_all(a)); 67228753Smm assertEqualInt(0, archive_read_support_format_all(a)); 68228753Smm assertEqualInt(ARCHIVE_OK, 69232153Smm archive_read_set_option(a, "iso9660", "rockridge", NULL)); 70228753Smm assertEqualInt(ARCHIVE_OK, 71228753Smm archive_read_open_filename(a, refname, 10240)); 72228753Smm 73228753Smm /* First entry is '.' root directory. */ 74228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 75228753Smm assertEqualString(".", archive_entry_pathname(ae)); 76228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 77228753Smm assertEqualInt(2048, archive_entry_size(ae)); 78228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 79228753Smm assertEqualInt(0, archive_entry_mtime_nsec(ae)); 80228753Smm assertEqualInt(86401, archive_entry_ctime(ae)); 81228753Smm assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 82228753Smm assertEqualInt(0, archive_entry_uid(ae)); 83228753Smm assertEqualIntA(a, ARCHIVE_EOF, 84228753Smm archive_read_data_block(a, &p, &size, &offset)); 85228753Smm assertEqualInt((int)size, 0); 86299529Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 87299529Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 88228753Smm 89228753Smm /* A directory. */ 90228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 91228753Smm assertEqualString("dir", archive_entry_pathname(ae)); 92228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 93228753Smm assertEqualInt(2048, archive_entry_size(ae)); 94228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 95228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 96299529Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 97299529Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 98228753Smm 99228753Smm /* A regular file with two names ("hardlink" gets returned 100228753Smm * first, so it's not marked as a hardlink). */ 101228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 102228753Smm assertEqualString("hardlink", 103228753Smm archive_entry_pathname(ae)); 104228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 105228753Smm assert(archive_entry_hardlink(ae) == NULL); 106228753Smm assertEqualInt(6, archive_entry_size(ae)); 107228753Smm assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); 108228753Smm assertEqualInt(6, (int)size); 109228753Smm assertEqualInt(0, offset); 110232153Smm assertEqualMem(p, "hello\n", 6); 111228753Smm 112228753Smm /* Second name for the same regular file (this happens to be 113228753Smm * returned second, so does get marked as a hardlink). */ 114228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 115228753Smm assertEqualString("long-joliet-file-name.textfile", 116228753Smm archive_entry_pathname(ae)); 117228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 118228753Smm assertEqualString("hardlink", 119228753Smm archive_entry_hardlink(ae)); 120228753Smm assert(!archive_entry_size_is_set(ae)); 121228753Smm 122228753Smm /* A symlink to the regular file. */ 123228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 124228753Smm assertEqualString("symlink", archive_entry_pathname(ae)); 125228753Smm assertEqualInt(0, archive_entry_size(ae)); 126228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 127228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 128299529Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 129299529Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 130228753Smm 131228753Smm /* End of archive. */ 132228753Smm assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 133228753Smm 134228753Smm /* Verify archive format. */ 135248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 136228753Smm 137228753Smm /* Close the archive. */ 138232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 139232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 140228753Smm} 141228753Smm 142