1 /*-
2 * Copyright (c) 2003-2009 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
27 /*
28 * Verify our ability to read various sample files.
29 * It should be easy to add any new sample files sent in by users
30 * to this collection of tests.
31 */
32
33 /* Copy this function for each test file and adjust it accordingly. */
34
35 /*
36 * test_compat_cpio_1.cpio checks heuristics for avoiding false
37 * hardlinks. foo1 and foo2 are files that have nlinks=1 and so
38 * should not be marked as hardlinks even though they have identical
39 * ino values. bar1 and bar2 have nlinks=2 so should be marked
40 * as hardlinks.
41 */
42 static void
test_compat_cpio_1(void)43 test_compat_cpio_1(void)
44 {
45 char name[] = "test_compat_cpio_1.cpio";
46 struct archive_entry *ae;
47 struct archive *a;
48
49 assert((a = archive_read_new()) != NULL);
50 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
51 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
52 extract_reference_file(name);
53 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 17));
54
55 /* Read first entry. */
56 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
57 assertEqualString("foo1", archive_entry_pathname(ae));
58 assertEqualString(NULL, archive_entry_hardlink(ae));
59 assertEqualInt(1260250228, archive_entry_mtime(ae));
60 assertEqualInt(1000, archive_entry_uid(ae));
61 assertEqualInt(1000, archive_entry_gid(ae));
62 assertEqualInt(0100644, archive_entry_mode(ae));
63
64 /* Read second entry. */
65 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
66 assertEqualString("foo2", archive_entry_pathname(ae));
67 assertEqualString(NULL, archive_entry_hardlink(ae));
68 assertEqualInt(1260250228, archive_entry_mtime(ae));
69 assertEqualInt(1000, archive_entry_uid(ae));
70 assertEqualInt(1000, archive_entry_gid(ae));
71 assertEqualInt(0100644, archive_entry_mode(ae));
72
73 /* Read third entry. */
74 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
75 assertEqualString("bar1", archive_entry_pathname(ae));
76 assertEqualString(NULL, archive_entry_hardlink(ae));
77 assertEqualInt(1260250228, archive_entry_mtime(ae));
78 assertEqualInt(1000, archive_entry_uid(ae));
79 assertEqualInt(1000, archive_entry_gid(ae));
80 assertEqualInt(0100644, archive_entry_mode(ae));
81
82 /* Read fourth entry. */
83 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
84 assertEqualString("bar2", archive_entry_pathname(ae));
85 assertEqualString("bar1", archive_entry_hardlink(ae));
86 assertEqualInt(1260250228, archive_entry_mtime(ae));
87 assertEqualInt(1000, archive_entry_uid(ae));
88 assertEqualInt(1000, archive_entry_gid(ae));
89 assertEqualInt(0100644, archive_entry_mode(ae));
90
91 /* Verify that the format detection worked. */
92 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE);
93 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC);
94
95 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
96 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
97 }
98
99
DEFINE_TEST(test_compat_cpio)100 DEFINE_TEST(test_compat_cpio)
101 {
102 test_compat_cpio_1();
103 }
104
105
106