From owner-p4-projects@FreeBSD.ORG Thu Jul 31 14:17:34 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8092A1065672; Thu, 31 Jul 2008 14:17:34 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 439B6106566B for ; Thu, 31 Jul 2008 14:17:34 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 35EEF8FC16 for ; Thu, 31 Jul 2008 14:17:34 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m6VEHYDY092377 for ; Thu, 31 Jul 2008 14:17:34 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6VEHYFc092375 for perforce@freebsd.org; Thu, 31 Jul 2008 14:17:34 GMT (envelope-from strauss@FreeBSD.org) Date: Thu, 31 Jul 2008 14:17:34 GMT Message-Id: <200807311417.m6VEHYFc092375@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 146318 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jul 2008 14:17:34 -0000 http://perforce.freebsd.org/chv.cgi?CH=146318 Change 146318 by strauss@strauss_marvelman on 2008/07/31 14:16:48 More tests Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#21 edit .. //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#4 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#21 (text+ko) ==== ==== //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#4 (text+ko) ==== @@ -1,14 +1,19 @@ /*- - * By Anselm Strauss. - */ +* By Anselm Strauss. +*/ #include "test.h" __FBSDID("$Id$ $Change$ $DateTime$ $Author$"); +/* Quick and dirty: Read 2-byte and 4-byte integers from Zip file. */ +static int i2(const char *p) { return ((p[0] & 0xff) | ((p[1] & 0xff) << 8)); } +static int i4(const char *p) { return (i2(p) | (i2(p + 2) << 16)); } + DEFINE_TEST(test_write_format_zip_no_compression) { struct archive *a; struct archive_entry *entry; char buff[100000]; + const char *p, *q, *buffend; size_t used; /* Create new ZIP archive in memory without padding. */ @@ -18,9 +23,9 @@ assertA(0 == archive_write_set_bytes_per_block(a, 1)); assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - + /* Write entries. */ - + /* Regular file */ assert((entry = archive_entry_new()) != NULL); archive_entry_set_pathname(entry, "file"); @@ -33,16 +38,61 @@ archive_entry_set_nlink(entry, 1); assertEqualIntA(a, 0, archive_write_header(a, entry)); assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); + archive_entry_free(entry); /* Close out the archive . */ assertA(0 == archive_write_close(a)); assertA(0 == archive_write_finish(a)); - /* Verify the correct format for an empy Zip archive. */ - //assertEqualInt(used, 22); - //assertEqualMem(buff, - // "PK\005\006\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", - // 22); + /* Verify the format of the Zip file. */ + buffend = buff + used; + + /* Verify "End of Central Directory" record. */ + /* Get address of end-of-central-directory record. */ + p = buffend - 22; /* Assumes there is no zip comment field. */ + failure("End-of-central-directory begins with PK\\005\\006 signature"); + assertEqualMem(p, "PK\005\006", 4); + failure("This must be disk 0"); + 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"); + assertEqualInt(i2(p + 8), i2(p + 10)); + failure("CD start (%d) + CD length (%d) should == archive size - 22", + i4(p + 12), i4(p + 16)); + assertEqualInt(i4(p + 12) + i4(p + 16), used - 22); + failure("no zip comment"); + assertEqualInt(i2(p + 20), 0); + + /* Get address of first entry in central directory. */ + p = buff + i4(buffend - 6); + failure("Central file record at offset %d should begin with" + " 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 + 12), XXXX); */ /* File time */ + /* assertEqualInt(i2(p + 14), XXXX); */ /* File date */ + /* assertEqualInt(i4(p + 16), XXXX); */ /* 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(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 */ + + /* Get address of local header for this file. */ + q = buff + i4(p + 42); + failure("Local file header at offset %d should begin with" + " PK\\003\\004 signature", + i4(p + 42)); + assertEqualMem(q, "PK\003\004", 4); + /* TODO: Verify local header */ - /* TODO: free archive entries */ }