]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libarchive/libarchive/test/test_read_format_isozisofs_bz2.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libarchive / libarchive / test / test_read_format_isozisofs_bz2.c
1 /*-
2  * Copyright (c) 2003-2007 Tim Kientzle
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "test.h"
26 __FBSDID("$FreeBSD$");
27
28 /*
29 Execute the following command to rebuild the data for this program:
30    tail -n +32 test_read_format_isozisofs_bz2.c | /bin/sh
31
32 rm -rf /tmp/iso /tmp/ziso
33 mkdir /tmp/iso
34 mkdir /tmp/iso/dir
35 echo "hello" >/tmp/iso/file
36 dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file
37 ln /tmp/iso/file /tmp/iso/hardlink
38 (cd /tmp/iso; ln -s file symlink)
39 (cd /tmp/iso; ln -s /tmp/ symlink2)
40 (cd /tmp/iso; ln -s /tmp/../ symlink3)
41 (cd /tmp/iso; ln -s .././../tmp/ symlink4)
42 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
43 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
44 mkzftree /tmp/iso /tmp/ziso
45 TZ=utc touch -afhm -t 197001020000.01 /tmp/ziso /tmp/ziso/file /tmp/ziso/dir
46 TZ=utc touch -afhm -t 197001030000.02 /tmp/ziso/symlink
47 F=test_read_format_iso_zisofs.iso.Z
48 mkhybrid -R -uid 1 -gid 2 -z /tmp/ziso | compress > $F
49 uuencode $F $F > $F.uu
50 exit 1
51
52  */
53
54 DEFINE_TEST(test_read_format_isozisofs_bz2)
55 {
56         const char *refname = "test_read_format_iso_zisofs.iso.Z";
57         struct archive_entry *ae;
58         struct archive *a;
59         const void *p;
60         size_t size;
61         int64_t offset;
62         int i;
63
64         extract_reference_file(refname);
65         assert((a = archive_read_new()) != NULL);
66         assertEqualInt(0, archive_read_support_filter_all(a));
67         assertEqualInt(0, archive_read_support_format_all(a));
68         assertEqualInt(ARCHIVE_OK,
69             archive_read_open_filename(a, refname, 10240));
70
71         /* Retrieve each of the 8 files on the ISO image and
72          * verify that each one is what we expect. */
73         for (i = 0; i < 8; ++i) {
74                 assertEqualInt(0, archive_read_next_header(a, &ae));
75
76                 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
77                         /* '.' root directory. */
78                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
79                         assertEqualInt(2048, archive_entry_size(ae));
80                         /* Now, we read timestamp recorded by RRIP "TF". */
81                         assertEqualInt(86401, archive_entry_mtime(ae));
82                         assertEqualInt(0, archive_entry_mtime_nsec(ae));
83                         /* Now, we read links recorded by RRIP "PX". */
84                         assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
85                         assertEqualInt(1, archive_entry_uid(ae));
86                         assertEqualIntA(a, ARCHIVE_EOF,
87                             archive_read_data_block(a, &p, &size, &offset));
88                         assertEqualInt((int)size, 0);
89                 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
90                         /* A directory. */
91                         assertEqualString("dir", archive_entry_pathname(ae));
92                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
93                         assertEqualInt(2048, archive_entry_size(ae));
94                         assertEqualInt(86401, archive_entry_mtime(ae));
95                         assertEqualInt(86401, archive_entry_atime(ae));
96                         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
97                         assertEqualInt(1, archive_entry_uid(ae));
98                         assertEqualInt(2, archive_entry_gid(ae));
99                 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
100                         int r;
101                         /* A regular file. */
102                         assertEqualString("file", archive_entry_pathname(ae));
103                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
104                         assertEqualInt(12345684, archive_entry_size(ae));
105                         r = archive_read_data_block(a, &p, &size, &offset);
106                         if (r == ARCHIVE_FAILED) {
107                           skipping("Can't read body of ZISOFS entry.");
108                         } else {
109                           assertEqualInt(ARCHIVE_OK, r);
110                           assertEqualInt(0, offset);
111                           assertEqualMem(p, "hello\n", 6);
112                         }
113                         assertEqualInt(86401, archive_entry_mtime(ae));
114                         assertEqualInt(86401, archive_entry_atime(ae));
115                         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
116                         assertEqualInt(1, archive_entry_uid(ae));
117                         assertEqualInt(2, archive_entry_gid(ae));
118                 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
119                         /* A hardlink to the regular file. */
120                         /* Note: If "hardlink" gets returned before "file",
121                          * then "hardlink" will get returned as a regular file
122                          * and "file" will get returned as the hardlink.
123                          * This test should tolerate that, since it's a
124                          * perfectly permissible thing for libarchive to do. */
125                         assertEqualString("hardlink", archive_entry_pathname(ae));
126                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
127                         assertEqualString("file", archive_entry_hardlink(ae));
128                         assertEqualInt(0, archive_entry_size_is_set(ae));
129                         assertEqualInt(0, archive_entry_size(ae));
130                         assertEqualInt(86401, archive_entry_mtime(ae));
131                         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
132                         assertEqualInt(1, archive_entry_uid(ae));
133                         assertEqualInt(2, archive_entry_gid(ae));
134                 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
135                         /* A symlink to the regular file. */
136                         assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
137                         assertEqualString("file", archive_entry_symlink(ae));
138                         assertEqualInt(0, archive_entry_size(ae));
139                         assertEqualInt(172802, archive_entry_mtime(ae));
140                         assertEqualInt(172802, archive_entry_atime(ae));
141                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
142                         assertEqualInt(1, archive_entry_uid(ae));
143                         assertEqualInt(2, archive_entry_gid(ae));
144                 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
145                         /* A symlink to /tmp (an absolute path) */
146                         assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
147                         assertEqualString("/tmp", archive_entry_symlink(ae));
148                         assertEqualInt(0, archive_entry_size(ae));
149                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
150                         assertEqualInt(1, archive_entry_uid(ae));
151                         assertEqualInt(2, archive_entry_gid(ae));
152                 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
153                         /* A symlink to /tmp/.. (with a ".." component) */
154                         assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
155                         assertEqualString("/tmp/..", archive_entry_symlink(ae));
156                         assertEqualInt(0, archive_entry_size(ae));
157                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
158                         assertEqualInt(1, archive_entry_uid(ae));
159                         assertEqualInt(2, archive_entry_gid(ae));
160                 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
161                         /* A symlink to a path with ".." and "." components */
162                         assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
163                         assertEqualString(".././../tmp",
164                             archive_entry_symlink(ae));
165                         assertEqualInt(0, archive_entry_size(ae));
166                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
167                         assertEqualInt(1, archive_entry_uid(ae));
168                         assertEqualInt(2, archive_entry_gid(ae));
169                 } else {
170                         failure("Saw a file that shouldn't have been there");
171                         assertEqualString(archive_entry_pathname(ae), "");
172                 }
173         }
174
175         /* End of archive. */
176         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
177
178         /* Verify archive format. */
179         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
180         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
181
182         /* Close the archive. */
183         assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
184         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
185 }
186
187