Home | History | Annotate | Line # | Download | only in test
      1 /*-
      2  * SPDX-License-Identifier: BSD-2-Clause
      3  *
      4  * Copyright (c) 2003-2010 Tim Kientzle
      5  * Copyright (c) 2024 Haelwenn (lanodan) Monnier
      6  * All rights reserved.
      7  */
      8 #include "test.h"
      9 
     10 DEFINE_TEST(test_option_group)
     11 {
     12 	char *reference, *data;
     13 	size_t s;
     14 
     15 	assertUmask(0);
     16 	assertMakeFile("file", 0644, "1234567890");
     17 
     18 	/* Create archive with no special options. */
     19 	failure("Error invoking %s c", testprog);
     20 	assertEqualInt(0,
     21 	    systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
     22 		testprog));
     23 	assertEmptyFile("stdout1.txt");
     24 	assertEmptyFile("stderr1.txt");
     25 	reference = slurpfile(&s, "archive1");
     26 
     27 	/* Create archive with --group (numeric) */
     28 	failure("Error invoking %s c", testprog);
     29 	assertEqualInt(0,
     30 	    systemf("%s cf archive2 --group=17 --format=ustar file >stdout2.txt 2>stderr2.txt",
     31 		testprog));
     32 	assertEmptyFile("stdout2.txt");
     33 	assertEmptyFile("stderr2.txt");
     34 	data = slurpfile(&s, "archive2");
     35 	assertEqualMem(data + 116, "000021 \0", 8);
     36 	/* Gname field in ustar header should be empty. */
     37 	assertEqualMem(data + 297, "\0", 1);
     38 	free(data);
     39 
     40 	/* Again with --group (name) */
     41 	failure("Error invoking %s c", testprog);
     42 	assertEqualInt(0,
     43 	    systemf("%s cf archive3 --group=foofoofoo --format=ustar file >stdout3.txt 2>stderr3.txt",
     44 		testprog));
     45 	assertEmptyFile("stdout3.txt");
     46 	assertEmptyFile("stderr3.txt");
     47 	data = slurpfile(&s, "archive3");
     48 	/* Gid should be unchanged from original reference. */
     49 	assertEqualMem(data + 116, reference + 116, 8);
     50 	assertEqualMem(data + 297, "foofoofoo\0", 10);
     51 	free(data);
     52 
     53 	/* Again with --group (name:id) */
     54 	failure("Error invoking %s c", testprog);
     55 	assertEqualInt(0,
     56 	    systemf("%s cf archive4 --group=foofoofoo:17 --format=ustar file >stdout4.txt 2>stderr4.txt",
     57 		testprog));
     58 	assertEmptyFile("stdout4.txt");
     59 	assertEmptyFile("stderr4.txt");
     60 	data = slurpfile(&s, "archive4");
     61 	assertEqualMem(data + 116, "000021 \0", 8);
     62 	assertEqualMem(data + 297, "foofoofoo\0", 10);
     63 	free(data);
     64 
     65 	free(reference);
     66 }
     67