xref: /freebsd/contrib/libarchive/cpio/test/test_cmdline.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 /*-
2  * Copyright (c) 2003-2009 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  * Test the command-line parsing.
30  */
31 
32 DEFINE_TEST(test_cmdline)
33 {
34 	FILE *f;
35 
36 	/* Create an empty file. */
37 	f = fopen("empty", "wb");
38 	assert(f != NULL);
39 	fclose(f);
40 
41 	failure("-Q is an invalid option on every cpio program I know of");
42 	assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
43 	assertEmptyFile("1.out");
44 
45 	failure("-f requires an argument");
46 	assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
47 	assertEmptyFile("2.out");
48 
49 	failure("-f requires an argument");
50 	assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
51 	assertEmptyFile("3.out");
52 
53 	failure("--format requires an argument");
54 	assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
55 	assertEmptyFile("4.out");
56 
57 	failure("--badopt is an invalid option");
58 	assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
59 	assertEmptyFile("5.out");
60 
61 	failure("--badopt is an invalid option");
62 	assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
63 	assertEmptyFile("6.out");
64 
65 	failure("--n is ambiguous");
66 	assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
67 	assertEmptyFile("7.out");
68 
69 	failure("--create forbids an argument");
70 	assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
71 	assertEmptyFile("8.out");
72 
73 	failure("-i with empty input should succeed");
74 	assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
75 	assertEmptyFile("9.out");
76 
77 	failure("-o with empty input should succeed");
78 	assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
79 
80 	failure("-i -p is nonsense");
81 	assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
82 	assertEmptyFile("11.out");
83 
84 	failure("-p -i is nonsense");
85 	assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
86 	assertEmptyFile("12.out");
87 
88 	failure("-i -o is nonsense");
89 	assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
90 	assertEmptyFile("13.out");
91 
92 	failure("-o -i is nonsense");
93 	assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
94 	assertEmptyFile("14.out");
95 
96 	failure("-o -p is nonsense");
97 	assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
98 	assertEmptyFile("15.out");
99 
100 	failure("-p -o is nonsense");
101 	assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog));
102 	assertEmptyFile("16.out");
103 
104 	failure("-p with empty input should fail");
105 	assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
106 	assertEmptyFile("17.out");
107 }
108