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