2 * Copyright (c) 2003-2009 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$");
29 gname_lookup(void *d, gid_t g)
37 uname_lookup(void *d, uid_t u)
44 DEFINE_TEST(test_read_disk_entry_from_file)
47 struct archive_entry *entry;
50 assert((a = archive_read_disk_new()) != NULL);
52 assertEqualInt(ARCHIVE_OK, archive_read_disk_set_uname_lookup(a,
53 NULL, &uname_lookup, NULL));
54 assertEqualInt(ARCHIVE_OK, archive_read_disk_set_gname_lookup(a,
55 NULL, &gname_lookup, NULL));
56 assertEqualString(archive_read_disk_uname(a, 0), "FOO");
57 assertEqualString(archive_read_disk_gname(a, 0), "FOOGROUP");
59 /* Create a file on disk. */
60 fd = open("foo", O_WRONLY | O_CREAT, 0777);
62 assertEqualInt(4, write(fd, "1234", 4));
65 /* Use archive_read_disk_entry_from_file to get information about it. */
66 entry = archive_entry_new();
67 assert(entry != NULL);
68 archive_entry_copy_pathname(entry, "foo");
69 assertEqualInt(ARCHIVE_OK,
70 archive_read_disk_entry_from_file(a, entry, -1, NULL));
72 /* Verify the information we got back. */
73 assertEqualString(archive_entry_uname(entry), "FOO");
74 assertEqualString(archive_entry_gname(entry), "FOOGROUP");
75 assertEqualInt(archive_entry_size(entry), 4);
77 /* Destroy the archive. */
78 archive_entry_free(entry);
79 assertEqualInt(ARCHIVE_OK, archive_read_finish(a));