10SN/A/*- 29330SN/A * Copyright (c) 2003-2007 Tim Kientzle 30SN/A * All rights reserved. 40SN/A * 50SN/A * Redistribution and use in source and binary forms, with or without 60SN/A * modification, are permitted provided that the following conditions 72362SN/A * are met: 80SN/A * 1. Redistributions of source code must retain the above copyright 92362SN/A * notice, this list of conditions and the following disclaimer. 100SN/A * 2. Redistributions in binary form must reproduce the above copyright 110SN/A * notice, this list of conditions and the following disclaimer in the 120SN/A * documentation and/or other materials provided with the distribution. 130SN/A * 140SN/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 150SN/A * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 160SN/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 170SN/A * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 180SN/A * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 190SN/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 200SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 212362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 222362SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 232362SN/A * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 240SN/A */ 250SN/A#include "test.h" 260SN/A 270SN/A/* 280SN/A * Check that an "empty" cpio archive is correctly created. 290SN/A */ 300SN/A 310SN/A/* Here's what an empty cpio archive should look like. */ 320SN/Astatic char ref[] = 330SN/A"070707" /* Magic number */ 340SN/A"000000" /* Dev = 0 */ 350SN/A"000000" /* ino = 0 */ 360SN/A"000000" /* mode = 0 */ 370SN/A"000000" /* uid = 0 */ 380SN/A"000000" /* gid = 0 */ 390SN/A"000001" /* nlink = 1 */ 400SN/A"000000" /* rdev = 0 */ 410SN/A"00000000000" /* mtime = 0 */ 420SN/A"000013" /* Namesize = 11 */ 430SN/A"00000000000" /* filesize = 0 */ 440SN/A"TRAILER!!!\0"; /* Name */ 450SN/A 460SN/ADEFINE_TEST(test_write_format_cpio_empty) 470SN/A{ 480SN/A struct archive *a; 490SN/A char buff[2048]; 500SN/A size_t used; 510SN/A 520SN/A /* Create a new archive in memory. */ 530SN/A assert((a = archive_write_new()) != NULL); 540SN/A assertA(0 == archive_write_set_format_cpio_odc(a)); 550SN/A assertA(0 == archive_write_add_filter_none(a)); 560SN/A /* 1-byte block size ensures we see only the required bytes. */ 570SN/A /* We're not testing the padding here. */ 580SN/A assertA(0 == archive_write_set_bytes_per_block(a, 1)); 590SN/A assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); 600SN/A assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); 610SN/A 620SN/A /* Close out the archive. */ 630SN/A assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); 640SN/A assertEqualInt(ARCHIVE_OK, archive_write_free(a)); 650SN/A 660SN/A failure("Empty cpio archive should be exactly 87 bytes, was %zu.", used); 6711813Savstepan assert(used == 87); 680SN/A failure("Empty cpio archive is incorrectly formatted."); 690SN/A assertEqualMem(buff, ref, 87); 700SN/A} 710SN/A