test_write_format_iso9660_empty.c revision 231200
1231200Smm/*- 2231200Smm * Copyright (c) 2009-2011 Michihiro NAKAJIMA 3231200Smm * All rights reserved. 4231200Smm * 5231200Smm * Redistribution and use in source and binary forms, with or without 6231200Smm * modification, are permitted provided that the following conditions 7231200Smm * are met: 8231200Smm * 1. Redistributions of source code must retain the above copyright 9231200Smm * notice, this list of conditions and the following disclaimer. 10231200Smm * 2. Redistributions in binary form must reproduce the above copyright 11231200Smm * notice, this list of conditions and the following disclaimer in the 12231200Smm * documentation and/or other materials provided with the distribution. 13231200Smm * 14231200Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15231200Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16231200Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17231200Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18231200Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19231200Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20231200Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21231200Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22231200Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23231200Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24231200Smm */ 25231200Smm#include "test.h" 26231200Smm 27231200Smm/* 28231200Smm * Check that an "empty" ISO 9660 image is correctly created. 29231200Smm */ 30231200Smm 31231200Smmstatic const unsigned char primary_id[] = { 32231200Smm 0x01, 0x43, 0x44, 0x30, 0x30, 0x31, 0x01, 0x00 33231200Smm}; 34231200Smmstatic const unsigned char volumesize[] = { 35231200Smm 0xb5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5 36231200Smm}; 37231200Smmstatic const unsigned char volumeidu16[] = { 38231200Smm 0x00, 0x43, 0x00, 0x44, 0x00, 0x52, 0x00, 0x4f, 39231200Smm 0x00, 0x4d, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 40231200Smm 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 41231200Smm 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20 42231200Smm}; 43231200Smmstatic const unsigned char supplementary_id[] = { 44231200Smm 0x02, 0x43, 0x44, 0x30, 0x30, 0x31, 0x01, 0x00 45231200Smm}; 46231200Smmstatic const unsigned char terminator_id[] = { 47231200Smm 0xff, 0x43, 0x44, 0x30, 0x30, 0x31, 0x01, 0x00 48231200Smm}; 49231200Smm 50231200SmmDEFINE_TEST(test_write_format_iso9660_empty) 51231200Smm{ 52231200Smm struct archive *a; 53231200Smm struct archive_entry *ae; 54231200Smm unsigned char *buff; 55231200Smm size_t buffsize = 190 * 2048; 56231200Smm size_t used; 57231200Smm unsigned int i; 58231200Smm 59231200Smm buff = malloc(buffsize); 60231200Smm assert(buff != NULL); 61231200Smm 62231200Smm /* ISO9660 format: Create a new archive in memory. */ 63231200Smm assert((a = archive_write_new()) != NULL); 64231200Smm assertA(0 == archive_write_set_format_iso9660(a)); 65231200Smm assertA(0 == archive_write_set_compression_none(a)); 66231200Smm assertA(0 == archive_write_set_bytes_per_block(a, 1)); 67231200Smm assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); 68231200Smm assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); 69231200Smm 70231200Smm /* Add "." entry which must be ignored. */ 71231200Smm assert((ae = archive_entry_new()) != NULL); 72231200Smm archive_entry_set_atime(ae, 2, 0); 73231200Smm archive_entry_set_ctime(ae, 4, 0); 74231200Smm archive_entry_set_mtime(ae, 5, 0); 75231200Smm archive_entry_copy_pathname(ae, "."); 76231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 77231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 78231200Smm archive_entry_free(ae); 79231200Smm 80231200Smm /* Add ".." entry which must be ignored. */ 81231200Smm assert((ae = archive_entry_new()) != NULL); 82231200Smm archive_entry_set_atime(ae, 2, 0); 83231200Smm archive_entry_set_ctime(ae, 4, 0); 84231200Smm archive_entry_set_mtime(ae, 5, 0); 85231200Smm archive_entry_copy_pathname(ae, ".."); 86231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 87231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 88231200Smm archive_entry_free(ae); 89231200Smm 90231200Smm /* Add "/" entry which must be ignored. */ 91231200Smm assert((ae = archive_entry_new()) != NULL); 92231200Smm archive_entry_set_atime(ae, 2, 0); 93231200Smm archive_entry_set_ctime(ae, 4, 0); 94231200Smm archive_entry_set_mtime(ae, 5, 0); 95231200Smm archive_entry_copy_pathname(ae, "/"); 96231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 97231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 98231200Smm archive_entry_free(ae); 99231200Smm 100231200Smm /* Add "../" entry which must be ignored. */ 101231200Smm assert((ae = archive_entry_new()) != NULL); 102231200Smm archive_entry_set_atime(ae, 2, 0); 103231200Smm archive_entry_set_ctime(ae, 4, 0); 104231200Smm archive_entry_set_mtime(ae, 5, 0); 105231200Smm archive_entry_copy_pathname(ae, "../"); 106231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 107231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 108231200Smm archive_entry_free(ae); 109231200Smm 110231200Smm /* Add "../../." entry which must be ignored. */ 111231200Smm assert((ae = archive_entry_new()) != NULL); 112231200Smm archive_entry_set_atime(ae, 2, 0); 113231200Smm archive_entry_set_ctime(ae, 4, 0); 114231200Smm archive_entry_set_mtime(ae, 5, 0); 115231200Smm archive_entry_copy_pathname(ae, "../../."); 116231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 117231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 118231200Smm archive_entry_free(ae); 119231200Smm 120231200Smm /* Add "..//.././" entry which must be ignored. */ 121231200Smm assert((ae = archive_entry_new()) != NULL); 122231200Smm archive_entry_set_atime(ae, 2, 0); 123231200Smm archive_entry_set_ctime(ae, 4, 0); 124231200Smm archive_entry_set_mtime(ae, 5, 0); 125231200Smm archive_entry_copy_pathname(ae, "..//.././"); 126231200Smm archive_entry_set_mode(ae, S_IFDIR | 0755); 127231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); 128231200Smm archive_entry_free(ae); 129231200Smm 130231200Smm /* Close out the archive. */ 131231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 132231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a)); 133231200Smm 134231200Smm assert(used == 2048 * 181); 135231200Smm /* Check System Area. */ 136231200Smm for (i = 0; i < 2048 * 16; i++) { 137231200Smm failure("System Area should be all nulls."); 138231200Smm assert(buff[i] == 0); 139231200Smm } 140231200Smm 141231200Smm /* Primary Volume. */ 142231200Smm failure("Primary Volume Descriptor should be in 16 Logical Sector."); 143231200Smm assertEqualMem(buff+2048*16, primary_id, 8); 144231200Smm assertEqualMem(buff+2048*16+0x28, 145231200Smm "CDROM ", 32); 146231200Smm assertEqualMem(buff+2048*16+0x50, volumesize, 8); 147231200Smm 148231200Smm /* Supplementary Volume. */ 149231200Smm failure("Supplementary Volume(Joliet) Descriptor " 150231200Smm "should be in 17 Logical Sector."); 151231200Smm assertEqualMem(buff+2048*17, supplementary_id, 8); 152231200Smm assertEqualMem(buff+2048*17+0x28, volumeidu16, 32); 153231200Smm assertEqualMem(buff+2048*17+0x50, volumesize, 8); 154231200Smm failure("Date and Time of Primary Volume and " 155231200Smm "Date and Time of Supplementary Volume " 156231200Smm "must be the same."); 157231200Smm assertEqualMem(buff+2048*16+0x32d, buff+2048*17+0x32d, 0x44); 158231200Smm 159231200Smm /* Terminator. */ 160231200Smm failure("Volume Descriptor Set Terminator " 161231200Smm "should be in 18 Logical Sector."); 162231200Smm assertEqualMem(buff+2048*18, terminator_id, 8); 163231200Smm for (i = 8; i < 2048; i++) { 164231200Smm failure("Body of Volume Descriptor Set Terminator " 165231200Smm "should be all nulls."); 166231200Smm assert(buff[2048*18+i] == 0); 167231200Smm } 168231200Smm 169231200Smm /* Padding data. */ 170231200Smm for (i = 0; i < 2048*150; i++) { 171231200Smm failure("Padding data should be all nulls."); 172231200Smm assert(buff[2048*31+i] == 0); 173231200Smm } 174231200Smm 175231200Smm /* 176231200Smm * Read ISO image. 177231200Smm */ 178231200Smm assert((a = archive_read_new()) != NULL); 179231200Smm assertEqualIntA(a, 0, archive_read_support_format_all(a)); 180231200Smm assertEqualIntA(a, 0, archive_read_support_filter_all(a)); 181231200Smm assertEqualIntA(a, 0, archive_read_open_memory(a, buff, used)); 182231200Smm 183231200Smm /* 184231200Smm * Read Root Directory 185231200Smm * Root Directory entry must be in ISO image. 186231200Smm */ 187231200Smm assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); 188231200Smm assertEqualInt(archive_entry_atime(ae), archive_entry_ctime(ae)); 189231200Smm assertEqualInt(archive_entry_atime(ae), archive_entry_mtime(ae)); 190231200Smm assertEqualString(".", archive_entry_pathname(ae)); 191231200Smm assert((S_IFDIR | 0555) == archive_entry_mode(ae)); 192231200Smm assertEqualInt(2048, archive_entry_size(ae)); 193231200Smm 194231200Smm /* 195231200Smm * Verify the end of the archive. 196231200Smm */ 197231200Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 198231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 199231200Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); 200231200Smm 201231200Smm free(buff); 202231200Smm} 203