16c95142eSMartin Matuska /*-
2*bd66c1b4SMartin Matuska * SPDX-License-Identifier: BSD-2-Clause
3*bd66c1b4SMartin Matuska *
46c95142eSMartin Matuska * Copyright (c) 2003-2010 Tim Kientzle
56c95142eSMartin Matuska * All rights reserved.
66c95142eSMartin Matuska */
76c95142eSMartin Matuska #include "test.h"
86c95142eSMartin Matuska
DEFINE_TEST(test_option_gid_gname)96c95142eSMartin Matuska DEFINE_TEST(test_option_gid_gname)
106c95142eSMartin Matuska {
116c95142eSMartin Matuska char *reference, *data;
126c95142eSMartin Matuska size_t s;
136c95142eSMartin Matuska
146c95142eSMartin Matuska assertUmask(0);
156c95142eSMartin Matuska assertMakeFile("file", 0644, "1234567890");
166c95142eSMartin Matuska
176c95142eSMartin Matuska /* Create archive with no special options. */
186c95142eSMartin Matuska failure("Error invoking %s c", testprog);
196c95142eSMartin Matuska assertEqualInt(0,
206c95142eSMartin Matuska systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
216c95142eSMartin Matuska testprog));
226c95142eSMartin Matuska assertEmptyFile("stdout1.txt");
236c95142eSMartin Matuska assertEmptyFile("stderr1.txt");
246c95142eSMartin Matuska reference = slurpfile(&s, "archive1");
256c95142eSMartin Matuska
266c95142eSMartin Matuska /* Again with both --gid and --gname */
276c95142eSMartin Matuska failure("Error invoking %s c", testprog);
286c95142eSMartin Matuska assertEqualInt(0,
296c95142eSMartin Matuska systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
306c95142eSMartin Matuska testprog));
316c95142eSMartin Matuska assertEmptyFile("stdout2.txt");
326c95142eSMartin Matuska assertEmptyFile("stderr2.txt");
336c95142eSMartin Matuska data = slurpfile(&s, "archive2");
346c95142eSMartin Matuska /* Should force gid and gname fields in ustar header. */
356c95142eSMartin Matuska assertEqualMem(data + 116, "000021 \0", 8);
366c95142eSMartin Matuska assertEqualMem(data + 297, "foofoofoo\0", 10);
3763ecfce8SEnji Cooper free(data);
386c95142eSMartin Matuska
396c95142eSMartin Matuska /* Again with just --gname */
406c95142eSMartin Matuska failure("Error invoking %s c", testprog);
416c95142eSMartin Matuska assertEqualInt(0,
426c95142eSMartin Matuska systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
436c95142eSMartin Matuska testprog));
446c95142eSMartin Matuska assertEmptyFile("stdout4.txt");
456c95142eSMartin Matuska assertEmptyFile("stderr4.txt");
466c95142eSMartin Matuska data = slurpfile(&s, "archive4");
476c95142eSMartin Matuska /* Gid should be unchanged from original reference. */
486c95142eSMartin Matuska assertEqualMem(data + 116, reference + 116, 8);
496c95142eSMartin Matuska assertEqualMem(data + 297, "foofoofoo\0", 10);
5063ecfce8SEnji Cooper free(data);
5163ecfce8SEnji Cooper free(reference);
526c95142eSMartin Matuska
536c95142eSMartin Matuska /* Again with --gid and force gname to empty. */
546c95142eSMartin Matuska failure("Error invoking %s c", testprog);
556c95142eSMartin Matuska assertEqualInt(0,
566c95142eSMartin Matuska systemf("%s cf archive3 --gid=17 --gname= --format=ustar file >stdout3.txt 2>stderr3.txt",
576c95142eSMartin Matuska testprog));
586c95142eSMartin Matuska assertEmptyFile("stdout3.txt");
596c95142eSMartin Matuska assertEmptyFile("stderr3.txt");
606c95142eSMartin Matuska data = slurpfile(&s, "archive3");
616c95142eSMartin Matuska assertEqualMem(data + 116, "000021 \0", 8);
626c95142eSMartin Matuska /* Gname field in ustar header should be empty. */
636c95142eSMartin Matuska assertEqualMem(data + 297, "\0", 1);
6463ecfce8SEnji Cooper free(data);
656c95142eSMartin Matuska
666c95142eSMartin Matuska /* TODO: It would be nice to verify that --gid= by itself
676c95142eSMartin Matuska * will look up the associated gname and use that, but
686c95142eSMartin Matuska * that requires some system-specific code. */
696c95142eSMartin Matuska
706c95142eSMartin Matuska /* TODO: It would be nice to verify that --gid= will
716c95142eSMartin Matuska * leave the gname field blank if the specified gid
726c95142eSMartin Matuska * isn't used on the local system. */
736c95142eSMartin Matuska }
74