xref: /freebsd/contrib/libarchive/tar/test/test_option_a.c (revision bd66c1b43e33540205dbc1187c2f2a15c58b57ba)
1acc60b03SMartin Matuska /*-
2*bd66c1b4SMartin Matuska  * SPDX-License-Identifier: BSD-2-Clause
3*bd66c1b4SMartin Matuska  *
4acc60b03SMartin Matuska  * Copyright (c) 2003-2007 Tim Kientzle
5acc60b03SMartin Matuska  * Copyright (c) 2012 Michihiro NAKAJIMA
6acc60b03SMartin Matuska  * All rights reserved.
7acc60b03SMartin Matuska  */
8acc60b03SMartin Matuska #include "test.h"
9acc60b03SMartin Matuska 
DEFINE_TEST(test_option_a)10acc60b03SMartin Matuska DEFINE_TEST(test_option_a)
11acc60b03SMartin Matuska {
12acc60b03SMartin Matuska 	size_t s;
13acc60b03SMartin Matuska 	char *p;
14acc60b03SMartin Matuska 
15acc60b03SMartin Matuska 	/* Create a file. */
16acc60b03SMartin Matuska 	assertMakeFile("f", 0644, "a");
17acc60b03SMartin Matuska 
18acc60b03SMartin Matuska 	/* Test1: archive it with .tar.Z suffix. */
19acc60b03SMartin Matuska 	assertEqualInt(0,
20acc60b03SMartin Matuska 	    systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));
21acc60b03SMartin Matuska 	assertEmptyFile("test1.err");
22acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
23acc60b03SMartin Matuska 	p = slurpfile(&s, "test1.tar.Z");
24acc60b03SMartin Matuska 	assert(s > 2);
25acc60b03SMartin Matuska 	failure("The archive should be compressed");
26acc60b03SMartin Matuska 	assertEqualMem(p, "\x1f\x9d", 2);
2763ecfce8SEnji Cooper 	free(p);
28acc60b03SMartin Matuska 
29acc60b03SMartin Matuska 	/* Test2: archive it with .taZ suffix. */
30acc60b03SMartin Matuska 	assertEqualInt(0,
31acc60b03SMartin Matuska 	    systemf("%s -acf test2.taZ f 2>test2.err", testprog));
32acc60b03SMartin Matuska 	assertEmptyFile("test2.err");
33acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
34acc60b03SMartin Matuska 	p = slurpfile(&s, "test2.taZ");
35acc60b03SMartin Matuska 	assert(s > 2);
36acc60b03SMartin Matuska 	failure("The archive should be compressed");
37acc60b03SMartin Matuska 	assertEqualMem(p, "\x1f\x9d", 2);
3863ecfce8SEnji Cooper 	free(p);
39acc60b03SMartin Matuska 
40acc60b03SMartin Matuska 	/* Test3: archive it with .tar.Z.uu suffix. */
41acc60b03SMartin Matuska 	assertEqualInt(0,
42acc60b03SMartin Matuska 	    systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));
43acc60b03SMartin Matuska 	assertEmptyFile("test3.err");
44acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
45acc60b03SMartin Matuska 	p = slurpfile(&s, "test3.tar.Z.uu");
46acc60b03SMartin Matuska 	assert(s > 12);
47acc60b03SMartin Matuska 	failure("The archive should be uuencoded");
48acc60b03SMartin Matuska 	assertEqualMem(p, "begin 644 -\n", 12);
4963ecfce8SEnji Cooper 	free(p);
50acc60b03SMartin Matuska 
51acc60b03SMartin Matuska 	/* Test4: archive it with .zip suffix. */
52acc60b03SMartin Matuska 	assertEqualInt(0,
53acc60b03SMartin Matuska 	    systemf("%s -acf test4.zip f 2>test4.err", testprog));
54acc60b03SMartin Matuska 	assertEmptyFile("test4.err");
55acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
56acc60b03SMartin Matuska 	p = slurpfile(&s, "test4.zip");
57acc60b03SMartin Matuska 	assert(s > 4);
58acc60b03SMartin Matuska 	failure("The archive should be zipped");
59acc60b03SMartin Matuska 	assertEqualMem(p, "\x50\x4b\x03\x04", 4);
6063ecfce8SEnji Cooper 	free(p);
61acc60b03SMartin Matuska 
62acc60b03SMartin Matuska 	/* Test5: archive it with .tar.Z suffix and --uuencode option. */
63acc60b03SMartin Matuska 	assertEqualInt(0,
64acc60b03SMartin Matuska 	    systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",
65acc60b03SMartin Matuska 		testprog));
66acc60b03SMartin Matuska 	assertEmptyFile("test5.err");
67acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
68acc60b03SMartin Matuska 	p = slurpfile(&s, "test5.tar.Z");
69acc60b03SMartin Matuska 	assert(s > 2);
70acc60b03SMartin Matuska 	failure("The archive should be compressed, ignoring --uuencode option");
71acc60b03SMartin Matuska 	assertEqualMem(p, "\x1f\x9d", 2);
7263ecfce8SEnji Cooper 	free(p);
73acc60b03SMartin Matuska 
74acc60b03SMartin Matuska 	/* Test6: archive it with .xxx suffix(unknown suffix) and
75acc60b03SMartin Matuska 	 * --uuencode option. */
76acc60b03SMartin Matuska 	assertEqualInt(0,
77acc60b03SMartin Matuska 	    systemf("%s -acf test6.xxx --uuencode f 2>test6.err",
78acc60b03SMartin Matuska 		testprog));
79acc60b03SMartin Matuska 	assertEmptyFile("test6.err");
80acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
81acc60b03SMartin Matuska 	p = slurpfile(&s, "test6.xxx");
82acc60b03SMartin Matuska 	assert(s > 12);
83acc60b03SMartin Matuska 	failure("The archive should be uuencoded");
84acc60b03SMartin Matuska 	assertEqualMem(p, "begin 644 -\n", 12);
8563ecfce8SEnji Cooper 	free(p);
86acc60b03SMartin Matuska 
87acc60b03SMartin Matuska 	/* Test7: archive it with .tar.Z suffix using a long-name option. */
88acc60b03SMartin Matuska 	assertEqualInt(0,
89acc60b03SMartin Matuska 	    systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",
90acc60b03SMartin Matuska 		testprog));
91acc60b03SMartin Matuska 	assertEmptyFile("test7.err");
92acc60b03SMartin Matuska 	/* Check that the archive file has a compress signature. */
93acc60b03SMartin Matuska 	p = slurpfile(&s, "test7.tar.Z");
94acc60b03SMartin Matuska 	assert(s > 2);
95acc60b03SMartin Matuska 	failure("The archive should be compressed");
96acc60b03SMartin Matuska 	assertEqualMem(p, "\x1f\x9d", 2);
9763ecfce8SEnji Cooper 	free(p);
98acc60b03SMartin Matuska }
99