]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_archive_match_time.c
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_archive_match_time.c
1 /*-
2  * Copyright (c) 2012 Michihiro NAKAJIMA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "test.h"
27 __FBSDID("$FreeBSD$");
28
29 #define __LIBARCHIVE_BUILD 1
30 #include "archive_getdate.h"
31
32 static void
33 test_newer_time(void)
34 {
35         struct archive_entry *ae;
36         struct archive *m;
37
38         if (!assert((m = archive_match_new()) != NULL))
39                 return;
40         if (!assert((ae = archive_entry_new()) != NULL)) {
41                 archive_match_free(m);
42                 return;
43         }
44
45         assertEqualIntA(m, 0, archive_match_include_time(m,
46             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
47             ARCHIVE_MATCH_NEWER, 7880, 0));
48
49         archive_entry_copy_pathname(ae, "file1");
50         archive_entry_set_mtime(ae, 7880, 0);
51         archive_entry_set_ctime(ae, 7880, 0);
52         failure("Both Its mtime and ctime should be excluded");
53         assertEqualInt(1, archive_match_time_excluded(m, ae));
54         assertEqualInt(1, archive_match_excluded(m, ae));
55         archive_entry_set_mtime(ae, 7879, 999);
56         archive_entry_set_ctime(ae, 7879, 999);
57         failure("Both Its mtime and ctime should be excluded");
58         assertEqualInt(1, archive_match_time_excluded(m, ae));
59         assertEqualInt(1, archive_match_excluded(m, ae));
60
61         archive_entry_set_mtime(ae, 7881, 0);
62         archive_entry_set_ctime(ae, 7881, 0);
63         failure("Both Its mtime and ctime should not be excluded");
64         assertEqualInt(0, archive_match_time_excluded(m, ae));
65         assertEqualInt(0, archive_match_excluded(m, ae));
66
67         archive_entry_set_mtime(ae, 7880, 1);
68         archive_entry_set_ctime(ae, 7880, 0);
69         failure("Its mtime should be excluded");
70         assertEqualInt(1, archive_match_time_excluded(m, ae));
71         assertEqualInt(1, archive_match_excluded(m, ae));
72
73         archive_entry_set_mtime(ae, 7880, 0);
74         archive_entry_set_ctime(ae, 7880, 1);
75         failure("Its ctime should be excluded");
76         assertEqualInt(1, archive_match_time_excluded(m, ae));
77         assertEqualInt(1, archive_match_excluded(m, ae));
78
79         /* Clean up. */
80         archive_entry_free(ae);
81         archive_match_free(m);
82 }
83
84 static void
85 test_newer_time_str(void)
86 {
87         struct archive_entry *ae;
88         struct archive *m;
89         time_t now, t;
90
91         if (!assert((m = archive_match_new()) != NULL))
92                 return;
93         if (!assert((ae = archive_entry_new()) != NULL)) {
94                 archive_match_free(m);
95                 return;
96         }
97
98         time(&now);
99
100         assertEqualIntA(m, 0, archive_match_include_date(m,
101             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
102             ARCHIVE_MATCH_NEWER, "1980/2/1 0:0:0 UTC"));
103
104         /* Test1: Allow newer time. */
105         archive_entry_copy_pathname(ae, "file1");
106         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
107         archive_entry_set_mtime(ae, t, 0);
108         archive_entry_set_ctime(ae, t, 0);
109         failure("Both Its mtime and ctime should be excluded");
110         assertEqualInt(1, archive_match_time_excluded(m, ae));
111         assertEqualInt(1, archive_match_excluded(m, ae));
112         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
113         archive_entry_set_mtime(ae, t, 0);
114         archive_entry_set_ctime(ae, t, 0);
115         failure("Both Its mtime and ctime should be excluded");
116         assertEqualInt(1, archive_match_time_excluded(m, ae));
117         assertEqualInt(1, archive_match_excluded(m, ae));
118
119         t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
120         archive_entry_set_mtime(ae, t, 0);
121         archive_entry_set_ctime(ae, t, 0);
122         failure("Both Its mtime and ctime should not be excluded");
123         assertEqualInt(0, archive_match_time_excluded(m, ae));
124         assertEqualInt(0, archive_match_excluded(m, ae));
125
126         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
127         archive_entry_set_mtime(ae, t, 1);
128         archive_entry_set_ctime(ae, t, 0);
129         failure("Its mtime should be excluded");
130         assertEqualInt(1, archive_match_time_excluded(m, ae));
131         assertEqualInt(1, archive_match_excluded(m, ae));
132
133         archive_entry_set_mtime(ae, t, 0);
134         archive_entry_set_ctime(ae, t, 1);
135         failure("Its ctime should be excluded");
136         assertEqualInt(1, archive_match_time_excluded(m, ae));
137         assertEqualInt(1, archive_match_excluded(m, ae));
138
139
140         /* Test2: Allow equal or newer time. */
141         assertEqualIntA(m, 0, archive_match_include_date(m,
142             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
143             ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_EQUAL,
144             "1980/2/1 0:0:0 UTC"));
145
146         archive_entry_copy_pathname(ae, "file1");
147         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
148         archive_entry_set_mtime(ae, t, 0);
149         archive_entry_set_ctime(ae, t, 0);
150         failure("Both Its mtime and ctime should not be excluded");
151         assertEqualInt(0, archive_match_time_excluded(m, ae));
152         assertEqualInt(0, archive_match_excluded(m, ae));
153         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
154         archive_entry_set_mtime(ae, t, 0);
155         archive_entry_set_ctime(ae, t, 0);
156         failure("Both Its mtime and ctime should be excluded");
157         assertEqualInt(1, archive_match_time_excluded(m, ae));
158         assertEqualInt(1, archive_match_excluded(m, ae));
159
160         t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
161         archive_entry_set_mtime(ae, t, 0);
162         archive_entry_set_ctime(ae, t, 0);
163         failure("Both Its mtime and ctime should not be excluded");
164         assertEqualInt(0, archive_match_time_excluded(m, ae));
165         assertEqualInt(0, archive_match_excluded(m, ae));
166
167         /* Clean up. */
168         archive_entry_free(ae);
169         archive_match_free(m);
170 }
171
172 static void
173 test_newer_time_str_w(void)
174 {
175         struct archive_entry *ae;
176         struct archive *m;
177         time_t now, t;
178
179         if (!assert((m = archive_match_new()) != NULL))
180                 return;
181         if (!assert((ae = archive_entry_new()) != NULL)) {
182                 archive_match_free(m);
183                 return;
184         }
185
186         time(&now);
187
188         assertEqualIntA(m, 0, archive_match_include_date_w(m,
189             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
190             ARCHIVE_MATCH_NEWER, L"1980/2/1 0:0:0 UTC"));
191
192         /* Test1: Allow newer time. */
193         archive_entry_copy_pathname(ae, "file1");
194         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
195         archive_entry_set_mtime(ae, t, 0);
196         archive_entry_set_ctime(ae, t, 0);
197         failure("Both Its mtime and ctime should be excluded");
198         assertEqualInt(1, archive_match_time_excluded(m, ae));
199         assertEqualInt(1, archive_match_excluded(m, ae));
200         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
201         archive_entry_set_mtime(ae, t, 0);
202         archive_entry_set_ctime(ae, t, 0);
203         failure("Both Its mtime and ctime should be excluded");
204         assertEqualInt(1, archive_match_time_excluded(m, ae));
205         assertEqualInt(1, archive_match_excluded(m, ae));
206
207         t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
208         archive_entry_set_mtime(ae, t, 0);
209         archive_entry_set_ctime(ae, t, 0);
210         failure("Both Its mtime and ctime should not be excluded");
211         assertEqualInt(0, archive_match_time_excluded(m, ae));
212         assertEqualInt(0, archive_match_excluded(m, ae));
213
214         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
215         archive_entry_set_mtime(ae, t, 1);
216         archive_entry_set_ctime(ae, t, 0);
217         failure("Its mtime should be excluded");
218         assertEqualInt(1, archive_match_time_excluded(m, ae));
219         assertEqualInt(1, archive_match_excluded(m, ae));
220
221         archive_entry_set_mtime(ae, t, 0);
222         archive_entry_set_ctime(ae, t, 1);
223         failure("Its ctime should be excluded");
224         assertEqualInt(1, archive_match_time_excluded(m, ae));
225         assertEqualInt(1, archive_match_excluded(m, ae));
226
227
228         /* Test2: Allow equal or newer time. */
229         assertEqualIntA(m, 0, archive_match_include_date_w(m,
230             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
231             ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_EQUAL,
232             L"1980/2/1 0:0:0 UTC"));
233
234         archive_entry_copy_pathname(ae, "file1");
235         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
236         archive_entry_set_mtime(ae, t, 0);
237         archive_entry_set_ctime(ae, t, 0);
238         failure("Both Its mtime and ctime should not be excluded");
239         assertEqualInt(0, archive_match_time_excluded(m, ae));
240         assertEqualInt(0, archive_match_excluded(m, ae));
241         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
242         archive_entry_set_mtime(ae, t, 0);
243         archive_entry_set_ctime(ae, t, 0);
244         failure("Both Its mtime and ctime should be excluded");
245         assertEqualInt(1, archive_match_time_excluded(m, ae));
246         assertEqualInt(1, archive_match_excluded(m, ae));
247
248         t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
249         archive_entry_set_mtime(ae, t, 0);
250         archive_entry_set_ctime(ae, t, 0);
251         failure("Both Its mtime and ctime should not be excluded");
252         assertEqualInt(0, archive_match_time_excluded(m, ae));
253         assertEqualInt(0, archive_match_excluded(m, ae));
254
255         /* Clean up. */
256         archive_entry_free(ae);
257         archive_match_free(m);
258 }
259
260 static void
261 test_newer_mtime_than_file_mbs(void)
262 {
263         struct archive *a;
264         struct archive_entry *ae;
265         struct archive *m;
266
267         if (!assert((m = archive_match_new()) != NULL))
268                 return;
269         if (!assert((ae = archive_entry_new()) != NULL)) {
270                 archive_match_free(m);
271                 return;
272         }
273         if (!assert((a = archive_read_disk_new()) != NULL)) {
274                 archive_match_free(m);
275                 archive_entry_free(ae);
276                 return;
277         }
278
279         /*
280          * Test: newer mtime than a file specified in MBS file name.
281          */
282         assertEqualIntA(m, 0, archive_match_include_file_time(m,
283             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "mid_mtime"));
284
285         /* Verify 'old_mtime' file. */
286         archive_entry_copy_pathname(ae, "old_mtime");
287         assertEqualIntA(a, ARCHIVE_OK,
288             archive_read_disk_entry_from_file(a, ae, -1, NULL));
289         failure("old_mtime should be excluded");
290         assertEqualInt(1, archive_match_time_excluded(m, ae));
291         assertEqualInt(1, archive_match_excluded(m, ae));
292
293         /* Verify 'mid_mtime' file. */
294         archive_entry_clear(ae);
295         archive_entry_copy_pathname(ae, "mid_mtime");
296         assertEqualIntA(a, ARCHIVE_OK,
297             archive_read_disk_entry_from_file(a, ae, -1, NULL));
298         failure("mid_mtime should be excluded");
299         assertEqualInt(1, archive_match_time_excluded(m, ae));
300         assertEqualInt(1, archive_match_excluded(m, ae));
301
302         /* Verify 'new_mtime' file. */
303         archive_entry_clear(ae);
304         archive_entry_copy_pathname(ae, "new_mtime");
305         assertEqualIntA(a, ARCHIVE_OK,
306             archive_read_disk_entry_from_file(a, ae, -1, NULL));
307         failure("new_mtime should not be excluded");
308         assertEqualInt(0, archive_match_time_excluded(m, ae));
309         assertEqualInt(0, archive_match_excluded(m, ae));
310
311         /* Clean up. */
312         archive_read_free(a);
313         archive_entry_free(ae);
314         archive_match_free(m);
315 }
316
317 static void
318 test_newer_ctime_than_file_mbs(void)
319 {
320         struct archive *a;
321         struct archive_entry *ae;
322         struct archive *m;
323
324         if (!assert((m = archive_match_new()) != NULL))
325                 return;
326         if (!assert((ae = archive_entry_new()) != NULL)) {
327                 archive_match_free(m);
328                 return;
329         }
330         if (!assert((a = archive_read_disk_new()) != NULL)) {
331                 archive_match_free(m);
332                 archive_entry_free(ae);
333                 return;
334         }
335
336         /*
337          * Test: newer ctime than a file specified in MBS file name.
338          */
339         assertEqualIntA(m, 0, archive_match_include_file_time(m,
340             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "mid_ctime"));
341
342         /* Verify 'old_ctime' file. */
343         archive_entry_copy_pathname(ae, "old_ctime");
344         assertEqualIntA(a, ARCHIVE_OK,
345             archive_read_disk_entry_from_file(a, ae, -1, NULL));
346         failure("old_ctime should be excluded");
347         assertEqualInt(1, archive_match_time_excluded(m, ae));
348         assertEqualInt(1, archive_match_excluded(m, ae));
349
350         /* Verify 'mid_ctime' file. */
351         archive_entry_clear(ae);
352         archive_entry_copy_pathname(ae, "mid_ctime");
353         assertEqualIntA(a, ARCHIVE_OK,
354             archive_read_disk_entry_from_file(a, ae, -1, NULL));
355         failure("mid_ctime should be excluded");
356         assertEqualInt(1, archive_match_time_excluded(m, ae));
357         assertEqualInt(1, archive_match_excluded(m, ae));
358
359         /* Verify 'new_ctime' file. */
360         archive_entry_clear(ae);
361         archive_entry_copy_pathname(ae, "new_ctime");
362         assertEqualIntA(a, ARCHIVE_OK,
363             archive_read_disk_entry_from_file(a, ae, -1, NULL));
364         failure("new_ctime should not be excluded");
365         assertEqualInt(0, archive_match_time_excluded(m, ae));
366         assertEqualInt(0, archive_match_excluded(m, ae));
367
368         /* Clean up. */
369         archive_read_free(a);
370         archive_entry_free(ae);
371         archive_match_free(m);
372 }
373
374 static void
375 test_newer_mtime_than_file_wcs(void)
376 {
377         struct archive *a;
378         struct archive_entry *ae;
379         struct archive *m;
380
381         if (!assert((m = archive_match_new()) != NULL))
382                 return;
383         if (!assert((ae = archive_entry_new()) != NULL)) {
384                 archive_match_free(m);
385                 return;
386         }
387         if (!assert((a = archive_read_disk_new()) != NULL)) {
388                 archive_match_free(m);
389                 archive_entry_free(ae);
390                 return;
391         }
392
393         /*
394          * Test: newer mtime than a file specified in WCS file name.
395          */
396         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
397             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"mid_mtime"));
398
399         /* Verify 'old_mtime' file. */
400         archive_entry_copy_pathname(ae, "old_mtime");
401         assertEqualIntA(a, ARCHIVE_OK,
402             archive_read_disk_entry_from_file(a, ae, -1, NULL));
403         failure("old_mtime should be excluded");
404         assertEqualInt(1, archive_match_time_excluded(m, ae));
405         assertEqualInt(1, archive_match_excluded(m, ae));
406
407         /* Verify 'mid_mtime' file. */
408         archive_entry_clear(ae);
409         archive_entry_copy_pathname(ae, "mid_mtime");
410         assertEqualIntA(a, ARCHIVE_OK,
411             archive_read_disk_entry_from_file(a, ae, -1, NULL));
412         failure("mid_mtime should be excluded");
413         assertEqualInt(1, archive_match_time_excluded(m, ae));
414         assertEqualInt(1, archive_match_excluded(m, ae));
415
416         /* Verify 'new_mtime' file. */
417         archive_entry_clear(ae);
418         archive_entry_copy_pathname(ae, "new_mtime");
419         assertEqualIntA(a, ARCHIVE_OK,
420             archive_read_disk_entry_from_file(a, ae, -1, NULL));
421         failure("new_mtime should not be excluded");
422         assertEqualInt(0, archive_match_time_excluded(m, ae));
423         assertEqualInt(0, archive_match_excluded(m, ae));
424
425         /* Clean up. */
426         archive_read_free(a);
427         archive_entry_free(ae);
428         archive_match_free(m);
429 }
430
431 static void
432 test_newer_ctime_than_file_wcs(void)
433 {
434         struct archive *a;
435         struct archive_entry *ae;
436         struct archive *m;
437
438         if (!assert((m = archive_match_new()) != NULL))
439                 return;
440         if (!assert((ae = archive_entry_new()) != NULL)) {
441                 archive_match_free(m);
442                 return;
443         }
444         if (!assert((a = archive_read_disk_new()) != NULL)) {
445                 archive_match_free(m);
446                 archive_entry_free(ae);
447                 return;
448         }
449
450         /*
451          * Test: newer ctime than a file specified in WCS file name.
452          */
453         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
454             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"mid_ctime"));
455
456         /* Verify 'old_ctime' file. */
457         archive_entry_clear(ae);
458         archive_entry_copy_pathname(ae, "old_ctime");
459         assertEqualIntA(a, ARCHIVE_OK,
460             archive_read_disk_entry_from_file(a, ae, -1, NULL));
461         failure("old_ctime should be excluded");
462         assertEqualInt(1, archive_match_time_excluded(m, ae));
463         assertEqualInt(1, archive_match_excluded(m, ae));
464
465         /* Verify 'mid_ctime' file. */
466         archive_entry_clear(ae);
467         archive_entry_copy_pathname(ae, "mid_ctime");
468         assertEqualIntA(a, ARCHIVE_OK,
469             archive_read_disk_entry_from_file(a, ae, -1, NULL));
470         failure("mid_ctime should be excluded");
471         assertEqualInt(1, archive_match_time_excluded(m, ae));
472         assertEqualInt(1, archive_match_excluded(m, ae));
473
474         /* Verify 'new_ctime' file. */
475         archive_entry_clear(ae);
476         archive_entry_copy_pathname(ae, "new_ctime");
477         assertEqualIntA(a, ARCHIVE_OK,
478             archive_read_disk_entry_from_file(a, ae, -1, NULL));
479         failure("new_ctime should not be excluded");
480         assertEqualInt(0, archive_match_time_excluded(m, ae));
481         assertEqualInt(0, archive_match_excluded(m, ae));
482
483         /* Clean up. */
484         archive_read_free(a);
485         archive_entry_free(ae);
486         archive_match_free(m);
487 }
488
489 static void
490 test_older_time(void)
491 {
492         struct archive_entry *ae;
493         struct archive *m;
494
495         if (!assert((m = archive_match_new()) != NULL))
496                 return;
497         if (!assert((ae = archive_entry_new()) != NULL)) {
498                 archive_match_free(m);
499                 return;
500         }
501
502         assertEqualIntA(m, 0, archive_match_include_time(m,
503             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
504             ARCHIVE_MATCH_OLDER, 7880, 0));
505
506         archive_entry_copy_pathname(ae, "file1");
507         archive_entry_set_mtime(ae, 7880, 0);
508         archive_entry_set_ctime(ae, 7880, 0);
509         failure("Both Its mtime and ctime should be excluded");
510         assertEqualInt(1, archive_match_time_excluded(m, ae));
511         assertEqualInt(1, archive_match_excluded(m, ae));
512         archive_entry_set_mtime(ae, 7879, 999);
513         archive_entry_set_ctime(ae, 7879, 999);
514         failure("Both Its mtime and ctime should not be excluded");
515         assertEqualInt(0, archive_match_time_excluded(m, ae));
516         assertEqualInt(0, archive_match_excluded(m, ae));
517
518         archive_entry_set_mtime(ae, 7881, 0);
519         archive_entry_set_ctime(ae, 7881, 0);
520         failure("Both Its mtime and ctime should be excluded");
521         assertEqualInt(1, archive_match_time_excluded(m, ae));
522         assertEqualInt(1, archive_match_excluded(m, ae));
523
524         archive_entry_set_mtime(ae, 7880, 1);
525         archive_entry_set_ctime(ae, 7879, 0);
526         failure("Its mtime should be excluded");
527         assertEqualInt(1, archive_match_time_excluded(m, ae));
528         assertEqualInt(1, archive_match_excluded(m, ae));
529
530         archive_entry_set_mtime(ae, 7879, 0);
531         archive_entry_set_ctime(ae, 7880, 1);
532         failure("Its ctime should be excluded");
533         assertEqualInt(1, archive_match_time_excluded(m, ae));
534         assertEqualInt(1, archive_match_excluded(m, ae));
535
536         /* Clean up. */
537         archive_entry_free(ae);
538         archive_match_free(m);
539 }
540
541 static void
542 test_older_time_str(void)
543 {
544         struct archive_entry *ae;
545         struct archive *m;
546         time_t now, t;
547
548         if (!assert((m = archive_match_new()) != NULL))
549                 return;
550         if (!assert((ae = archive_entry_new()) != NULL)) {
551                 archive_match_free(m);
552                 return;
553         }
554
555         time(&now);
556
557         /* Test1: Allow newer time. */
558         assertEqualIntA(m, 0, archive_match_include_date(m,
559             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
560             ARCHIVE_MATCH_OLDER, "1980/2/1 0:0:0 UTC"));
561
562         archive_entry_copy_pathname(ae, "file1");
563         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
564         archive_entry_set_mtime(ae, t, 0);
565         archive_entry_set_ctime(ae, t, 0);
566         failure("Both Its mtime and ctime should be excluded");
567         assertEqualInt(1, archive_match_time_excluded(m, ae));
568         assertEqualInt(1, archive_match_excluded(m, ae));
569         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
570         archive_entry_set_mtime(ae, t, 0);
571         archive_entry_set_ctime(ae, t, 0);
572         failure("Both Its mtime and ctime should not be excluded");
573         assertEqualInt(0, archive_match_time_excluded(m, ae));
574         assertEqualInt(0, archive_match_excluded(m, ae));
575
576         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
577         archive_entry_set_mtime(ae, t, 0);
578         archive_entry_set_ctime(ae, t, 0);
579         failure("Both Its mtime and ctime should be excluded");
580         assertEqualInt(1, archive_match_time_excluded(m, ae));
581         assertEqualInt(1, archive_match_excluded(m, ae));
582
583         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
584         archive_entry_set_mtime(ae, t, 0);
585         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
586         archive_entry_set_ctime(ae, t, 0);
587         failure("Its mtime should be excluded");
588         assertEqualInt(1, archive_match_time_excluded(m, ae));
589         assertEqualInt(1, archive_match_excluded(m, ae));
590
591         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
592         archive_entry_set_mtime(ae, t, 0);
593         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
594         archive_entry_set_ctime(ae, t, 0);
595         failure("Its ctime should be excluded");
596         assertEqualInt(1, archive_match_time_excluded(m, ae));
597         assertEqualInt(1, archive_match_excluded(m, ae));
598
599         /* Test2: Allow equal or newer time. */
600         assertEqualIntA(m, 0, archive_match_include_date(m,
601             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
602             ARCHIVE_MATCH_OLDER | ARCHIVE_MATCH_EQUAL,
603             "1980/2/1 0:0:0 UTC"));
604
605         archive_entry_copy_pathname(ae, "file1");
606         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
607         archive_entry_set_mtime(ae, t, 0);
608         archive_entry_set_ctime(ae, t, 0);
609         failure("Both Its mtime and ctime should not be excluded");
610         assertEqualInt(0, archive_match_time_excluded(m, ae));
611         assertEqualInt(0, archive_match_excluded(m, ae));
612         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
613         archive_entry_set_mtime(ae, t, 0);
614         archive_entry_set_ctime(ae, t, 0);
615         failure("Both Its mtime and ctime should not be excluded");
616         assertEqualInt(0, archive_match_time_excluded(m, ae));
617         assertEqualInt(0, archive_match_excluded(m, ae));
618
619         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
620         archive_entry_set_mtime(ae, t, 0);
621         archive_entry_set_ctime(ae, t, 0);
622         failure("Both Its mtime and ctime should be excluded");
623         assertEqualInt(1, archive_match_time_excluded(m, ae));
624         assertEqualInt(1, archive_match_excluded(m, ae));
625
626         /* Clean up. */
627         archive_entry_free(ae);
628         archive_match_free(m);
629 }
630
631 static void
632 test_older_time_str_w(void)
633 {
634         struct archive_entry *ae;
635         struct archive *m;
636         time_t now, t;
637
638         if (!assert((m = archive_match_new()) != NULL))
639                 return;
640         if (!assert((ae = archive_entry_new()) != NULL)) {
641                 archive_match_free(m);
642                 return;
643         }
644
645         time(&now);
646
647         /* Test1: Allow newer time. */
648         assertEqualIntA(m, 0, archive_match_include_date_w(m,
649             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
650             ARCHIVE_MATCH_OLDER, L"1980/2/1 0:0:0 UTC"));
651
652         archive_entry_copy_pathname(ae, "file1");
653         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
654         archive_entry_set_mtime(ae, t, 0);
655         archive_entry_set_ctime(ae, t, 0);
656         failure("Both Its mtime and ctime should be excluded");
657         assertEqualInt(1, archive_match_time_excluded(m, ae));
658         assertEqualInt(1, archive_match_excluded(m, ae));
659         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
660         archive_entry_set_mtime(ae, t, 0);
661         archive_entry_set_ctime(ae, t, 0);
662         failure("Both Its mtime and ctime should not be excluded");
663         assertEqualInt(0, archive_match_time_excluded(m, ae));
664         assertEqualInt(0, archive_match_excluded(m, ae));
665
666         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
667         archive_entry_set_mtime(ae, t, 0);
668         archive_entry_set_ctime(ae, t, 0);
669         failure("Both Its mtime and ctime should be excluded");
670         assertEqualInt(1, archive_match_time_excluded(m, ae));
671         assertEqualInt(1, archive_match_excluded(m, ae));
672
673         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
674         archive_entry_set_mtime(ae, t, 0);
675         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
676         archive_entry_set_ctime(ae, t, 0);
677         failure("Its mtime should be excluded");
678         assertEqualInt(1, archive_match_time_excluded(m, ae));
679         assertEqualInt(1, archive_match_excluded(m, ae));
680
681         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
682         archive_entry_set_mtime(ae, t, 0);
683         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
684         archive_entry_set_ctime(ae, t, 0);
685         failure("Its ctime should be excluded");
686         assertEqualInt(1, archive_match_time_excluded(m, ae));
687         assertEqualInt(1, archive_match_excluded(m, ae));
688
689         /* Test2: Allow equal or newer time. */
690         assertEqualIntA(m, 0, archive_match_include_date_w(m,
691             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
692             ARCHIVE_MATCH_OLDER | ARCHIVE_MATCH_EQUAL,
693             L"1980/2/1 0:0:0 UTC"));
694
695         archive_entry_copy_pathname(ae, "file1");
696         t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
697         archive_entry_set_mtime(ae, t, 0);
698         archive_entry_set_ctime(ae, t, 0);
699         failure("Both Its mtime and ctime should not be excluded");
700         assertEqualInt(0, archive_match_time_excluded(m, ae));
701         assertEqualInt(0, archive_match_excluded(m, ae));
702         t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
703         archive_entry_set_mtime(ae, t, 0);
704         archive_entry_set_ctime(ae, t, 0);
705         failure("Both Its mtime and ctime should not be excluded");
706         assertEqualInt(0, archive_match_time_excluded(m, ae));
707         assertEqualInt(0, archive_match_excluded(m, ae));
708
709         t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
710         archive_entry_set_mtime(ae, t, 0);
711         archive_entry_set_ctime(ae, t, 0);
712         failure("Both Its mtime and ctime should be excluded");
713         assertEqualInt(1, archive_match_time_excluded(m, ae));
714         assertEqualInt(1, archive_match_excluded(m, ae));
715
716         /* Clean up. */
717         archive_entry_free(ae);
718         archive_match_free(m);
719 }
720
721 static void
722 test_older_mtime_than_file_mbs(void)
723 {
724         struct archive *a;
725         struct archive_entry *ae;
726         struct archive *m;
727
728         if (!assert((m = archive_match_new()) != NULL))
729                 return;
730         if (!assert((ae = archive_entry_new()) != NULL)) {
731                 archive_match_free(m);
732                 return;
733         }
734         if (!assert((a = archive_read_disk_new()) != NULL)) {
735                 archive_match_free(m);
736                 archive_entry_free(ae);
737                 return;
738         }
739
740         /*
741          * Test: older mtime than a file specified in MBS file name.
742          */
743         assertEqualIntA(m, 0, archive_match_include_file_time(m,
744             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "mid_mtime"));
745
746         /* Verify 'old_mtime' file. */
747         archive_entry_copy_pathname(ae, "old_mtime");
748         assertEqualIntA(a, ARCHIVE_OK,
749             archive_read_disk_entry_from_file(a, ae, -1, NULL));
750         failure("old_mtime should not be excluded");
751         assertEqualInt(0, archive_match_time_excluded(m, ae));
752         assertEqualInt(0, archive_match_excluded(m, ae));
753
754         /* Verify 'mid_mtime' file. */
755         archive_entry_clear(ae);
756         archive_entry_copy_pathname(ae, "mid_mtime");
757         assertEqualIntA(a, ARCHIVE_OK,
758             archive_read_disk_entry_from_file(a, ae, -1, NULL));
759         failure("mid_mtime should be excluded");
760         assertEqualInt(1, archive_match_time_excluded(m, ae));
761         assertEqualInt(1, archive_match_excluded(m, ae));
762
763         /* Verify 'new_mtime' file. */
764         archive_entry_clear(ae);
765         archive_entry_copy_pathname(ae, "new_mtime");
766         assertEqualIntA(a, ARCHIVE_OK,
767             archive_read_disk_entry_from_file(a, ae, -1, NULL));
768         failure("new_mtime should be excluded");
769         assertEqualInt(1, archive_match_time_excluded(m, ae));
770         assertEqualInt(1, archive_match_excluded(m, ae));
771
772         /* Clean up. */
773         archive_read_free(a);
774         archive_entry_free(ae);
775         archive_match_free(m);
776 }
777
778 static void
779 test_older_ctime_than_file_mbs(void)
780 {
781         struct archive *a;
782         struct archive_entry *ae;
783         struct archive *m;
784
785         if (!assert((m = archive_match_new()) != NULL))
786                 return;
787         if (!assert((ae = archive_entry_new()) != NULL)) {
788                 archive_match_free(m);
789                 return;
790         }
791         if (!assert((a = archive_read_disk_new()) != NULL)) {
792                 archive_match_free(m);
793                 archive_entry_free(ae);
794                 return;
795         }
796
797         /*
798          * Test: older ctime than a file specified in MBS file name.
799          */
800         assertEqualIntA(m, 0, archive_match_include_file_time(m,
801             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "mid_ctime"));
802
803         /* Verify 'old_ctime' file. */
804         archive_entry_clear(ae);
805         archive_entry_copy_pathname(ae, "old_ctime");
806         assertEqualIntA(a, ARCHIVE_OK,
807             archive_read_disk_entry_from_file(a, ae, -1, NULL));
808         failure("old_ctime should not be excluded");
809         assertEqualInt(0, archive_match_time_excluded(m, ae));
810         assertEqualInt(0, archive_match_excluded(m, ae));
811
812         /* Verify 'mid_ctime' file. */
813         archive_entry_clear(ae);
814         archive_entry_copy_pathname(ae, "mid_ctime");
815         assertEqualIntA(a, ARCHIVE_OK,
816             archive_read_disk_entry_from_file(a, ae, -1, NULL));
817         failure("mid_ctime should be excluded");
818         assertEqualInt(1, archive_match_time_excluded(m, ae));
819         assertEqualInt(1, archive_match_excluded(m, ae));
820
821         /* Verify 'new_ctime' file. */
822         archive_entry_clear(ae);
823         archive_entry_copy_pathname(ae, "new_ctime");
824         assertEqualIntA(a, ARCHIVE_OK,
825             archive_read_disk_entry_from_file(a, ae, -1, NULL));
826         failure("new_ctime should be excluded");
827         assertEqualInt(1, archive_match_time_excluded(m, ae));
828         assertEqualInt(1, archive_match_excluded(m, ae));
829
830         /* Clean up. */
831         archive_read_free(a);
832         archive_entry_free(ae);
833         archive_match_free(m);
834 }
835
836 static void
837 test_older_mtime_than_file_wcs(void)
838 {
839         struct archive *a;
840         struct archive_entry *ae;
841         struct archive *m;
842
843         if (!assert((m = archive_match_new()) != NULL))
844                 return;
845         if (!assert((ae = archive_entry_new()) != NULL)) {
846                 archive_match_free(m);
847                 return;
848         }
849         if (!assert((a = archive_read_disk_new()) != NULL)) {
850                 archive_match_free(m);
851                 archive_entry_free(ae);
852                 return;
853         }
854
855         /*
856          * Test: older mtime than a file specified in WCS file name.
857          */
858         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
859             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"mid_mtime"));
860
861         /* Verify 'old_mtime' file. */
862         archive_entry_copy_pathname(ae, "old_mtime");
863         assertEqualIntA(a, ARCHIVE_OK,
864             archive_read_disk_entry_from_file(a, ae, -1, NULL));
865         failure("old_mtime should not be excluded");
866         assertEqualInt(0, archive_match_time_excluded(m, ae));
867         assertEqualInt(0, archive_match_excluded(m, ae));
868
869         /* Verify 'mid_mtime' file. */
870         archive_entry_clear(ae);
871         archive_entry_copy_pathname(ae, "mid_mtime");
872         assertEqualIntA(a, ARCHIVE_OK,
873             archive_read_disk_entry_from_file(a, ae, -1, NULL));
874         failure("mid_mtime should be excluded");
875         assertEqualInt(1, archive_match_time_excluded(m, ae));
876         assertEqualInt(1, archive_match_excluded(m, ae));
877
878         /* Verify 'new_mtime' file. */
879         archive_entry_clear(ae);
880         archive_entry_copy_pathname(ae, "new_mtime");
881         assertEqualIntA(a, ARCHIVE_OK,
882             archive_read_disk_entry_from_file(a, ae, -1, NULL));
883         failure("new_mtime should be excluded");
884         assertEqualInt(1, archive_match_time_excluded(m, ae));
885         assertEqualInt(1, archive_match_excluded(m, ae));
886
887         /* Clean up. */
888         archive_read_free(a);
889         archive_entry_free(ae);
890         archive_match_free(m);
891 }
892
893 static void
894 test_older_ctime_than_file_wcs(void)
895 {
896         struct archive *a;
897         struct archive_entry *ae;
898         struct archive *m;
899
900         if (!assert((m = archive_match_new()) != NULL))
901                 return;
902         if (!assert((ae = archive_entry_new()) != NULL)) {
903                 archive_match_free(m);
904                 return;
905         }
906         if (!assert((a = archive_read_disk_new()) != NULL)) {
907                 archive_match_free(m);
908                 archive_entry_free(ae);
909                 return;
910         }
911
912         /*
913          * Test: older ctime than a file specified in WCS file name.
914          */
915         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
916             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"mid_ctime"));
917
918         /* Verify 'old_ctime' file. */
919         archive_entry_clear(ae);
920         archive_entry_copy_pathname(ae, "old_ctime");
921         assertEqualIntA(a, ARCHIVE_OK,
922             archive_read_disk_entry_from_file(a, ae, -1, NULL));
923         failure("old_ctime should not be excluded");
924         assertEqualInt(0, archive_match_time_excluded(m, ae));
925         assertEqualInt(0, archive_match_excluded(m, ae));
926
927         /* Verify 'mid_ctime' file. */
928         archive_entry_clear(ae);
929         archive_entry_copy_pathname(ae, "mid_ctime");
930         assertEqualIntA(a, ARCHIVE_OK,
931             archive_read_disk_entry_from_file(a, ae, -1, NULL));
932         failure("mid_ctime should be excluded");
933         assertEqualInt(1, archive_match_time_excluded(m, ae));
934         assertEqualInt(1, archive_match_excluded(m, ae));
935
936         /* Verify 'new_ctime' file. */
937         archive_entry_clear(ae);
938         archive_entry_copy_pathname(ae, "new_ctime");
939         assertEqualIntA(a, ARCHIVE_OK,
940             archive_read_disk_entry_from_file(a, ae, -1, NULL));
941         failure("new_ctime should be excluded");
942         assertEqualInt(1, archive_match_time_excluded(m, ae));
943         assertEqualInt(1, archive_match_excluded(m, ae));
944
945         /* Clean up. */
946         archive_read_free(a);
947         archive_entry_free(ae);
948         archive_match_free(m);
949 }
950
951 static void
952 test_mtime_between_files_mbs(void)
953 {
954         struct archive *a;
955         struct archive_entry *ae;
956         struct archive *m;
957
958         if (!assert((m = archive_match_new()) != NULL))
959                 return;
960         if (!assert((ae = archive_entry_new()) != NULL)) {
961                 archive_match_free(m);
962                 return;
963         }
964         if (!assert((a = archive_read_disk_new()) != NULL)) {
965                 archive_match_free(m);
966                 archive_entry_free(ae);
967                 return;
968         }
969
970         /*
971          * Test: mtime between  file specified in MBS file name.
972          */
973         assertEqualIntA(m, 0, archive_match_include_file_time(m,
974             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "old_mtime"));
975         assertEqualIntA(m, 0, archive_match_include_file_time(m,
976             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "new_mtime"));
977
978         /* Verify 'old_mtime' file. */
979         archive_entry_copy_pathname(ae, "old_mtime");
980         assertEqualIntA(a, ARCHIVE_OK,
981             archive_read_disk_entry_from_file(a, ae, -1, NULL));
982         failure("old_mtime should be excluded");
983         assertEqualInt(1, archive_match_time_excluded(m, ae));
984         assertEqualInt(1, archive_match_excluded(m, ae));
985
986         /* Verify 'mid_mtime' file. */
987         archive_entry_clear(ae);
988         archive_entry_copy_pathname(ae, "mid_mtime");
989         assertEqualIntA(a, ARCHIVE_OK,
990             archive_read_disk_entry_from_file(a, ae, -1, NULL));
991         failure("mid_mtime should not be excluded");
992         assertEqualInt(0, archive_match_time_excluded(m, ae));
993         assertEqualInt(0, archive_match_excluded(m, ae));
994
995         /* Verify 'new_mtime' file. */
996         archive_entry_clear(ae);
997         archive_entry_copy_pathname(ae, "new_mtime");
998         assertEqualIntA(a, ARCHIVE_OK,
999             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1000         failure("new_mtime should be excluded");
1001         assertEqualInt(1, archive_match_time_excluded(m, ae));
1002         assertEqualInt(1, archive_match_excluded(m, ae));
1003
1004         /* Clean up. */
1005         archive_read_free(a);
1006         archive_entry_free(ae);
1007         archive_match_free(m);
1008 }
1009
1010 static void
1011 test_mtime_between_files_wcs(void)
1012 {
1013         struct archive *a;
1014         struct archive_entry *ae;
1015         struct archive *m;
1016
1017         if (!assert((m = archive_match_new()) != NULL))
1018                 return;
1019         if (!assert((ae = archive_entry_new()) != NULL)) {
1020                 archive_match_free(m);
1021                 return;
1022         }
1023         if (!assert((a = archive_read_disk_new()) != NULL)) {
1024                 archive_match_free(m);
1025                 archive_entry_free(ae);
1026                 return;
1027         }
1028
1029         /*
1030          * Test: mtime between  file specified in WCS file name.
1031          */
1032         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1033             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"old_mtime"));
1034         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1035             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"new_mtime"));
1036
1037         /* Verify 'old_mtime' file. */
1038         archive_entry_copy_pathname(ae, "old_mtime");
1039         assertEqualIntA(a, ARCHIVE_OK,
1040             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1041         failure("old_mtime should be excluded");
1042         assertEqualInt(1, archive_match_time_excluded(m, ae));
1043         assertEqualInt(1, archive_match_excluded(m, ae));
1044
1045         /* Verify 'mid_mtime' file. */
1046         archive_entry_clear(ae);
1047         archive_entry_copy_pathname(ae, "mid_mtime");
1048         assertEqualIntA(a, ARCHIVE_OK,
1049             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1050         failure("mid_mtime should not be excluded");
1051         assertEqualInt(0, archive_match_time_excluded(m, ae));
1052         assertEqualInt(0, archive_match_excluded(m, ae));
1053
1054         /* Verify 'new_mtime' file. */
1055         archive_entry_clear(ae);
1056         archive_entry_copy_pathname(ae, "new_mtime");
1057         assertEqualIntA(a, ARCHIVE_OK,
1058             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1059         failure("new_mtime should be excluded");
1060         assertEqualInt(1, archive_match_time_excluded(m, ae));
1061         assertEqualInt(1, archive_match_excluded(m, ae));
1062
1063         /* Clean up. */
1064         archive_read_free(a);
1065         archive_entry_free(ae);
1066         archive_match_free(m);
1067 }
1068
1069 static void
1070 test_ctime_between_files_mbs(void)
1071 {
1072         struct archive *a;
1073         struct archive_entry *ae;
1074         struct archive *m;
1075
1076         if (!assert((m = archive_match_new()) != NULL))
1077                 return;
1078         if (!assert((ae = archive_entry_new()) != NULL)) {
1079                 archive_match_free(m);
1080                 return;
1081         }
1082         if (!assert((a = archive_read_disk_new()) != NULL)) {
1083                 archive_match_free(m);
1084                 archive_entry_free(ae);
1085                 return;
1086         }
1087
1088         /*
1089          * Test: ctime between files specified in MBS file name.
1090          */
1091         assertEqualIntA(m, 0, archive_match_include_file_time(m,
1092             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "old_ctime"));
1093         assertEqualIntA(m, 0, archive_match_include_file_time(m,
1094             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "new_ctime"));
1095
1096         /* Verify 'old_ctime' file. */
1097         archive_entry_copy_pathname(ae, "old_ctime");
1098         assertEqualIntA(a, ARCHIVE_OK,
1099             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1100         failure("old_ctime should be excluded");
1101         assertEqualInt(1, archive_match_time_excluded(m, ae));
1102         assertEqualInt(1, archive_match_excluded(m, ae));
1103
1104         /* Verify 'mid_ctime' file. */
1105         archive_entry_clear(ae);
1106         archive_entry_copy_pathname(ae, "mid_ctime");
1107         assertEqualIntA(a, ARCHIVE_OK,
1108             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1109         failure("mid_ctime should not be excluded");
1110         assertEqualInt(0, archive_match_time_excluded(m, ae));
1111         assertEqualInt(0, archive_match_excluded(m, ae));
1112
1113         /* Verify 'new_ctime' file. */
1114         archive_entry_clear(ae);
1115         archive_entry_copy_pathname(ae, "new_ctime");
1116         assertEqualIntA(a, ARCHIVE_OK,
1117             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1118         failure("new_ctime should be excluded");
1119         assertEqualInt(1, archive_match_time_excluded(m, ae));
1120         assertEqualInt(1, archive_match_excluded(m, ae));
1121
1122         /* Clean up. */
1123         archive_read_free(a);
1124         archive_entry_free(ae);
1125         archive_match_free(m);
1126 }
1127
1128 static void
1129 test_ctime_between_files_wcs(void)
1130 {
1131         struct archive *a;
1132         struct archive_entry *ae;
1133         struct archive *m;
1134
1135         if (!assert((m = archive_match_new()) != NULL))
1136                 return;
1137         if (!assert((ae = archive_entry_new()) != NULL)) {
1138                 archive_match_free(m);
1139                 return;
1140         }
1141         if (!assert((a = archive_read_disk_new()) != NULL)) {
1142                 archive_match_free(m);
1143                 archive_entry_free(ae);
1144                 return;
1145         }
1146
1147         /*
1148          * Test: ctime between files specified in WCS file name.
1149          */
1150         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1151             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"old_ctime"));
1152         assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1153             ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"new_ctime"));
1154
1155         /* Verify 'old_ctime' file. */
1156         archive_entry_copy_pathname(ae, "old_ctime");
1157         assertEqualIntA(a, ARCHIVE_OK,
1158             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1159         failure("old_ctime should be excluded");
1160         assertEqualInt(1, archive_match_time_excluded(m, ae));
1161         assertEqualInt(1, archive_match_excluded(m, ae));
1162
1163         /* Verify 'mid_ctime' file. */
1164         archive_entry_clear(ae);
1165         archive_entry_copy_pathname(ae, "mid_ctime");
1166         assertEqualIntA(a, ARCHIVE_OK,
1167             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1168         failure("mid_ctime should not be excluded");
1169         assertEqualInt(0, archive_match_time_excluded(m, ae));
1170         assertEqualInt(0, archive_match_excluded(m, ae));
1171
1172         /* Verify 'new_ctime' file. */
1173         archive_entry_clear(ae);
1174         archive_entry_copy_pathname(ae, "new_ctime");
1175         assertEqualIntA(a, ARCHIVE_OK,
1176             archive_read_disk_entry_from_file(a, ae, -1, NULL));
1177         failure("new_ctime should be excluded");
1178         assertEqualInt(1, archive_match_time_excluded(m, ae));
1179         assertEqualInt(1, archive_match_excluded(m, ae));
1180
1181         /* Clean up. */
1182         archive_read_free(a);
1183         archive_entry_free(ae);
1184         archive_match_free(m);
1185 }
1186
1187 static void
1188 excluded(struct archive *m)
1189 {
1190         struct archive_entry *ae;
1191
1192         if (!assert((ae = archive_entry_new()) != NULL))
1193                 return;
1194
1195         archive_entry_copy_pathname(ae, "file1");
1196         archive_entry_set_mtime(ae, 7879, 999);
1197         failure("It should be excluded");
1198         assertEqualInt(1, archive_match_time_excluded(m, ae));
1199         assertEqualInt(1, archive_match_excluded(m, ae));
1200         archive_entry_set_mtime(ae, 7880, 0);
1201         failure("It should be excluded");
1202         assertEqualInt(1, archive_match_time_excluded(m, ae));
1203         assertEqualInt(1, archive_match_excluded(m, ae));
1204         archive_entry_set_mtime(ae, 7880, 1);
1205         failure("It should not be excluded");
1206         assertEqualInt(0, archive_match_time_excluded(m, ae));
1207         assertEqualInt(0, archive_match_excluded(m, ae));
1208
1209         archive_entry_copy_pathname(ae, "file2");
1210         archive_entry_set_mtime(ae, 7879, 999);
1211         failure("It should not be excluded");
1212         assertEqualInt(0, archive_match_time_excluded(m, ae));
1213         assertEqualInt(0, archive_match_excluded(m, ae));
1214         archive_entry_set_mtime(ae, 7880, 0);
1215         failure("It should not be excluded");
1216         assertEqualInt(0, archive_match_time_excluded(m, ae));
1217         assertEqualInt(0, archive_match_excluded(m, ae));
1218         archive_entry_set_mtime(ae, 7880, 1);
1219         failure("It should not be excluded");
1220         assertEqualInt(0, archive_match_time_excluded(m, ae));
1221         assertEqualInt(0, archive_match_excluded(m, ae));
1222
1223         archive_entry_copy_pathname(ae, "file3");
1224         archive_entry_set_mtime(ae, 7879, 999);
1225         failure("It should be excluded");
1226         assertEqualInt(1, archive_match_time_excluded(m, ae));
1227         assertEqualInt(1, archive_match_excluded(m, ae));
1228         archive_entry_set_mtime(ae, 7880, 0);
1229         failure("It should be excluded");
1230         assertEqualInt(1, archive_match_time_excluded(m, ae));
1231         assertEqualInt(1, archive_match_excluded(m, ae));
1232         archive_entry_set_mtime(ae, 7880, 1);
1233         failure("It should be excluded");
1234         assertEqualInt(1, archive_match_time_excluded(m, ae));
1235         assertEqualInt(1, archive_match_excluded(m, ae));
1236
1237         /*
1238          * "file4" is not registered, that sort of a file should not be
1239          * excluded with any mtime.
1240          */
1241         archive_entry_copy_pathname(ae, "file4");
1242         archive_entry_set_mtime(ae, 7879, 999);
1243         failure("It should not be excluded");
1244         assertEqualInt(0, archive_match_time_excluded(m, ae));
1245         assertEqualInt(0, archive_match_excluded(m, ae));
1246         archive_entry_set_mtime(ae, 7880, 0);
1247         failure("It should not be excluded");
1248         assertEqualInt(0, archive_match_time_excluded(m, ae));
1249         assertEqualInt(0, archive_match_excluded(m, ae));
1250         archive_entry_set_mtime(ae, 7880, 1);
1251         failure("It should not be excluded");
1252         assertEqualInt(0, archive_match_time_excluded(m, ae));
1253         assertEqualInt(0, archive_match_excluded(m, ae));
1254
1255
1256         /* Clean up. */
1257         archive_entry_free(ae);
1258 }
1259
1260 static void
1261 test_pathname_newer_mtime(void)
1262 {
1263         struct archive_entry *ae;
1264         struct archive *m;
1265
1266         if (!assert((m = archive_match_new()) != NULL))
1267                 return;
1268         if (!assert((ae = archive_entry_new()) != NULL)) {
1269                 archive_match_free(m);
1270                 return;
1271         }
1272
1273         archive_entry_copy_pathname(ae, "file1");
1274         archive_entry_set_mtime(ae, 7880, 0);
1275         assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1276             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1277             ARCHIVE_MATCH_EQUAL, ae));
1278         archive_entry_copy_pathname(ae, "file2");
1279         archive_entry_set_mtime(ae, 1, 0);
1280         assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1281             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1282             ARCHIVE_MATCH_EQUAL, ae));
1283         archive_entry_copy_pathname(ae, "file3");
1284         archive_entry_set_mtime(ae, 99999, 0);
1285         assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1286             ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1287             ARCHIVE_MATCH_EQUAL, ae));
1288
1289         excluded(m);
1290
1291         /* Clean up. */
1292         archive_entry_free(ae);
1293         archive_match_free(m);
1294 }
1295
1296 DEFINE_TEST(test_archive_match_time)
1297 {
1298         struct stat st;
1299
1300         /* Test: matching newer times. */
1301         test_newer_time();
1302         test_newer_time_str();
1303         test_newer_time_str_w();
1304         /* Test: matching older times. */
1305         test_older_time();
1306         test_older_time_str();
1307         test_older_time_str_w();
1308
1309         /*
1310          * Create sample files for tests matching mtime.
1311          * ctimes of those files may be all the same or the ctime of
1312          * new_mtime may be older than old_mtime.
1313          */
1314         assertMakeFile("new_mtime", 0666, "new");
1315         assertUtimes("new_mtime", 10002, 0, 10002, 0);
1316         assertMakeFile("mid_mtime", 0666, "mid");
1317         assertUtimes("mid_mtime", 10001, 0, 10001, 0);
1318         assertMakeFile("old_mtime", 0666, "old");
1319         assertUtimes("old_mtime", 10000, 0, 10000, 0);
1320
1321         /*
1322          * Create sample files for tests matching ctime.
1323          * the mtime of mid_ctime is older than old_ctime and also the mtime
1324          * of new_ctime is older than both mid_ctime and old_ctime.
1325          */
1326         assertMakeFile("old_ctime", 0666, "old");
1327         assertUtimes("old_ctime", 10002, 0, 10002, 0);
1328         assertEqualInt(0, stat("old_ctime", &st));
1329         sleepUntilAfter(st.st_ctime);
1330         assertMakeFile("mid_ctime", 0666, "mid");
1331         assertUtimes("mid_ctime", 10001, 0, 10001, 0);
1332         assertEqualInt(0, stat("mid_ctime", &st));
1333         sleepUntilAfter(st.st_ctime);
1334         assertMakeFile("new_ctime", 0666, "new");
1335         assertUtimes("new_ctime", 10000, 0, 10000, 0);
1336
1337         /*
1338          * Test: matching mtime which indicated by files on the disk.
1339          */
1340         test_newer_mtime_than_file_mbs();
1341         test_newer_mtime_than_file_wcs();
1342         test_older_mtime_than_file_mbs();
1343         test_older_mtime_than_file_wcs();
1344         test_mtime_between_files_mbs();
1345         test_mtime_between_files_wcs();
1346
1347         /*
1348          * Test: matching ctime which indicated by files on the disk.
1349          */
1350         test_newer_ctime_than_file_mbs();
1351         test_newer_ctime_than_file_wcs();
1352         test_older_ctime_than_file_mbs();
1353         test_older_ctime_than_file_wcs();
1354         test_ctime_between_files_mbs();
1355         test_ctime_between_files_wcs();
1356
1357         /* Test: matching both pathname and mtime. */
1358         test_pathname_newer_mtime();
1359 }