]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_read_format_iso_xorriso.c
MFC r299529,r299540,r299576,r299896:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_read_format_iso_xorriso.c
1 /*-
2  * Copyright (c) 2011 Michihiro NAKAJIMA
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 /*
30 Execute the following command to rebuild the data for this program:
31    tail -n +32 test_read_format_iso_xorriso.c | /bin/sh
32 #
33 rm -rf /tmp/iso
34 mkdir /tmp/iso
35 mkdir /tmp/iso/dir
36 mkdir /tmp/iso/dir2
37 echo "hello" >/tmp/iso/file
38 ln /tmp/iso/file /tmp/iso/hardlink
39 (cd /tmp/iso; ln -s file symlink)
40 TZ=utc touch -afm -t 197001020000.01  /tmp/iso/empty
41 echo "hello2" >/tmp/iso/dir/file2
42 echo "hello3" >/tmp/iso/dir/file3
43 echo "hello4" >/tmp/iso/dir2/file4
44
45 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir/file2 /tmp/iso/dir/file3
46 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir2/file4
47 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
48 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir2
49 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
50 F=test_read_format_iso_xorriso.iso
51 xorriso -outdev - -map /tmp/iso / > $F
52 compress $F
53 uuencode $F.Z $F.Z > $F.Z.uu
54 rm $F.Z
55 exit 1
56  */
57
58 /*
59  * A test for the iso images made by xorriso which versions are
60  * from 0.6.5 to 1.0.1.
61  * The xorriso set 0 to the location of empty files(include symlink
62  * files) that caused our iso reader could not read following directory
63  * entries at all.
64  *
65  */
66
67 DEFINE_TEST(test_read_format_iso_xorriso)
68 {
69         const char *refname = "test_read_format_iso_xorriso.iso.Z";
70         struct archive_entry *ae;
71         struct archive *a;
72         const void *p;
73         size_t size;
74         int64_t offset;
75         int i;
76
77         extract_reference_file(refname);
78         assert((a = archive_read_new()) != NULL);
79         assertEqualInt(0, archive_read_support_filter_all(a));
80         assertEqualInt(0, archive_read_support_format_all(a));
81         assertEqualInt(ARCHIVE_OK,
82             archive_read_open_filename(a, refname, 10240));
83
84         /* Retrieve each of the 10 files on the ISO image and
85          * verify that each one is what we expect. */
86         for (i = 0; i < 10; ++i) {
87                 assertEqualInt(0, archive_read_next_header(a, &ae));
88
89                 assertEqualInt(archive_entry_is_encrypted(ae), 0);
90                 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
91
92                 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
93                         /* '.' root directory. */
94                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
95                         assertEqualInt(2048, archive_entry_size(ae));
96                         /* Now, we read timestamp recorded by RRIP "TF". */
97                         assertEqualInt(86401, archive_entry_mtime(ae));
98                         assertEqualInt(0, archive_entry_mtime_nsec(ae));
99                         /* Now, we read links recorded by RRIP "PX". */
100                         assertEqualInt(4, archive_entry_nlink(ae));
101                         assertEqualIntA(a, ARCHIVE_EOF,
102                             archive_read_data_block(a, &p, &size, &offset));
103                         assertEqualInt((int)size, 0);
104                 } else if (strcmp("./dir", archive_entry_pathname(ae)) == 0) {
105                         /* A directory. */
106                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
107                         assertEqualInt(2048, archive_entry_size(ae));
108                         assertEqualInt(86401, archive_entry_mtime(ae));
109                         assertEqualInt(86401, archive_entry_atime(ae));
110                         assertEqualInt(2, archive_entry_nlink(ae));
111                 } else if (strcmp("./dir2", archive_entry_pathname(ae)) == 0) {
112                         /* A directory. */
113                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
114                         assertEqualInt(2048, archive_entry_size(ae));
115                         assertEqualInt(86401, archive_entry_mtime(ae));
116                         assertEqualInt(86401, archive_entry_atime(ae));
117                         assertEqualInt(2, archive_entry_nlink(ae));
118                 } else if (strcmp("./file",
119                     archive_entry_pathname(ae)) == 0) {
120                         /* A regular file. */
121                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
122                         assertEqualInt(6, archive_entry_size(ae));
123                         assertEqualInt(0,
124                             archive_read_data_block(a, &p, &size, &offset));
125                         assertEqualInt(0, offset);
126                         assertEqualMem(p, "hello\n", 6);
127                         assertEqualInt(86401, archive_entry_mtime(ae));
128                         assertEqualInt(86401, archive_entry_atime(ae));
129                         assertEqualInt(2, archive_entry_nlink(ae));
130                 } else if (strcmp("./hardlink",
131                     archive_entry_pathname(ae)) == 0) {
132                         /* A hardlink to the regular file. */
133                         /* Note: If "hardlink" gets returned before "file",
134                          * then "hardlink" will get returned as a regular file
135                          * and "file" will get returned as the hardlink.
136                          * This test should tolerate that, since it's a
137                          * perfectly permissible thing for libarchive to do. */
138                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
139                         assertEqualString("./file", archive_entry_hardlink(ae));
140                         assertEqualInt(0, archive_entry_size_is_set(ae));
141                         assertEqualInt(0, archive_entry_size(ae));
142                         assertEqualInt(86401, archive_entry_mtime(ae));
143                         assertEqualInt(86401, archive_entry_atime(ae));
144                         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
145                 } else if (strcmp("./symlink",
146                     archive_entry_pathname(ae)) == 0) {
147                         /* A symlink to the regular file. */
148                         assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
149                         assertEqualString("file", archive_entry_symlink(ae));
150                         assertEqualInt(0, archive_entry_size(ae));
151                         assertEqualInt(172802, archive_entry_mtime(ae));
152                         assertEqualInt(172802, archive_entry_atime(ae));
153                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
154                 } else if (strcmp("./empty",
155                     archive_entry_pathname(ae)) == 0) {
156                         /* A empty file. */
157                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
158                         assertEqualInt(0, archive_entry_size(ae));
159                         assertEqualInt(86401, archive_entry_mtime(ae));
160                         assertEqualInt(86401, archive_entry_atime(ae));
161                         assertEqualInt(1, archive_entry_nlink(ae));
162                 } else if (strcmp("./dir/file2",
163                     archive_entry_pathname(ae)) == 0) {
164                         /* A regular file. */
165                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
166                         assertEqualInt(7, archive_entry_size(ae));
167                         assertEqualInt(0,
168                             archive_read_data_block(a, &p, &size, &offset));
169                         assertEqualInt(0, offset);
170                         assertEqualMem(p, "hello2\n", 7);
171                         assertEqualInt(86401, archive_entry_mtime(ae));
172                         assertEqualInt(86401, archive_entry_atime(ae));
173                         assertEqualInt(1, archive_entry_nlink(ae));
174                 } else if (strcmp("./dir/file3",
175                     archive_entry_pathname(ae)) == 0) {
176                         /* A regular file. */
177                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
178                         assertEqualInt(7, archive_entry_size(ae));
179                         assertEqualInt(0,
180                             archive_read_data_block(a, &p, &size, &offset));
181                         assertEqualInt(0, offset);
182                         assertEqualMem(p, "hello3\n", 7);
183                         assertEqualInt(86401, archive_entry_mtime(ae));
184                         assertEqualInt(86401, archive_entry_atime(ae));
185                         assertEqualInt(1, archive_entry_nlink(ae));
186                 } else if (strcmp("./dir2/file4",
187                     archive_entry_pathname(ae)) == 0) {
188                         /* A regular file. */
189                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
190                         assertEqualInt(7, archive_entry_size(ae));
191                         assertEqualInt(0,
192                             archive_read_data_block(a, &p, &size, &offset));
193                         assertEqualInt(0, offset);
194                         assertEqualMem(p, "hello4\n", 7);
195                         assertEqualInt(86401, archive_entry_mtime(ae));
196                         assertEqualInt(86401, archive_entry_atime(ae));
197                         assertEqualInt(1, archive_entry_nlink(ae));
198                 } else {
199                         failure("Saw a file that shouldn't have been there");
200                         assertEqualString(archive_entry_pathname(ae), "");
201                 }
202         }
203
204         /* End of archive. */
205         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
206
207         /* Verify archive format. */
208         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
209         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
210
211         /* Close the archive. */
212         assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
213         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
214 }
215
216