1 /*- 2 * Copyright (c) 2003-2010 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 27 DEFINE_TEST(test_option_gid_gname) 28 { 29 char *reference, *data; 30 size_t s; 31 32 assertUmask(0); 33 assertMakeFile("file", 0644, "1234567890"); 34 35 /* Create archive with no special options. */ 36 failure("Error invoking %s c", testprog); 37 assertEqualInt(0, 38 systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt", 39 testprog)); 40 assertEmptyFile("stdout1.txt"); 41 assertEmptyFile("stderr1.txt"); 42 reference = slurpfile(&s, "archive1"); 43 44 /* Again with both --gid and --gname */ 45 failure("Error invoking %s c", testprog); 46 assertEqualInt(0, 47 systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt", 48 testprog)); 49 assertEmptyFile("stdout2.txt"); 50 assertEmptyFile("stderr2.txt"); 51 data = slurpfile(&s, "archive2"); 52 /* Should force gid and gname fields in ustar header. */ 53 assertEqualMem(data + 116, "000021 \0", 8); 54 assertEqualMem(data + 297, "foofoofoo\0", 10); 55 free(data); 56 57 /* Again with just --gname */ 58 failure("Error invoking %s c", testprog); 59 assertEqualInt(0, 60 systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt", 61 testprog)); 62 assertEmptyFile("stdout4.txt"); 63 assertEmptyFile("stderr4.txt"); 64 data = slurpfile(&s, "archive4"); 65 /* Gid should be unchanged from original reference. */ 66 assertEqualMem(data + 116, reference + 116, 8); 67 assertEqualMem(data + 297, "foofoofoo\0", 10); 68 free(data); 69 free(reference); 70 71 /* Again with --gid and force gname to empty. */ 72 failure("Error invoking %s c", testprog); 73 assertEqualInt(0, 74 systemf("%s cf archive3 --gid=17 --gname= --format=ustar file >stdout3.txt 2>stderr3.txt", 75 testprog)); 76 assertEmptyFile("stdout3.txt"); 77 assertEmptyFile("stderr3.txt"); 78 data = slurpfile(&s, "archive3"); 79 assertEqualMem(data + 116, "000021 \0", 8); 80 /* Gname field in ustar header should be empty. */ 81 assertEqualMem(data + 297, "\0", 1); 82 free(data); 83 84 /* TODO: It would be nice to verify that --gid= by itself 85 * will look up the associated gname and use that, but 86 * that requires some system-specific code. */ 87 88 /* TODO: It would be nice to verify that --gid= will 89 * leave the gname field blank if the specified gid 90 * isn't used on the local system. */ 91 } 92