pkgsrc - initial commit
[pkgsrc.git] / archivers / libarchive / files / 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: src/lib/libarchive/test/test_read_format_isorr_bz2.c,v 1.4 2008/06/21 19:11:51 kientzle Exp $");
27
28 /*
29 Execute the following 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 ln /tmp/iso/file /tmp/iso/hardlink
37 (cd /tmp/iso; ln -s file symlink)
38 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
39 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
40 mkhybrid -R -uid 1 -gid 2 /tmp/iso | bzip2 > test_read_format_isorr_bz2.iso.bz2
41 F=test_read_format_isorr_bz2.iso.bz2
42 uuencode $F $F > $F.uu
43 exit 1
44  */
45
46 DEFINE_TEST(test_read_format_isorr_bz2)
47 {
48         const char *refname = "test_read_format_isorr_bz2.iso.bz2";
49         struct archive_entry *ae;
50         struct archive *a;
51         const void *p;
52         size_t size;
53         off_t offset;
54
55         extract_reference_file(refname);
56         assert((a = archive_read_new()) != NULL);
57         assertEqualInt(0, archive_read_support_compression_all(a));
58         assertEqualInt(0, archive_read_support_format_all(a));
59         assertEqualInt(0, archive_read_open_filename(a, refname, 10240));
60
61         /* First entry is '.' root directory. */
62         assertEqualInt(0, archive_read_next_header(a, &ae));
63         assertEqualString(".", archive_entry_pathname(ae));
64         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
65         assertEqualInt(2048, archive_entry_size(ae));
66         assertEqualInt(86401, archive_entry_mtime(ae));
67         assertEqualInt(0, archive_entry_mtime_nsec(ae));
68         assertEqualInt(86401, archive_entry_ctime(ae));
69         assertEqualInt(0, archive_entry_stat(ae)->st_nlink);
70         assertEqualInt(0, archive_entry_uid(ae));
71         assertEqualIntA(a, ARCHIVE_EOF,
72             archive_read_data_block(a, &p, &size, &offset));
73         assertEqualInt(size, 0);
74
75         /* A directory. */
76         assertEqualInt(0, archive_read_next_header(a, &ae));
77         assertEqualString("dir", archive_entry_pathname(ae));
78         assert(S_ISDIR(archive_entry_stat(ae)->st_mode));
79         assertEqualInt(2048, archive_entry_size(ae));
80         assertEqualInt(86401, archive_entry_mtime(ae));
81         assertEqualInt(86401, archive_entry_atime(ae));
82         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
83         assertEqualInt(1, archive_entry_uid(ae));
84         assertEqualInt(2, archive_entry_gid(ae));
85
86         /* A regular file. */
87         assertEqualInt(0, archive_read_next_header(a, &ae));
88         assertEqualString("file", archive_entry_pathname(ae));
89         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
90         assertEqualInt(6, archive_entry_size(ae));
91         assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
92         assertEqualInt(6, size);
93         assertEqualInt(0, offset);
94         assertEqualInt(0, memcmp(p, "hello\n", 6));
95         assertEqualInt(86401, archive_entry_mtime(ae));
96         assertEqualInt(86401, archive_entry_atime(ae));
97         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
98         assertEqualInt(1, archive_entry_uid(ae));
99         assertEqualInt(2, archive_entry_gid(ae));
100
101         /* A hardlink to the regular file. */
102         assertEqualInt(0, archive_read_next_header(a, &ae));
103         assertEqualString("hardlink", archive_entry_pathname(ae));
104         assert(S_ISREG(archive_entry_stat(ae)->st_mode));
105         assertEqualString("file", archive_entry_hardlink(ae));
106         assertEqualInt(6, archive_entry_size(ae));
107         assertEqualInt(86401, archive_entry_mtime(ae));
108         assertEqualInt(86401, archive_entry_atime(ae));
109         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
110         assertEqualInt(1, archive_entry_uid(ae));
111         assertEqualInt(2, archive_entry_gid(ae));
112
113         /* A symlink to the regular file. */
114         assertEqualInt(0, archive_read_next_header(a, &ae));
115         assertEqualString("symlink", archive_entry_pathname(ae));
116         assert(S_ISLNK(archive_entry_stat(ae)->st_mode));
117         assertEqualString("file", archive_entry_symlink(ae));
118         assertEqualInt(0, archive_entry_size(ae));
119         assertEqualInt(172802, archive_entry_mtime(ae));
120         assertEqualInt(172802, archive_entry_atime(ae));
121         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
122         assertEqualInt(1, archive_entry_uid(ae));
123         assertEqualInt(2, archive_entry_gid(ae));
124
125         /* End of archive. */
126         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
127
128         /* Verify archive format. */
129         assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2);
130         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
131
132         /* Close the archive. */
133         assertEqualInt(0, archive_read_close(a));
134 #if ARCHIVE_API_VERSION > 1
135         assertEqualInt(0, archive_read_finish(a));
136 #else
137         archive_read_finish(a);
138 #endif
139 }
140
141