]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libarchive/test/test_read_format_isojoliet_bz2.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libarchive / test / test_read_format_isojoliet_bz2.c
1 /*-
2  * Copyright (c) 2003-2007 Tim Kientzle
3  * All rights reserved.
4  *
5  * Based on libarchive/test/test_read_format_isorr_bz2.c with
6  * bugs introduced by Andreas Henriksson <andreas@fatal.se> for
7  * testing ISO9660 image with Joliet extension.
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$");
31
32 /*
33 Execute the following to rebuild the data for this program:
34    tail -n +35 test_read_format_isojoliet_bz2.c | /bin/sh
35
36 rm -rf /tmp/iso
37 mkdir /tmp/iso
38 mkdir /tmp/iso/dir
39 echo "hello" >/tmp/iso/long-joliet-file-name.textfile
40 ln /tmp/iso/long-joliet-file-name.textfile /tmp/iso/hardlink
41 (cd /tmp/iso; ln -s long-joliet-file-name.textfile symlink)
42 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
43 TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir
44 TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink
45 else
46 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir
47 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
48 fi
49 mkhybrid -J -uid 1 -gid 2 /tmp/iso | bzip2 > test_read_format_isojoliet_bz2.iso.bz2
50 F=test_read_format_isojoliet_bz2.iso.bz2
51 uuencode $F $F > $F.uu
52 exit 1
53  */
54
55 static void
56 joliettest(int withrr)
57 {
58         const char *refname = "test_read_format_isojoliet_bz2.iso.bz2";
59         struct archive_entry *ae;
60         struct archive *a;
61         const void *p;
62         size_t size;
63         off_t offset;
64         int r;
65
66         if (withrr) {
67                 refname = "test_read_format_isojolietrr_bz2.iso.bz2";
68         }
69
70         extract_reference_file(refname);
71         assert((a = archive_read_new()) != NULL);
72         r = archive_read_support_compression_bzip2(a);
73         if (r == ARCHIVE_WARN) {
74                 skipping("bzip2 reading not fully supported on this platform");
75                 assertEqualInt(0, archive_read_finish(a));
76                 return;
77         }
78         assertEqualInt(0, r);
79         assertEqualInt(0, archive_read_support_format_all(a));
80         assertEqualInt(ARCHIVE_OK,
81             archive_read_open_filename(a, refname, 10240));
82
83         /* First entry is '.' root directory. */
84         assertEqualInt(0, archive_read_next_header(a, &ae));
85         assertEqualString(".", archive_entry_pathname(ae));
86         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
87         assertEqualInt(2048, archive_entry_size(ae));
88         assertEqualInt(86401, archive_entry_mtime(ae));
89         assertEqualInt(0, archive_entry_mtime_nsec(ae));
90         assertEqualInt(86401, archive_entry_ctime(ae));
91         assertEqualInt(0, archive_entry_stat(ae)->st_nlink);
92         assertEqualInt(0, archive_entry_uid(ae));
93         assertEqualIntA(a, ARCHIVE_EOF,
94             archive_read_data_block(a, &p, &size, &offset));
95         assertEqualInt((int)size, 0);
96
97         /* A directory. */
98         assertEqualInt(0, archive_read_next_header(a, &ae));
99         assertEqualString("dir", archive_entry_pathname(ae));
100         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
101         assertEqualInt(2048, archive_entry_size(ae));
102         assertEqualInt(86401, archive_entry_mtime(ae));
103         assertEqualInt(86401, archive_entry_atime(ae));
104         if (withrr) {
105                 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
106                 assertEqualInt(1, archive_entry_uid(ae));
107                 assertEqualInt(2, archive_entry_gid(ae));
108         }
109
110         /* A hardlink to the regular file. */
111         assertEqualInt(0, archive_read_next_header(a, &ae));
112         assertEqualString("hardlink", archive_entry_pathname(ae));
113         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
114         if (withrr) {
115                 assertEqualString("long-joliet-file-name.textfile",
116                     archive_entry_hardlink(ae));
117         }
118         assertEqualInt(6, archive_entry_size(ae));
119         assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
120         assertEqualInt(6, (int)size);
121         assertEqualInt(0, offset);
122         assertEqualInt(0, memcmp(p, "hello\n", 6));
123         if (withrr) {
124                 assertEqualInt(86401, archive_entry_mtime(ae));
125                 assertEqualInt(86401, archive_entry_atime(ae));
126                 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
127                 assertEqualInt(1, archive_entry_uid(ae));
128                 assertEqualInt(2, archive_entry_gid(ae));
129         }
130
131         /* A regular file. */
132         assertEqualInt(0, archive_read_next_header(a, &ae));
133         assertEqualString("long-joliet-file-name.textfile", archive_entry_pathname(ae));
134         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
135         assertEqualInt(6, archive_entry_size(ae));
136         if (withrr) {
137                 assertEqualInt(86401, archive_entry_mtime(ae));
138                 assertEqualInt(86401, archive_entry_atime(ae));
139                 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
140                 assertEqualInt(1, archive_entry_uid(ae));
141                 assertEqualInt(2, archive_entry_gid(ae));
142         }
143
144         /* A symlink to the regular file. */
145         assertEqualInt(0, archive_read_next_header(a, &ae));
146         assertEqualString("symlink", archive_entry_pathname(ae));
147         if (withrr) {
148                 assert(S_ISLNK(archive_entry_stat(ae)->st_mode));
149                 assertEqualString("long-joliet-file-name.textfile",
150                     archive_entry_symlink(ae));
151         }
152         assertEqualInt(0, archive_entry_size(ae));
153         assertEqualInt(172802, archive_entry_mtime(ae));
154         assertEqualInt(172802, archive_entry_atime(ae));
155         if (withrr) {
156                 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
157                 assertEqualInt(1, archive_entry_uid(ae));
158                 assertEqualInt(2, archive_entry_gid(ae));
159         }
160
161         /* End of archive. */
162         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
163
164         /* Verify archive format. */
165         assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2);
166         if (withrr) {
167                 assertEqualInt(archive_format(a),
168                     ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
169         }
170
171         /* Close the archive. */
172         assertEqualInt(0, archive_read_close(a));
173         assertEqualInt(0, archive_read_finish(a));
174 }
175
176
177 DEFINE_TEST(test_read_format_isojoliet_bz2)
178 {
179         joliettest(0);
180
181         /* XXXX This doesn't work today; can it be made to work? */
182 #if 0
183         joliettest(1);
184 #else
185         skipping("Mixed Joliet/RR not fully supported yet.");
186 #endif
187 }
188
189
190
191