1 /*-
2 * Copyright (c) 2003-2009 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 static const char *
gname_lookup(void * d,int64_t g)29 gname_lookup(void *d, int64_t g)
30 {
31 (void)d; /* UNUSED */
32 (void)g; /* UNUSED */
33 return ("FOOGROUP");
34 }
35
36 static const char *
uname_lookup(void * d,int64_t u)37 uname_lookup(void *d, int64_t u)
38 {
39 (void)d; /* UNUSED */
40 (void)u; /* UNUSED */
41 return ("FOO");
42 }
43
DEFINE_TEST(test_read_disk_entry_from_file)44 DEFINE_TEST(test_read_disk_entry_from_file)
45 {
46 struct archive *a;
47 struct archive_entry *entry;
48 FILE *f;
49
50 assert((a = archive_read_disk_new()) != NULL);
51
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");
58
59 /* Create a file on disk. */
60 f = fopen("foo", "wb");
61 assert(f != NULL);
62 assertEqualInt(4, fwrite("1234", 1, 4, f));
63 fclose(f);
64
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 assertEqualIntA(a, ARCHIVE_OK,
70 archive_read_disk_entry_from_file(a, entry, -1, NULL));
71
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);
76
77 /* Destroy the archive. */
78 archive_entry_free(entry);
79 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
80 }
81