1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Based on libarchive/test/test_read_format_isojoliet_bz2.c with
6 * bugs introduced by Andreas Henriksson <andreas@fatal.se> for
7 * testing ISO9660 image with Joliet extension and versioned files.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29#include "test.h"
30
31/*
32 * The data for this testcase was provided by Mike Qin <mikeandmore@gmail.com>
33 * and created with Nero.
34 */
35
36DEFINE_TEST(test_read_format_isojoliet_versioned)
37{
38	const char *refname = "test_read_format_iso_joliet_by_nero.iso.Z";
39	struct archive_entry *ae;
40	struct archive *a;
41
42	extract_reference_file(refname);
43	assert((a = archive_read_new()) != NULL);
44	assertEqualInt(0, archive_read_support_filter_all(a));
45	assertEqualInt(0, archive_read_support_format_all(a));
46	assertEqualInt(ARCHIVE_OK,
47	    archive_read_set_option(a, "iso9660", "rockridge", NULL));
48	assertEqualInt(ARCHIVE_OK,
49	    archive_read_open_filename(a, refname, 10240));
50
51	/* First entry is '.' root directory. */
52	assertEqualInt(0, archive_read_next_header(a, &ae));
53	assertEqualString(".", archive_entry_pathname(ae));
54	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
55
56	/* A directory. */
57	assertEqualInt(0, archive_read_next_header(a, &ae));
58	assertEqualString("test", archive_entry_pathname(ae));
59	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
60	assertEqualInt(archive_entry_is_encrypted(ae), 0);
61	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
62
63	/* A regular file which is called test.txt and has
64	 * ;1 appended to it because apparently Nero always
65	 * appends versions to all files in the joliet extension.
66	 *
67	 * We test to make sure the version has been stripped.
68	 */
69	assertEqualInt(0, archive_read_next_header(a, &ae));
70	assertEqualString("test/test.txt",
71	    archive_entry_pathname(ae));
72	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
73	assertEqualInt(archive_entry_is_encrypted(ae), 0);
74	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
75
76	/* End of archive. */
77	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
78
79	/* Verify archive format. */
80	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
81
82	/* Close the archive. */
83	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
84	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
85}
86
87