2 * Copyright (c) 2012 Michihiro NAKAJIMA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 __FBSDID("$FreeBSD$");
29 time_t __archive_get_date(time_t, const char *);
34 struct archive_entry *ae;
37 if (!assert((m = archive_match_new()) != NULL))
39 if (!assert((ae = archive_entry_new()) != NULL)) {
40 archive_match_free(m);
44 assertEqualIntA(m, 0, archive_match_include_time(m,
45 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
46 ARCHIVE_MATCH_NEWER, 7880, 0));
48 archive_entry_copy_pathname(ae, "file1");
49 archive_entry_set_mtime(ae, 7880, 0);
50 archive_entry_set_ctime(ae, 7880, 0);
51 failure("Both Its mtime and ctime should be excluded");
52 assertEqualInt(1, archive_match_time_excluded(m, ae));
53 assertEqualInt(1, archive_match_excluded(m, ae));
54 archive_entry_set_mtime(ae, 7879, 999);
55 archive_entry_set_ctime(ae, 7879, 999);
56 failure("Both Its mtime and ctime should be excluded");
57 assertEqualInt(1, archive_match_time_excluded(m, ae));
58 assertEqualInt(1, archive_match_excluded(m, ae));
60 archive_entry_set_mtime(ae, 7881, 0);
61 archive_entry_set_ctime(ae, 7881, 0);
62 failure("Both Its mtime and ctime should not be excluded");
63 assertEqualInt(0, archive_match_time_excluded(m, ae));
64 assertEqualInt(0, archive_match_excluded(m, ae));
66 archive_entry_set_mtime(ae, 7880, 1);
67 archive_entry_set_ctime(ae, 7880, 0);
68 failure("Its mtime should be excluded");
69 assertEqualInt(1, archive_match_time_excluded(m, ae));
70 assertEqualInt(1, archive_match_excluded(m, ae));
72 archive_entry_set_mtime(ae, 7880, 0);
73 archive_entry_set_ctime(ae, 7880, 1);
74 failure("Its ctime should be excluded");
75 assertEqualInt(1, archive_match_time_excluded(m, ae));
76 assertEqualInt(1, archive_match_excluded(m, ae));
79 archive_entry_free(ae);
80 archive_match_free(m);
84 test_newer_time_str(void)
86 struct archive_entry *ae;
90 if (!assert((m = archive_match_new()) != NULL))
92 if (!assert((ae = archive_entry_new()) != NULL)) {
93 archive_match_free(m);
99 assertEqualIntA(m, 0, archive_match_include_date(m,
100 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
101 ARCHIVE_MATCH_NEWER, "1980/2/1 0:0:0 UTC"));
103 /* Test1: Allow newer time. */
104 archive_entry_copy_pathname(ae, "file1");
105 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
106 archive_entry_set_mtime(ae, t, 0);
107 archive_entry_set_ctime(ae, t, 0);
108 failure("Both Its mtime and ctime should be excluded");
109 assertEqualInt(1, archive_match_time_excluded(m, ae));
110 assertEqualInt(1, archive_match_excluded(m, ae));
111 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
112 archive_entry_set_mtime(ae, t, 0);
113 archive_entry_set_ctime(ae, t, 0);
114 failure("Both Its mtime and ctime should be excluded");
115 assertEqualInt(1, archive_match_time_excluded(m, ae));
116 assertEqualInt(1, archive_match_excluded(m, ae));
118 t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
119 archive_entry_set_mtime(ae, t, 0);
120 archive_entry_set_ctime(ae, t, 0);
121 failure("Both Its mtime and ctime should not be excluded");
122 assertEqualInt(0, archive_match_time_excluded(m, ae));
123 assertEqualInt(0, archive_match_excluded(m, ae));
125 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
126 archive_entry_set_mtime(ae, t, 1);
127 archive_entry_set_ctime(ae, t, 0);
128 failure("Its mtime should be excluded");
129 assertEqualInt(1, archive_match_time_excluded(m, ae));
130 assertEqualInt(1, archive_match_excluded(m, ae));
132 archive_entry_set_mtime(ae, t, 0);
133 archive_entry_set_ctime(ae, t, 1);
134 failure("Its ctime should be excluded");
135 assertEqualInt(1, archive_match_time_excluded(m, ae));
136 assertEqualInt(1, archive_match_excluded(m, ae));
139 /* Test2: Allow equal or newer time. */
140 assertEqualIntA(m, 0, archive_match_include_date(m,
141 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
142 ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_EQUAL,
143 "1980/2/1 0:0:0 UTC"));
145 archive_entry_copy_pathname(ae, "file1");
146 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
147 archive_entry_set_mtime(ae, t, 0);
148 archive_entry_set_ctime(ae, t, 0);
149 failure("Both Its mtime and ctime should not be excluded");
150 assertEqualInt(0, archive_match_time_excluded(m, ae));
151 assertEqualInt(0, archive_match_excluded(m, ae));
152 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
153 archive_entry_set_mtime(ae, t, 0);
154 archive_entry_set_ctime(ae, t, 0);
155 failure("Both Its mtime and ctime should be excluded");
156 assertEqualInt(1, archive_match_time_excluded(m, ae));
157 assertEqualInt(1, archive_match_excluded(m, ae));
159 t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
160 archive_entry_set_mtime(ae, t, 0);
161 archive_entry_set_ctime(ae, t, 0);
162 failure("Both Its mtime and ctime should not be excluded");
163 assertEqualInt(0, archive_match_time_excluded(m, ae));
164 assertEqualInt(0, archive_match_excluded(m, ae));
167 archive_entry_free(ae);
168 archive_match_free(m);
172 test_newer_time_str_w(void)
174 struct archive_entry *ae;
178 if (!assert((m = archive_match_new()) != NULL))
180 if (!assert((ae = archive_entry_new()) != NULL)) {
181 archive_match_free(m);
187 assertEqualIntA(m, 0, archive_match_include_date_w(m,
188 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
189 ARCHIVE_MATCH_NEWER, L"1980/2/1 0:0:0 UTC"));
191 /* Test1: Allow newer time. */
192 archive_entry_copy_pathname(ae, "file1");
193 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
194 archive_entry_set_mtime(ae, t, 0);
195 archive_entry_set_ctime(ae, t, 0);
196 failure("Both Its mtime and ctime should be excluded");
197 assertEqualInt(1, archive_match_time_excluded(m, ae));
198 assertEqualInt(1, archive_match_excluded(m, ae));
199 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
200 archive_entry_set_mtime(ae, t, 0);
201 archive_entry_set_ctime(ae, t, 0);
202 failure("Both Its mtime and ctime should be excluded");
203 assertEqualInt(1, archive_match_time_excluded(m, ae));
204 assertEqualInt(1, archive_match_excluded(m, ae));
206 t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
207 archive_entry_set_mtime(ae, t, 0);
208 archive_entry_set_ctime(ae, t, 0);
209 failure("Both Its mtime and ctime should not be excluded");
210 assertEqualInt(0, archive_match_time_excluded(m, ae));
211 assertEqualInt(0, archive_match_excluded(m, ae));
213 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
214 archive_entry_set_mtime(ae, t, 1);
215 archive_entry_set_ctime(ae, t, 0);
216 failure("Its mtime should be excluded");
217 assertEqualInt(1, archive_match_time_excluded(m, ae));
218 assertEqualInt(1, archive_match_excluded(m, ae));
220 archive_entry_set_mtime(ae, t, 0);
221 archive_entry_set_ctime(ae, t, 1);
222 failure("Its ctime should be excluded");
223 assertEqualInt(1, archive_match_time_excluded(m, ae));
224 assertEqualInt(1, archive_match_excluded(m, ae));
227 /* Test2: Allow equal or newer time. */
228 assertEqualIntA(m, 0, archive_match_include_date_w(m,
229 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
230 ARCHIVE_MATCH_NEWER | ARCHIVE_MATCH_EQUAL,
231 L"1980/2/1 0:0:0 UTC"));
233 archive_entry_copy_pathname(ae, "file1");
234 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
235 archive_entry_set_mtime(ae, t, 0);
236 archive_entry_set_ctime(ae, t, 0);
237 failure("Both Its mtime and ctime should not be excluded");
238 assertEqualInt(0, archive_match_time_excluded(m, ae));
239 assertEqualInt(0, archive_match_excluded(m, ae));
240 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
241 archive_entry_set_mtime(ae, t, 0);
242 archive_entry_set_ctime(ae, t, 0);
243 failure("Both Its mtime and ctime should be excluded");
244 assertEqualInt(1, archive_match_time_excluded(m, ae));
245 assertEqualInt(1, archive_match_excluded(m, ae));
247 t = __archive_get_date(now, "1980/2/1 0:0:1 UTC");
248 archive_entry_set_mtime(ae, t, 0);
249 archive_entry_set_ctime(ae, t, 0);
250 failure("Both Its mtime and ctime should not be excluded");
251 assertEqualInt(0, archive_match_time_excluded(m, ae));
252 assertEqualInt(0, archive_match_excluded(m, ae));
255 archive_entry_free(ae);
256 archive_match_free(m);
260 test_newer_mtime_than_file_mbs(void)
263 struct archive_entry *ae;
266 if (!assert((m = archive_match_new()) != NULL))
268 if (!assert((ae = archive_entry_new()) != NULL)) {
269 archive_match_free(m);
272 if (!assert((a = archive_read_disk_new()) != NULL)) {
273 archive_match_free(m);
274 archive_entry_free(ae);
279 * Test: newer mtime than a file specified in MBS file name.
281 assertEqualIntA(m, 0, archive_match_include_file_time(m,
282 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "mid_mtime"));
284 /* Verify 'old_mtime' file. */
285 archive_entry_copy_pathname(ae, "old_mtime");
286 assertEqualIntA(a, ARCHIVE_OK,
287 archive_read_disk_entry_from_file(a, ae, -1, NULL));
288 failure("old_mtime should be excluded");
289 assertEqualInt(1, archive_match_time_excluded(m, ae));
290 assertEqualInt(1, archive_match_excluded(m, ae));
292 /* Verify 'mid_mtime' file. */
293 archive_entry_clear(ae);
294 archive_entry_copy_pathname(ae, "mid_mtime");
295 assertEqualIntA(a, ARCHIVE_OK,
296 archive_read_disk_entry_from_file(a, ae, -1, NULL));
297 failure("mid_mtime should be excluded");
298 assertEqualInt(1, archive_match_time_excluded(m, ae));
299 assertEqualInt(1, archive_match_excluded(m, ae));
301 /* Verify 'new_mtime' file. */
302 archive_entry_clear(ae);
303 archive_entry_copy_pathname(ae, "new_mtime");
304 assertEqualIntA(a, ARCHIVE_OK,
305 archive_read_disk_entry_from_file(a, ae, -1, NULL));
306 failure("new_mtime should not be excluded");
307 assertEqualInt(0, archive_match_time_excluded(m, ae));
308 assertEqualInt(0, archive_match_excluded(m, ae));
311 archive_read_free(a);
312 archive_entry_free(ae);
313 archive_match_free(m);
317 test_newer_ctime_than_file_mbs(void)
320 struct archive_entry *ae;
323 if (!assert((m = archive_match_new()) != NULL))
325 if (!assert((ae = archive_entry_new()) != NULL)) {
326 archive_match_free(m);
329 if (!assert((a = archive_read_disk_new()) != NULL)) {
330 archive_match_free(m);
331 archive_entry_free(ae);
336 * Test: newer ctime than a file specified in MBS file name.
338 assertEqualIntA(m, 0, archive_match_include_file_time(m,
339 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "mid_ctime"));
341 /* Verify 'old_ctime' file. */
342 archive_entry_copy_pathname(ae, "old_ctime");
343 assertEqualIntA(a, ARCHIVE_OK,
344 archive_read_disk_entry_from_file(a, ae, -1, NULL));
345 failure("old_ctime should be excluded");
346 assertEqualInt(1, archive_match_time_excluded(m, ae));
347 assertEqualInt(1, archive_match_excluded(m, ae));
349 /* Verify 'mid_ctime' file. */
350 archive_entry_clear(ae);
351 archive_entry_copy_pathname(ae, "mid_ctime");
352 assertEqualIntA(a, ARCHIVE_OK,
353 archive_read_disk_entry_from_file(a, ae, -1, NULL));
354 failure("mid_ctime should be excluded");
355 assertEqualInt(1, archive_match_time_excluded(m, ae));
356 assertEqualInt(1, archive_match_excluded(m, ae));
358 /* Verify 'new_ctime' file. */
359 archive_entry_clear(ae);
360 archive_entry_copy_pathname(ae, "new_ctime");
361 assertEqualIntA(a, ARCHIVE_OK,
362 archive_read_disk_entry_from_file(a, ae, -1, NULL));
363 failure("new_ctime should not be excluded");
364 assertEqualInt(0, archive_match_time_excluded(m, ae));
365 assertEqualInt(0, archive_match_excluded(m, ae));
368 archive_read_free(a);
369 archive_entry_free(ae);
370 archive_match_free(m);
374 test_newer_mtime_than_file_wcs(void)
377 struct archive_entry *ae;
380 if (!assert((m = archive_match_new()) != NULL))
382 if (!assert((ae = archive_entry_new()) != NULL)) {
383 archive_match_free(m);
386 if (!assert((a = archive_read_disk_new()) != NULL)) {
387 archive_match_free(m);
388 archive_entry_free(ae);
393 * Test: newer mtime than a file specified in WCS file name.
395 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
396 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"mid_mtime"));
398 /* Verify 'old_mtime' file. */
399 archive_entry_copy_pathname(ae, "old_mtime");
400 assertEqualIntA(a, ARCHIVE_OK,
401 archive_read_disk_entry_from_file(a, ae, -1, NULL));
402 failure("old_mtime should be excluded");
403 assertEqualInt(1, archive_match_time_excluded(m, ae));
404 assertEqualInt(1, archive_match_excluded(m, ae));
406 /* Verify 'mid_mtime' file. */
407 archive_entry_clear(ae);
408 archive_entry_copy_pathname(ae, "mid_mtime");
409 assertEqualIntA(a, ARCHIVE_OK,
410 archive_read_disk_entry_from_file(a, ae, -1, NULL));
411 failure("mid_mtime should be excluded");
412 assertEqualInt(1, archive_match_time_excluded(m, ae));
413 assertEqualInt(1, archive_match_excluded(m, ae));
415 /* Verify 'new_mtime' file. */
416 archive_entry_clear(ae);
417 archive_entry_copy_pathname(ae, "new_mtime");
418 assertEqualIntA(a, ARCHIVE_OK,
419 archive_read_disk_entry_from_file(a, ae, -1, NULL));
420 failure("new_mtime should not be excluded");
421 assertEqualInt(0, archive_match_time_excluded(m, ae));
422 assertEqualInt(0, archive_match_excluded(m, ae));
425 archive_read_free(a);
426 archive_entry_free(ae);
427 archive_match_free(m);
431 test_newer_ctime_than_file_wcs(void)
434 struct archive_entry *ae;
437 if (!assert((m = archive_match_new()) != NULL))
439 if (!assert((ae = archive_entry_new()) != NULL)) {
440 archive_match_free(m);
443 if (!assert((a = archive_read_disk_new()) != NULL)) {
444 archive_match_free(m);
445 archive_entry_free(ae);
450 * Test: newer ctime than a file specified in WCS file name.
452 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
453 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"mid_ctime"));
455 /* Verify 'old_ctime' file. */
456 archive_entry_clear(ae);
457 archive_entry_copy_pathname(ae, "old_ctime");
458 assertEqualIntA(a, ARCHIVE_OK,
459 archive_read_disk_entry_from_file(a, ae, -1, NULL));
460 failure("old_ctime should be excluded");
461 assertEqualInt(1, archive_match_time_excluded(m, ae));
462 assertEqualInt(1, archive_match_excluded(m, ae));
464 /* Verify 'mid_ctime' file. */
465 archive_entry_clear(ae);
466 archive_entry_copy_pathname(ae, "mid_ctime");
467 assertEqualIntA(a, ARCHIVE_OK,
468 archive_read_disk_entry_from_file(a, ae, -1, NULL));
469 failure("mid_ctime should be excluded");
470 assertEqualInt(1, archive_match_time_excluded(m, ae));
471 assertEqualInt(1, archive_match_excluded(m, ae));
473 /* Verify 'new_ctime' file. */
474 archive_entry_clear(ae);
475 archive_entry_copy_pathname(ae, "new_ctime");
476 assertEqualIntA(a, ARCHIVE_OK,
477 archive_read_disk_entry_from_file(a, ae, -1, NULL));
478 failure("new_ctime should not be excluded");
479 assertEqualInt(0, archive_match_time_excluded(m, ae));
480 assertEqualInt(0, archive_match_excluded(m, ae));
483 archive_read_free(a);
484 archive_entry_free(ae);
485 archive_match_free(m);
489 test_older_time(void)
491 struct archive_entry *ae;
494 if (!assert((m = archive_match_new()) != NULL))
496 if (!assert((ae = archive_entry_new()) != NULL)) {
497 archive_match_free(m);
501 assertEqualIntA(m, 0, archive_match_include_time(m,
502 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
503 ARCHIVE_MATCH_OLDER, 7880, 0));
505 archive_entry_copy_pathname(ae, "file1");
506 archive_entry_set_mtime(ae, 7880, 0);
507 archive_entry_set_ctime(ae, 7880, 0);
508 failure("Both Its mtime and ctime should be excluded");
509 assertEqualInt(1, archive_match_time_excluded(m, ae));
510 assertEqualInt(1, archive_match_excluded(m, ae));
511 archive_entry_set_mtime(ae, 7879, 999);
512 archive_entry_set_ctime(ae, 7879, 999);
513 failure("Both Its mtime and ctime should not be excluded");
514 assertEqualInt(0, archive_match_time_excluded(m, ae));
515 assertEqualInt(0, archive_match_excluded(m, ae));
517 archive_entry_set_mtime(ae, 7881, 0);
518 archive_entry_set_ctime(ae, 7881, 0);
519 failure("Both Its mtime and ctime should be excluded");
520 assertEqualInt(1, archive_match_time_excluded(m, ae));
521 assertEqualInt(1, archive_match_excluded(m, ae));
523 archive_entry_set_mtime(ae, 7880, 1);
524 archive_entry_set_ctime(ae, 7879, 0);
525 failure("Its mtime should be excluded");
526 assertEqualInt(1, archive_match_time_excluded(m, ae));
527 assertEqualInt(1, archive_match_excluded(m, ae));
529 archive_entry_set_mtime(ae, 7879, 0);
530 archive_entry_set_ctime(ae, 7880, 1);
531 failure("Its ctime should be excluded");
532 assertEqualInt(1, archive_match_time_excluded(m, ae));
533 assertEqualInt(1, archive_match_excluded(m, ae));
536 archive_entry_free(ae);
537 archive_match_free(m);
541 test_older_time_str(void)
543 struct archive_entry *ae;
547 if (!assert((m = archive_match_new()) != NULL))
549 if (!assert((ae = archive_entry_new()) != NULL)) {
550 archive_match_free(m);
556 /* Test1: Allow newer time. */
557 assertEqualIntA(m, 0, archive_match_include_date(m,
558 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
559 ARCHIVE_MATCH_OLDER, "1980/2/1 0:0:0 UTC"));
561 archive_entry_copy_pathname(ae, "file1");
562 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
563 archive_entry_set_mtime(ae, t, 0);
564 archive_entry_set_ctime(ae, t, 0);
565 failure("Both Its mtime and ctime should be excluded");
566 assertEqualInt(1, archive_match_time_excluded(m, ae));
567 assertEqualInt(1, archive_match_excluded(m, ae));
568 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
569 archive_entry_set_mtime(ae, t, 0);
570 archive_entry_set_ctime(ae, t, 0);
571 failure("Both Its mtime and ctime should not be excluded");
572 assertEqualInt(0, archive_match_time_excluded(m, ae));
573 assertEqualInt(0, archive_match_excluded(m, ae));
575 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
576 archive_entry_set_mtime(ae, t, 0);
577 archive_entry_set_ctime(ae, t, 0);
578 failure("Both Its mtime and ctime should be excluded");
579 assertEqualInt(1, archive_match_time_excluded(m, ae));
580 assertEqualInt(1, archive_match_excluded(m, ae));
582 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
583 archive_entry_set_mtime(ae, t, 0);
584 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
585 archive_entry_set_ctime(ae, t, 0);
586 failure("Its mtime should be excluded");
587 assertEqualInt(1, archive_match_time_excluded(m, ae));
588 assertEqualInt(1, archive_match_excluded(m, ae));
590 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
591 archive_entry_set_mtime(ae, t, 0);
592 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
593 archive_entry_set_ctime(ae, t, 0);
594 failure("Its ctime should be excluded");
595 assertEqualInt(1, archive_match_time_excluded(m, ae));
596 assertEqualInt(1, archive_match_excluded(m, ae));
598 /* Test2: Allow equal or newer time. */
599 assertEqualIntA(m, 0, archive_match_include_date(m,
600 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
601 ARCHIVE_MATCH_OLDER | ARCHIVE_MATCH_EQUAL,
602 "1980/2/1 0:0:0 UTC"));
604 archive_entry_copy_pathname(ae, "file1");
605 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
606 archive_entry_set_mtime(ae, t, 0);
607 archive_entry_set_ctime(ae, t, 0);
608 failure("Both Its mtime and ctime should not be excluded");
609 assertEqualInt(0, archive_match_time_excluded(m, ae));
610 assertEqualInt(0, archive_match_excluded(m, ae));
611 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
612 archive_entry_set_mtime(ae, t, 0);
613 archive_entry_set_ctime(ae, t, 0);
614 failure("Both Its mtime and ctime should not be excluded");
615 assertEqualInt(0, archive_match_time_excluded(m, ae));
616 assertEqualInt(0, archive_match_excluded(m, ae));
618 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
619 archive_entry_set_mtime(ae, t, 0);
620 archive_entry_set_ctime(ae, t, 0);
621 failure("Both Its mtime and ctime should be excluded");
622 assertEqualInt(1, archive_match_time_excluded(m, ae));
623 assertEqualInt(1, archive_match_excluded(m, ae));
626 archive_entry_free(ae);
627 archive_match_free(m);
631 test_older_time_str_w(void)
633 struct archive_entry *ae;
637 if (!assert((m = archive_match_new()) != NULL))
639 if (!assert((ae = archive_entry_new()) != NULL)) {
640 archive_match_free(m);
646 /* Test1: Allow newer time. */
647 assertEqualIntA(m, 0, archive_match_include_date_w(m,
648 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
649 ARCHIVE_MATCH_OLDER, L"1980/2/1 0:0:0 UTC"));
651 archive_entry_copy_pathname(ae, "file1");
652 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
653 archive_entry_set_mtime(ae, t, 0);
654 archive_entry_set_ctime(ae, t, 0);
655 failure("Both Its mtime and ctime should be excluded");
656 assertEqualInt(1, archive_match_time_excluded(m, ae));
657 assertEqualInt(1, archive_match_excluded(m, ae));
658 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
659 archive_entry_set_mtime(ae, t, 0);
660 archive_entry_set_ctime(ae, t, 0);
661 failure("Both Its mtime and ctime should not be excluded");
662 assertEqualInt(0, archive_match_time_excluded(m, ae));
663 assertEqualInt(0, archive_match_excluded(m, ae));
665 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
666 archive_entry_set_mtime(ae, t, 0);
667 archive_entry_set_ctime(ae, t, 0);
668 failure("Both Its mtime and ctime should be excluded");
669 assertEqualInt(1, archive_match_time_excluded(m, ae));
670 assertEqualInt(1, archive_match_excluded(m, ae));
672 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
673 archive_entry_set_mtime(ae, t, 0);
674 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
675 archive_entry_set_ctime(ae, t, 0);
676 failure("Its mtime should be excluded");
677 assertEqualInt(1, archive_match_time_excluded(m, ae));
678 assertEqualInt(1, archive_match_excluded(m, ae));
680 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
681 archive_entry_set_mtime(ae, t, 0);
682 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
683 archive_entry_set_ctime(ae, t, 0);
684 failure("Its ctime should be excluded");
685 assertEqualInt(1, archive_match_time_excluded(m, ae));
686 assertEqualInt(1, archive_match_excluded(m, ae));
688 /* Test2: Allow equal or newer time. */
689 assertEqualIntA(m, 0, archive_match_include_date_w(m,
690 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
691 ARCHIVE_MATCH_OLDER | ARCHIVE_MATCH_EQUAL,
692 L"1980/2/1 0:0:0 UTC"));
694 archive_entry_copy_pathname(ae, "file1");
695 t = __archive_get_date(now, "1980/2/1 0:0:0 UTC");
696 archive_entry_set_mtime(ae, t, 0);
697 archive_entry_set_ctime(ae, t, 0);
698 failure("Both Its mtime and ctime should not be excluded");
699 assertEqualInt(0, archive_match_time_excluded(m, ae));
700 assertEqualInt(0, archive_match_excluded(m, ae));
701 t = __archive_get_date(now, "1980/1/1 0:0:0 UTC");
702 archive_entry_set_mtime(ae, t, 0);
703 archive_entry_set_ctime(ae, t, 0);
704 failure("Both Its mtime and ctime should not be excluded");
705 assertEqualInt(0, archive_match_time_excluded(m, ae));
706 assertEqualInt(0, archive_match_excluded(m, ae));
708 t = __archive_get_date(now, "1980/3/1 0:0:0 UTC");
709 archive_entry_set_mtime(ae, t, 0);
710 archive_entry_set_ctime(ae, t, 0);
711 failure("Both Its mtime and ctime should be excluded");
712 assertEqualInt(1, archive_match_time_excluded(m, ae));
713 assertEqualInt(1, archive_match_excluded(m, ae));
716 archive_entry_free(ae);
717 archive_match_free(m);
721 test_older_mtime_than_file_mbs(void)
724 struct archive_entry *ae;
727 if (!assert((m = archive_match_new()) != NULL))
729 if (!assert((ae = archive_entry_new()) != NULL)) {
730 archive_match_free(m);
733 if (!assert((a = archive_read_disk_new()) != NULL)) {
734 archive_match_free(m);
735 archive_entry_free(ae);
740 * Test: older mtime than a file specified in MBS file name.
742 assertEqualIntA(m, 0, archive_match_include_file_time(m,
743 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "mid_mtime"));
745 /* Verify 'old_mtime' file. */
746 archive_entry_copy_pathname(ae, "old_mtime");
747 assertEqualIntA(a, ARCHIVE_OK,
748 archive_read_disk_entry_from_file(a, ae, -1, NULL));
749 failure("old_mtime should not be excluded");
750 assertEqualInt(0, archive_match_time_excluded(m, ae));
751 assertEqualInt(0, archive_match_excluded(m, ae));
753 /* Verify 'mid_mtime' file. */
754 archive_entry_clear(ae);
755 archive_entry_copy_pathname(ae, "mid_mtime");
756 assertEqualIntA(a, ARCHIVE_OK,
757 archive_read_disk_entry_from_file(a, ae, -1, NULL));
758 failure("mid_mtime should be excluded");
759 assertEqualInt(1, archive_match_time_excluded(m, ae));
760 assertEqualInt(1, archive_match_excluded(m, ae));
762 /* Verify 'new_mtime' file. */
763 archive_entry_clear(ae);
764 archive_entry_copy_pathname(ae, "new_mtime");
765 assertEqualIntA(a, ARCHIVE_OK,
766 archive_read_disk_entry_from_file(a, ae, -1, NULL));
767 failure("new_mtime should be excluded");
768 assertEqualInt(1, archive_match_time_excluded(m, ae));
769 assertEqualInt(1, archive_match_excluded(m, ae));
772 archive_read_free(a);
773 archive_entry_free(ae);
774 archive_match_free(m);
778 test_older_ctime_than_file_mbs(void)
781 struct archive_entry *ae;
784 if (!assert((m = archive_match_new()) != NULL))
786 if (!assert((ae = archive_entry_new()) != NULL)) {
787 archive_match_free(m);
790 if (!assert((a = archive_read_disk_new()) != NULL)) {
791 archive_match_free(m);
792 archive_entry_free(ae);
797 * Test: older ctime than a file specified in MBS file name.
799 assertEqualIntA(m, 0, archive_match_include_file_time(m,
800 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "mid_ctime"));
802 /* Verify 'old_ctime' file. */
803 archive_entry_clear(ae);
804 archive_entry_copy_pathname(ae, "old_ctime");
805 assertEqualIntA(a, ARCHIVE_OK,
806 archive_read_disk_entry_from_file(a, ae, -1, NULL));
807 failure("old_ctime should not be excluded");
808 assertEqualInt(0, archive_match_time_excluded(m, ae));
809 assertEqualInt(0, archive_match_excluded(m, ae));
811 /* Verify 'mid_ctime' file. */
812 archive_entry_clear(ae);
813 archive_entry_copy_pathname(ae, "mid_ctime");
814 assertEqualIntA(a, ARCHIVE_OK,
815 archive_read_disk_entry_from_file(a, ae, -1, NULL));
816 failure("mid_ctime should be excluded");
817 assertEqualInt(1, archive_match_time_excluded(m, ae));
818 assertEqualInt(1, archive_match_excluded(m, ae));
820 /* Verify 'new_ctime' file. */
821 archive_entry_clear(ae);
822 archive_entry_copy_pathname(ae, "new_ctime");
823 assertEqualIntA(a, ARCHIVE_OK,
824 archive_read_disk_entry_from_file(a, ae, -1, NULL));
825 failure("new_ctime should be excluded");
826 assertEqualInt(1, archive_match_time_excluded(m, ae));
827 assertEqualInt(1, archive_match_excluded(m, ae));
830 archive_read_free(a);
831 archive_entry_free(ae);
832 archive_match_free(m);
836 test_older_mtime_than_file_wcs(void)
839 struct archive_entry *ae;
842 if (!assert((m = archive_match_new()) != NULL))
844 if (!assert((ae = archive_entry_new()) != NULL)) {
845 archive_match_free(m);
848 if (!assert((a = archive_read_disk_new()) != NULL)) {
849 archive_match_free(m);
850 archive_entry_free(ae);
855 * Test: older mtime than a file specified in WCS file name.
857 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
858 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"mid_mtime"));
860 /* Verify 'old_mtime' file. */
861 archive_entry_copy_pathname(ae, "old_mtime");
862 assertEqualIntA(a, ARCHIVE_OK,
863 archive_read_disk_entry_from_file(a, ae, -1, NULL));
864 failure("old_mtime should not be excluded");
865 assertEqualInt(0, archive_match_time_excluded(m, ae));
866 assertEqualInt(0, archive_match_excluded(m, ae));
868 /* Verify 'mid_mtime' file. */
869 archive_entry_clear(ae);
870 archive_entry_copy_pathname(ae, "mid_mtime");
871 assertEqualIntA(a, ARCHIVE_OK,
872 archive_read_disk_entry_from_file(a, ae, -1, NULL));
873 failure("mid_mtime should be excluded");
874 assertEqualInt(1, archive_match_time_excluded(m, ae));
875 assertEqualInt(1, archive_match_excluded(m, ae));
877 /* Verify 'new_mtime' file. */
878 archive_entry_clear(ae);
879 archive_entry_copy_pathname(ae, "new_mtime");
880 assertEqualIntA(a, ARCHIVE_OK,
881 archive_read_disk_entry_from_file(a, ae, -1, NULL));
882 failure("new_mtime should be excluded");
883 assertEqualInt(1, archive_match_time_excluded(m, ae));
884 assertEqualInt(1, archive_match_excluded(m, ae));
887 archive_read_free(a);
888 archive_entry_free(ae);
889 archive_match_free(m);
893 test_older_ctime_than_file_wcs(void)
896 struct archive_entry *ae;
899 if (!assert((m = archive_match_new()) != NULL))
901 if (!assert((ae = archive_entry_new()) != NULL)) {
902 archive_match_free(m);
905 if (!assert((a = archive_read_disk_new()) != NULL)) {
906 archive_match_free(m);
907 archive_entry_free(ae);
912 * Test: older ctime than a file specified in WCS file name.
914 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
915 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"mid_ctime"));
917 /* Verify 'old_ctime' file. */
918 archive_entry_clear(ae);
919 archive_entry_copy_pathname(ae, "old_ctime");
920 assertEqualIntA(a, ARCHIVE_OK,
921 archive_read_disk_entry_from_file(a, ae, -1, NULL));
922 failure("old_ctime should not be excluded");
923 assertEqualInt(0, archive_match_time_excluded(m, ae));
924 assertEqualInt(0, archive_match_excluded(m, ae));
926 /* Verify 'mid_ctime' file. */
927 archive_entry_clear(ae);
928 archive_entry_copy_pathname(ae, "mid_ctime");
929 assertEqualIntA(a, ARCHIVE_OK,
930 archive_read_disk_entry_from_file(a, ae, -1, NULL));
931 failure("mid_ctime should be excluded");
932 assertEqualInt(1, archive_match_time_excluded(m, ae));
933 assertEqualInt(1, archive_match_excluded(m, ae));
935 /* Verify 'new_ctime' file. */
936 archive_entry_clear(ae);
937 archive_entry_copy_pathname(ae, "new_ctime");
938 assertEqualIntA(a, ARCHIVE_OK,
939 archive_read_disk_entry_from_file(a, ae, -1, NULL));
940 failure("new_ctime should be excluded");
941 assertEqualInt(1, archive_match_time_excluded(m, ae));
942 assertEqualInt(1, archive_match_excluded(m, ae));
945 archive_read_free(a);
946 archive_entry_free(ae);
947 archive_match_free(m);
951 test_mtime_between_files_mbs(void)
954 struct archive_entry *ae;
957 if (!assert((m = archive_match_new()) != NULL))
959 if (!assert((ae = archive_entry_new()) != NULL)) {
960 archive_match_free(m);
963 if (!assert((a = archive_read_disk_new()) != NULL)) {
964 archive_match_free(m);
965 archive_entry_free(ae);
970 * Test: mtime between file specified in MBS file name.
972 assertEqualIntA(m, 0, archive_match_include_file_time(m,
973 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "old_mtime"));
974 assertEqualIntA(m, 0, archive_match_include_file_time(m,
975 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "new_mtime"));
977 /* Verify 'old_mtime' file. */
978 archive_entry_copy_pathname(ae, "old_mtime");
979 assertEqualIntA(a, ARCHIVE_OK,
980 archive_read_disk_entry_from_file(a, ae, -1, NULL));
981 failure("old_mtime should be excluded");
982 assertEqualInt(1, archive_match_time_excluded(m, ae));
983 assertEqualInt(1, archive_match_excluded(m, ae));
985 /* Verify 'mid_mtime' file. */
986 archive_entry_clear(ae);
987 archive_entry_copy_pathname(ae, "mid_mtime");
988 assertEqualIntA(a, ARCHIVE_OK,
989 archive_read_disk_entry_from_file(a, ae, -1, NULL));
990 failure("mid_mtime should not be excluded");
991 assertEqualInt(0, archive_match_time_excluded(m, ae));
992 assertEqualInt(0, archive_match_excluded(m, ae));
994 /* Verify 'new_mtime' file. */
995 archive_entry_clear(ae);
996 archive_entry_copy_pathname(ae, "new_mtime");
997 assertEqualIntA(a, ARCHIVE_OK,
998 archive_read_disk_entry_from_file(a, ae, -1, NULL));
999 failure("new_mtime should be excluded");
1000 assertEqualInt(1, archive_match_time_excluded(m, ae));
1001 assertEqualInt(1, archive_match_excluded(m, ae));
1004 archive_read_free(a);
1005 archive_entry_free(ae);
1006 archive_match_free(m);
1010 test_mtime_between_files_wcs(void)
1013 struct archive_entry *ae;
1016 if (!assert((m = archive_match_new()) != NULL))
1018 if (!assert((ae = archive_entry_new()) != NULL)) {
1019 archive_match_free(m);
1022 if (!assert((a = archive_read_disk_new()) != NULL)) {
1023 archive_match_free(m);
1024 archive_entry_free(ae);
1029 * Test: mtime between file specified in WCS file name.
1031 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1032 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"old_mtime"));
1033 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1034 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"new_mtime"));
1036 /* Verify 'old_mtime' file. */
1037 archive_entry_copy_pathname(ae, "old_mtime");
1038 assertEqualIntA(a, ARCHIVE_OK,
1039 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1040 failure("old_mtime should be excluded");
1041 assertEqualInt(1, archive_match_time_excluded(m, ae));
1042 assertEqualInt(1, archive_match_excluded(m, ae));
1044 /* Verify 'mid_mtime' file. */
1045 archive_entry_clear(ae);
1046 archive_entry_copy_pathname(ae, "mid_mtime");
1047 assertEqualIntA(a, ARCHIVE_OK,
1048 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1049 failure("mid_mtime should not be excluded");
1050 assertEqualInt(0, archive_match_time_excluded(m, ae));
1051 assertEqualInt(0, archive_match_excluded(m, ae));
1053 /* Verify 'new_mtime' file. */
1054 archive_entry_clear(ae);
1055 archive_entry_copy_pathname(ae, "new_mtime");
1056 assertEqualIntA(a, ARCHIVE_OK,
1057 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1058 failure("new_mtime should be excluded");
1059 assertEqualInt(1, archive_match_time_excluded(m, ae));
1060 assertEqualInt(1, archive_match_excluded(m, ae));
1063 archive_read_free(a);
1064 archive_entry_free(ae);
1065 archive_match_free(m);
1069 test_ctime_between_files_mbs(void)
1072 struct archive_entry *ae;
1075 if (!assert((m = archive_match_new()) != NULL))
1077 if (!assert((ae = archive_entry_new()) != NULL)) {
1078 archive_match_free(m);
1081 if (!assert((a = archive_read_disk_new()) != NULL)) {
1082 archive_match_free(m);
1083 archive_entry_free(ae);
1088 * Test: ctime between files specified in MBS file name.
1090 assertEqualIntA(m, 0, archive_match_include_file_time(m,
1091 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "old_ctime"));
1092 assertEqualIntA(m, 0, archive_match_include_file_time(m,
1093 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "new_ctime"));
1095 /* Verify 'old_ctime' file. */
1096 archive_entry_copy_pathname(ae, "old_ctime");
1097 assertEqualIntA(a, ARCHIVE_OK,
1098 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1099 failure("old_ctime should be excluded");
1100 assertEqualInt(1, archive_match_time_excluded(m, ae));
1101 assertEqualInt(1, archive_match_excluded(m, ae));
1103 /* Verify 'mid_ctime' file. */
1104 archive_entry_clear(ae);
1105 archive_entry_copy_pathname(ae, "mid_ctime");
1106 assertEqualIntA(a, ARCHIVE_OK,
1107 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1108 failure("mid_ctime should not be excluded");
1109 assertEqualInt(0, archive_match_time_excluded(m, ae));
1110 assertEqualInt(0, archive_match_excluded(m, ae));
1112 /* Verify 'new_ctime' file. */
1113 archive_entry_clear(ae);
1114 archive_entry_copy_pathname(ae, "new_ctime");
1115 assertEqualIntA(a, ARCHIVE_OK,
1116 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1117 failure("new_ctime should be excluded");
1118 assertEqualInt(1, archive_match_time_excluded(m, ae));
1119 assertEqualInt(1, archive_match_excluded(m, ae));
1122 archive_read_free(a);
1123 archive_entry_free(ae);
1124 archive_match_free(m);
1128 test_ctime_between_files_wcs(void)
1131 struct archive_entry *ae;
1134 if (!assert((m = archive_match_new()) != NULL))
1136 if (!assert((ae = archive_entry_new()) != NULL)) {
1137 archive_match_free(m);
1140 if (!assert((a = archive_read_disk_new()) != NULL)) {
1141 archive_match_free(m);
1142 archive_entry_free(ae);
1147 * Test: ctime between files specified in WCS file name.
1149 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1150 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"old_ctime"));
1151 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
1152 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"new_ctime"));
1154 /* Verify 'old_ctime' file. */
1155 archive_entry_copy_pathname(ae, "old_ctime");
1156 assertEqualIntA(a, ARCHIVE_OK,
1157 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1158 failure("old_ctime should be excluded");
1159 assertEqualInt(1, archive_match_time_excluded(m, ae));
1160 assertEqualInt(1, archive_match_excluded(m, ae));
1162 /* Verify 'mid_ctime' file. */
1163 archive_entry_clear(ae);
1164 archive_entry_copy_pathname(ae, "mid_ctime");
1165 assertEqualIntA(a, ARCHIVE_OK,
1166 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1167 failure("mid_ctime should not be excluded");
1168 assertEqualInt(0, archive_match_time_excluded(m, ae));
1169 assertEqualInt(0, archive_match_excluded(m, ae));
1171 /* Verify 'new_ctime' file. */
1172 archive_entry_clear(ae);
1173 archive_entry_copy_pathname(ae, "new_ctime");
1174 assertEqualIntA(a, ARCHIVE_OK,
1175 archive_read_disk_entry_from_file(a, ae, -1, NULL));
1176 failure("new_ctime should be excluded");
1177 assertEqualInt(1, archive_match_time_excluded(m, ae));
1178 assertEqualInt(1, archive_match_excluded(m, ae));
1181 archive_read_free(a);
1182 archive_entry_free(ae);
1183 archive_match_free(m);
1187 excluded(struct archive *m)
1189 struct archive_entry *ae;
1191 if (!assert((ae = archive_entry_new()) != NULL))
1194 archive_entry_copy_pathname(ae, "file1");
1195 archive_entry_set_mtime(ae, 7879, 999);
1196 failure("It should be excluded");
1197 assertEqualInt(1, archive_match_time_excluded(m, ae));
1198 assertEqualInt(1, archive_match_excluded(m, ae));
1199 archive_entry_set_mtime(ae, 7880, 0);
1200 failure("It should be excluded");
1201 assertEqualInt(1, archive_match_time_excluded(m, ae));
1202 assertEqualInt(1, archive_match_excluded(m, ae));
1203 archive_entry_set_mtime(ae, 7880, 1);
1204 failure("It should not be excluded");
1205 assertEqualInt(0, archive_match_time_excluded(m, ae));
1206 assertEqualInt(0, archive_match_excluded(m, ae));
1208 archive_entry_copy_pathname(ae, "file2");
1209 archive_entry_set_mtime(ae, 7879, 999);
1210 failure("It should not be excluded");
1211 assertEqualInt(0, archive_match_time_excluded(m, ae));
1212 assertEqualInt(0, archive_match_excluded(m, ae));
1213 archive_entry_set_mtime(ae, 7880, 0);
1214 failure("It should not be excluded");
1215 assertEqualInt(0, archive_match_time_excluded(m, ae));
1216 assertEqualInt(0, archive_match_excluded(m, ae));
1217 archive_entry_set_mtime(ae, 7880, 1);
1218 failure("It should not be excluded");
1219 assertEqualInt(0, archive_match_time_excluded(m, ae));
1220 assertEqualInt(0, archive_match_excluded(m, ae));
1222 archive_entry_copy_pathname(ae, "file3");
1223 archive_entry_set_mtime(ae, 7879, 999);
1224 failure("It should be excluded");
1225 assertEqualInt(1, archive_match_time_excluded(m, ae));
1226 assertEqualInt(1, archive_match_excluded(m, ae));
1227 archive_entry_set_mtime(ae, 7880, 0);
1228 failure("It should be excluded");
1229 assertEqualInt(1, archive_match_time_excluded(m, ae));
1230 assertEqualInt(1, archive_match_excluded(m, ae));
1231 archive_entry_set_mtime(ae, 7880, 1);
1232 failure("It should be excluded");
1233 assertEqualInt(1, archive_match_time_excluded(m, ae));
1234 assertEqualInt(1, archive_match_excluded(m, ae));
1237 * "file4" is not registered, that sort of a file should not be
1238 * excluded with any mtime.
1240 archive_entry_copy_pathname(ae, "file4");
1241 archive_entry_set_mtime(ae, 7879, 999);
1242 failure("It should not be excluded");
1243 assertEqualInt(0, archive_match_time_excluded(m, ae));
1244 assertEqualInt(0, archive_match_excluded(m, ae));
1245 archive_entry_set_mtime(ae, 7880, 0);
1246 failure("It should not be excluded");
1247 assertEqualInt(0, archive_match_time_excluded(m, ae));
1248 assertEqualInt(0, archive_match_excluded(m, ae));
1249 archive_entry_set_mtime(ae, 7880, 1);
1250 failure("It should not be excluded");
1251 assertEqualInt(0, archive_match_time_excluded(m, ae));
1252 assertEqualInt(0, archive_match_excluded(m, ae));
1256 archive_entry_free(ae);
1260 test_pathname_newer_mtime(void)
1262 struct archive_entry *ae;
1265 if (!assert((m = archive_match_new()) != NULL))
1267 if (!assert((ae = archive_entry_new()) != NULL)) {
1268 archive_match_free(m);
1272 archive_entry_copy_pathname(ae, "file1");
1273 archive_entry_set_mtime(ae, 7880, 0);
1274 assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1275 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1276 ARCHIVE_MATCH_EQUAL, ae));
1277 archive_entry_copy_pathname(ae, "file2");
1278 archive_entry_set_mtime(ae, 1, 0);
1279 assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1280 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1281 ARCHIVE_MATCH_EQUAL, ae));
1282 archive_entry_copy_pathname(ae, "file3");
1283 archive_entry_set_mtime(ae, 99999, 0);
1284 assertEqualIntA(m, 0, archive_match_exclude_entry(m,
1285 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER |
1286 ARCHIVE_MATCH_EQUAL, ae));
1291 archive_entry_free(ae);
1292 archive_match_free(m);
1295 DEFINE_TEST(test_archive_match_time)
1299 /* Test: matching newer times. */
1301 test_newer_time_str();
1302 test_newer_time_str_w();
1303 /* Test: matching older times. */
1305 test_older_time_str();
1306 test_older_time_str_w();
1309 * Create sample files for tests matching mtime.
1310 * ctimes of those files may be all the same or the ctime of
1311 * new_mtime may be older than old_mtime.
1313 assertMakeFile("new_mtime", 0666, "new");
1314 assertUtimes("new_mtime", 10002, 0, 10002, 0);
1315 assertMakeFile("mid_mtime", 0666, "mid");
1316 assertUtimes("mid_mtime", 10001, 0, 10001, 0);
1317 assertMakeFile("old_mtime", 0666, "old");
1318 assertUtimes("old_mtime", 10000, 0, 10000, 0);
1321 * Create sample files for tests matching ctime.
1322 * the mtime of mid_ctime is older than old_ctime and also the mtime
1323 * of new_ctime is older than both mid_ctime and old_ctime.
1325 assertMakeFile("old_ctime", 0666, "old");
1326 assertUtimes("old_ctime", 10002, 0, 10002, 0);
1327 assertEqualInt(0, stat("old_ctime", &st));
1328 sleepUntilAfter(st.st_ctime);
1329 assertMakeFile("mid_ctime", 0666, "mid");
1330 assertUtimes("mid_ctime", 10001, 0, 10001, 0);
1331 assertEqualInt(0, stat("mid_ctime", &st));
1332 sleepUntilAfter(st.st_ctime);
1333 assertMakeFile("new_ctime", 0666, "new");
1334 assertUtimes("new_ctime", 10000, 0, 10000, 0);
1337 * Test: matching mtime which indicated by files on the disk.
1339 test_newer_mtime_than_file_mbs();
1340 test_newer_mtime_than_file_wcs();
1341 test_older_mtime_than_file_mbs();
1342 test_older_mtime_than_file_wcs();
1343 test_mtime_between_files_mbs();
1344 test_mtime_between_files_wcs();
1347 * Test: matching ctime which indicated by files on the disk.
1349 test_newer_ctime_than_file_mbs();
1350 test_newer_ctime_than_file_wcs();
1351 test_older_ctime_than_file_mbs();
1352 test_older_ctime_than_file_wcs();
1353 test_ctime_between_files_mbs();
1354 test_ctime_between_files_wcs();
1356 /* Test: matching both pathname and mtime. */
1357 test_pathname_newer_mtime();