]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libarchive/test/test_read_format_ar.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libarchive / test / test_read_format_ar.c
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 #if ARCHIVE_VERSION_NUMBER >= 1009000
32 /*
33  * This "archive" is created by "GNU ar". Here we try to verify
34  * our GNU format handling functionality.
35  */
36 static unsigned char archive[] = {
37 '!','<','a','r','c','h','>',10,'/','/',' ',' ',' ',' ',' ',' ',' ',
38 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
39 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
40 ' ',' ',' ',' ',' ','4','0',' ',' ',' ',' ',' ',' ',' ',' ','`',10,
41 'y','y','y','t','t','t','s','s','s','a','a','a','f','f','f','.','o',
42 '/',10,'h','h','h','h','j','j','j','j','k','k','k','k','l','l','l',
43 'l','.','o','/',10,10,'/','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
44 ' ',' ',' ',' ','1','1','7','5','4','6','5','6','5','2',' ',' ','1',
45 '0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',
46 ' ',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'5','5','6',
47 '6','7','7','8','8','g','g','h','h','.','o','/',' ',' ',' ',' ',' ',
48 ' ',' ',' ',' ','1','1','7','5','4','6','5','6','6','8',' ',' ','1',
49 '0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',
50 ' ',' ','4',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'3','3','3',
51 '3','/','1','9',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
52 '1','1','7','5','4','6','5','7','1','3',' ',' ','1','0','0','1',' ',
53 ' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',' ',' ','9',' ',
54 ' ',' ',' ',' ',' ',' ',' ',' ','`',10,'9','8','7','6','5','4','3',
55 '2','1',10};
56
57 char buff[64];
58 #endif
59
60 DEFINE_TEST(test_read_format_ar)
61 {
62 #if ARCHIVE_VERSION_NUMBER < 1009000
63         skipping("test_read_support_format_ar()");
64 #else
65         struct archive_entry *ae;
66         struct archive *a;
67         assert((a = archive_read_new()) != NULL);
68         assertA(0 == archive_read_support_compression_all(a));
69         assertA(0 == archive_read_support_format_all(a));
70         assertA(0 == archive_read_open_memory(a, archive, sizeof(archive)));
71
72         /* Filename table.  */
73         assertA(0 == archive_read_next_header(a, &ae));
74         assertEqualString("//", archive_entry_pathname(ae));
75         assertEqualInt(0, archive_entry_mtime(ae));
76         assertEqualInt(0, archive_entry_uid(ae));
77         assertEqualInt(0, archive_entry_gid(ae));
78         assertEqualInt(0, archive_entry_size(ae));
79
80         /* First Entry */
81         assertA(0 == archive_read_next_header(a, &ae));
82         assertEqualString("yyytttsssaaafff.o", archive_entry_pathname(ae));
83         assertEqualInt(1175465652, archive_entry_mtime(ae));
84         assertEqualInt(1001, archive_entry_uid(ae));
85         assertEqualInt(0, archive_entry_gid(ae));
86         assert(8 == archive_entry_size(ae));
87         assertA(8 == archive_read_data(a, buff, 10));
88         assert(0 == memcmp(buff, "55667788", 8));
89
90         /* Second Entry */
91         assertA(0 == archive_read_next_header(a, &ae));
92         assertEqualString("gghh.o", archive_entry_pathname(ae));
93         assertEqualInt(1175465668, archive_entry_mtime(ae));
94         assertEqualInt(1001, archive_entry_uid(ae));
95         assertEqualInt(0, archive_entry_gid(ae));
96         assert(4 == archive_entry_size(ae));
97         assertA(4 == archive_read_data(a, buff, 10));
98         assert(0 == memcmp(buff, "3333", 4));
99
100         /* Third Entry */
101         assertA(0 == archive_read_next_header(a, &ae));
102         assertEqualString("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae));
103         assertEqualInt(1175465713, archive_entry_mtime(ae));
104         assertEqualInt(1001, archive_entry_uid(ae));
105         assertEqualInt(0, archive_entry_gid(ae));
106         assert(9 == archive_entry_size(ae));
107         assertA(9 == archive_read_data(a, buff, 9));
108         assert(0 == memcmp(buff, "987654321", 9));
109
110         /* Test EOF */
111         assertA(1 == archive_read_next_header(a, &ae));
112         assert(0 == archive_read_close(a));
113 #if ARCHIVE_VERSION_NUMBER < 2000000
114         archive_read_finish(a);
115 #else
116         assert(0 == archive_read_finish(a));
117 #endif
118 #endif
119 }