2
* Copyright (c) 2003-2007 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
26
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_mtree.c 201247 2009-12-30 05:59:21Z kientzle $");
29
test_read_format_mtree1(void)
31
const char reffile[] = "test_read_format_mtree.mtree";
33
struct archive_entry *ae;
37
extract_reference_file(reffile);
40
* An access error occurred on some platform when mtree
41
* format handling open a directory. It is for through
42
* the routine which open a directory that we create
43
* "dir" and "dir2" directories.
45
assertMakeDir("dir", 0775);
46
assertMakeDir("dir2", 0775);
48
assert((a = archive_read_new()) != NULL);
49
assertEqualIntA(a, ARCHIVE_OK,
50
archive_read_support_compression_all(a));
51
assertEqualIntA(a, ARCHIVE_OK,
52
archive_read_support_format_all(a));
53
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11));
56
* Read "file", whose data is available on disk.
58
f = fopen("file", "wb");
60
assertEqualInt(3, fwrite("hi\n", 1, 3, f));
62
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
63
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE);
64
assertEqualString(archive_entry_pathname(ae), "file");
65
assertEqualInt(archive_entry_uid(ae), 18);
66
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
67
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123);
68
assertEqualInt(archive_entry_size(ae), 3);
69
assertEqualInt(3, archive_read_data(a, buff, 3));
70
assertEqualMem(buff, "hi\n", 3);
72
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
73
assertEqualString(archive_entry_pathname(ae), "dir");
74
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
76
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
77
assertEqualString(archive_entry_pathname(ae), "dir/file with space");
79
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
80
assertEqualString(archive_entry_pathname(ae), "file with space");
82
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
83
assertEqualString(archive_entry_pathname(ae), "dir2");
85
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
86
assertEqualString(archive_entry_pathname(ae), "dir2/dir3a");
88
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
89
assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a");
91
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
92
assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2");
93
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
95
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
96
assertEqualString(archive_entry_pathname(ae), "dir2/indir2");
98
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
99
assertEqualString(archive_entry_pathname(ae), "dir2/dir3b");
101
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
102
assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b");
104
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
105
assertEqualString(archive_entry_pathname(ae), "notindir");
107
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
108
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
109
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
113
test_read_format_mtree2(void)
115
static char archive[] =
117
"d type=dir content=.\n";
118
struct archive_entry *ae;
121
assert((a = archive_read_new()) != NULL);
122
assertEqualIntA(a, ARCHIVE_OK,
123
archive_read_support_compression_all(a));
124
assertEqualIntA(a, ARCHIVE_OK,
125
archive_read_support_format_all(a));
126
assertEqualIntA(a, ARCHIVE_OK,
127
archive_read_open_memory(a, archive, sizeof(archive)));
128
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
129
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE);
130
assertEqualString(archive_entry_pathname(ae), "d");
131
assertEqualInt(archive_entry_filetype(ae), AE_IFDIR);
132
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
133
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
134
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
139
DEFINE_TEST(test_read_format_mtree)
141
test_read_format_mtree1();
142
test_read_format_mtree2();