1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * Copyright (c) 2009 Michihiro NAKAJIMA
4228753Smm * All rights reserved.
5228753Smm *
6228753Smm * Redistribution and use in source and binary forms, with or without
7228753Smm * modification, are permitted provided that the following conditions
8228753Smm * are met:
9228753Smm * 1. Redistributions of source code must retain the above copyright
10228753Smm *    notice, this list of conditions and the following disclaimer.
11228753Smm * 2. Redistributions in binary form must reproduce the above copyright
12228753Smm *    notice, this list of conditions and the following disclaimer in the
13228753Smm *    documentation and/or other materials provided with the distribution.
14228753Smm *
15228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25228753Smm */
26228753Smm#include "test.h"
27228763Smm__FBSDID("$FreeBSD$");
28228753Smm
29228753SmmDEFINE_TEST(test_read_format_iso_multi_extent)
30228753Smm{
31228753Smm	const char *refname = "test_read_format_iso_multi_extent.iso.Z";
32228753Smm	struct archive_entry *ae;
33228753Smm	struct archive *a;
34228753Smm	const void *p;
35228753Smm	size_t size;
36232153Smm	int64_t offset;
37228753Smm	int i;
38228753Smm
39228753Smm	extract_reference_file(refname);
40228753Smm	assert((a = archive_read_new()) != NULL);
41232153Smm	assertEqualInt(0, archive_read_support_filter_all(a));
42228753Smm	assertEqualInt(0, archive_read_support_format_all(a));
43228753Smm	assertEqualInt(ARCHIVE_OK,
44228753Smm	    archive_read_open_filename(a, refname, 10240));
45228753Smm
46228753Smm	/* Retrieve each of the 2 files on the ISO image and
47228753Smm	 * verify that each one is what we expect. */
48228753Smm	for (i = 0; i < 2; ++i) {
49228753Smm		assertEqualInt(0, archive_read_next_header(a, &ae));
50228753Smm
51228753Smm		if (strcmp(".", archive_entry_pathname(ae)) == 0) {
52228753Smm			/* '.' root directory. */
53228753Smm			assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
54228753Smm			assertEqualInt(2048, archive_entry_size(ae));
55228753Smm			assertEqualInt(86401, archive_entry_mtime(ae));
56228753Smm			assertEqualInt(0, archive_entry_mtime_nsec(ae));
57228753Smm			assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
58228753Smm			assertEqualInt(1, archive_entry_uid(ae));
59228753Smm			assertEqualIntA(a, ARCHIVE_EOF,
60228753Smm			    archive_read_data_block(a, &p, &size, &offset));
61228753Smm			assertEqualInt((int)size, 0);
62228753Smm		} else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
63228753Smm			/* A regular file. */
64228753Smm			assertEqualString("file", archive_entry_pathname(ae));
65228753Smm			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
66228753Smm			assertEqualInt(262280, archive_entry_size(ae));
67228753Smm			assertEqualInt(0,
68228753Smm			    archive_read_data_block(a, &p, &size, &offset));
69228753Smm			assertEqualInt(0, offset);
70228753Smm			assertEqualMem(p, "head--head--head", 16);
71228753Smm			assertEqualInt(86401, archive_entry_mtime(ae));
72228753Smm			assertEqualInt(86401, archive_entry_atime(ae));
73228753Smm			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
74228753Smm			assertEqualInt(1, archive_entry_uid(ae));
75228753Smm			assertEqualInt(2, archive_entry_gid(ae));
76302001Smm			assertEqualInt(archive_entry_is_encrypted(ae), 0);
77302001Smm			assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
78228753Smm		} else {
79228753Smm			failure("Saw a file that shouldn't have been there");
80228753Smm			assertEqualString(archive_entry_pathname(ae), "");
81228753Smm		}
82228753Smm	}
83228753Smm
84228753Smm	/* End of archive. */
85228753Smm	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
86228753Smm
87228753Smm	/* Verify archive format. */
88248616Smm	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
89228753Smm	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
90228753Smm
91228753Smm	/* Close the archive. */
92232153Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
93232153Smm	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
94228753Smm}
95228753Smm
96228753Smm
97