test_read_format_isorr_ce.c revision 228759
1/*- 2 * Copyright (c) 2003-2007 Tim Kientzle 3 * Copyright (c) 2009 Michihiro NAKAJIMA 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26#include "test.h" 27__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_ce.c 201247 2009-12-30 05:59:21Z kientzle $"); 28 29/* 30Execute the following command to rebuild the data for this program: 31 tail -n +32 test_read_format_isorr_ce.c | /bin/sh 32 33dirname=/tmp/iso 34# 35rm -rf $dirname 36mkdir $dirname 37# 38num=0 39file="" 40while [ $num -lt 150 ] 41do 42 num=$((num+1)) 43 file="a$file" 44done 45# 46num=0 47while [ $num -lt 3 ] 48do 49 num=$((num+1)) 50 file="a$file" 51 echo "hello $((num+150))" > $dirname/$file 52 dd if=/dev/zero count=1 bs=4080 >> $dirname/$file 53 (cd $dirname; ln -s $file sym$num) 54done 55# 56mkdir $dirname/dir 57# 58time1="197001020000.01" 59time2="197001030000.02" 60TZ=utc touch -afhm -t $time1 $dirname/dir $dirname/aaaa* 61TZ=utc touch -afhm -t $time2 $dirname/sym* 62TZ=utc touch -afhm -t $time1 $dirname 63# 64F=test_read_format_iso_rockridge_ce.iso.Z 65mkisofs -R -uid 1 -gid 2 $dirname | compress > $F 66uuencode $F $F > $F.uu 67rm -rf $dirname 68exit 1 69 */ 70 71/* 72 * Test reading SUSP "CE" extension is works fine. 73 */ 74 75static void 76mkpath(char *p, int len) 77{ 78 int i; 79 80 for (i = 0; i < len; i++) 81 p[i] = 'a'; 82 p[len] = '\0'; 83} 84 85DEFINE_TEST(test_read_format_isorr_ce) 86{ 87 const char *refname = "test_read_format_iso_rockridge_ce.iso.Z"; 88 char path1[160]; 89 char path2[160]; 90 char path3[160]; 91 struct archive_entry *ae; 92 struct archive *a; 93 const void *p; 94 size_t size; 95 off_t offset; 96 int i; 97 98 mkpath(path1, 151); 99 mkpath(path2, 152); 100 mkpath(path3, 153); 101 extract_reference_file(refname); 102 assert((a = archive_read_new()) != NULL); 103 assertEqualInt(0, archive_read_support_compression_all(a)); 104 assertEqualInt(0, archive_read_support_format_all(a)); 105 assertEqualInt(ARCHIVE_OK, 106 archive_read_open_filename(a, refname, 10240)); 107 108 /* Retrieve each of the 8 files on the ISO image and 109 * verify that each one is what we expect. */ 110 for (i = 0; i < 8; ++i) { 111 assertEqualInt(0, archive_read_next_header(a, &ae)); 112 113 if (strcmp(".", archive_entry_pathname(ae)) == 0) { 114 /* '.' root directory. */ 115 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 116 assertEqualInt(2048, archive_entry_size(ae)); 117 /* Now, we read timestamp recorded by RRIP "TF". */ 118 assertEqualInt(86401, archive_entry_mtime(ae)); 119 assertEqualInt(0, archive_entry_mtime_nsec(ae)); 120 /* Now, we read links recorded by RRIP "PX". */ 121 assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 122 assertEqualInt(1, archive_entry_uid(ae)); 123 assertEqualIntA(a, ARCHIVE_EOF, 124 archive_read_data_block(a, &p, &size, &offset)); 125 assertEqualInt((int)size, 0); 126 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 127 /* A directory. */ 128 assertEqualString("dir", archive_entry_pathname(ae)); 129 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 130 assertEqualInt(2048, archive_entry_size(ae)); 131 assertEqualInt(86401, archive_entry_mtime(ae)); 132 assertEqualInt(86401, archive_entry_atime(ae)); 133 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 134 assertEqualInt(1, archive_entry_uid(ae)); 135 assertEqualInt(2, archive_entry_gid(ae)); 136 } else if (strcmp(path1, archive_entry_pathname(ae)) == 0) { 137 /* A regular file. */ 138 assertEqualString(path1, archive_entry_pathname(ae)); 139 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 140 assertEqualInt(4090, archive_entry_size(ae)); 141 assertEqualInt(0, 142 archive_read_data_block(a, &p, &size, &offset)); 143 assertEqualInt(0, offset); 144 assertEqualMem(p, "hello 151\n", 10); 145 assertEqualInt(86401, archive_entry_mtime(ae)); 146 assertEqualInt(86401, archive_entry_atime(ae)); 147 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 148 assertEqualInt(1, archive_entry_uid(ae)); 149 assertEqualInt(2, archive_entry_gid(ae)); 150 } else if (strcmp(path2, archive_entry_pathname(ae)) == 0) { 151 /* A regular file. */ 152 assertEqualString(path2, archive_entry_pathname(ae)); 153 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 154 assertEqualInt(4090, archive_entry_size(ae)); 155 assertEqualInt(0, 156 archive_read_data_block(a, &p, &size, &offset)); 157 assertEqualInt(0, offset); 158 assertEqualMem(p, "hello 152\n", 10); 159 assertEqualInt(86401, archive_entry_mtime(ae)); 160 assertEqualInt(86401, archive_entry_atime(ae)); 161 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 162 assertEqualInt(1, archive_entry_uid(ae)); 163 assertEqualInt(2, archive_entry_gid(ae)); 164 } else if (strcmp(path3, archive_entry_pathname(ae)) == 0) { 165 /* A regular file. */ 166 assertEqualString(path3, archive_entry_pathname(ae)); 167 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 168 assertEqualInt(4090, archive_entry_size(ae)); 169 assertEqualInt(0, 170 archive_read_data_block(a, &p, &size, &offset)); 171 assertEqualInt(0, offset); 172 assertEqualMem(p, "hello 153\n", 10); 173 assertEqualInt(86401, archive_entry_mtime(ae)); 174 assertEqualInt(86401, archive_entry_atime(ae)); 175 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 176 assertEqualInt(1, archive_entry_uid(ae)); 177 assertEqualInt(2, archive_entry_gid(ae)); 178 } else if (strcmp("sym1", archive_entry_pathname(ae)) == 0) { 179 /* A symlink to the regular file. */ 180 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 181 assertEqualString(path1, archive_entry_symlink(ae)); 182 assertEqualInt(0, archive_entry_size(ae)); 183 assertEqualInt(172802, archive_entry_mtime(ae)); 184 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 185 assertEqualInt(1, archive_entry_uid(ae)); 186 assertEqualInt(2, archive_entry_gid(ae)); 187 } else if (strcmp("sym2", archive_entry_pathname(ae)) == 0) { 188 /* A symlink to the regular file. */ 189 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 190 assertEqualString(path2, archive_entry_symlink(ae)); 191 assertEqualInt(0, archive_entry_size(ae)); 192 assertEqualInt(172802, archive_entry_mtime(ae)); 193 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 194 assertEqualInt(1, archive_entry_uid(ae)); 195 assertEqualInt(2, archive_entry_gid(ae)); 196 } else if (strcmp("sym3", archive_entry_pathname(ae)) == 0) { 197 /* A symlink to the regular file. */ 198 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 199 assertEqualString(path3, archive_entry_symlink(ae)); 200 assertEqualInt(0, archive_entry_size(ae)); 201 assertEqualInt(172802, archive_entry_mtime(ae)); 202 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 203 assertEqualInt(1, archive_entry_uid(ae)); 204 assertEqualInt(2, archive_entry_gid(ae)); 205 } else { 206 failure("Saw a file that shouldn't have been there"); 207 assertEqualString(archive_entry_pathname(ae), ""); 208 } 209 } 210 211 /* End of archive. */ 212 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 213 214 /* Verify archive format. */ 215 assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); 216 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 217 218 /* Close the archive. */ 219 assertEqualInt(0, archive_read_close(a)); 220 assertEqualInt(0, archive_read_finish(a)); 221} 222 223 224