1228753Smm/*-
2228753Smm * Copyright (c) 2003-2009 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm */
25228753Smm#include "test.h"
26228753Smm__FBSDID("$FreeBSD$");
27228753Smm
28228753Smm/*
29228753Smm * Test the command-line parsing.
30228753Smm */
31228753Smm
32228753SmmDEFINE_TEST(test_cmdline)
33228753Smm{
34228753Smm	FILE *f;
35228753Smm
36228753Smm	/* Create an empty file. */
37228753Smm	f = fopen("empty", "wb");
38228753Smm	assert(f != NULL);
39228753Smm	fclose(f);
40228753Smm
41228753Smm	failure("-Q is an invalid option on every cpio program I know of");
42228753Smm	assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
43228753Smm	assertEmptyFile("1.out");
44228753Smm
45228753Smm	failure("-f requires an argument");
46228753Smm	assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
47228753Smm	assertEmptyFile("2.out");
48228753Smm
49228753Smm	failure("-f requires an argument");
50228753Smm	assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
51228753Smm	assertEmptyFile("3.out");
52228753Smm
53228753Smm	failure("--format requires an argument");
54228753Smm	assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
55228753Smm	assertEmptyFile("4.out");
56228753Smm
57228753Smm	failure("--badopt is an invalid option");
58228753Smm	assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
59228753Smm	assertEmptyFile("5.out");
60228753Smm
61228753Smm	failure("--badopt is an invalid option");
62228753Smm	assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
63228753Smm	assertEmptyFile("6.out");
64228753Smm
65228753Smm	failure("--n is ambiguous");
66228753Smm	assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
67228753Smm	assertEmptyFile("7.out");
68228753Smm
69228753Smm	failure("--create forbids an argument");
70228753Smm	assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
71228753Smm	assertEmptyFile("8.out");
72228753Smm
73228753Smm	failure("-i with empty input should succeed");
74228753Smm	assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
75228753Smm	assertEmptyFile("9.out");
76228753Smm
77228753Smm	failure("-o with empty input should succeed");
78228753Smm	assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
79228753Smm
80228753Smm	failure("-i -p is nonsense");
81228753Smm	assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
82228753Smm	assertEmptyFile("11.out");
83228753Smm
84228753Smm	failure("-p -i is nonsense");
85228753Smm	assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
86228753Smm	assertEmptyFile("12.out");
87228753Smm
88228753Smm	failure("-i -o is nonsense");
89228753Smm	assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
90228753Smm	assertEmptyFile("13.out");
91228753Smm
92228753Smm	failure("-o -i is nonsense");
93228753Smm	assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
94228753Smm	assertEmptyFile("14.out");
95228753Smm
96228753Smm	failure("-o -p is nonsense");
97228753Smm	assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
98228753Smm	assertEmptyFile("15.out");
99228753Smm
100228753Smm	failure("-p -o is nonsense");
101228753Smm	assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog));
102228753Smm	assertEmptyFile("16.out");
103228753Smm
104228753Smm	failure("-p with empty input should fail");
105228753Smm	assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
106228753Smm	assertEmptyFile("17.out");
107228753Smm}
108