1 /*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2009 Michihiro NAKAJIMA
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 #include "test.h"
27
DEFINE_TEST(test_read_format_iso_multi_extent)28 DEFINE_TEST(test_read_format_iso_multi_extent)
29 {
30 const char *refname = "test_read_format_iso_multi_extent.iso.Z";
31 struct archive_entry *ae;
32 struct archive *a;
33 const void *p;
34 size_t size;
35 int64_t offset;
36 int i;
37
38 extract_reference_file(refname);
39 assert((a = archive_read_new()) != NULL);
40 assertEqualInt(0, archive_read_support_filter_all(a));
41 assertEqualInt(0, archive_read_support_format_all(a));
42 assertEqualInt(ARCHIVE_OK,
43 archive_read_open_filename(a, refname, 10240));
44
45 /* Retrieve each of the 2 files on the ISO image and
46 * verify that each one is what we expect. */
47 for (i = 0; i < 2; ++i) {
48 assertEqualInt(0, archive_read_next_header(a, &ae));
49
50 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
51 /* '.' root directory. */
52 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
53 assertEqualInt(2048, archive_entry_size(ae));
54 assertEqualInt(86401, archive_entry_mtime(ae));
55 assertEqualInt(0, archive_entry_mtime_nsec(ae));
56 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
57 assertEqualInt(1, archive_entry_uid(ae));
58 assertEqualIntA(a, ARCHIVE_EOF,
59 archive_read_data_block(a, &p, &size, &offset));
60 assertEqualInt((int)size, 0);
61 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
62 /* A regular file. */
63 assertEqualString("file", archive_entry_pathname(ae));
64 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
65 assertEqualInt(262280, archive_entry_size(ae));
66 assertEqualInt(0,
67 archive_read_data_block(a, &p, &size, &offset));
68 assertEqualInt(0, offset);
69 assertEqualMem(p, "head--head--head", 16);
70 assertEqualInt(86401, archive_entry_mtime(ae));
71 assertEqualInt(86401, archive_entry_atime(ae));
72 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
73 assertEqualInt(1, archive_entry_uid(ae));
74 assertEqualInt(2, archive_entry_gid(ae));
75 assertEqualInt(archive_entry_is_encrypted(ae), 0);
76 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
77 } else {
78 failure("Saw a file that shouldn't have been there");
79 assertEqualString(archive_entry_pathname(ae), "");
80 }
81 }
82
83 /* End of archive. */
84 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
85
86 /* Verify archive format. */
87 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
88 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
89
90 /* Close the archive. */
91 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
92 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
93 }
94
95
96