1248590Smm/*-
2248590Smm * Copyright (c) 2012 Michihiro NAKAJIMA
3248590Smm * All rights reserved.
4248590Smm *
5248590Smm * Redistribution and use in source and binary forms, with or without
6248590Smm * modification, are permitted provided that the following conditions
7248590Smm * are met:
8248590Smm * 1. Redistributions of source code must retain the above copyright
9248590Smm *    notice, this list of conditions and the following disclaimer.
10248590Smm * 2. Redistributions in binary form must reproduce the above copyright
11248590Smm *    notice, this list of conditions and the following disclaimer in the
12248590Smm *    documentation and/or other materials provided with the distribution.
13248590Smm *
14248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15248590Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16248590Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17248590Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18248590Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19248590Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20248590Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21248590Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22248590Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23248590Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24248590Smm */
25248590Smm#include "test.h"
26248590Smm__FBSDID("$FreeBSD$");
27248590Smm
28248590Smm/*
29248590Smm * Read a zip file that has a zip comment in the end of the central
30248590Smm * directory record.
31248590Smm */
32248590Smmstatic void
33248590Smmverify(const char *refname)
34248590Smm{
35248590Smm	char *p;
36248590Smm	size_t s;
37248590Smm	struct archive *a;
38248590Smm	struct archive_entry *ae;
39248590Smm
40248590Smm	extract_reference_file(refname);
41248590Smm	p = slurpfile(&s, refname);
42248590Smm
43248590Smm	/* Symlinks can only be extracted with the seeking reader. */
44248590Smm	assert((a = archive_read_new()) != NULL);
45248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
46248590Smm	assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
47248590Smm
48248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
49248590Smm	assertEqualString("file0", archive_entry_pathname(ae));
50248590Smm	assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
51248590Smm
52248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
53248590Smm	assertEqualString("build.sh", archive_entry_pathname(ae));
54248590Smm	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
55248590Smm	assertEqualInt(23, archive_entry_size(ae));
56248590Smm
57248590Smm	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
58248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
59248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
60248590Smm}
61248590Smm
62248590SmmDEFINE_TEST(test_read_format_zip_comment_stored)
63248590Smm{
64248590Smm	verify("test_read_format_zip_comment_stored_1.zip");
65248590Smm	verify("test_read_format_zip_comment_stored_2.zip");
66248590Smm}
67