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
28 /*
29 Execute the following to rebuild the data for this program:
30 tail -n +35 test_read_format_isojoliet_long.c | /bin/sh
31
32 rm -rf /tmp/iso
33 mkdir /tmp/iso
34 num=0
35 file="";
36 while [ $num -lt 100 ]
37 do
38 num=$((num+10))
39 file="${file}1234567890"
40 done
41 dir="${file}dir"
42 mkdir /tmp/iso/${dir}
43 file="${file}123"
44 echo "hello" > /tmp/iso/${file}
45 ln /tmp/iso/${file} /tmp/iso/hardlink
46 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
47 TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
48 else
49 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
50 fi
51 F=test_read_format_iso_joliet_long.iso.Z
52 mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F
53 uuencode $F $F > $F.uu
54 rm -rf /tmp/iso
55 exit 1
56 */
57
DEFINE_TEST(test_read_format_isojoliet_long)58 DEFINE_TEST(test_read_format_isojoliet_long)
59 {
60 const char *refname = "test_read_format_iso_joliet_long.iso.Z";
61 char pathname[104];
62 struct archive_entry *ae;
63 struct archive *a;
64 const void *p;
65 size_t size;
66 int64_t offset;
67 int i;
68
69 for (i = 0; i < 100; i++)
70 pathname[i] = '0' + ((i+1) % 10);
71 extract_reference_file(refname);
72 assert((a = archive_read_new()) != NULL);
73 assertEqualInt(0, archive_read_support_filter_all(a));
74 assertEqualInt(0, archive_read_support_format_all(a));
75 assertEqualInt(ARCHIVE_OK,
76 archive_read_set_options(a, "iso9660:!rockridge"));
77 assertEqualInt(ARCHIVE_OK,
78 archive_read_open_filename(a, refname, 10240));
79
80 /* First entry is '.' root directory. */
81 assertEqualInt(0, archive_read_next_header(a, &ae));
82 assertEqualString(".", archive_entry_pathname(ae));
83 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
84 assertEqualInt(2048, archive_entry_size(ae));
85 assertEqualInt(86401, archive_entry_mtime(ae));
86 assertEqualInt(0, archive_entry_mtime_nsec(ae));
87 assertEqualInt(86401, archive_entry_ctime(ae));
88 assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
89 assertEqualInt(0, archive_entry_uid(ae));
90 assertEqualIntA(a, ARCHIVE_EOF,
91 archive_read_data_block(a, &p, &size, &offset));
92 assertEqualInt((int)size, 0);
93 assertEqualInt(archive_entry_is_encrypted(ae), 0);
94 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
95
96 /* A directory. */
97 pathname[100] = 'd';
98 pathname[101] = 'i';
99 pathname[102] = 'r';
100 pathname[103] = '\0';
101 assertEqualInt(0, archive_read_next_header(a, &ae));
102 assertEqualString(pathname, archive_entry_pathname(ae));
103 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
104 assertEqualInt(2048, archive_entry_size(ae));
105 assertEqualInt(86401, archive_entry_mtime(ae));
106 assertEqualInt(86401, archive_entry_atime(ae));
107 assertEqualInt(archive_entry_is_encrypted(ae), 0);
108 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
109
110 /* A regular file with two names (pathname gets returned
111 * first, so it's not marked as a hardlink). */
112 pathname[100] = '1';
113 pathname[101] = '2';
114 pathname[102] = '3';
115 pathname[103] = '\0';
116 assertEqualInt(0, archive_read_next_header(a, &ae));
117 assertEqualString(pathname, archive_entry_pathname(ae));
118 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
119 assert(archive_entry_hardlink(ae) == NULL);
120 assertEqualInt(6, archive_entry_size(ae));
121 assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
122 assertEqualInt(6, (int)size);
123 assertEqualInt(0, offset);
124 assertEqualMem(p, "hello\n", 6);
125 assertEqualInt(archive_entry_is_encrypted(ae), 0);
126 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
127
128 /* Second name for the same regular file (this happens to be
129 * returned second, so does get marked as a hardlink). */
130 assertEqualInt(0, archive_read_next_header(a, &ae));
131 assertEqualString("hardlink", archive_entry_pathname(ae));
132 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
133 assertEqualString(pathname, archive_entry_hardlink(ae));
134 assert(!archive_entry_size_is_set(ae));
135 assertEqualInt(archive_entry_is_encrypted(ae), 0);
136 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
137
138 /* End of archive. */
139 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
140
141 /* Verify archive format. */
142 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
143
144 /* Close the archive. */
145 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
146 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
147 }
148
149