test_option_t.c revision 228753
116239Sjkh/*- 24Srgrimes * Copyright (c) 2003-2007 Tim Kientzle 3509Srgrimes * All rights reserved. 443174Speter * 54Srgrimes * Redistribution and use in source and binary forms, with or without 6509Srgrimes * modification, are permitted provided that the following conditions 7509Srgrimes * are met: 84Srgrimes * 1. Redistributions of source code must retain the above copyright 94Srgrimes * notice, this list of conditions and the following disclaimer. 104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 114Srgrimes * notice, this list of conditions and the following disclaimer in the 124Srgrimes * documentation and/or other materials provided with the distribution. 134Srgrimes * 144Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 154Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 164Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 174Srgrimes * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 184Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1930640Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2041176Sdfr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2130640Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2242368Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2325083Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2427674Sphk */ 2527674Sphk#include "test.h" 262056Swollman__FBSDID("$FreeBSD$"); 272056Swollman 282056Swollman 294SrgrimesDEFINE_TEST(test_option_t) 302056Swollman{ 312056Swollman char *p; 324Srgrimes int r; 334836Sdg 3418518Sbde /* List reference archive, make sure the TOC is correct. */ 357627Snate extract_reference_file("test_option_t.cpio"); 367627Snate r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog); 377627Snate assertEqualInt(r, 0); 387627Snate assertTextFileContents("1 block\n", "it.err"); 397627Snate extract_reference_file("test_option_t.stdout"); 407627Snate p = slurpfile(NULL, "test_option_t.stdout"); 4125202Speter assertTextFileContents(p, "it.out"); 42712Swollman free(p); 4338714Sjb 4439537Sbde /* We accept plain "-t" as a synonym for "-it" */ 4539537Sbde r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog); 4639537Sbde assertEqualInt(r, 0); 4739537Sbde assertTextFileContents("1 block\n", "t.err"); 4839169Sjkh extract_reference_file("test_option_t.stdout"); 4939169Sjkh p = slurpfile(NULL, "test_option_t.stdout"); 5038714Sjb assertTextFileContents(p, "t.out"); 5139537Sbde free(p); 5239537Sbde 5338714Sjb /* But "-ot" is an error. */ 5438714Sjb assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err", 5538714Sjb testprog)); 5638714Sjb assertEmptyFile("ot.out"); 5738714Sjb 5838714Sjb /* List reference archive verbosely, make sure the TOC is correct. */ 59974Sdg r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog); 6027065Sbde assertEqualInt(r, 0); 6120395Sbde assertTextFileContents("1 block\n", "tv.err"); 6227065Sbde extract_reference_file("test_option_tv.stdout"); 6320395Sbde 6420395Sbde /* This doesn't work because the usernames on different systems 6520395Sbde * are different and cpio now looks up numeric UIDs on 6620395Sbde * the local system. */ 6720395Sbde /* assertEqualFile("tv.out", "test_option_tv.stdout"); */ 684Srgrimes 694Srgrimes /* List reference archive with numeric IDs, verify TOC is correct. */ 7037580Sbde r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err", 7139537Sbde testprog); 724Srgrimes assertEqualInt(r, 0); 7337580Sbde assertTextFileContents("1 block\n", "itnv.err"); 7439537Sbde p = slurpfile(NULL, "itnv.out"); 7537580Sbde /* Since -n uses numeric UID/GID, this part should be the 762408Sbde * same on every system. */ 7742771Speter assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42); 7842771Speter /* Date varies depending on local timezone. */ 7939537Sbde if (memcmp(p + 42, "Dec 31 1969", 12) == 0) { 8025985Sjdp /* East of Greenwich we get Dec 31, 1969. */ 8125985Sjdp } else { 8225985Sjdp /* West of Greenwich get Jan 1, 1970 */ 832408Sbde assertEqualMem(p + 42, "Jan ", 4); 8413031Sbde /* Some systems format "Jan 01", some "Jan 1" */ 855908Sbde assert(p[46] == ' ' || p[46] == '0'); 865908Sbde assertEqualMem(p + 47, "1 1970 ", 8); 875908Sbde } 8835514Simp assertEqualMem(p + 54, " file", 5); 8940907Speter free(p); 9025985Sjdp 9138714Sjb /* But "-n" without "-t" is an error. */ 9225537Sdfr assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err", 9335514Simp testprog)); 9438714Sjb assertEmptyFile("in.out"); 9525537Sdfr} 9638714Sjb