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: head/lib/libarchive/test/test_read_format_ar.c 201247 2009-12-30 05:59:21Z kientzle $");
30 
31 
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_compression_all(a));
42 	assertA(0 == archive_read_support_format_all(a));
43 	assertA(0 == archive_read_open_file(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 	assert(0 == memcmp(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 	assert(0 == memcmp(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 	assert(0 == memcmp(buff, "987654321", 9));
82 
83 	/* Test EOF */
84 	assertA(1 == archive_read_next_header(a, &ae));
85 	assert(0 == archive_read_close(a));
86 	assert(0 == archive_read_finish(a));
87 }
88