]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libarchive/test/test_read_format_mtree.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libarchive / test / test_read_format_mtree.c
1 /*-
2  * Copyright (c) 2003-2007 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 __FBSDID("$FreeBSD$");
27
28 /* Single entry with a hardlink. */
29 static unsigned char archive[] = {
30         "#mtree\n"
31         "file type=file uid=18 mode=0123\n"
32         "dir type=dir\n"
33         " file\\040with\\040space type=file uid=18\n"
34         " ..\n"
35         "file\\04with\\040space type=file\n"
36         "dir2 type=dir\n"
37         " dir3a type=dir\n"
38         "  indir3a type=file\n"
39         "dir2/fullindir2 type=file mode=0777\n"
40         "  ..\n"
41         " indir2 type=file\n"
42         " dir3b type=dir\n"
43         "  indir3b type=file\n"
44         "  ..\n"
45         " ..\n"
46         "notindir type=file\n"
47         "dir2/fullindir2 mode=0644\n"
48 };
49
50 DEFINE_TEST(test_read_format_mtree)
51 {
52         struct archive_entry *ae;
53         struct archive *a;
54
55         assert((a = archive_read_new()) != NULL);
56         assertEqualIntA(a, ARCHIVE_OK,
57             archive_read_support_compression_all(a));
58         assertEqualIntA(a, ARCHIVE_OK,
59             archive_read_support_format_all(a));
60         assertEqualIntA(a, ARCHIVE_OK,
61             archive_read_open_memory(a, archive, sizeof(archive)));
62         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
63         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE_V1);
64         assertEqualString(archive_entry_pathname(ae), "file");
65         assertEqualInt(archive_entry_uid(ae), 18);
66         assert(S_ISREG(archive_entry_mode(ae)));
67         assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123);
68
69         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
70         assertEqualString(archive_entry_pathname(ae), "dir");
71         assert(S_ISDIR(archive_entry_mode(ae)));
72
73         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
74         assertEqualString(archive_entry_pathname(ae), "dir/file with space");
75
76         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
77         assertEqualString(archive_entry_pathname(ae), "file\\04with space");
78
79         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
80         assertEqualString(archive_entry_pathname(ae), "dir2");
81
82         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
83         assertEqualString(archive_entry_pathname(ae), "dir2/dir3a");
84
85         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
86         assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a");
87
88         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
89         assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2");
90         assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
91
92         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
93         assertEqualString(archive_entry_pathname(ae), "dir2/indir2");
94
95         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
96         assertEqualString(archive_entry_pathname(ae), "dir2/dir3b");
97
98         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
99         assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b");
100
101         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
102         assertEqualString(archive_entry_pathname(ae), "notindir");
103
104         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
105         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
106 #if ARCHIVE_API_VERSION > 1
107         assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
108 #else
109         archive_read_finish(a);
110 #endif
111 }
112
113