xref: /freebsd/contrib/libarchive/unzip/test/test_x.c (revision 401026e4825a05abba6f945cf1b74b3328876fa2)
1 /*
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2023 Adrian Vovk
5  * All rights reserved.
6  */
7 #include "test.h"
8 
9 /* Test x arg with single exclude path */
DEFINE_TEST(test_x_single)10 DEFINE_TEST(test_x_single)
11 {
12 #ifdef HAVE_LIBZ
13 	const char *reffile = "test_basic.zip";
14 	int r;
15 
16 	extract_reference_file(reffile);
17 	r = systemf("%s %s -x test_basic/c >test.out 2>test.err", testprog, reffile);
18 	assertEqualInt(0, r);
19 	assertNonEmptyFile("test.out");
20 	assertEmptyFile("test.err");
21 
22 	assertTextFileContents("contents a\n", "test_basic/a");
23 	assertTextFileContents("contents b\n", "test_basic/b");
24 	assertFileNotExists("test_basic/c");
25 	assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
26 #else
27 	skipping("zlib not available");
28 #endif
29 }
30 
31 /* Test x arg with multiple exclude paths */
DEFINE_TEST(test_x_multiple)32 DEFINE_TEST(test_x_multiple)
33 {
34 #ifdef HAVE_LIBZ
35 	const char *reffile = "test_basic.zip";
36 	int r;
37 
38 	extract_reference_file(reffile);
39 	r = systemf("%s %s -x test_basic/c test_basic/b >test.out 2>test.err", testprog, reffile);
40 	assertEqualInt(0, r);
41 	assertNonEmptyFile("test.out");
42 	assertEmptyFile("test.err");
43 
44 	assertTextFileContents("contents a\n", "test_basic/a");
45 	assertFileNotExists("test_basic/b");
46 	assertFileNotExists("test_basic/c");
47 	assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
48 #else
49 	skipping("zlib not available");
50 #endif
51 }
52 
53 /* Test x arg with multiple exclude paths and a d arg afterwards */
DEFINE_TEST(test_x_multiple_with_d)54 DEFINE_TEST(test_x_multiple_with_d)
55 {
56 #ifdef HAVE_LIBZ
57 	const char *reffile = "test_basic.zip";
58 	int r;
59 
60 	extract_reference_file(reffile);
61 	r = systemf("%s %s -x test_basic/c test_basic/b -d foobar >test.out 2>test.err", testprog, reffile);
62 	assertEqualInt(0, r);
63 	assertNonEmptyFile("test.out");
64 	assertEmptyFile("test.err");
65 
66 	assertTextFileContents("contents a\n", "foobar/test_basic/a");
67 	assertFileNotExists("foobar/test_basic/b");
68 	assertFileNotExists("foobar/test_basic/c");
69 	assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
70 #else
71 	skipping("zlib not available");
72 #endif
73 }
74