1109998Smarkm/*- 2109998Smarkm * Copyright (c) 2003-2007 Tim Kientzle 3109998Smarkm * All rights reserved. 4109998Smarkm * 5109998Smarkm * Redistribution and use in source and binary forms, with or without 6109998Smarkm * modification, are permitted provided that the following conditions 7109998Smarkm * are met: 8280304Sjkim * 1. Redistributions of source code must retain the above copyright 9109998Smarkm * notice, this list of conditions and the following disclaimer. 10109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 11109998Smarkm * notice, this list of conditions and the following disclaimer in the 12109998Smarkm * documentation and/or other materials provided with the distribution. 13109998Smarkm * 14109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15280304Sjkim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16109998Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17109998Smarkm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18109998Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20109998Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21109998Smarkm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22280304Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23109998Smarkm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24109998Smarkm */ 25109998Smarkm#include "test.h" 26109998Smarkm 27109998Smarkm/* 28109998Smarkm * Check that an "empty" tar archive is correctly created. 29109998Smarkm */ 30109998Smarkm 31109998SmarkmDEFINE_TEST(test_write_format_tar_empty) 32109998Smarkm{ 33109998Smarkm struct archive *a; 34109998Smarkm char buff[2048]; 35109998Smarkm size_t used; 36109998Smarkm unsigned int i; 37280304Sjkim 38109998Smarkm /* USTAR format: Create a new archive in memory. */ 39109998Smarkm assert((a = archive_write_new()) != NULL); 40280304Sjkim assertA(0 == archive_write_set_format_ustar(a)); 41109998Smarkm assertA(0 == archive_write_add_filter_none(a)); 42109998Smarkm assertA(0 == archive_write_set_bytes_per_block(a, 512)); 43109998Smarkm assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); 44109998Smarkm assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); 45109998Smarkm 46109998Smarkm /* Close out the archive. */ 47109998Smarkm assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 48109998Smarkm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 49109998Smarkm 50109998Smarkm assert(used == 1024); 51109998Smarkm for (i = 0; i < used; i++) { 52280304Sjkim failure("Empty tar archive should be all nulls."); 53109998Smarkm assert(buff[i] == 0); 54109998Smarkm } 55109998Smarkm 56109998Smarkm /* PAX format: Create a new archive in memory. */ 57109998Smarkm assert((a = archive_write_new()) != NULL); 58109998Smarkm assertA(0 == archive_write_set_format_pax(a)); 59109998Smarkm assertA(0 == archive_write_add_filter_none(a)); 60109998Smarkm assertA(0 == archive_write_set_bytes_per_block(a, 512)); 61109998Smarkm assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); 62109998Smarkm assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); 63109998Smarkm 64109998Smarkm /* Close out the archive. */ 65109998Smarkm assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 66109998Smarkm assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 67109998Smarkm 68109998Smarkm assertEqualInt((int)used, 1024); 69109998Smarkm for (i = 0; i < used; i++) { 70280304Sjkim failure("Empty tar archive should be all nulls."); 71280304Sjkim assert(buff[i] == 0); 72109998Smarkm } 73280304Sjkim} 74280304Sjkim