1*543adbedSBen Gras /*-
2*543adbedSBen Gras * Copyright (c) 2003-2007 Tim Kientzle
3*543adbedSBen Gras * All rights reserved.
4*543adbedSBen Gras *
5*543adbedSBen Gras * Redistribution and use in source and binary forms, with or without
6*543adbedSBen Gras * modification, are permitted provided that the following conditions
7*543adbedSBen Gras * are met:
8*543adbedSBen Gras * 1. Redistributions of source code must retain the above copyright
9*543adbedSBen Gras * notice, this list of conditions and the following disclaimer.
10*543adbedSBen Gras * 2. Redistributions in binary form must reproduce the above copyright
11*543adbedSBen Gras * notice, this list of conditions and the following disclaimer in the
12*543adbedSBen Gras * documentation and/or other materials provided with the distribution.
13*543adbedSBen Gras *
14*543adbedSBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*543adbedSBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*543adbedSBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*543adbedSBen Gras * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*543adbedSBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*543adbedSBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*543adbedSBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*543adbedSBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*543adbedSBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*543adbedSBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*543adbedSBen Gras */
25*543adbedSBen Gras #include "test.h"
26*543adbedSBen Gras __FBSDID("$FreeBSD$");
27*543adbedSBen Gras
28*543adbedSBen Gras
DEFINE_TEST(test_option_t)29*543adbedSBen Gras DEFINE_TEST(test_option_t)
30*543adbedSBen Gras {
31*543adbedSBen Gras char *p;
32*543adbedSBen Gras int r;
33*543adbedSBen Gras
34*543adbedSBen Gras /* List reference archive, make sure the TOC is correct. */
35*543adbedSBen Gras extract_reference_file("test_option_t.cpio");
36*543adbedSBen Gras r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog);
37*543adbedSBen Gras assertEqualInt(r, 0);
38*543adbedSBen Gras assertTextFileContents("1 block\n", "it.err");
39*543adbedSBen Gras extract_reference_file("test_option_t.stdout");
40*543adbedSBen Gras p = slurpfile(NULL, "test_option_t.stdout");
41*543adbedSBen Gras assertTextFileContents(p, "it.out");
42*543adbedSBen Gras free(p);
43*543adbedSBen Gras
44*543adbedSBen Gras /* We accept plain "-t" as a synonym for "-it" */
45*543adbedSBen Gras r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog);
46*543adbedSBen Gras assertEqualInt(r, 0);
47*543adbedSBen Gras assertTextFileContents("1 block\n", "t.err");
48*543adbedSBen Gras extract_reference_file("test_option_t.stdout");
49*543adbedSBen Gras p = slurpfile(NULL, "test_option_t.stdout");
50*543adbedSBen Gras assertTextFileContents(p, "t.out");
51*543adbedSBen Gras free(p);
52*543adbedSBen Gras
53*543adbedSBen Gras /* But "-ot" is an error. */
54*543adbedSBen Gras assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err",
55*543adbedSBen Gras testprog));
56*543adbedSBen Gras assertEmptyFile("ot.out");
57*543adbedSBen Gras
58*543adbedSBen Gras /* List reference archive verbosely, make sure the TOC is correct. */
59*543adbedSBen Gras r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog);
60*543adbedSBen Gras assertEqualInt(r, 0);
61*543adbedSBen Gras assertTextFileContents("1 block\n", "tv.err");
62*543adbedSBen Gras extract_reference_file("test_option_tv.stdout");
63*543adbedSBen Gras
64*543adbedSBen Gras /* This doesn't work because the usernames on different systems
65*543adbedSBen Gras * are different and cpio now looks up numeric UIDs on
66*543adbedSBen Gras * the local system. */
67*543adbedSBen Gras /* assertEqualFile("tv.out", "test_option_tv.stdout"); */
68*543adbedSBen Gras
69*543adbedSBen Gras /* List reference archive with numeric IDs, verify TOC is correct. */
70*543adbedSBen Gras r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err",
71*543adbedSBen Gras testprog);
72*543adbedSBen Gras assertEqualInt(r, 0);
73*543adbedSBen Gras assertTextFileContents("1 block\n", "itnv.err");
74*543adbedSBen Gras p = slurpfile(NULL, "itnv.out");
75*543adbedSBen Gras /* Since -n uses numeric UID/GID, this part should be the
76*543adbedSBen Gras * same on every system. */
77*543adbedSBen Gras assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42);
78*543adbedSBen Gras /* Date varies depending on local timezone. */
79*543adbedSBen Gras if (memcmp(p + 42, "Dec 31 1969", 12) == 0) {
80*543adbedSBen Gras /* East of Greenwich we get Dec 31, 1969. */
81*543adbedSBen Gras } else {
82*543adbedSBen Gras /* West of Greenwich get Jan 1, 1970 */
83*543adbedSBen Gras assertEqualMem(p + 42, "Jan ", 4);
84*543adbedSBen Gras /* Some systems format "Jan 01", some "Jan 1" */
85*543adbedSBen Gras assert(p[46] == ' ' || p[46] == '0');
86*543adbedSBen Gras assertEqualMem(p + 47, "1 1970 ", 8);
87*543adbedSBen Gras }
88*543adbedSBen Gras assertEqualMem(p + 54, " file", 5);
89*543adbedSBen Gras free(p);
90*543adbedSBen Gras
91*543adbedSBen Gras /* But "-n" without "-t" is an error. */
92*543adbedSBen Gras assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err",
93*543adbedSBen Gras testprog));
94*543adbedSBen Gras assertEmptyFile("in.out");
95*543adbedSBen Gras }
96