test_option_t.c revision 228753
1258945Sroberto/*- 2280849Scy * Copyright (c) 2003-2007 Tim Kientzle 3258945Sroberto * All rights reserved. 4258945Sroberto * 5258945Sroberto * Redistribution and use in source and binary forms, with or without 6258945Sroberto * modification, are permitted provided that the following conditions 7258945Sroberto * are met: 8258945Sroberto * 1. Redistributions of source code must retain the above copyright 9258945Sroberto * notice, this list of conditions and the following disclaimer. 10258945Sroberto * 2. Redistributions in binary form must reproduce the above copyright 11258945Sroberto * notice, this list of conditions and the following disclaimer in the 12258945Sroberto * documentation and/or other materials provided with the distribution. 13258945Sroberto * 14258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15258945Sroberto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16258945Sroberto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17258945Sroberto * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18280849Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19258945Sroberto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20258945Sroberto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21258945Sroberto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22258945Sroberto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23258945Sroberto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24258945Sroberto */ 25258945Sroberto#include "test.h" 26258945Sroberto__FBSDID("$FreeBSD$"); 27258945Sroberto 28258945Sroberto 29258945SrobertoDEFINE_TEST(test_option_t) 30258945Sroberto{ 31258945Sroberto char *p; 32258945Sroberto int r; 33258945Sroberto 34258945Sroberto /* List reference archive, make sure the TOC is correct. */ 35258945Sroberto extract_reference_file("test_option_t.cpio"); 36258945Sroberto r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog); 37258945Sroberto assertEqualInt(r, 0); 38258945Sroberto assertTextFileContents("1 block\n", "it.err"); 39258945Sroberto extract_reference_file("test_option_t.stdout"); 40258945Sroberto p = slurpfile(NULL, "test_option_t.stdout"); 41258945Sroberto assertTextFileContents(p, "it.out"); 42258945Sroberto free(p); 43258945Sroberto 44258945Sroberto /* We accept plain "-t" as a synonym for "-it" */ 45258945Sroberto r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog); 46258945Sroberto assertEqualInt(r, 0); 47258945Sroberto assertTextFileContents("1 block\n", "t.err"); 48258945Sroberto extract_reference_file("test_option_t.stdout"); 49258945Sroberto p = slurpfile(NULL, "test_option_t.stdout"); 50258945Sroberto assertTextFileContents(p, "t.out"); 51258945Sroberto free(p); 52258945Sroberto 53258945Sroberto /* But "-ot" is an error. */ 54258945Sroberto assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err", 55258945Sroberto testprog)); 56258945Sroberto assertEmptyFile("ot.out"); 57258945Sroberto 58258945Sroberto /* List reference archive verbosely, make sure the TOC is correct. */ 59258945Sroberto r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog); 60258945Sroberto assertEqualInt(r, 0); 61258945Sroberto assertTextFileContents("1 block\n", "tv.err"); 62258945Sroberto extract_reference_file("test_option_tv.stdout"); 63258945Sroberto 64258945Sroberto /* This doesn't work because the usernames on different systems 65258945Sroberto * are different and cpio now looks up numeric UIDs on 66258945Sroberto * the local system. */ 67258945Sroberto /* assertEqualFile("tv.out", "test_option_tv.stdout"); */ 68258945Sroberto 69258945Sroberto /* List reference archive with numeric IDs, verify TOC is correct. */ 70258945Sroberto r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err", 71258945Sroberto testprog); 72258945Sroberto assertEqualInt(r, 0); 73258945Sroberto assertTextFileContents("1 block\n", "itnv.err"); 74258945Sroberto p = slurpfile(NULL, "itnv.out"); 75258945Sroberto /* Since -n uses numeric UID/GID, this part should be the 76258945Sroberto * same on every system. */ 77258945Sroberto assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42); 78258945Sroberto /* Date varies depending on local timezone. */ 79258945Sroberto if (memcmp(p + 42, "Dec 31 1969", 12) == 0) { 80258945Sroberto /* East of Greenwich we get Dec 31, 1969. */ 81258945Sroberto } else { 82258945Sroberto /* West of Greenwich get Jan 1, 1970 */ 83258945Sroberto assertEqualMem(p + 42, "Jan ", 4); 84258945Sroberto /* Some systems format "Jan 01", some "Jan 1" */ 85258945Sroberto assert(p[46] == ' ' || p[46] == '0'); 86258945Sroberto assertEqualMem(p + 47, "1 1970 ", 8); 87258945Sroberto } 88258945Sroberto assertEqualMem(p + 54, " file", 5); 89258945Sroberto free(p); 90280849Scy 91280849Scy /* But "-n" without "-t" is an error. */ 92258945Sroberto assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err", 93258945Sroberto testprog)); 94258945Sroberto assertEmptyFile("in.out"); 95258945Sroberto} 96258945Sroberto