]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_read_format_isojoliet_long.c
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_read_format_isojoliet_long.c
1 /*-
2  * Copyright (c) 2003-2007 Tim Kientzle
3  * Copyright (c) 2009 Michihiro NAKAJIMA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #include "test.h"
27 __FBSDID("$FreeBSD$");
28
29 /*
30 Execute the following to rebuild the data for this program:
31    tail -n +35 test_read_format_isojoliet_long.c | /bin/sh
32
33 rm -rf /tmp/iso
34 mkdir /tmp/iso
35 num=0
36 file="";
37 while [ $num -lt 100 ]
38 do
39   num=$((num+10))
40   file="${file}1234567890"
41 done
42 dir="${file}dir"
43 mkdir /tmp/iso/${dir}
44 file="${file}123"
45 echo "hello" > /tmp/iso/${file}
46 ln /tmp/iso/${file} /tmp/iso/hardlink
47 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
48 TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
49 else
50 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
51 fi
52 F=test_read_format_iso_joliet_long.iso.Z
53 mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F
54 uuencode $F $F > $F.uu
55 rm -rf /tmp/iso
56 exit 1
57  */
58
59 DEFINE_TEST(test_read_format_isojoliet_long)
60 {
61         const char *refname = "test_read_format_iso_joliet_long.iso.Z";
62         char pathname[104];
63         struct archive_entry *ae;
64         struct archive *a;
65         const void *p;
66         size_t size;
67         int64_t offset;
68         int i;
69
70         for (i = 0; i < 100; i++)
71                 pathname[i] = '0' + ((i+1) % 10); 
72         extract_reference_file(refname);
73         assert((a = archive_read_new()) != NULL);
74         assertEqualInt(0, archive_read_support_filter_all(a));
75         assertEqualInt(0, archive_read_support_format_all(a));
76         assertEqualInt(ARCHIVE_OK,
77             archive_read_set_options(a, "iso9660:!rockridge"));
78         assertEqualInt(ARCHIVE_OK,
79             archive_read_open_filename(a, refname, 10240));
80
81         /* First entry is '.' root directory. */
82         assertEqualInt(0, archive_read_next_header(a, &ae));
83         assertEqualString(".", archive_entry_pathname(ae));
84         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
85         assertEqualInt(2048, archive_entry_size(ae));
86         assertEqualInt(86401, archive_entry_mtime(ae));
87         assertEqualInt(0, archive_entry_mtime_nsec(ae));
88         assertEqualInt(86401, archive_entry_ctime(ae));
89         assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
90         assertEqualInt(0, archive_entry_uid(ae));
91         assertEqualIntA(a, ARCHIVE_EOF,
92             archive_read_data_block(a, &p, &size, &offset));
93         assertEqualInt((int)size, 0);
94         assertEqualInt(archive_entry_is_encrypted(ae), 0);
95         assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
96
97         /* A directory. */
98         pathname[100] = 'd';
99         pathname[101] = 'i';
100         pathname[102] = 'r';
101         pathname[103] = '\0';
102         assertEqualInt(0, archive_read_next_header(a, &ae));
103         assertEqualString(pathname, archive_entry_pathname(ae));
104         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
105         assertEqualInt(2048, archive_entry_size(ae));
106         assertEqualInt(86401, archive_entry_mtime(ae));
107         assertEqualInt(86401, archive_entry_atime(ae));
108         assertEqualInt(archive_entry_is_encrypted(ae), 0);
109         assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
110
111         /* A regular file with two names (pathname gets returned
112          * first, so it's not marked as a hardlink). */
113         pathname[100] = '1';
114         pathname[101] = '2';
115         pathname[102] = '3';
116         pathname[103] = '\0';
117         assertEqualInt(0, archive_read_next_header(a, &ae));
118         assertEqualString("hardlink", archive_entry_pathname(ae));
119         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
120         assert(archive_entry_hardlink(ae) == NULL);
121         assertEqualInt(6, archive_entry_size(ae));
122         assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
123         assertEqualInt(6, (int)size);
124         assertEqualInt(0, offset);
125         assertEqualMem(p, "hello\n", 6);
126         assertEqualInt(archive_entry_is_encrypted(ae), 0);
127         assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
128
129         /* Second name for the same regular file (this happens to be
130          * returned second, so does get marked as a hardlink). */
131         assertEqualInt(0, archive_read_next_header(a, &ae));
132         assertEqualString(pathname, archive_entry_pathname(ae));
133         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
134         assertEqualString("hardlink", archive_entry_hardlink(ae));
135         assert(!archive_entry_size_is_set(ae));
136         assertEqualInt(archive_entry_is_encrypted(ae), 0);
137         assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
138
139         /* End of archive. */
140         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
141
142         /* Verify archive format. */
143         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
144
145         /* Close the archive. */
146         assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
147         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
148 }
149