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 time_t __archive_get_date(time_t, const char *);
30
31 static void
test_newer_time(void)32 test_newer_time(void)
33 {
34 struct archive_entry *ae;
35 struct archive *m;
36
37 if (!assert((m = archive_match_new()) != NULL))
38 return;
39 if (!assert((ae = archive_entry_new()) != NULL)) {
40 archive_match_free(m);
41 return;
42 }
43
44 assertEqualIntA(m, 0, archive_match_include_time(m,
45 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
46 ARCHIVE_MATCH_NEWER, 7880, 0));
47
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));
59
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));
65
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));
71
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));
77
78 /* Clean up. */
79 archive_entry_free(ae);
80 archive_match_free(m);
81 }
82
83 static void
test_newer_time_str(void)84 test_newer_time_str(void)
85 {
86 struct archive_entry *ae;
87 struct archive *m;
88 time_t now, t;
89
90 if (!assert((m = archive_match_new()) != NULL))
91 return;
92 if (!assert((ae = archive_entry_new()) != NULL)) {
93 archive_match_free(m);
94 return;
95 }
96
97 time(&now);
98
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"));
102
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));
117
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));
124
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));
131
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));
137
138
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"));
144
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));
158
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));
165
166 /* Clean up. */
167 archive_entry_free(ae);
168 archive_match_free(m);
169 }
170
171 static void
test_newer_time_str_w(void)172 test_newer_time_str_w(void)
173 {
174 struct archive_entry *ae;
175 struct archive *m;
176 time_t now, t;
177
178 if (!assert((m = archive_match_new()) != NULL))
179 return;
180 if (!assert((ae = archive_entry_new()) != NULL)) {
181 archive_match_free(m);
182 return;
183 }
184
185 time(&now);
186
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"));
190
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));
205
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));
212
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));
219
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));
225
226
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"));
232
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));
246
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));
253
254 /* Clean up. */
255 archive_entry_free(ae);
256 archive_match_free(m);
257 }
258
259 static void
test_newer_mtime_than_file_mbs(void)260 test_newer_mtime_than_file_mbs(void)
261 {
262 struct archive *a;
263 struct archive_entry *ae;
264 struct archive *m;
265
266 if (!assert((m = archive_match_new()) != NULL))
267 return;
268 if (!assert((ae = archive_entry_new()) != NULL)) {
269 archive_match_free(m);
270 return;
271 }
272 if (!assert((a = archive_read_disk_new()) != NULL)) {
273 archive_match_free(m);
274 archive_entry_free(ae);
275 return;
276 }
277
278 /*
279 * Test: newer mtime than a file specified in MBS file name.
280 */
281 assertEqualIntA(m, 0, archive_match_include_file_time(m,
282 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, "mid_mtime"));
283
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));
291
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));
300
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));
309
310 /* Clean up. */
311 archive_read_free(a);
312 archive_entry_free(ae);
313 archive_match_free(m);
314 }
315
316 static void
test_newer_ctime_than_file_mbs(void)317 test_newer_ctime_than_file_mbs(void)
318 {
319 struct archive *a;
320 struct archive_entry *ae;
321 struct archive *m;
322
323 if (!assert((m = archive_match_new()) != NULL))
324 return;
325 if (!assert((ae = archive_entry_new()) != NULL)) {
326 archive_match_free(m);
327 return;
328 }
329 if (!assert((a = archive_read_disk_new()) != NULL)) {
330 archive_match_free(m);
331 archive_entry_free(ae);
332 return;
333 }
334
335 /*
336 * Test: newer ctime than a file specified in MBS file name.
337 */
338 assertEqualIntA(m, 0, archive_match_include_file_time(m,
339 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, "mid_ctime"));
340
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));
348
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));
357
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));
366
367 /* Clean up. */
368 archive_read_free(a);
369 archive_entry_free(ae);
370 archive_match_free(m);
371 }
372
373 static void
test_newer_mtime_than_file_wcs(void)374 test_newer_mtime_than_file_wcs(void)
375 {
376 struct archive *a;
377 struct archive_entry *ae;
378 struct archive *m;
379
380 if (!assert((m = archive_match_new()) != NULL))
381 return;
382 if (!assert((ae = archive_entry_new()) != NULL)) {
383 archive_match_free(m);
384 return;
385 }
386 if (!assert((a = archive_read_disk_new()) != NULL)) {
387 archive_match_free(m);
388 archive_entry_free(ae);
389 return;
390 }
391
392 /*
393 * Test: newer mtime than a file specified in WCS file name.
394 */
395 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
396 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER, L"mid_mtime"));
397
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));
405
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));
414
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));
423
424 /* Clean up. */
425 archive_read_free(a);
426 archive_entry_free(ae);
427 archive_match_free(m);
428 }
429
430 static void
test_newer_ctime_than_file_wcs(void)431 test_newer_ctime_than_file_wcs(void)
432 {
433 struct archive *a;
434 struct archive_entry *ae;
435 struct archive *m;
436
437 if (!assert((m = archive_match_new()) != NULL))
438 return;
439 if (!assert((ae = archive_entry_new()) != NULL)) {
440 archive_match_free(m);
441 return;
442 }
443 if (!assert((a = archive_read_disk_new()) != NULL)) {
444 archive_match_free(m);
445 archive_entry_free(ae);
446 return;
447 }
448
449 /*
450 * Test: newer ctime than a file specified in WCS file name.
451 */
452 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
453 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER, L"mid_ctime"));
454
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));
463
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));
472
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));
481
482 /* Clean up. */
483 archive_read_free(a);
484 archive_entry_free(ae);
485 archive_match_free(m);
486 }
487
488 static void
test_older_time(void)489 test_older_time(void)
490 {
491 struct archive_entry *ae;
492 struct archive *m;
493
494 if (!assert((m = archive_match_new()) != NULL))
495 return;
496 if (!assert((ae = archive_entry_new()) != NULL)) {
497 archive_match_free(m);
498 return;
499 }
500
501 assertEqualIntA(m, 0, archive_match_include_time(m,
502 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_CTIME |
503 ARCHIVE_MATCH_OLDER, 7880, 0));
504
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));
516
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));
522
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));
528
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));
534
535 /* Clean up. */
536 archive_entry_free(ae);
537 archive_match_free(m);
538 }
539
540 static void
test_older_time_str(void)541 test_older_time_str(void)
542 {
543 struct archive_entry *ae;
544 struct archive *m;
545 time_t now, t;
546
547 if (!assert((m = archive_match_new()) != NULL))
548 return;
549 if (!assert((ae = archive_entry_new()) != NULL)) {
550 archive_match_free(m);
551 return;
552 }
553
554 time(&now);
555
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"));
560
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));
574
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));
581
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));
589
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));
597
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"));
603
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));
617
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));
624
625 /* Clean up. */
626 archive_entry_free(ae);
627 archive_match_free(m);
628 }
629
630 static void
test_older_time_str_w(void)631 test_older_time_str_w(void)
632 {
633 struct archive_entry *ae;
634 struct archive *m;
635 time_t now, t;
636
637 if (!assert((m = archive_match_new()) != NULL))
638 return;
639 if (!assert((ae = archive_entry_new()) != NULL)) {
640 archive_match_free(m);
641 return;
642 }
643
644 time(&now);
645
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"));
650
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));
664
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));
671
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));
679
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));
687
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"));
693
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));
707
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));
714
715 /* Clean up. */
716 archive_entry_free(ae);
717 archive_match_free(m);
718 }
719
720 static void
test_older_mtime_than_file_mbs(void)721 test_older_mtime_than_file_mbs(void)
722 {
723 struct archive *a;
724 struct archive_entry *ae;
725 struct archive *m;
726
727 if (!assert((m = archive_match_new()) != NULL))
728 return;
729 if (!assert((ae = archive_entry_new()) != NULL)) {
730 archive_match_free(m);
731 return;
732 }
733 if (!assert((a = archive_read_disk_new()) != NULL)) {
734 archive_match_free(m);
735 archive_entry_free(ae);
736 return;
737 }
738
739 /*
740 * Test: older mtime than a file specified in MBS file name.
741 */
742 assertEqualIntA(m, 0, archive_match_include_file_time(m,
743 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, "mid_mtime"));
744
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));
752
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));
761
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));
770
771 /* Clean up. */
772 archive_read_free(a);
773 archive_entry_free(ae);
774 archive_match_free(m);
775 }
776
777 static void
test_older_ctime_than_file_mbs(void)778 test_older_ctime_than_file_mbs(void)
779 {
780 struct archive *a;
781 struct archive_entry *ae;
782 struct archive *m;
783
784 if (!assert((m = archive_match_new()) != NULL))
785 return;
786 if (!assert((ae = archive_entry_new()) != NULL)) {
787 archive_match_free(m);
788 return;
789 }
790 if (!assert((a = archive_read_disk_new()) != NULL)) {
791 archive_match_free(m);
792 archive_entry_free(ae);
793 return;
794 }
795
796 /*
797 * Test: older ctime than a file specified in MBS file name.
798 */
799 assertEqualIntA(m, 0, archive_match_include_file_time(m,
800 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, "mid_ctime"));
801
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));
810
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));
819
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));
828
829 /* Clean up. */
830 archive_read_free(a);
831 archive_entry_free(ae);
832 archive_match_free(m);
833 }
834
835 static void
test_older_mtime_than_file_wcs(void)836 test_older_mtime_than_file_wcs(void)
837 {
838 struct archive *a;
839 struct archive_entry *ae;
840 struct archive *m;
841
842 if (!assert((m = archive_match_new()) != NULL))
843 return;
844 if (!assert((ae = archive_entry_new()) != NULL)) {
845 archive_match_free(m);
846 return;
847 }
848 if (!assert((a = archive_read_disk_new()) != NULL)) {
849 archive_match_free(m);
850 archive_entry_free(ae);
851 return;
852 }
853
854 /*
855 * Test: older mtime than a file specified in WCS file name.
856 */
857 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
858 ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER, L"mid_mtime"));
859
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));
867
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));
876
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));
885
886 /* Clean up. */
887 archive_read_free(a);
888 archive_entry_free(ae);
889 archive_match_free(m);
890 }
891
892 static void
test_older_ctime_than_file_wcs(void)893 test_older_ctime_than_file_wcs(void)
894 {
895 struct archive *a;
896 struct archive_entry *ae;
897 struct archive *m;
898
899 if (!assert((m = archive_match_new()) != NULL))
900 return;
901 if (!assert((ae = archive_entry_new()) != NULL)) {
902 archive_match_free(m);
903 return;
904 }
905 if (!assert((a = archive_read_disk_new()) != NULL)) {
906 archive_match_free(m);
907 archive_entry_free(ae);
908 return;
909 }
910
911 /*
912 * Test: older ctime than a file specified in WCS file name.
913 */
914 assertEqualIntA(m, 0, archive_match_include_file_time_w(m,
915 ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER, L"mid_ctime"));
916
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));
925
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));
934
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));
943
944 /* Clean up. */
945 archive_read_free(a);
946 archive_entry_free(ae);
947 archive_match_free(m);
948 }
949
950 static void
test_mtime_between_files_mbs(void)951 test_mtime_between_files_mbs(void)
952 {
953 struct archive *a;
954 struct archive_entry *ae;
955 struct archive *m;
956
957 if (!assert((m = archive_match_new()) != NULL))
958 return;
959 if (!assert((ae = archive_entry_new()) != NULL)) {
960 archive_match_free(m);
961 return;
962 }
963 if (!assert((a = archive_read_disk_new()) != NULL)) {
964 archive_match_free(m);
965 archive_entry_free(ae);
966 return;
967 }
968
969 /*
970 * Test: mtime between file specified in MBS file name.
971 */
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"));
976
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));
984
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));
993
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));
1002
1003 /* Clean up. */
1004 archive_read_free(a);
1005 archive_entry_free(ae);
1006 archive_match_free(m);
1007 }
1008
1009 static void
test_mtime_between_files_wcs(void)1010 test_mtime_between_files_wcs(void)
1011 {
1012 struct archive *a;
1013 struct archive_entry *ae;
1014 struct archive *m;
1015
1016 if (!assert((m = archive_match_new()) != NULL))
1017 return;
1018 if (!assert((ae = archive_entry_new()) != NULL)) {
1019 archive_match_free(m);
1020 return;
1021 }
1022 if (!assert((a = archive_read_disk_new()) != NULL)) {
1023 archive_match_free(m);
1024 archive_entry_free(ae);
1025 return;
1026 }
1027
1028 /*
1029 * Test: mtime between file specified in WCS file name.
1030 */
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"));
1035
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));
1043
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));
1052
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));
1061
1062 /* Clean up. */
1063 archive_read_free(a);
1064 archive_entry_free(ae);
1065 archive_match_free(m);
1066 }
1067
1068 static void
test_ctime_between_files_mbs(void)1069 test_ctime_between_files_mbs(void)
1070 {
1071 struct archive *a;
1072 struct archive_entry *ae;
1073 struct archive *m;
1074
1075 if (!assert((m = archive_match_new()) != NULL))
1076 return;
1077 if (!assert((ae = archive_entry_new()) != NULL)) {
1078 archive_match_free(m);
1079 return;
1080 }
1081 if (!assert((a = archive_read_disk_new()) != NULL)) {
1082 archive_match_free(m);
1083 archive_entry_free(ae);
1084 return;
1085 }
1086
1087 /*
1088 * Test: ctime between files specified in MBS file name.
1089 */
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"));
1094
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));
1102
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));
1111
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));
1120
1121 /* Clean up. */
1122 archive_read_free(a);
1123 archive_entry_free(ae);
1124 archive_match_free(m);
1125 }
1126
1127 static void
test_ctime_between_files_wcs(void)1128 test_ctime_between_files_wcs(void)
1129 {
1130 struct archive *a;
1131 struct archive_entry *ae;
1132 struct archive *m;
1133
1134 if (!assert((m = archive_match_new()) != NULL))
1135 return;
1136 if (!assert((ae = archive_entry_new()) != NULL)) {
1137 archive_match_free(m);
1138 return;
1139 }
1140 if (!assert((a = archive_read_disk_new()) != NULL)) {
1141 archive_match_free(m);
1142 archive_entry_free(ae);
1143 return;
1144 }
1145
1146 /*
1147 * Test: ctime between files specified in WCS file name.
1148 */
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"));
1153
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));
1161
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));
1170
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));
1179
1180 /* Clean up. */
1181 archive_read_free(a);
1182 archive_entry_free(ae);
1183 archive_match_free(m);
1184 }
1185
1186 static void
excluded(struct archive * m)1187 excluded(struct archive *m)
1188 {
1189 struct archive_entry *ae;
1190
1191 if (!assert((ae = archive_entry_new()) != NULL))
1192 return;
1193
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));
1207
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));
1221
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));
1235
1236 /*
1237 * "file4" is not registered, that sort of a file should not be
1238 * excluded with any mtime.
1239 */
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));
1253
1254
1255 /* Clean up. */
1256 archive_entry_free(ae);
1257 }
1258
1259 static void
test_pathname_newer_mtime(void)1260 test_pathname_newer_mtime(void)
1261 {
1262 struct archive_entry *ae;
1263 struct archive *m;
1264
1265 if (!assert((m = archive_match_new()) != NULL))
1266 return;
1267 if (!assert((ae = archive_entry_new()) != NULL)) {
1268 archive_match_free(m);
1269 return;
1270 }
1271
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));
1287
1288 excluded(m);
1289
1290 /* Clean up. */
1291 archive_entry_free(ae);
1292 archive_match_free(m);
1293 }
1294
DEFINE_TEST(test_archive_match_time)1295 DEFINE_TEST(test_archive_match_time)
1296 {
1297 struct stat st;
1298
1299 /* Test: matching newer times. */
1300 test_newer_time();
1301 test_newer_time_str();
1302 test_newer_time_str_w();
1303 /* Test: matching older times. */
1304 test_older_time();
1305 test_older_time_str();
1306 test_older_time_str_w();
1307
1308 /*
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.
1312 */
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);
1319
1320 /*
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.
1324 */
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);
1335
1336 /*
1337 * Test: matching mtime which indicated by files on the disk.
1338 */
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();
1345
1346 /*
1347 * Test: matching ctime which indicated by files on the disk.
1348 */
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();
1355
1356 /* Test: matching both pathname and mtime. */
1357 test_pathname_newer_mtime();
1358 }
1359