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__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isojoliet_bz2.c 201247 2009-12-30 05:59:21Z kientzle $");
31
32/*
33 * The data for this testcase was provided by Mike Qin <mikeandmore@gmail.com>
34 * and created with Nero.
35 */
36
37DEFINE_TEST(test_read_format_isojoliet_versioned)
38{
39	const char *refname = "test_read_format_iso_joliet_by_nero.iso.Z";
40	struct archive_entry *ae;
41	struct archive *a;
42
43	extract_reference_file(refname);
44	assert((a = archive_read_new()) != NULL);
45	assertEqualInt(0, archive_read_support_filter_all(a));
46	assertEqualInt(0, archive_read_support_format_all(a));
47	assertEqualInt(ARCHIVE_OK,
48	    archive_read_set_option(a, "iso9660", "rockridge", NULL));
49	assertEqualInt(ARCHIVE_OK,
50	    archive_read_open_filename(a, refname, 10240));
51
52	/* First entry is '.' root directory. */
53	assertEqualInt(0, archive_read_next_header(a, &ae));
54	assertEqualString(".", archive_entry_pathname(ae));
55	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
56
57	/* A directory. */
58	assertEqualInt(0, archive_read_next_header(a, &ae));
59	assertEqualString("test", archive_entry_pathname(ae));
60	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
61	assertEqualInt(archive_entry_is_encrypted(ae), 0);
62	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
63
64	/* A regular file which is called test.txt and has
65	 * ;1 appended to it because apparently Nero always
66	 * appends versions to all files in the joliet extension.
67	 *
68	 * We test to make sure the version has been stripped.
69	 */
70	assertEqualInt(0, archive_read_next_header(a, &ae));
71	assertEqualString("test/test.txt",
72	    archive_entry_pathname(ae));
73	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
74	assertEqualInt(archive_entry_is_encrypted(ae), 0);
75	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
76
77	/* End of archive. */
78	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
79
80	/* Verify archive format. */
81	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
82
83	/* Close the archive. */
84	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
85	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
86}
87
88