xref: /NextBSD/contrib/libarchive/libarchive/test/test_read_format_ar.c (revision eb1a5f8de9f7ea602c373a710f531abbf81141c4)
1 /*-
2  * Copyright (c) 2007 Kai Wang
3  * Copyright (c) 2007 Tim Kientzle
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  *    in this position and unchanged.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "test.h"
29 __FBSDID("$FreeBSD$");
30 
31 
DEFINE_TEST(test_read_format_ar)32 DEFINE_TEST(test_read_format_ar)
33 {
34 	char buff[64];
35 	const char reffile[] = "test_read_format_ar.ar";
36 	struct archive_entry *ae;
37 	struct archive *a;
38 
39 	extract_reference_file(reffile);
40 	assert((a = archive_read_new()) != NULL);
41 	assertA(0 == archive_read_support_filter_all(a));
42 	assertA(0 == archive_read_support_format_all(a));
43 	assertA(0 == archive_read_open_filename(a, reffile, 7));
44 
45 	/* Filename table.  */
46 	assertA(0 == archive_read_next_header(a, &ae));
47 	assertEqualString("//", archive_entry_pathname(ae));
48 	assertEqualInt(0, archive_entry_mtime(ae));
49 	assertEqualInt(0, archive_entry_uid(ae));
50 	assertEqualInt(0, archive_entry_gid(ae));
51 	assertEqualInt(0, archive_entry_size(ae));
52 
53 	/* First Entry */
54 	assertA(0 == archive_read_next_header(a, &ae));
55 	assertEqualString("yyytttsssaaafff.o", archive_entry_pathname(ae));
56 	assertEqualInt(1175465652, archive_entry_mtime(ae));
57 	assertEqualInt(1001, archive_entry_uid(ae));
58 	assertEqualInt(0, archive_entry_gid(ae));
59 	assert(8 == archive_entry_size(ae));
60 	assertA(8 == archive_read_data(a, buff, 10));
61 	assertEqualMem(buff, "55667788", 8);
62 
63 	/* Second Entry */
64 	assertA(0 == archive_read_next_header(a, &ae));
65 	assertEqualString("gghh.o", archive_entry_pathname(ae));
66 	assertEqualInt(1175465668, archive_entry_mtime(ae));
67 	assertEqualInt(1001, archive_entry_uid(ae));
68 	assertEqualInt(0, archive_entry_gid(ae));
69 	assert(4 == archive_entry_size(ae));
70 	assertA(4 == archive_read_data(a, buff, 10));
71 	assertEqualMem(buff, "3333", 4);
72 
73 	/* Third Entry */
74 	assertA(0 == archive_read_next_header(a, &ae));
75 	assertEqualString("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae));
76 	assertEqualInt(1175465713, archive_entry_mtime(ae));
77 	assertEqualInt(1001, archive_entry_uid(ae));
78 	assertEqualInt(0, archive_entry_gid(ae));
79 	assert(9 == archive_entry_size(ae));
80 	assertA(9 == archive_read_data(a, buff, 9));
81 	assertEqualMem(buff, "987654321", 9);
82 
83 	/* Test EOF */
84 	assertA(1 == archive_read_next_header(a, &ae));
85 	assertEqualInt(4, archive_file_count(a));
86 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
87 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
88 }
89