Date: Wed, 13 Aug 2008 21:31:11 GMT From: Anselm Strauss <strauss@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 147349 for review Message-ID: <200808132131.m7DLVBiC044579@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147349 Change 147349 by strauss@strauss_marvelman on 2008/08/13 21:30:44 Some more assertion tests. Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#35 edit .. //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#11 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#35 (text+ko) ==== @@ -362,8 +362,8 @@ */ memset(&h, 0, sizeof(h)); zip_encode(ZIP_SIGNATURE_FILE_HEADER, &h.signature, sizeof(h.signature)); + zip_encode(ZIP_VERSION_BY, &h.version_by, sizeof(h.version_by)); zip_encode(ZIP_VERSION_EXTRACT, &h.version_extract, sizeof(h.version_extract)); - zip_encode(ZIP_VERSION_BY, &h.version_by, sizeof(h.version_by)); zip_encode(ZIP_FLAGS, &h.flags, sizeof(h.flags)); entries = 0; ==== //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#11 (text+ko) ==== @@ -24,6 +24,7 @@ */ #include "test.h" +#include <zlib.h> __FBSDID("$Id$ $Change$ $DateTime$ $Author$"); /* Quick and dirty: Read 2-byte and 4-byte integers from Zip file. */ @@ -34,17 +35,26 @@ { struct archive *a; struct archive_entry *entry; - char data1[] = {'1', '2', '3', '4', '5'}; - char data2[] = {'6', '7', '8', '9', '0'}; char buff[100000]; const char *p, *q, *buffend; size_t used; int crc; + + /* File data */ + char file_name[] = "file"; + char file_data1[] = {'1', '2', '3', '4', '5'}; + char file_data2[] = {'6', '7', '8', '9', '0'}; + int file_perm = 00644; + + /* Folder data */ + char folder_name[] = "folder"; + int folder_perm = 00755; + + /* Time fields */ time_t t; struct tm *tm; - - t = time(NULL); - tm = localtime(&t); + t = time(NULL); + tm = localtime(&t); /* Create new ZIP archive in memory without padding. */ assert((a = archive_write_new()) != NULL); @@ -58,7 +68,7 @@ /* Regular file */ assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, "file"); + archive_entry_set_pathname(entry, file_name); archive_entry_set_mode(entry, S_IFREG | 0644); archive_entry_set_size(entry, 10); archive_entry_set_uid(entry, 80); @@ -68,14 +78,14 @@ archive_entry_set_nlink(entry, 1); archive_entry_set_mtime(entry, t, 0); assertEqualIntA(a, 0, archive_write_header(a, entry)); - assertEqualIntA(a, sizeof(data1), archive_write_data(a, data1, sizeof(data1))); - assertEqualIntA(a, sizeof(data2), archive_write_data(a, data2, sizeof(data2))); + assertEqualIntA(a, sizeof(file_data1), archive_write_data(a, file_data1, sizeof(file_data1))); + assertEqualIntA(a, sizeof(file_data2), archive_write_data(a, file_data2, sizeof(file_data2))); archive_entry_free(entry); /* Folder */ /*assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, "folder"); - archive_entry_set_mode(entry, S_IFDIR | 0755); + archive_entry_set_pathname(entry, folder_name); + archive_entry_set_mode(entry, S_IFDIR | folder_perm); archive_entry_set_size(entry, 0); archive_entry_set_uid(entry, 80); archive_entry_set_gid(entry, 90); @@ -102,7 +112,7 @@ assertEqualInt(i2(p + 4), 0); failure("Central dir must start on disk 0"); assertEqualInt(i2(p + 6), 0); - failure("all central dir entries are on this disk"); + failure("All central dir entries are on this disk"); assertEqualInt(i2(p + 8), i2(p + 10)); failure("CD start (%d) + CD length (%d) should == archive size - 22", i4(p + 12), i4(p + 16)); @@ -116,24 +126,24 @@ " PK\\001\\002 signature", i4(buffend - 10)); assertEqualMem(p, "PK\001\002", 4); - /* TODO: Verify that this central file record makes sense. */ - /* assertEqualInt(i2(p + 4), XXXX); */ /* Version made by */ - /* assertEqualInt(i2(p + 6), XXXX); */ /* Version needed to extract */ - /* assertEqualInt(i2(p + 8), XXXX); */ /* Flags */ - /* assertEqualInt(i2(p + 10), XXXX); */ /* Compression method */ + assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ + assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ + assertEqualInt(i2(p + 8), 8); /* Flags */ + assertEqualInt(i2(p + 10), 0); /* Compression method */ assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - crc = crc32(0, &data1, sizeof(data1)); - crc = crc32(crc, &data2, sizeof(data2)); + crc = crc32(0, file_data1, sizeof(file_data1)); + crc = crc32(crc, file_data2, sizeof(file_data2)); assertEqualInt(i4(p + 16), crc); /* CRC-32 */ - /* assertEqualInt(i4(p + 20), XXXX); */ /* Compressed size */ - /* assertEqualInt(i4(p + 24), XXXX); */ /* Uncompressed size */ - /* assertEqualInt(i2(p + 28), XXXX); */ /* Filename length */ - /* assertEqualInt(i2(p + 30), XXXX); */ /* Extra field length */ + assertEqualInt(i4(p + 20), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ + assertEqualInt(i4(p + 24), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ + assertEqualInt(i2(p + 28), strlen(file_name)); /* Filename length */ + assertEqualInt(i2(p + 30), 13); /* Extra field length */ assertEqualInt(i2(p + 32), 0); /* File comment length */ assertEqualInt(i2(p + 34), 0); /* Disk number start */ - /* assertEqualInt(i2(p + 36), XXXX); */ /* Internal file attrs */ - /* assertEqualInt(i4(p + 38), XXXX); */ /* External file attrs */ + assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ + assertEqualInt(i4(p + 38) >> 16 & 01777, file_perm); /* External file attrs */ + /* Get address of local header for this file. */ q = buff + i4(p + 42);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808132131.m7DLVBiC044579>