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$");
28 /* Single entry with a hardlink. */
29 static unsigned char archive[] = {
31 "file type=file uid=18 mode=0123\n"
33 " file\\040with\\040space type=file uid=18\n"
35 "file\\04with\\040space type=file\n"
38 " indir3a type=file\n"
39 "dir2/fullindir2 type=file mode=0777\n"
43 " indir3b type=file\n"
46 "notindir type=file\n"
47 "dir2/fullindir2 mode=0644\n"
50 DEFINE_TEST(test_read_format_mtree)
52 struct archive_entry *ae;
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);
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);
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)));
73 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
74 assertEqualString(archive_entry_pathname(ae), "dir/file with space");
76 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
77 assertEqualString(archive_entry_pathname(ae), "file\\04with space");
79 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
80 assertEqualString(archive_entry_pathname(ae), "dir2");
82 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
83 assertEqualString(archive_entry_pathname(ae), "dir2/dir3a");
85 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
86 assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a");
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);
92 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
93 assertEqualString(archive_entry_pathname(ae), "dir2/indir2");
95 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
96 assertEqualString(archive_entry_pathname(ae), "dir2/dir3b");
98 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
99 assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b");
101 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
102 assertEqualString(archive_entry_pathname(ae), "notindir");
104 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
105 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
106 #if ARCHIVE_VERSION_NUMBER < 2000000
107 archive_read_finish(a);
109 assertEqualInt(ARCHIVE_OK, archive_read_finish(a));