]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.bin/cpio/test/test_option_t.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.bin / cpio / test / test_option_t.c
1 /*-
2  * Copyright (c) 2003-2007 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 __FBSDID("$FreeBSD$");
27
28
29 DEFINE_TEST(test_option_t)
30 {
31         char *p;
32         int r;
33
34         /* List reference archive, make sure the TOC is correct. */
35         extract_reference_file("test_option_t.cpio");
36         r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog);
37         assertEqualInt(r, 0);
38         assertTextFileContents("1 block\n", "it.err");
39         extract_reference_file("test_option_t.stdout");
40         p = slurpfile(NULL, "test_option_t.stdout");
41         assertTextFileContents(p, "it.out");
42         free(p);
43
44         /* We accept plain "-t" as a synonym for "-it" */
45         r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog);
46         assertEqualInt(r, 0);
47         assertTextFileContents("1 block\n", "t.err");
48         extract_reference_file("test_option_t.stdout");
49         p = slurpfile(NULL, "test_option_t.stdout");
50         assertTextFileContents(p, "t.out");
51         free(p);
52
53         /* But "-ot" is an error. */
54         assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err",
55                             testprog));
56         assertEmptyFile("ot.out");
57
58         /* List reference archive verbosely, make sure the TOC is correct. */
59         r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog);
60         assertEqualInt(r, 0);
61         assertTextFileContents("1 block\n", "tv.err");
62         extract_reference_file("test_option_tv.stdout");
63
64         /* This doesn't work because the usernames on different systems
65          * are different and cpio now looks up numeric UIDs on
66          * the local system. */
67         /* assertEqualFile("tv.out", "test_option_tv.stdout"); */
68
69         /* List reference archive with numeric IDs, verify TOC is correct. */
70         r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err",
71                     testprog);
72         assertEqualInt(r, 0);
73         assertTextFileContents("1 block\n", "itnv.err");
74         extract_reference_file("test_option_tnv.stdout");
75         /* This does work because numeric IDs come from archive. */
76         /* Unfortunately, the timestamp still gets localized, so
77          * we can't just compare against a fixed result. */
78         /* TODO: Fix this. */
79         /* assertEqualFile("itnv.out", "test_option_tnv.stdout"); */
80
81         /* But "-n" without "-t" is an error. */
82         assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err",
83                             testprog));
84         assertEmptyFile("in.out");
85 }