1231200Smm/*-
2231200Smm * Copyright (c) 2003-2010 Tim Kientzle
3231200Smm * All rights reserved.
4231200Smm *
5231200Smm * Redistribution and use in source and binary forms, with or without
6231200Smm * modification, are permitted provided that the following conditions
7231200Smm * are met:
8231200Smm * 1. Redistributions of source code must retain the above copyright
9231200Smm *    notice, this list of conditions and the following disclaimer.
10231200Smm * 2. Redistributions in binary form must reproduce the above copyright
11231200Smm *    notice, this list of conditions and the following disclaimer in the
12231200Smm *    documentation and/or other materials provided with the distribution.
13231200Smm *
14231200Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15231200Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16231200Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17231200Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18231200Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19231200Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20231200Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21231200Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22231200Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23231200Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24231200Smm */
25231200Smm#include "test.h"
26231200Smm__FBSDID("$FreeBSD$");
27231200Smm
28231200SmmDEFINE_TEST(test_option_0)
29231200Smm{
30231200Smm	FILE *filelist;
31231200Smm	int r;
32231200Smm
33231200Smm	assertUmask(0);
34231200Smm
35231200Smm	/* Create a few files. */
36231200Smm	assertMakeFile("file1", 0644, "1234567890");
37231200Smm	assertMakeFile("file2", 0644, "1234567890");
38231200Smm	assertMakeFile("file3", 0644, "1234567890");
39231200Smm	assertMakeFile("file4", 0644, "1234567890");
40231200Smm
41231200Smm	/* Create a file list of filenames with varying end-of-line. */
42231200Smm	filelist = fopen("filelist", "wb");
43231200Smm	assertEqualInt(fwrite("file1\x0a", 1, 6, filelist), 6);
44231200Smm	assertEqualInt(fwrite("file2\x0d", 1, 6, filelist), 6);
45231200Smm	assertEqualInt(fwrite("file3\x0a\x0d", 1, 7, filelist), 7);
46231200Smm	assertEqualInt(fwrite("file4", 1, 5, filelist), 5);
47231200Smm	fclose(filelist);
48231200Smm
49231200Smm	/* Create a file list of null-delimited names. */
50231200Smm	filelist = fopen("filelistNull", "wb");
51231200Smm	assertEqualInt(fwrite("file1\0", 1, 6, filelist), 6);
52231200Smm	assertEqualInt(fwrite("file2\0", 1, 6, filelist), 6);
53231200Smm	assertEqualInt(fwrite("file3\0", 1, 6, filelist), 6);
54231200Smm	assertEqualInt(fwrite("file4", 1, 5, filelist), 5);
55231200Smm	fclose(filelist);
56231200Smm
57231200Smm	assertUmask(022);
58231200Smm
59231200Smm	/* Pack up using the file list with text line endings. */
60231200Smm	r = systemf("%s -o < filelist > archive 2> stderr1.txt", testprog);
61231200Smm	assertEqualInt(r, 0);
62231200Smm
63231200Smm	/* Extract into a new dir. */
64231200Smm	assertMakeDir("copy", 0775);
65231200Smm	assertChdir("copy");
66231200Smm	r = systemf("%s -i < ../archive > stdout3.txt 2> stderr3.txt", testprog);
67231200Smm	assertEqualInt(r, 0);
68231200Smm
69231200Smm	/* Verify the files. */
70231200Smm	assertIsReg("file1", 0644);
71231200Smm	assertIsReg("file2", 0644);
72231200Smm	assertIsReg("file3", 0644);
73231200Smm	assertIsReg("file4", 0644);
74231200Smm
75231200Smm	assertChdir("..");
76231200Smm
77231200Smm	/* Pack up using the file list with nulls. */
78231200Smm	r = systemf("%s -o0 < filelistNull > archiveNull 2> stderr2.txt", testprog);
79231200Smm	assertEqualInt(r, 0);
80231200Smm
81231200Smm	/* Extract into a new dir. */
82231200Smm	assertMakeDir("copyNull", 0775);
83231200Smm	assertChdir("copyNull");
84231200Smm	r = systemf("%s -i < ../archiveNull > stdout4.txt 2> stderr4.txt", testprog);
85231200Smm	assertEqualInt(r, 0);
86231200Smm
87231200Smm	/* Verify the files. */
88231200Smm	assertIsReg("file1", 0644);
89231200Smm	assertIsReg("file2", 0644);
90231200Smm	assertIsReg("file3", 0644);
91231200Smm	assertIsReg("file4", 0644);
92231200Smm}
93