]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_read_format_iso_multi_extent.c
MFC r299529,r299540,r299576,r299896:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_read_format_iso_multi_extent.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 DEFINE_TEST(test_read_format_iso_multi_extent)
30 {
31         const char *refname = "test_read_format_iso_multi_extent.iso.Z";
32         struct archive_entry *ae;
33         struct archive *a;
34         const void *p;
35         size_t size;
36         int64_t offset;
37         int i;
38
39         extract_reference_file(refname);
40         assert((a = archive_read_new()) != NULL);
41         assertEqualInt(0, archive_read_support_filter_all(a));
42         assertEqualInt(0, archive_read_support_format_all(a));
43         assertEqualInt(ARCHIVE_OK,
44             archive_read_open_filename(a, refname, 10240));
45
46         /* Retrieve each of the 2 files on the ISO image and
47          * verify that each one is what we expect. */
48         for (i = 0; i < 2; ++i) {
49                 assertEqualInt(0, archive_read_next_header(a, &ae));
50
51                 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
52                         /* '.' root directory. */
53                         assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
54                         assertEqualInt(2048, archive_entry_size(ae));
55                         assertEqualInt(86401, archive_entry_mtime(ae));
56                         assertEqualInt(0, archive_entry_mtime_nsec(ae));
57                         assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
58                         assertEqualInt(1, archive_entry_uid(ae));
59                         assertEqualIntA(a, ARCHIVE_EOF,
60                             archive_read_data_block(a, &p, &size, &offset));
61                         assertEqualInt((int)size, 0);
62                 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
63                         /* A regular file. */
64                         assertEqualString("file", archive_entry_pathname(ae));
65                         assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
66                         assertEqualInt(262280, archive_entry_size(ae));
67                         assertEqualInt(0,
68                             archive_read_data_block(a, &p, &size, &offset));
69                         assertEqualInt(0, offset);
70                         assertEqualMem(p, "head--head--head", 16);
71                         assertEqualInt(86401, archive_entry_mtime(ae));
72                         assertEqualInt(86401, archive_entry_atime(ae));
73                         assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
74                         assertEqualInt(1, archive_entry_uid(ae));
75                         assertEqualInt(2, archive_entry_gid(ae));
76                         assertEqualInt(archive_entry_is_encrypted(ae), 0);
77                         assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
78                 } else {
79                         failure("Saw a file that shouldn't have been there");
80                         assertEqualString(archive_entry_pathname(ae), "");
81                 }
82         }
83
84         /* End of archive. */
85         assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
86
87         /* Verify archive format. */
88         assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
89         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
90
91         /* Close the archive. */
92         assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
93         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
94 }
95
96