1228753Smm/*- 2228753Smm * Copyright (c) 2008 Anselm Strauss 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm */ 25228753Smm 26228753Smm/* 27228753Smm * Development supported by Google Summer of Code 2008. 28228753Smm */ 29228753Smm 30228753Smm#include "test.h" 31228763Smm__FBSDID("$FreeBSD: stable/10/contrib/libarchive/libarchive/test/test_write_format_zip_empty.c 311042 2017-01-02 01:43:11Z mm $"); 32228753Smm 33228753SmmDEFINE_TEST(test_write_format_zip_empty) 34228753Smm{ 35228753Smm struct archive *a; 36232153Smm struct archive_entry *ae; 37228753Smm char buff[256]; 38228753Smm size_t used; 39228753Smm 40228753Smm /* Zip format: Create a new archive in memory. */ 41228753Smm assert((a = archive_write_new()) != NULL); 42232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_zip(a)); 43248616Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a)); 44232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_set_bytes_per_block(a, 1)); 45232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_set_bytes_in_last_block(a, 1)); 46232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); 47228753Smm 48228753Smm /* Close out the archive without writing anything. */ 49232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 50232153Smm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 51228753Smm 52311042Smm /* Verify the correct format for an empty Zip archive. */ 53228753Smm assertEqualInt(used, 22); 54228753Smm assertEqualMem(buff, 55228753Smm "PK\005\006\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 56228753Smm 22); 57232153Smm 58232153Smm /* Verify that we read this kind of empty archive correctly. */ 59232153Smm /* Try with the standard memory reader, and with the test 60232153Smm memory reader with and without seek support. */ 61232153Smm assert((a = archive_read_new()) != NULL); 62232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); 63232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, 22)); 64232153Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 65232153Smm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 66232153Smm 67232153Smm assert((a = archive_read_new()) != NULL); 68232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); 69232153Smm assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, buff, 22, 1)); 70232153Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 71232153Smm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 72232153Smm 73232153Smm assert((a = archive_read_new()) != NULL); 74232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); 75232153Smm assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, 22, 22)); 76232153Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 77232153Smm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 78228753Smm} 79