1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2003-2010 Tim Kientzle
5 * All rights reserved.
6 */
7 #include "test.h"
8
DEFINE_TEST(test_option_gid_gname)9 DEFINE_TEST(test_option_gid_gname)
10 {
11 char *reference, *data;
12 size_t s;
13
14 assertUmask(0);
15 assertMakeFile("file", 0644, "1234567890");
16
17 /* Create archive with no special options. */
18 failure("Error invoking %s c", testprog);
19 assertEqualInt(0,
20 systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
21 testprog));
22 assertEmptyFile("stdout1.txt");
23 assertEmptyFile("stderr1.txt");
24 reference = slurpfile(&s, "archive1");
25
26 /* Again with both --gid and --gname */
27 failure("Error invoking %s c", testprog);
28 assertEqualInt(0,
29 systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
30 testprog));
31 assertEmptyFile("stdout2.txt");
32 assertEmptyFile("stderr2.txt");
33 data = slurpfile(&s, "archive2");
34 /* Should force gid and gname fields in ustar header. */
35 assertEqualMem(data + 116, "000021 \0", 8);
36 assertEqualMem(data + 297, "foofoofoo\0", 10);
37 free(data);
38
39 /* Again with just --gname */
40 failure("Error invoking %s c", testprog);
41 assertEqualInt(0,
42 systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
43 testprog));
44 assertEmptyFile("stdout4.txt");
45 assertEmptyFile("stderr4.txt");
46 data = slurpfile(&s, "archive4");
47 /* Gid should be unchanged from original reference. */
48 assertEqualMem(data + 116, reference + 116, 8);
49 assertEqualMem(data + 297, "foofoofoo\0", 10);
50 free(data);
51 free(reference);
52
53 /* Again with --gid and force gname to empty. */
54 failure("Error invoking %s c", testprog);
55 assertEqualInt(0,
56 systemf("%s cf archive3 --gid=17 --gname= --format=ustar file >stdout3.txt 2>stderr3.txt",
57 testprog));
58 assertEmptyFile("stdout3.txt");
59 assertEmptyFile("stderr3.txt");
60 data = slurpfile(&s, "archive3");
61 assertEqualMem(data + 116, "000021 \0", 8);
62 /* Gname field in ustar header should be empty. */
63 assertEqualMem(data + 297, "\0", 1);
64 free(data);
65
66 /* TODO: It would be nice to verify that --gid= by itself
67 * will look up the associated gname and use that, but
68 * that requires some system-specific code. */
69
70 /* TODO: It would be nice to verify that --gid= will
71 * leave the gname field blank if the specified gid
72 * isn't used on the local system. */
73 }
74