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 is a SFX.
30248590Smm */
31248590SmmDEFINE_TEST(test_read_format_zip_sfx)
32248590Smm{
33248590Smm	const char *refname = "test_read_format_zip_sfx";
34248590Smm	char *p;
35248590Smm	size_t s;
36248590Smm	struct archive *a;
37248590Smm	struct archive_entry *ae;
38248590Smm
39248590Smm	extract_reference_file(refname);
40248590Smm	p = slurpfile(&s, refname);
41248590Smm
42248590Smm	/* Symlinks can only be extracted with the seeking reader. */
43248590Smm	assert((a = archive_read_new()) != NULL);
44248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
45248590Smm	assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
46248590Smm
47248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
48248590Smm	assertEqualString("file0", archive_entry_pathname(ae));
49248590Smm	assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
50248590Smm
51248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
52248590Smm	assertEqualString("build.sh", archive_entry_pathname(ae));
53248590Smm	assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
54248590Smm	assertEqualInt(23, archive_entry_size(ae));
55248590Smm
56248590Smm	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
57248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
58248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
59248590Smm}
60