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