1238106Sdes/*-
2238106Sdes * Copyright (c) 2003-2007 Tim Kientzle
3238106Sdes * All rights reserved.
4238106Sdes *
5238106Sdes * Redistribution and use in source and binary forms, with or without
6238106Sdes * modification, are permitted provided that the following conditions
7238106Sdes * are met:
8238106Sdes * 1. Redistributions of source code must retain the above copyright
9238106Sdes *    notice, this list of conditions and the following disclaimer.
10238106Sdes * 2. Redistributions in binary form must reproduce the above copyright
11238106Sdes *    notice, this list of conditions and the following disclaimer in the
12238106Sdes *    documentation and/or other materials provided with the distribution.
13238106Sdes *
14238106Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15238106Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16238106Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17238106Sdes * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18238106Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19238106Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20238106Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21238106Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22238106Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23238106Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24269257Sdes */
25269257Sdes#include "test.h"
26269257Sdes
27269257Sdes/*
28269257Sdes * Check that an "empty" shar archive is correctly created as an empty file.
29269257Sdes */
30269257Sdes
31269257SdesDEFINE_TEST(test_write_format_shar_empty)
32269257Sdes{
33269257Sdes	struct archive *a;
34238106Sdes	char buff[2048];
35238106Sdes	size_t used;
36238106Sdes
37238106Sdes	/* Create a new archive in memory. */
38238106Sdes	assert((a = archive_write_new()) != NULL);
39238106Sdes	assertA(0 == archive_write_set_format_shar(a));
40238106Sdes	assertA(0 == archive_write_add_filter_none(a));
41238106Sdes	/* 1-byte block size ensures we see only the required bytes. */
42238106Sdes	/* We're not testing the padding here. */
43238106Sdes	assertA(0 == archive_write_set_bytes_per_block(a, 1));
44238106Sdes	assertA(0 == archive_write_set_bytes_in_last_block(a, 1));
45238106Sdes	assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used));
46238106Sdes
47238106Sdes	/* Close out the archive. */
48238106Sdes	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
49238106Sdes	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
50238106Sdes
51238106Sdes	failure("Empty shar archive should be exactly 0 bytes, was %zu.", used);
52238106Sdes	assert(used == 0);
53238106Sdes}
54238106Sdes