]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libarchive/test/test_read_format_isorr_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_isorr_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_isorr_bz2.c | /bin/sh
31
32 rm -rf /tmp/iso
33 mkdir /tmp/iso
34 mkdir /tmp/iso/dir
35 echo "hello" >/tmp/iso/file
36 dd if=/dev/zero bs=1 count=12345678 >>/tmp/iso/file
37 ln /tmp/iso/file /tmp/iso/hardlink
38 (cd /tmp/iso; ln -s file symlink)
39 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
40 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
41 mkhybrid -R -uid 1 -gid 2 /tmp/iso | bzip2 > test_read_format_isorr_bz2.iso.bz2
42 F=test_read_format_isorr_bz2.iso.bz2
43 uuencode $F $F > $F.uu
44 exit 1
45  */
46
47 DEFINE_TEST(test_read_format_isorr_bz2)
48 {
49         const char *refname = "test_read_format_isorr_bz2.iso.bz2";
50         struct archive_entry *ae;
51         struct archive *a;
52         const void *p;
53         size_t size;
54         off_t offset;
55         int r;
56
57         extract_reference_file(refname);
58         assert((a = archive_read_new()) != NULL);
59         r = archive_read_support_compression_bzip2(a);
60         if (r == ARCHIVE_WARN) {
61                 skipping("bzip2 reading not fully supported on this platform");
62                 assertEqualInt(0, archive_read_finish(a));
63                 return;
64         }
65         assertEqualInt(0, r);
66         assertEqualInt(0, archive_read_support_format_all(a));
67         assertEqualInt(ARCHIVE_OK,
68             archive_read_open_filename(a, refname, 10240));
69
70         /* First entry is '.' root directory. */
71         assertEqualInt(0, archive_read_next_header(a, &ae));
72         assertEqualString(".", archive_entry_pathname(ae));
73         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
74         assertEqualInt(2048, archive_entry_size(ae));
75         assertEqualInt(86401, archive_entry_mtime(ae));
76         assertEqualInt(0, archive_entry_mtime_nsec(ae));
77         assertEqualInt(86401, archive_entry_ctime(ae));
78         assertEqualInt(0, archive_entry_stat(ae)->st_nlink);
79         assertEqualInt(0, archive_entry_uid(ae));
80         assertEqualIntA(a, ARCHIVE_EOF,
81             archive_read_data_block(a, &p, &size, &offset));
82         assertEqualInt((int)size, 0);
83
84         /* A directory. */
85         assertEqualInt(0, archive_read_next_header(a, &ae));
86         assertEqualString("dir", archive_entry_pathname(ae));
87         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
88         assertEqualInt(2048, archive_entry_size(ae));
89         assertEqualInt(86401, archive_entry_mtime(ae));
90         assertEqualInt(86401, archive_entry_atime(ae));
91         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
92         assertEqualInt(1, archive_entry_uid(ae));
93         assertEqualInt(2, archive_entry_gid(ae));
94
95         /* A regular file. */
96         assertEqualInt(0, archive_read_next_header(a, &ae));
97         assertEqualString("file", archive_entry_pathname(ae));
98         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
99         assertEqualInt(12345684, archive_entry_size(ae));
100         assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
101         assertEqualInt(0, offset);
102         assertEqualMem(p, "hello\n", 6);
103         assertEqualInt(86401, archive_entry_mtime(ae));
104         assertEqualInt(86401, archive_entry_atime(ae));
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         /* A hardlink to the regular file. */
110         assertEqualInt(0, archive_read_next_header(a, &ae));
111         assertEqualString("hardlink", archive_entry_pathname(ae));
112         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
113         assertEqualString("file", archive_entry_hardlink(ae));
114         assertEqualInt(12345684, archive_entry_size(ae));
115         assertEqualInt(86401, archive_entry_mtime(ae));
116         assertEqualInt(86401, archive_entry_atime(ae));
117         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
118         assertEqualInt(1, archive_entry_uid(ae));
119         assertEqualInt(2, archive_entry_gid(ae));
120
121         /* A symlink to the regular file. */
122         assertEqualInt(0, archive_read_next_header(a, &ae));
123         assertEqualString("symlink", archive_entry_pathname(ae));
124         assert(S_ISLNK(archive_entry_stat(ae)->st_mode));
125         assertEqualString("file", archive_entry_symlink(ae));
126         assertEqualInt(0, archive_entry_size(ae));
127         assertEqualInt(172802, archive_entry_mtime(ae));
128         assertEqualInt(172802, archive_entry_atime(ae));
129         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
130         assertEqualInt(1, archive_entry_uid(ae));
131         assertEqualInt(2, archive_entry_gid(ae));
132
133         /* End of archive. */
134         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
135
136         /* Verify archive format. */
137         assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2);
138         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
139
140         /* Close the archive. */
141         assertEqualInt(0, archive_read_close(a));
142 #if ARCHIVE_VERSION_NUMBER < 2000000
143         archive_read_finish(a);
144 #else
145         assertEqualInt(0, archive_read_finish(a));
146 #endif
147 }
148
149