xref: /freebsd/contrib/libarchive/libarchive/test/test_archive_match_path.c (revision b9128a37faafede823eb456aa65a11ac69997284)
1*fd082e96SMartin Matuska /*-
2*fd082e96SMartin Matuska  * Copyright (c) 2012 Michihiro NAKAJIMA
3*fd082e96SMartin Matuska  * All rights reserved.
4*fd082e96SMartin Matuska  *
5*fd082e96SMartin Matuska  * Redistribution and use in source and binary forms, with or without
6*fd082e96SMartin Matuska  * modification, are permitted provided that the following conditions
7*fd082e96SMartin Matuska  * are met:
8*fd082e96SMartin Matuska  * 1. Redistributions of source code must retain the above copyright
9*fd082e96SMartin Matuska  *    notice, this list of conditions and the following disclaimer.
10*fd082e96SMartin Matuska  * 2. Redistributions in binary form must reproduce the above copyright
11*fd082e96SMartin Matuska  *    notice, this list of conditions and the following disclaimer in the
12*fd082e96SMartin Matuska  *    documentation and/or other materials provided with the distribution.
13*fd082e96SMartin Matuska  *
14*fd082e96SMartin Matuska  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*fd082e96SMartin Matuska  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*fd082e96SMartin Matuska  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*fd082e96SMartin Matuska  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*fd082e96SMartin Matuska  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*fd082e96SMartin Matuska  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*fd082e96SMartin Matuska  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*fd082e96SMartin Matuska  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*fd082e96SMartin Matuska  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*fd082e96SMartin Matuska  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*fd082e96SMartin Matuska  */
25*fd082e96SMartin Matuska 
26*fd082e96SMartin Matuska #include "test.h"
27*fd082e96SMartin Matuska 
28*fd082e96SMartin Matuska static void
29*fd082e96SMartin Matuska test_exclusion_mbs(void)
30*fd082e96SMartin Matuska {
31*fd082e96SMartin Matuska 	struct archive_entry *ae;
32*fd082e96SMartin Matuska 	struct archive *m;
33*fd082e96SMartin Matuska 
34*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
35*fd082e96SMartin Matuska 		return;
36*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
37*fd082e96SMartin Matuska 		archive_match_free(m);
38*fd082e96SMartin Matuska 		return;
39*fd082e96SMartin Matuska 	}
40*fd082e96SMartin Matuska 
41*fd082e96SMartin Matuska 	/* Test for pattern "^aa*" */
42*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_exclude_pattern(m, "^aa*"));
43*fd082e96SMartin Matuska 
44*fd082e96SMartin Matuska 	/* Test with 'aa1234', which should be excluded. */
45*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aa1234");
46*fd082e96SMartin Matuska 	failure("'aa1234' should be excluded");
47*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
48*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
49*fd082e96SMartin Matuska 	archive_entry_clear(ae);
50*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aa1234");
51*fd082e96SMartin Matuska 	failure("'aa1234' should be excluded");
52*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
53*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
54*fd082e96SMartin Matuska 
55*fd082e96SMartin Matuska 	/* Test with 'a1234', which should not be excluded. */
56*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "a1234");
57*fd082e96SMartin Matuska 	failure("'a1234' should not be excluded");
58*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
59*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
60*fd082e96SMartin Matuska 	archive_entry_clear(ae);
61*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"a1234");
62*fd082e96SMartin Matuska 	failure("'a1234' should not be excluded");
63*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
64*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
65*fd082e96SMartin Matuska 
66*fd082e96SMartin Matuska 	/* Clean up. */
67*fd082e96SMartin Matuska 	archive_entry_free(ae);
68*fd082e96SMartin Matuska 	archive_match_free(m);
69*fd082e96SMartin Matuska }
70*fd082e96SMartin Matuska 
71*fd082e96SMartin Matuska static void
72*fd082e96SMartin Matuska test_exclusion_wcs(void)
73*fd082e96SMartin Matuska {
74*fd082e96SMartin Matuska 	struct archive_entry *ae;
75*fd082e96SMartin Matuska 	struct archive *m;
76*fd082e96SMartin Matuska 
77*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
78*fd082e96SMartin Matuska 		return;
79*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
80*fd082e96SMartin Matuska 		archive_match_free(m);
81*fd082e96SMartin Matuska 		return;
82*fd082e96SMartin Matuska 	}
83*fd082e96SMartin Matuska 
84*fd082e96SMartin Matuska 	/* Test for pattern "^aa*" */
85*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_exclude_pattern_w(m, L"^aa*"));
86*fd082e96SMartin Matuska 
87*fd082e96SMartin Matuska 	/* Test with 'aa1234', which should be excluded. */
88*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aa1234");
89*fd082e96SMartin Matuska 	failure("'aa1234' should be excluded");
90*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
91*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
92*fd082e96SMartin Matuska 	archive_entry_clear(ae);
93*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aa1234");
94*fd082e96SMartin Matuska 	failure("'aa1234' should be excluded");
95*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
96*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
97*fd082e96SMartin Matuska 
98*fd082e96SMartin Matuska 	/* Test with 'a1234', which should not be excluded. */
99*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "a1234");
100*fd082e96SMartin Matuska 	failure("'a1234' should not be excluded");
101*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
102*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
103*fd082e96SMartin Matuska 	archive_entry_clear(ae);
104*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"a1234");
105*fd082e96SMartin Matuska 	failure("'a1234' should not be excluded");
106*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
107*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
108*fd082e96SMartin Matuska 
109*fd082e96SMartin Matuska 	/* Clean up. */
110*fd082e96SMartin Matuska 	archive_entry_free(ae);
111*fd082e96SMartin Matuska 	archive_match_free(m);
112*fd082e96SMartin Matuska }
113*fd082e96SMartin Matuska 
114*fd082e96SMartin Matuska static void
115*fd082e96SMartin Matuska exclusion_from_file(struct archive *m)
116*fd082e96SMartin Matuska {
117*fd082e96SMartin Matuska 	struct archive_entry *ae;
118*fd082e96SMartin Matuska 
119*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
120*fd082e96SMartin Matuska 		archive_match_free(m);
121*fd082e96SMartin Matuska 		return;
122*fd082e96SMartin Matuska 	}
123*fd082e96SMartin Matuska 
124*fd082e96SMartin Matuska 	/* Test with 'first', which should not be excluded. */
125*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "first");
126*fd082e96SMartin Matuska 	failure("'first' should not be excluded");
127*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
128*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
129*fd082e96SMartin Matuska 	archive_entry_clear(ae);
130*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"first");
131*fd082e96SMartin Matuska 	failure("'first' should not be excluded");
132*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
133*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
134*fd082e96SMartin Matuska 
135*fd082e96SMartin Matuska 	/* Test with 'second', which should be excluded. */
136*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "second");
137*fd082e96SMartin Matuska 	failure("'second' should be excluded");
138*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
139*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
140*fd082e96SMartin Matuska 	archive_entry_clear(ae);
141*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"second");
142*fd082e96SMartin Matuska 	failure("'second' should be excluded");
143*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
144*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
145*fd082e96SMartin Matuska 
146*fd082e96SMartin Matuska 	/* Test with 'third', which should not be excluded. */
147*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "third");
148*fd082e96SMartin Matuska 	failure("'third' should not be excluded");
149*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
150*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
151*fd082e96SMartin Matuska 	archive_entry_clear(ae);
152*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"third");
153*fd082e96SMartin Matuska 	failure("'third' should not be excluded");
154*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
155*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
156*fd082e96SMartin Matuska 
157*fd082e96SMartin Matuska 	/* Test with 'four', which should be excluded. */
158*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "four");
159*fd082e96SMartin Matuska 	failure("'four' should be excluded");
160*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
161*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
162*fd082e96SMartin Matuska 	archive_entry_clear(ae);
163*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"four");
164*fd082e96SMartin Matuska 	failure("'four' should be excluded");
165*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
166*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
167*fd082e96SMartin Matuska 
168*fd082e96SMartin Matuska 	/* Clean up. */
169*fd082e96SMartin Matuska 	archive_entry_free(ae);
170*fd082e96SMartin Matuska }
171*fd082e96SMartin Matuska 
172*fd082e96SMartin Matuska static void
173*fd082e96SMartin Matuska test_exclusion_from_file_mbs(void)
174*fd082e96SMartin Matuska {
175*fd082e96SMartin Matuska 	struct archive *m;
176*fd082e96SMartin Matuska 
177*fd082e96SMartin Matuska 	/* Test1: read exclusion patterns from file */
178*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
179*fd082e96SMartin Matuska 		return;
180*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
181*fd082e96SMartin Matuska 	    archive_match_exclude_pattern_from_file(m, "exclusion", 0));
182*fd082e96SMartin Matuska 	exclusion_from_file(m);
183*fd082e96SMartin Matuska 	/* Clean up. */
184*fd082e96SMartin Matuska 	archive_match_free(m);
185*fd082e96SMartin Matuska 
186*fd082e96SMartin Matuska 	/* Test2: read exclusion patterns in a null separator from file */
187*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
188*fd082e96SMartin Matuska 		return;
189*fd082e96SMartin Matuska 	/* Test for pattern reading from file */
190*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
191*fd082e96SMartin Matuska 	    archive_match_exclude_pattern_from_file(m, "exclusion_null", 1));
192*fd082e96SMartin Matuska 	exclusion_from_file(m);
193*fd082e96SMartin Matuska 	/* Clean up. */
194*fd082e96SMartin Matuska 	archive_match_free(m);
195*fd082e96SMartin Matuska }
196*fd082e96SMartin Matuska 
197*fd082e96SMartin Matuska static void
198*fd082e96SMartin Matuska test_exclusion_from_file_wcs(void)
199*fd082e96SMartin Matuska {
200*fd082e96SMartin Matuska 	struct archive *m;
201*fd082e96SMartin Matuska 
202*fd082e96SMartin Matuska 	/* Test1: read exclusion patterns from file */
203*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
204*fd082e96SMartin Matuska 		return;
205*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
206*fd082e96SMartin Matuska 	    archive_match_exclude_pattern_from_file_w(m, L"exclusion", 0));
207*fd082e96SMartin Matuska 	exclusion_from_file(m);
208*fd082e96SMartin Matuska 	/* Clean up. */
209*fd082e96SMartin Matuska 	archive_match_free(m);
210*fd082e96SMartin Matuska 
211*fd082e96SMartin Matuska 	/* Test2: read exclusion patterns in a null separator from file */
212*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
213*fd082e96SMartin Matuska 		return;
214*fd082e96SMartin Matuska 	/* Test for pattern reading from file */
215*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
216*fd082e96SMartin Matuska 	    archive_match_exclude_pattern_from_file_w(m, L"exclusion_null", 1));
217*fd082e96SMartin Matuska 	exclusion_from_file(m);
218*fd082e96SMartin Matuska 	/* Clean up. */
219*fd082e96SMartin Matuska 	archive_match_free(m);
220*fd082e96SMartin Matuska }
221*fd082e96SMartin Matuska 
222*fd082e96SMartin Matuska static void
223*fd082e96SMartin Matuska test_inclusion_mbs(void)
224*fd082e96SMartin Matuska {
225*fd082e96SMartin Matuska 	struct archive_entry *ae;
226*fd082e96SMartin Matuska 	struct archive *m;
227*fd082e96SMartin Matuska 	const char *mp;
228*fd082e96SMartin Matuska 
229*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
230*fd082e96SMartin Matuska 		return;
231*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
232*fd082e96SMartin Matuska 		archive_match_free(m);
233*fd082e96SMartin Matuska 		return;
234*fd082e96SMartin Matuska 	}
235*fd082e96SMartin Matuska 
236*fd082e96SMartin Matuska 	/* Test for pattern "^aa*" */
237*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_include_pattern(m, "^aa*"));
238*fd082e96SMartin Matuska 
239*fd082e96SMartin Matuska 	/* Test with 'aa1234', which should not be excluded. */
240*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aa1234");
241*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
242*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
243*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
244*fd082e96SMartin Matuska 	archive_entry_clear(ae);
245*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aa1234");
246*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
247*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
248*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
249*fd082e96SMartin Matuska 
250*fd082e96SMartin Matuska 	/* Test with 'a1234', which should be excluded. */
251*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "a1234");
252*fd082e96SMartin Matuska 	failure("'a1234' should be excluded");
253*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
254*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
255*fd082e96SMartin Matuska 	archive_entry_clear(ae);
256*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"a1234");
257*fd082e96SMartin Matuska 	failure("'a1234' should be excluded");
258*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
259*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
260*fd082e96SMartin Matuska 
261*fd082e96SMartin Matuska 	/* Verify unmatched_inclusions. */
262*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_unmatched_inclusions(m));
263*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_EOF,
264*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next(m, &mp));
265*fd082e96SMartin Matuska 
266*fd082e96SMartin Matuska 	/* Clean up. */
267*fd082e96SMartin Matuska 	archive_entry_free(ae);
268*fd082e96SMartin Matuska 	archive_match_free(m);
269*fd082e96SMartin Matuska }
270*fd082e96SMartin Matuska 
271*fd082e96SMartin Matuska static void
272*fd082e96SMartin Matuska test_inclusion_wcs(void)
273*fd082e96SMartin Matuska {
274*fd082e96SMartin Matuska 	struct archive_entry *ae;
275*fd082e96SMartin Matuska 	struct archive *m;
276*fd082e96SMartin Matuska 	const char *mp;
277*fd082e96SMartin Matuska 
278*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
279*fd082e96SMartin Matuska 		return;
280*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
281*fd082e96SMartin Matuska 		archive_match_free(m);
282*fd082e96SMartin Matuska 		return;
283*fd082e96SMartin Matuska 	}
284*fd082e96SMartin Matuska 
285*fd082e96SMartin Matuska 	/* Test for pattern "^aa*" */
286*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"^aa*"));
287*fd082e96SMartin Matuska 
288*fd082e96SMartin Matuska 	/* Test with 'aa1234', which should not be excluded. */
289*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aa1234");
290*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
291*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
292*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
293*fd082e96SMartin Matuska 	archive_entry_clear(ae);
294*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aa1234");
295*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
296*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
297*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
298*fd082e96SMartin Matuska 
299*fd082e96SMartin Matuska 	/* Test with 'a1234', which should be excluded. */
300*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "a1234");
301*fd082e96SMartin Matuska 	failure("'a1234' should be excluded");
302*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
303*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
304*fd082e96SMartin Matuska 	archive_entry_clear(ae);
305*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"a1234");
306*fd082e96SMartin Matuska 	failure("'a1234' should be excluded");
307*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
308*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
309*fd082e96SMartin Matuska 
310*fd082e96SMartin Matuska 	/* Verify unmatched_inclusions. */
311*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_unmatched_inclusions(m));
312*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_EOF,
313*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next(m, &mp));
314*fd082e96SMartin Matuska 
315*fd082e96SMartin Matuska 	/* Clean up. */
316*fd082e96SMartin Matuska 	archive_entry_free(ae);
317*fd082e96SMartin Matuska 	archive_match_free(m);
318*fd082e96SMartin Matuska }
319*fd082e96SMartin Matuska 
320*fd082e96SMartin Matuska static void
321*fd082e96SMartin Matuska test_inclusion_from_file_mbs(void)
322*fd082e96SMartin Matuska {
323*fd082e96SMartin Matuska 	struct archive *m;
324*fd082e96SMartin Matuska 
325*fd082e96SMartin Matuska 	/* Test1: read inclusion patterns from file */
326*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
327*fd082e96SMartin Matuska 		return;
328*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
329*fd082e96SMartin Matuska 	    archive_match_include_pattern_from_file(m, "inclusion", 0));
330*fd082e96SMartin Matuska 	exclusion_from_file(m);
331*fd082e96SMartin Matuska 	/* Clean up. */
332*fd082e96SMartin Matuska 	archive_match_free(m);
333*fd082e96SMartin Matuska 
334*fd082e96SMartin Matuska 	/* Test2: read inclusion patterns in a null separator from file */
335*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
336*fd082e96SMartin Matuska 		return;
337*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
338*fd082e96SMartin Matuska 	    archive_match_include_pattern_from_file(m, "inclusion_null", 1));
339*fd082e96SMartin Matuska 	exclusion_from_file(m);
340*fd082e96SMartin Matuska 	/* Clean up. */
341*fd082e96SMartin Matuska 	archive_match_free(m);
342*fd082e96SMartin Matuska }
343*fd082e96SMartin Matuska 
344*fd082e96SMartin Matuska static void
345*fd082e96SMartin Matuska test_inclusion_from_file_wcs(void)
346*fd082e96SMartin Matuska {
347*fd082e96SMartin Matuska 	struct archive *m;
348*fd082e96SMartin Matuska 
349*fd082e96SMartin Matuska 	/* Test1: read inclusion patterns from file */
350*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
351*fd082e96SMartin Matuska 		return;
352*fd082e96SMartin Matuska 	/* Test for pattern reading from file */
353*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
354*fd082e96SMartin Matuska 	    archive_match_include_pattern_from_file_w(m, L"inclusion", 0));
355*fd082e96SMartin Matuska 	exclusion_from_file(m);
356*fd082e96SMartin Matuska 	/* Clean up. */
357*fd082e96SMartin Matuska 	archive_match_free(m);
358*fd082e96SMartin Matuska 
359*fd082e96SMartin Matuska 	/* Test2: read inclusion patterns in a null separator from file */
360*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
361*fd082e96SMartin Matuska 		return;
362*fd082e96SMartin Matuska 	/* Test for pattern reading from file */
363*fd082e96SMartin Matuska 	assertEqualIntA(m, 0,
364*fd082e96SMartin Matuska 	    archive_match_include_pattern_from_file_w(m, L"inclusion_null", 1));
365*fd082e96SMartin Matuska 	exclusion_from_file(m);
366*fd082e96SMartin Matuska 	/* Clean up. */
367*fd082e96SMartin Matuska 	archive_match_free(m);
368*fd082e96SMartin Matuska }
369*fd082e96SMartin Matuska 
370*fd082e96SMartin Matuska static void
371*fd082e96SMartin Matuska test_exclusion_and_inclusion(void)
372*fd082e96SMartin Matuska {
373*fd082e96SMartin Matuska 	struct archive_entry *ae;
374*fd082e96SMartin Matuska 	struct archive *m;
375*fd082e96SMartin Matuska 	const char *mp;
376*fd082e96SMartin Matuska 	const wchar_t *wp;
377*fd082e96SMartin Matuska 
378*fd082e96SMartin Matuska 	if (!assert((m = archive_match_new()) != NULL))
379*fd082e96SMartin Matuska 		return;
380*fd082e96SMartin Matuska 	if (!assert((ae = archive_entry_new()) != NULL)) {
381*fd082e96SMartin Matuska 		archive_match_free(m);
382*fd082e96SMartin Matuska 		return;
383*fd082e96SMartin Matuska 	}
384*fd082e96SMartin Matuska 
385*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_exclude_pattern(m, "^aaa*"));
386*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"^aa*"));
387*fd082e96SMartin Matuska 	assertEqualIntA(m, 0, archive_match_include_pattern(m, "^a1*"));
388*fd082e96SMartin Matuska 
389*fd082e96SMartin Matuska 	/* Test with 'aa1234', which should not be excluded. */
390*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aa1234");
391*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
392*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
393*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
394*fd082e96SMartin Matuska 	archive_entry_clear(ae);
395*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aa1234");
396*fd082e96SMartin Matuska 	failure("'aa1234' should not be excluded");
397*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_path_excluded(m, ae));
398*fd082e96SMartin Matuska 	assertEqualInt(0, archive_match_excluded(m, ae));
399*fd082e96SMartin Matuska 
400*fd082e96SMartin Matuska 	/* Test with 'aaa1234', which should be excluded. */
401*fd082e96SMartin Matuska 	archive_entry_copy_pathname(ae, "aaa1234");
402*fd082e96SMartin Matuska 	failure("'aaa1234' should be excluded");
403*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
404*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
405*fd082e96SMartin Matuska 	archive_entry_clear(ae);
406*fd082e96SMartin Matuska 	archive_entry_copy_pathname_w(ae, L"aaa1234");
407*fd082e96SMartin Matuska 	failure("'aaa1234' should be excluded");
408*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_excluded(m, ae));
409*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_excluded(m, ae));
410*fd082e96SMartin Matuska 
411*fd082e96SMartin Matuska 	/* Verify unmatched_inclusions. */
412*fd082e96SMartin Matuska 	assertEqualInt(1, archive_match_path_unmatched_inclusions(m));
413*fd082e96SMartin Matuska 	/* Verify unmatched inclusion patterns. */
414*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_OK,
415*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next(m, &mp));
416*fd082e96SMartin Matuska 	assertEqualString("^a1*", mp);
417*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_EOF,
418*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next(m, &mp));
419*fd082e96SMartin Matuska 	/* Verify unmatched inclusion patterns again in Wide-Char. */
420*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_OK,
421*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next_w(m, &wp));
422*fd082e96SMartin Matuska 	assertEqualWString(L"^a1*", wp);
423*fd082e96SMartin Matuska 	assertEqualIntA(m, ARCHIVE_EOF,
424*fd082e96SMartin Matuska 	    archive_match_path_unmatched_inclusions_next_w(m, &wp));
425*fd082e96SMartin Matuska 
426*fd082e96SMartin Matuska 	/* Clean up. */
427*fd082e96SMartin Matuska 	archive_entry_free(ae);
428*fd082e96SMartin Matuska 	archive_match_free(m);
429*fd082e96SMartin Matuska }
430*fd082e96SMartin Matuska 
431*fd082e96SMartin Matuska DEFINE_TEST(test_archive_match_path)
432*fd082e96SMartin Matuska {
433*fd082e96SMartin Matuska 	/* Make exclusion sample files which contain exclusion patterns. */
434*fd082e96SMartin Matuska 	assertMakeFile("exclusion", 0666, "second\nfour\n");
435*fd082e96SMartin Matuska 	assertMakeBinFile("exclusion_null", 0666, 12, "second\0four\0");
436*fd082e96SMartin Matuska 	/* Make inclusion sample files which contain inclusion patterns. */
437*fd082e96SMartin Matuska 	assertMakeFile("inclusion", 0666, "first\nthird\n");
438*fd082e96SMartin Matuska 	assertMakeBinFile("inclusion_null", 0666, 12, "first\0third\0");
439*fd082e96SMartin Matuska 
440*fd082e96SMartin Matuska 	test_exclusion_mbs();
441*fd082e96SMartin Matuska 	test_exclusion_wcs();
442*fd082e96SMartin Matuska 	test_exclusion_from_file_mbs();
443*fd082e96SMartin Matuska 	test_exclusion_from_file_wcs();
444*fd082e96SMartin Matuska 	test_inclusion_mbs();
445*fd082e96SMartin Matuska 	test_inclusion_wcs();
446*fd082e96SMartin Matuska 	test_inclusion_from_file_mbs();
447*fd082e96SMartin Matuska 	test_inclusion_from_file_wcs();
448*fd082e96SMartin Matuska 	test_exclusion_and_inclusion();
449*fd082e96SMartin Matuska }
450