1248590Smm/*-
2248590Smm * Copyright (c) 2003-2007 Tim Kientzle
3248590Smm * Copyright (c) 2012 Michihiro NAKAJIMA
4248590Smm * All rights reserved.
5248590Smm *
6248590Smm * Redistribution and use in source and binary forms, with or without
7248590Smm * modification, are permitted provided that the following conditions
8248590Smm * are met:
9248590Smm * 1. Redistributions of source code must retain the above copyright
10248590Smm *    notice, this list of conditions and the following disclaimer.
11248590Smm * 2. Redistributions in binary form must reproduce the above copyright
12248590Smm *    notice, this list of conditions and the following disclaimer in the
13248590Smm *    documentation and/or other materials provided with the distribution.
14248590Smm *
15248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16248590Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17248590Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18248590Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19248590Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20248590Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21248590Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22248590Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23248590Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24248590Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25248590Smm */
26248590Smm#include "test.h"
27248590Smm__FBSDID("$FreeBSD$");
28248590Smm
29248590SmmDEFINE_TEST(test_option_a)
30248590Smm{
31248590Smm	size_t s;
32248590Smm	char *p;
33248590Smm
34248590Smm	/* Create a file. */
35248590Smm	assertMakeFile("f", 0644, "a");
36248590Smm
37248590Smm	/* Test1: archive it with .tar.Z suffix. */
38248590Smm	assertEqualInt(0,
39248590Smm	    systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));
40248590Smm	assertEmptyFile("test1.err");
41248590Smm	/* Check that the archive file has a compress signature. */
42248590Smm	p = slurpfile(&s, "test1.tar.Z");
43248590Smm	assert(s > 2);
44248590Smm	failure("The archive should be compressed");
45248590Smm	assertEqualMem(p, "\x1f\x9d", 2);
46248590Smm
47248590Smm	/* Test2: archive it with .taZ suffix. */
48248590Smm	assertEqualInt(0,
49248590Smm	    systemf("%s -acf test2.taZ f 2>test2.err", testprog));
50248590Smm	assertEmptyFile("test2.err");
51248590Smm	/* Check that the archive file has a compress signature. */
52248590Smm	p = slurpfile(&s, "test2.taZ");
53248590Smm	assert(s > 2);
54248590Smm	failure("The archive should be compressed");
55248590Smm	assertEqualMem(p, "\x1f\x9d", 2);
56248590Smm
57248590Smm	/* Test3: archive it with .tar.Z.uu suffix. */
58248590Smm	assertEqualInt(0,
59248590Smm	    systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));
60248590Smm	assertEmptyFile("test3.err");
61248590Smm	/* Check that the archive file has a compress signature. */
62248590Smm	p = slurpfile(&s, "test3.tar.Z.uu");
63248590Smm	assert(s > 12);
64248590Smm	failure("The archive should be uuencoded");
65248590Smm	assertEqualMem(p, "begin 644 -\n", 12);
66248590Smm
67248590Smm	/* Test4: archive it with .zip suffix. */
68248590Smm	assertEqualInt(0,
69248590Smm	    systemf("%s -acf test4.zip f 2>test4.err", testprog));
70248590Smm	assertEmptyFile("test4.err");
71248590Smm	/* Check that the archive file has a compress signature. */
72248590Smm	p = slurpfile(&s, "test4.zip");
73248590Smm	assert(s > 4);
74248590Smm	failure("The archive should be zipped");
75248590Smm	assertEqualMem(p, "\x50\x4b\x03\x04", 4);
76248590Smm
77248590Smm	/* Test5: archive it with .tar.Z suffix and --uuencode option. */
78248590Smm	assertEqualInt(0,
79248590Smm	    systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",
80248590Smm		testprog));
81248590Smm	assertEmptyFile("test5.err");
82248590Smm	/* Check that the archive file has a compress signature. */
83248590Smm	p = slurpfile(&s, "test5.tar.Z");
84248590Smm	assert(s > 2);
85248590Smm	failure("The archive should be compressed, ignoring --uuencode option");
86248590Smm	assertEqualMem(p, "\x1f\x9d", 2);
87248590Smm
88248590Smm	/* Test6: archive it with .xxx suffix(unknown suffix) and
89248590Smm	 * --uuencode option. */
90248590Smm	assertEqualInt(0,
91248590Smm	    systemf("%s -acf test6.xxx --uuencode f 2>test6.err",
92248590Smm		testprog));
93248590Smm	assertEmptyFile("test6.err");
94248590Smm	/* Check that the archive file has a compress signature. */
95248590Smm	p = slurpfile(&s, "test6.xxx");
96248590Smm	assert(s > 12);
97248590Smm	failure("The archive should be uuencoded");
98248590Smm	assertEqualMem(p, "begin 644 -\n", 12);
99248590Smm
100248590Smm	/* Test7: archive it with .tar.Z suffix using a long-name option. */
101248590Smm	assertEqualInt(0,
102248590Smm	    systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",
103248590Smm		testprog));
104248590Smm	assertEmptyFile("test7.err");
105248590Smm	/* Check that the archive file has a compress signature. */
106248590Smm	p = slurpfile(&s, "test7.tar.Z");
107248590Smm	assert(s > 2);
108248590Smm	failure("The archive should be compressed");
109248590Smm	assertEqualMem(p, "\x1f\x9d", 2);
110248590Smm}
111