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 #define __LIBARCHIVE_BUILD 1
30 #include "archive_getdate.h"
35 struct archive_entry *ae;
38 if (!assert((m = archive_match_new()) != NULL))
40 if (!assert((ae = archive_entry_new()) != NULL)) {
41 archive_match_free(m);
45 assertEqualIntA(m, 0, archive_match_include_time(m,
46 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
47 ARCHIVE_MATCH_NEWER, 7880, 0));
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));
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));
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));
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));
80 archive_entry_free(ae);
81 archive_match_free(m);
85 test_newer_time_str(void)
87 struct archive_entry *ae;
91 if (!assert((m = archive_match_new()) != NULL))
93 if (!assert((ae = archive_entry_new()) != NULL)) {
94 archive_match_free(m);
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"));
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));
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));
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));
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));
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"));
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));
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));
168 archive_entry_free(ae);
169 archive_match_free(m);
173 test_newer_time_str_w(void)
175 struct archive_entry *ae;
179 if (!assert((m = archive_match_new()) != NULL))
181 if (!assert((ae = archive_entry_new()) != NULL)) {
182 archive_match_free(m);
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"));
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));
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));
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));
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));
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"));
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));
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));
256 archive_entry_free(ae);
257 archive_match_free(m);
261 test_newer_mtime_than_file_mbs(void)
264 struct archive_entry *ae;
267 if (!assert((m = archive_match_new()) != NULL))
269 if (!assert((ae = archive_entry_new()) != NULL)) {
270 archive_match_free(m);
273 if (!assert((a = archive_read_disk_new()) != NULL)) {
274 archive_match_free(m);
275 archive_entry_free(ae);
280 * Test: newer mtime than a file specified in MBS file name.
282 assertEqualIntA(m, 0, archive_match_include_file_time(m,
283 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "mid_mtime"));
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));
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));
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));
312 archive_read_free(a);
313 archive_entry_free(ae);
314 archive_match_free(m);
318 test_newer_ctime_than_file_mbs(void)
321 struct archive_entry *ae;
324 if (!assert((m = archive_match_new()) != NULL))
326 if (!assert((ae = archive_entry_new()) != NULL)) {
327 archive_match_free(m);
330 if (!assert((a = archive_read_disk_new()) != NULL)) {
331 archive_match_free(m);
332 archive_entry_free(ae);
337 * Test: newer ctime than a file specified in MBS file name.
339 assertEqualIntA(m, 0, archive_match_include_file_time(m,
340 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "mid_ctime"));
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));
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));
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));
369 archive_read_free(a);
370 archive_entry_free(ae);
371 archive_match_free(m);
375 test_newer_mtime_than_file_wcs(void)
378 struct archive_entry *ae;
381 if (!assert((m = archive_match_new()) != NULL))
383 if (!assert((ae = archive_entry_new()) != NULL)) {
384 archive_match_free(m);
387 if (!assert((a = archive_read_disk_new()) != NULL)) {
388 archive_match_free(m);
389 archive_entry_free(ae);
394 * Test: newer mtime than a file specified in WCS file name.
396 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
397 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"mid_mtime"));
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));
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));
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));
426 archive_read_free(a);
427 archive_entry_free(ae);
428 archive_match_free(m);
432 test_newer_ctime_than_file_wcs(void)
435 struct archive_entry *ae;
438 if (!assert((m = archive_match_new()) != NULL))
440 if (!assert((ae = archive_entry_new()) != NULL)) {
441 archive_match_free(m);
444 if (!assert((a = archive_read_disk_new()) != NULL)) {
445 archive_match_free(m);
446 archive_entry_free(ae);
451 * Test: newer ctime than a file specified in WCS file name.
453 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
454 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"mid_ctime"));
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));
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));
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));
484 archive_read_free(a);
485 archive_entry_free(ae);
486 archive_match_free(m);
490 test_older_time(void)
492 struct archive_entry *ae;
495 if (!assert((m = archive_match_new()) != NULL))
497 if (!assert((ae = archive_entry_new()) != NULL)) {
498 archive_match_free(m);
502 assertEqualIntA(m, 0, archive_match_include_time(m,
503 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
504 ARCHIVE_MATCH_OLDER, 7880, 0));
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));
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));
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));
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));
537 archive_entry_free(ae);
538 archive_match_free(m);
542 test_older_time_str(void)
544 struct archive_entry *ae;
548 if (!assert((m = archive_match_new()) != NULL))
550 if (!assert((ae = archive_entry_new()) != NULL)) {
551 archive_match_free(m);
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"));
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));
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));
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));
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));
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"));
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));
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));
627 archive_entry_free(ae);
628 archive_match_free(m);
632 test_older_time_str_w(void)
634 struct archive_entry *ae;
638 if (!assert((m = archive_match_new()) != NULL))
640 if (!assert((ae = archive_entry_new()) != NULL)) {
641 archive_match_free(m);
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"));
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));
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));
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));
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));
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"));
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));
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));
717 archive_entry_free(ae);
718 archive_match_free(m);
722 test_older_mtime_than_file_mbs(void)
725 struct archive_entry *ae;
728 if (!assert((m = archive_match_new()) != NULL))
730 if (!assert((ae = archive_entry_new()) != NULL)) {
731 archive_match_free(m);
734 if (!assert((a = archive_read_disk_new()) != NULL)) {
735 archive_match_free(m);
736 archive_entry_free(ae);
741 * Test: older mtime than a file specified in MBS file name.
743 assertEqualIntA(m, 0, archive_match_include_file_time(m,
744 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "mid_mtime"));
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));
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));
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));
773 archive_read_free(a);
774 archive_entry_free(ae);
775 archive_match_free(m);
779 test_older_ctime_than_file_mbs(void)
782 struct archive_entry *ae;
785 if (!assert((m = archive_match_new()) != NULL))
787 if (!assert((ae = archive_entry_new()) != NULL)) {
788 archive_match_free(m);
791 if (!assert((a = archive_read_disk_new()) != NULL)) {
792 archive_match_free(m);
793 archive_entry_free(ae);
798 * Test: older ctime than a file specified in MBS file name.
800 assertEqualIntA(m, 0, archive_match_include_file_time(m,
801 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "mid_ctime"));
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));
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));
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));
831 archive_read_free(a);
832 archive_entry_free(ae);
833 archive_match_free(m);
837 test_older_mtime_than_file_wcs(void)
840 struct archive_entry *ae;
843 if (!assert((m = archive_match_new()) != NULL))
845 if (!assert((ae = archive_entry_new()) != NULL)) {
846 archive_match_free(m);
849 if (!assert((a = archive_read_disk_new()) != NULL)) {
850 archive_match_free(m);
851 archive_entry_free(ae);
856 * Test: older mtime than a file specified in WCS file name.
858 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
859 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"mid_mtime"));
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));
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));
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));
888 archive_read_free(a);
889 archive_entry_free(ae);
890 archive_match_free(m);
894 test_older_ctime_than_file_wcs(void)
897 struct archive_entry *ae;
900 if (!assert((m = archive_match_new()) != NULL))
902 if (!assert((ae = archive_entry_new()) != NULL)) {
903 archive_match_free(m);
906 if (!assert((a = archive_read_disk_new()) != NULL)) {
907 archive_match_free(m);
908 archive_entry_free(ae);
913 * Test: older ctime than a file specified in WCS file name.
915 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
916 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"mid_ctime"));
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));
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));
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));
946 archive_read_free(a);
947 archive_entry_free(ae);
948 archive_match_free(m);
952 test_mtime_between_files_mbs(void)
955 struct archive_entry *ae;
958 if (!assert((m = archive_match_new()) != NULL))
960 if (!assert((ae = archive_entry_new()) != NULL)) {
961 archive_match_free(m);
964 if (!assert((a = archive_read_disk_new()) != NULL)) {
965 archive_match_free(m);
966 archive_entry_free(ae);
971 * Test: mtime between file specified in MBS file name.
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"));
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));
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));
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));
1005 archive_read_free(a);
1006 archive_entry_free(ae);
1007 archive_match_free(m);
1011 test_mtime_between_files_wcs(void)
1014 struct archive_entry *ae;
1017 if (!assert((m = archive_match_new()) != NULL))
1019 if (!assert((ae = archive_entry_new()) != NULL)) {
1020 archive_match_free(m);
1023 if (!assert((a = archive_read_disk_new()) != NULL)) {
1024 archive_match_free(m);
1025 archive_entry_free(ae);
1030 * Test: mtime between file specified in WCS file name.
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"));
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));
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));
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));
1064 archive_read_free(a);
1065 archive_entry_free(ae);
1066 archive_match_free(m);
1070 test_ctime_between_files_mbs(void)
1073 struct archive_entry *ae;
1076 if (!assert((m = archive_match_new()) != NULL))
1078 if (!assert((ae = archive_entry_new()) != NULL)) {
1079 archive_match_free(m);
1082 if (!assert((a = archive_read_disk_new()) != NULL)) {
1083 archive_match_free(m);
1084 archive_entry_free(ae);
1089 * Test: ctime between files specified in MBS file name.
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"));
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));
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));
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));
1123 archive_read_free(a);
1124 archive_entry_free(ae);
1125 archive_match_free(m);
1129 test_ctime_between_files_wcs(void)
1132 struct archive_entry *ae;
1135 if (!assert((m = archive_match_new()) != NULL))
1137 if (!assert((ae = archive_entry_new()) != NULL)) {
1138 archive_match_free(m);
1141 if (!assert((a = archive_read_disk_new()) != NULL)) {
1142 archive_match_free(m);
1143 archive_entry_free(ae);
1148 * Test: ctime between files specified in WCS file name.
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"));
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));
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));
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));
1182 archive_read_free(a);
1183 archive_entry_free(ae);
1184 archive_match_free(m);
1188 excluded(struct archive *m)
1190 struct archive_entry *ae;
1192 if (!assert((ae = archive_entry_new()) != NULL))
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));
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));
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));
1238 * "file4" is not registered, that sort of a file should not be
1239 * excluded with any mtime.
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));
1257 archive_entry_free(ae);
1261 test_pathname_newer_mtime(void)
1263 struct archive_entry *ae;
1266 if (!assert((m = archive_match_new()) != NULL))
1268 if (!assert((ae = archive_entry_new()) != NULL)) {
1269 archive_match_free(m);
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));
1292 archive_entry_free(ae);
1293 archive_match_free(m);
1296 DEFINE_TEST(test_archive_match_time)
1300 /* Test: matching newer times. */
1302 test_newer_time_str();
1303 test_newer_time_str_w();
1304 /* Test: matching older times. */
1306 test_older_time_str();
1307 test_older_time_str_w();
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.
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);
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.
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);
1338 * Test: matching mtime which indicated by files on the disk.
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();
1348 * Test: matching ctime which indicated by files on the disk.
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();
1357 /* Test: matching both pathname and mtime. */
1358 test_pathname_newer_mtime();