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
29228753Smm/*
30228753SmmExecute the following to rebuild the data for this program:
31228753Smm   tail -n +35 test_read_format_isojoliet_long.c | /bin/sh
32228753Smm
33228753Smmrm -rf /tmp/iso
34228753Smmmkdir /tmp/iso
35228753Smmnum=0
36228753Smmfile="";
37228753Smmwhile [ $num -lt 100 ]
38228753Smmdo
39228753Smm  num=$((num+10))
40228753Smm  file="${file}1234567890"
41228753Smmdone
42228753Smmdir="${file}dir"
43228753Smmmkdir /tmp/iso/${dir}
44228753Smmfile="${file}123"
45228753Smmecho "hello" > /tmp/iso/${file}
46228753Smmln /tmp/iso/${file} /tmp/iso/hardlink
47228753Smmif [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
48228753SmmTZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
49228753Smmelse
50228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
51228753Smmfi
52228753SmmF=test_read_format_iso_joliet_long.iso.Z
53228753Smmmkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F
54228753Smmuuencode $F $F > $F.uu
55228753Smmrm -rf /tmp/iso
56228753Smmexit 1
57228753Smm */
58228753Smm
59228753SmmDEFINE_TEST(test_read_format_isojoliet_long)
60228753Smm{
61228753Smm	const char *refname = "test_read_format_iso_joliet_long.iso.Z";
62228753Smm	char pathname[104];
63228753Smm	struct archive_entry *ae;
64228753Smm	struct archive *a;
65228753Smm	const void *p;
66228753Smm	size_t size;
67232153Smm	int64_t offset;
68228753Smm	int i;
69228753Smm
70228753Smm	for (i = 0; i < 100; i++)
71228753Smm		pathname[i] = '0' + ((i+1) % 10);
72228753Smm	extract_reference_file(refname);
73228753Smm	assert((a = archive_read_new()) != NULL);
74232153Smm	assertEqualInt(0, archive_read_support_filter_all(a));
75228753Smm	assertEqualInt(0, archive_read_support_format_all(a));
76228753Smm	assertEqualInt(ARCHIVE_OK,
77228753Smm	    archive_read_set_options(a, "iso9660:!rockridge"));
78228753Smm	assertEqualInt(ARCHIVE_OK,
79228753Smm	    archive_read_open_filename(a, refname, 10240));
80228753Smm
81228753Smm	/* First entry is '.' root directory. */
82228753Smm	assertEqualInt(0, archive_read_next_header(a, &ae));
83228753Smm	assertEqualString(".", archive_entry_pathname(ae));
84228753Smm	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
85228753Smm	assertEqualInt(2048, archive_entry_size(ae));
86228753Smm	assertEqualInt(86401, archive_entry_mtime(ae));
87228753Smm	assertEqualInt(0, archive_entry_mtime_nsec(ae));
88228753Smm	assertEqualInt(86401, archive_entry_ctime(ae));
89228753Smm	assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
90228753Smm	assertEqualInt(0, archive_entry_uid(ae));
91228753Smm	assertEqualIntA(a, ARCHIVE_EOF,
92228753Smm	    archive_read_data_block(a, &p, &size, &offset));
93228753Smm	assertEqualInt((int)size, 0);
94228753Smm
95228753Smm	/* A directory. */
96228753Smm	pathname[100] = 'd';
97228753Smm	pathname[101] = 'i';
98228753Smm	pathname[102] = 'r';
99228753Smm	pathname[103] = '\0';
100228753Smm	assertEqualInt(0, archive_read_next_header(a, &ae));
101228753Smm	assertEqualString(pathname, archive_entry_pathname(ae));
102228753Smm	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
103228753Smm	assertEqualInt(2048, archive_entry_size(ae));
104228753Smm	assertEqualInt(86401, archive_entry_mtime(ae));
105228753Smm	assertEqualInt(86401, archive_entry_atime(ae));
106228753Smm
107228753Smm	/* A regular file with two names (pathname gets returned
108228753Smm	 * first, so it's not marked as a hardlink). */
109228753Smm	pathname[100] = '1';
110228753Smm	pathname[101] = '2';
111228753Smm	pathname[102] = '3';
112228753Smm	pathname[103] = '\0';
113228753Smm	assertEqualInt(0, archive_read_next_header(a, &ae));
114228753Smm	assertEqualString("hardlink", archive_entry_pathname(ae));
115228753Smm	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
116228753Smm	assert(archive_entry_hardlink(ae) == NULL);
117228753Smm	assertEqualInt(6, archive_entry_size(ae));
118228753Smm	assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
119228753Smm	assertEqualInt(6, (int)size);
120228753Smm	assertEqualInt(0, offset);
121232153Smm	assertEqualMem(p, "hello\n", 6);
122228753Smm
123228753Smm	/* Second name for the same regular file (this happens to be
124228753Smm	 * returned second, so does get marked as a hardlink). */
125228753Smm	assertEqualInt(0, archive_read_next_header(a, &ae));
126228753Smm	assertEqualString(pathname, archive_entry_pathname(ae));
127228753Smm	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
128228753Smm	assertEqualString("hardlink", archive_entry_hardlink(ae));
129228753Smm	assert(!archive_entry_size_is_set(ae));
130228753Smm
131228753Smm	/* End of archive. */
132228753Smm	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
133228753Smm
134228753Smm	/* Verify archive format. */
135248616Smm	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
136228753Smm
137228753Smm	/* Close the archive. */
138232153Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
139232153Smm	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
140228753Smm}
141228753Smm
142