2 * Copyright (c) 2003-2007 Tim Kientzle
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.
26 __FBSDID("$FreeBSD$");
31 * Most of these tests are system-independent, though a few depend on
32 * features of the local system. Such tests are conditionalized on
33 * the platform name. On unsupported platforms, only the
34 * system-independent features will be tested.
36 * No, I don't want to use config.h in the test files because I want
37 * the tests to also serve as a check on the correctness of config.h.
38 * A mis-configured library build should cause tests to fail.
41 DEFINE_TEST(test_entry)
46 struct archive_entry *e, *e2;
47 const struct stat *pst;
48 unsigned long set, clear; /* For fflag testing. */
49 int type, permset, tag, qual; /* For ACL testing. */
50 const char *name; /* For ACL testing. */
51 const char *xname; /* For xattr tests. */
52 const void *xval; /* For xattr tests. */
53 size_t xsize; /* For xattr tests. */
56 assert((e = archive_entry_new()) != NULL);
59 * Basic set/read tests for all fields.
60 * We should be able to set any field and read
61 * back the same value.
63 * For methods that "copy" a string, we should be able
64 * to overwrite the original passed-in string without
65 * changing the value in the entry.
67 * The following tests are ordered alphabetically by the
71 archive_entry_set_atime(e, 13579, 24680);
72 assertEqualInt(archive_entry_atime(e), 13579);
73 assertEqualInt(archive_entry_atime_nsec(e), 24680);
75 archive_entry_set_ctime(e, 13580, 24681);
76 assertEqualInt(archive_entry_ctime(e), 13580);
77 assertEqualInt(archive_entry_ctime_nsec(e), 24681);
78 #if ARCHIVE_VERSION_STAMP >= 1009000
80 archive_entry_set_dev(e, 235);
81 assertEqualInt(archive_entry_dev(e), 235);
83 skipping("archive_entry_dev()");
85 /* devmajor/devminor are tested specially below. */
86 #if ARCHIVE_VERSION_STAMP >= 1009000
88 archive_entry_set_filetype(e, AE_IFREG);
89 assertEqualInt(archive_entry_filetype(e), AE_IFREG);
91 skipping("archive_entry_filetype()");
93 /* fflags are tested specially below */
95 archive_entry_set_gid(e, 204);
96 assertEqualInt(archive_entry_gid(e), 204);
98 archive_entry_set_gname(e, "group");
99 assertEqualString(archive_entry_gname(e), "group");
100 wcscpy(wbuff, L"wgroup");
101 archive_entry_copy_gname_w(e, wbuff);
102 assertEqualWString(archive_entry_gname_w(e), L"wgroup");
103 memset(wbuff, 0, sizeof(wbuff));
104 assertEqualWString(archive_entry_gname_w(e), L"wgroup");
106 archive_entry_set_hardlink(e, "hardlinkname");
107 assertEqualString(archive_entry_hardlink(e), "hardlinkname");
108 strcpy(buff, "hardlinkname2");
109 archive_entry_copy_hardlink(e, buff);
110 assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
111 memset(buff, 0, sizeof(buff));
112 assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
113 wcscpy(wbuff, L"whardlink");
114 archive_entry_copy_hardlink_w(e, wbuff);
115 assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
116 memset(wbuff, 0, sizeof(wbuff));
117 assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
118 #if ARCHIVE_VERSION_STAMP >= 1009000
120 archive_entry_set_ino(e, 8593);
121 assertEqualInt(archive_entry_ino(e), 8593);
123 skipping("archive_entry_ino()");
127 archive_entry_set_hardlink(e, "hardlinkname");
128 archive_entry_set_symlink(e, NULL);
129 archive_entry_set_link(e, "link");
130 assertEqualString(archive_entry_hardlink(e), "link");
131 assertEqualString(archive_entry_symlink(e), NULL);
132 archive_entry_copy_link(e, "link2");
133 assertEqualString(archive_entry_hardlink(e), "link2");
134 assertEqualString(archive_entry_symlink(e), NULL);
135 archive_entry_copy_link_w(e, L"link3");
136 assertEqualString(archive_entry_hardlink(e), "link3");
137 assertEqualString(archive_entry_symlink(e), NULL);
138 archive_entry_set_hardlink(e, NULL);
139 archive_entry_set_symlink(e, "symlink");
140 archive_entry_set_link(e, "link");
141 assertEqualString(archive_entry_hardlink(e), NULL);
142 assertEqualString(archive_entry_symlink(e), "link");
143 archive_entry_copy_link(e, "link2");
144 assertEqualString(archive_entry_hardlink(e), NULL);
145 assertEqualString(archive_entry_symlink(e), "link2");
146 archive_entry_copy_link_w(e, L"link3");
147 assertEqualString(archive_entry_hardlink(e), NULL);
148 assertEqualString(archive_entry_symlink(e), "link3");
149 /* Arbitrarily override hardlink if both hardlink and symlink set. */
150 archive_entry_set_hardlink(e, "hardlink");
151 archive_entry_set_symlink(e, "symlink");
152 archive_entry_set_link(e, "link");
153 assertEqualString(archive_entry_hardlink(e), "hardlink");
154 assertEqualString(archive_entry_symlink(e), "link");
157 archive_entry_set_mode(e, 0123456);
158 assertEqualInt(archive_entry_mode(e), 0123456);
160 archive_entry_set_mtime(e, 13581, 24682);
161 assertEqualInt(archive_entry_mtime(e), 13581);
162 assertEqualInt(archive_entry_mtime_nsec(e), 24682);
163 #if ARCHIVE_VERSION_STAMP >= 1009000
165 archive_entry_set_nlink(e, 736);
166 assertEqualInt(archive_entry_nlink(e), 736);
168 skipping("archive_entry_nlink()");
171 archive_entry_set_pathname(e, "path");
172 assertEqualString(archive_entry_pathname(e), "path");
173 archive_entry_set_pathname(e, "path");
174 assertEqualString(archive_entry_pathname(e), "path");
175 strcpy(buff, "path2");
176 archive_entry_copy_pathname(e, buff);
177 assertEqualString(archive_entry_pathname(e), "path2");
178 memset(buff, 0, sizeof(buff));
179 assertEqualString(archive_entry_pathname(e), "path2");
180 wcscpy(wbuff, L"wpath");
181 archive_entry_copy_pathname_w(e, wbuff);
182 assertEqualWString(archive_entry_pathname_w(e), L"wpath");
183 memset(wbuff, 0, sizeof(wbuff));
184 assertEqualWString(archive_entry_pathname_w(e), L"wpath");
185 #if ARCHIVE_VERSION_STAMP >= 1009000
187 archive_entry_set_rdev(e, 532);
188 assertEqualInt(archive_entry_rdev(e), 532);
190 skipping("archive_entry_rdev()");
192 /* rdevmajor/rdevminor are tested specially below. */
194 archive_entry_set_size(e, 987654321);
195 assertEqualInt(archive_entry_size(e), 987654321);
197 archive_entry_set_symlink(e, "symlinkname");
198 assertEqualString(archive_entry_symlink(e), "symlinkname");
199 #if ARCHIVE_VERSION_STAMP >= 1009000
200 strcpy(buff, "symlinkname2");
201 archive_entry_copy_symlink(e, buff);
202 assertEqualString(archive_entry_symlink(e), "symlinkname2");
203 memset(buff, 0, sizeof(buff));
204 assertEqualString(archive_entry_symlink(e), "symlinkname2");
206 archive_entry_copy_symlink_w(e, L"wsymlink");
207 assertEqualWString(archive_entry_symlink_w(e), L"wsymlink");
209 archive_entry_set_uid(e, 83);
210 assertEqualInt(archive_entry_uid(e), 83);
212 archive_entry_set_uname(e, "user");
213 assertEqualString(archive_entry_uname(e), "user");
214 wcscpy(wbuff, L"wuser");
215 archive_entry_copy_gname_w(e, wbuff);
216 assertEqualWString(archive_entry_gname_w(e), L"wuser");
217 memset(wbuff, 0, sizeof(wbuff));
218 assertEqualWString(archive_entry_gname_w(e), L"wuser");
220 /* Test fflags interface. */
221 archive_entry_set_fflags(e, 0x55, 0xAA);
222 archive_entry_fflags(e, &set, &clear);
223 failure("Testing set/get of fflags data.");
224 assertEqualInt(set, 0x55);
225 failure("Testing set/get of fflags data.");
226 assertEqualInt(clear, 0xAA);
228 /* Converting fflags bitmap to string is currently system-dependent. */
229 /* TODO: Make this system-independent. */
230 assertEqualString(archive_entry_fflags_text(e),
231 "uappnd,nouchg,nodump,noopaque,uunlnk");
232 /* TODO: Test archive_entry_copy_fflags_text_w() */
235 /* See test_acl_basic.c for tests of ACL set/get consistency. */
237 /* Test xattrs set/get consistency. */
238 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
239 assertEqualInt(1, archive_entry_xattr_reset(e));
240 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
241 assertEqualString(xname, "xattr1");
242 assertEqualString(xval, "xattrvalue1");
243 assertEqualInt(xsize, 12);
244 assertEqualInt(1, archive_entry_xattr_count(e));
245 assertEqualInt(ARCHIVE_WARN,
246 archive_entry_xattr_next(e, &xname, &xval, &xsize));
247 assertEqualString(xname, NULL);
248 assertEqualString(xval, NULL);
249 assertEqualInt(xsize, 0);
250 archive_entry_xattr_clear(e);
251 assertEqualInt(0, archive_entry_xattr_reset(e));
252 assertEqualInt(ARCHIVE_WARN,
253 archive_entry_xattr_next(e, &xname, &xval, &xsize));
254 assertEqualString(xname, NULL);
255 assertEqualString(xval, NULL);
256 assertEqualInt(xsize, 0);
257 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
258 assertEqualInt(1, archive_entry_xattr_reset(e));
259 archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12);
260 assertEqualInt(2, archive_entry_xattr_reset(e));
261 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
262 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
263 assertEqualInt(ARCHIVE_WARN,
264 archive_entry_xattr_next(e, &xname, &xval, &xsize));
265 assertEqualString(xname, NULL);
266 assertEqualString(xval, NULL);
267 assertEqualInt(xsize, 0);
271 * Test clone() implementation.
274 /* Set values in 'e' */
275 archive_entry_clear(e);
276 archive_entry_set_atime(e, 13579, 24680);
277 archive_entry_set_ctime(e, 13580, 24681);
278 #if ARCHIVE_VERSION_STAMP >= 1009000
279 archive_entry_set_dev(e, 235);
281 archive_entry_set_fflags(e, 0x55, 0xAA);
282 archive_entry_set_gid(e, 204);
283 archive_entry_set_gname(e, "group");
284 archive_entry_set_hardlink(e, "hardlinkname");
285 #if ARCHIVE_VERSION_STAMP >= 1009000
286 archive_entry_set_ino(e, 8593);
288 archive_entry_set_mode(e, 0123456);
289 archive_entry_set_mtime(e, 13581, 24682);
290 #if ARCHIVE_VERSION_STAMP >= 1009000
291 archive_entry_set_nlink(e, 736);
293 archive_entry_set_pathname(e, "path");
294 #if ARCHIVE_VERSION_STAMP >= 1009000
295 archive_entry_set_rdev(e, 532);
297 archive_entry_set_size(e, 987654321);
298 archive_entry_set_symlink(e, "symlinkname");
299 archive_entry_set_uid(e, 83);
300 archive_entry_set_uname(e, "user");
301 /* Add an ACL entry. */
302 archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
303 ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77");
304 /* Add an extended attribute. */
305 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11);
308 e2 = archive_entry_clone(e);
310 /* Clone should have same contents. */
311 assertEqualInt(archive_entry_atime(e2), 13579);
312 assertEqualInt(archive_entry_atime_nsec(e2), 24680);
313 assertEqualInt(archive_entry_ctime(e2), 13580);
314 assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
315 #if ARCHIVE_VERSION_STAMP >= 1009000
316 assertEqualInt(archive_entry_dev(e2), 235);
318 archive_entry_fflags(e, &set, &clear);
319 assertEqualInt(clear, 0xAA);
320 assertEqualInt(set, 0x55);
321 assertEqualInt(archive_entry_gid(e2), 204);
322 assertEqualString(archive_entry_gname(e2), "group");
323 assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
324 #if ARCHIVE_VERSION_STAMP >= 1009000
325 assertEqualInt(archive_entry_ino(e2), 8593);
327 assertEqualInt(archive_entry_mode(e2), 0123456);
328 assertEqualInt(archive_entry_mtime(e2), 13581);
329 assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
330 #if ARCHIVE_VERSION_STAMP >= 1009000
331 assertEqualInt(archive_entry_nlink(e2), 736);
333 assertEqualString(archive_entry_pathname(e2), "path");
334 #if ARCHIVE_VERSION_STAMP >= 1009000
335 assertEqualInt(archive_entry_rdev(e2), 532);
337 assertEqualInt(archive_entry_size(e2), 987654321);
338 assertEqualString(archive_entry_symlink(e2), "symlinkname");
339 assertEqualInt(archive_entry_uid(e2), 83);
340 assertEqualString(archive_entry_uname(e2), "user");
341 #if ARCHIVE_VERSION_STAMP < 1009000
342 skipping("ACL preserved by archive_entry_clone()");
344 /* Verify ACL was copied. */
345 assertEqualInt(4, c = archive_entry_acl_reset(e2,
346 ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
347 /* First three are standard permission bits. */
348 assertEqualInt(0, archive_entry_acl_next(e2,
349 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
350 &type, &permset, &tag, &qual, &name));
351 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
352 assertEqualInt(permset, 4);
353 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
354 assertEqualInt(qual, -1);
355 assertEqualString(name, NULL);
356 assertEqualInt(0, archive_entry_acl_next(e2,
357 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
358 &type, &permset, &tag, &qual, &name));
359 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
360 assertEqualInt(permset, 5);
361 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
362 assertEqualInt(qual, -1);
363 assertEqualString(name, NULL);
364 assertEqualInt(0, archive_entry_acl_next(e2,
365 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
366 &type, &permset, &tag, &qual, &name));
367 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
368 assertEqualInt(permset, 6);
369 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
370 assertEqualInt(qual, -1);
371 assertEqualString(name, NULL);
372 /* Fourth is custom one. */
373 assertEqualInt(0, archive_entry_acl_next(e2,
374 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
375 &type, &permset, &tag, &qual, &name));
376 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
377 assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
378 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
379 assertEqualInt(qual, 77);
380 assertEqualString(name, "user77");
382 #if ARCHIVE_VERSION_STAMP < 1009000
383 skipping("xattr data preserved by archive_entry_clone");
385 /* Verify xattr was copied. */
386 assertEqualInt(1, c = archive_entry_xattr_reset(e2));
387 assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize));
388 assertEqualString(xname, "xattr1");
389 assertEqualString(xval, "xattrvalue");
390 assertEqualInt(xsize, 11);
391 assertEqualInt(ARCHIVE_WARN,
392 archive_entry_xattr_next(e2, &xname, &xval, &xsize));
393 assertEqualString(xname, NULL);
394 assertEqualString(xval, NULL);
395 assertEqualInt(xsize, 0);
398 /* Change the original */
399 archive_entry_set_atime(e, 13580, 24690);
400 archive_entry_set_ctime(e, 13590, 24691);
401 #if ARCHIVE_VERSION_STAMP >= 1009000
402 archive_entry_set_dev(e, 245);
404 archive_entry_set_fflags(e, 0x85, 0xDA);
405 #if ARCHIVE_VERSION_STAMP >= 1009000
406 archive_entry_set_filetype(e, AE_IFLNK);
408 archive_entry_set_gid(e, 214);
409 archive_entry_set_gname(e, "grouper");
410 archive_entry_set_hardlink(e, "hardlinkpath");
411 #if ARCHIVE_VERSION_STAMP >= 1009000
412 archive_entry_set_ino(e, 8763);
414 archive_entry_set_mode(e, 0123654);
415 archive_entry_set_mtime(e, 18351, 28642);
416 #if ARCHIVE_VERSION_STAMP >= 1009000
417 archive_entry_set_nlink(e, 73);
419 archive_entry_set_pathname(e, "pathest");
420 #if ARCHIVE_VERSION_STAMP >= 1009000
421 archive_entry_set_rdev(e, 132);
423 archive_entry_set_size(e, 987456321);
424 archive_entry_set_symlink(e, "symlinkpath");
425 archive_entry_set_uid(e, 93);
426 archive_entry_set_uname(e, "username");
427 archive_entry_acl_clear(e);
428 archive_entry_xattr_clear(e);
430 /* Clone should still have same contents. */
431 assertEqualInt(archive_entry_atime(e2), 13579);
432 assertEqualInt(archive_entry_atime_nsec(e2), 24680);
433 assertEqualInt(archive_entry_ctime(e2), 13580);
434 assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
435 #if ARCHIVE_VERSION_STAMP >= 1009000
436 assertEqualInt(archive_entry_dev(e2), 235);
438 archive_entry_fflags(e2, &set, &clear);
439 assertEqualInt(clear, 0xAA);
440 assertEqualInt(set, 0x55);
441 assertEqualInt(archive_entry_gid(e2), 204);
442 assertEqualString(archive_entry_gname(e2), "group");
443 assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
444 #if ARCHIVE_VERSION_STAMP >= 1009000
445 assertEqualInt(archive_entry_ino(e2), 8593);
447 assertEqualInt(archive_entry_mode(e2), 0123456);
448 assertEqualInt(archive_entry_mtime(e2), 13581);
449 assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
450 #if ARCHIVE_VERSION_STAMP >= 1009000
451 assertEqualInt(archive_entry_nlink(e2), 736);
453 assertEqualString(archive_entry_pathname(e2), "path");
454 #if ARCHIVE_VERSION_STAMP >= 1009000
455 assertEqualInt(archive_entry_rdev(e2), 532);
457 assertEqualInt(archive_entry_size(e2), 987654321);
458 assertEqualString(archive_entry_symlink(e2), "symlinkname");
459 assertEqualInt(archive_entry_uid(e2), 83);
460 assertEqualString(archive_entry_uname(e2), "user");
461 #if ARCHIVE_VERSION_STAMP < 1009000
462 skipping("ACL held by clone of archive_entry");
464 /* Verify ACL was unchanged. */
465 assertEqualInt(4, c = archive_entry_acl_reset(e2,
466 ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
467 /* First three are standard permission bits. */
468 assertEqualInt(0, archive_entry_acl_next(e2,
469 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
470 &type, &permset, &tag, &qual, &name));
471 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
472 assertEqualInt(permset, 4);
473 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
474 assertEqualInt(qual, -1);
475 assertEqualString(name, NULL);
476 assertEqualInt(0, archive_entry_acl_next(e2,
477 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
478 &type, &permset, &tag, &qual, &name));
479 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
480 assertEqualInt(permset, 5);
481 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
482 assertEqualInt(qual, -1);
483 assertEqualString(name, NULL);
484 assertEqualInt(0, archive_entry_acl_next(e2,
485 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
486 &type, &permset, &tag, &qual, &name));
487 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
488 assertEqualInt(permset, 6);
489 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
490 assertEqualInt(qual, -1);
491 assertEqualString(name, NULL);
492 /* Fourth is custom one. */
493 assertEqualInt(0, archive_entry_acl_next(e2,
494 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
495 &type, &permset, &tag, &qual, &name));
496 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
497 assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
498 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
499 assertEqualInt(qual, 77);
500 assertEqualString(name, "user77");
501 assertEqualInt(1, archive_entry_acl_next(e2,
502 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
503 &type, &permset, &tag, &qual, &name));
504 assertEqualInt(type, 0);
505 assertEqualInt(permset, 0);
506 assertEqualInt(tag, 0);
507 assertEqualInt(qual, -1);
508 assertEqualString(name, NULL);
510 #if ARCHIVE_VERSION_STAMP < 1009000
511 skipping("xattr preserved in archive_entry copy");
513 /* Verify xattr was unchanged. */
514 assertEqualInt(1, archive_entry_xattr_reset(e2));
518 archive_entry_free(e2);
521 * Test clear() implementation.
523 archive_entry_clear(e);
524 assertEqualInt(archive_entry_atime(e), 0);
525 assertEqualInt(archive_entry_atime_nsec(e), 0);
526 assertEqualInt(archive_entry_ctime(e), 0);
527 assertEqualInt(archive_entry_ctime_nsec(e), 0);
528 assertEqualInt(archive_entry_dev(e), 0);
529 archive_entry_fflags(e, &set, &clear);
530 assertEqualInt(clear, 0);
531 assertEqualInt(set, 0);
532 #if ARCHIVE_VERSION_STAMP >= 1009000
533 assertEqualInt(archive_entry_filetype(e), 0);
535 assertEqualInt(archive_entry_gid(e), 0);
536 assertEqualString(archive_entry_gname(e), NULL);
537 assertEqualString(archive_entry_hardlink(e), NULL);
538 assertEqualInt(archive_entry_ino(e), 0);
539 assertEqualInt(archive_entry_mode(e), 0);
540 assertEqualInt(archive_entry_mtime(e), 0);
541 assertEqualInt(archive_entry_mtime_nsec(e), 0);
542 #if ARCHIVE_VERSION_STAMP >= 1009000
543 assertEqualInt(archive_entry_nlink(e), 0);
545 assertEqualString(archive_entry_pathname(e), NULL);
546 assertEqualInt(archive_entry_rdev(e), 0);
547 assertEqualInt(archive_entry_size(e), 0);
548 assertEqualString(archive_entry_symlink(e), NULL);
549 assertEqualInt(archive_entry_uid(e), 0);
550 assertEqualString(archive_entry_uname(e), NULL);
551 /* ACLs should be cleared. */
552 assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0);
553 assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0);
554 /* Extended attributes should be cleared. */
555 assertEqualInt(archive_entry_xattr_count(e), 0);
558 * Test archive_entry_copy_stat().
560 memset(&st, 0, sizeof(st));
561 /* Set all of the standard 'struct stat' fields. */
562 st.st_atime = 456789;
563 st.st_ctime = 345678;
568 st.st_mtime = 234567;
570 st.st_size = 123456789;
573 /* On FreeBSD, high-res timestamp data should come through. */
574 st.st_atimespec.tv_nsec = 6543210;
575 st.st_ctimespec.tv_nsec = 5432109;
576 st.st_mtimespec.tv_nsec = 3210987;
578 /* Copy them into the entry. */
579 archive_entry_copy_stat(e, &st);
580 /* Read each one back separately and compare. */
581 assertEqualInt(archive_entry_atime(e), 456789);
582 assertEqualInt(archive_entry_ctime(e), 345678);
583 assertEqualInt(archive_entry_dev(e), 123);
584 assertEqualInt(archive_entry_gid(e), 34);
585 assertEqualInt(archive_entry_ino(e), 234);
586 assertEqualInt(archive_entry_mode(e), 077777);
587 assertEqualInt(archive_entry_mtime(e), 234567);
588 #if ARCHIVE_VERSION_STAMP >= 1009000
589 assertEqualInt(archive_entry_nlink(e), 345);
591 assertEqualInt(archive_entry_size(e), 123456789);
592 assertEqualInt(archive_entry_uid(e), 23);
594 /* On FreeBSD, high-res timestamp data should come through. */
595 assertEqualInt(archive_entry_atime_nsec(e), 6543210);
596 assertEqualInt(archive_entry_ctime_nsec(e), 5432109);
597 assertEqualInt(archive_entry_mtime_nsec(e), 3210987);
601 * Test archive_entry_stat().
603 /* First, clear out any existing stat data. */
604 memset(&st, 0, sizeof(st));
605 archive_entry_copy_stat(e, &st);
606 /* Set a bunch of fields individually. */
607 archive_entry_set_atime(e, 456789, 321);
608 archive_entry_set_ctime(e, 345678, 432);
609 #if ARCHIVE_VERSION_STAMP >= 1009000
610 archive_entry_set_dev(e, 123);
612 archive_entry_set_gid(e, 34);
613 #if ARCHIVE_VERSION_STAMP >= 1009000
614 archive_entry_set_ino(e, 234);
616 archive_entry_set_mode(e, 012345);
617 archive_entry_set_mode(e, 012345);
618 archive_entry_set_mtime(e, 234567, 543);
619 #if ARCHIVE_VERSION_STAMP >= 1009000
620 archive_entry_set_nlink(e, 345);
622 archive_entry_set_size(e, 123456789);
623 archive_entry_set_uid(e, 23);
624 /* Retrieve a stat structure. */
625 assert((pst = archive_entry_stat(e)) != NULL);
626 /* Check that the values match. */
627 assertEqualInt(pst->st_atime, 456789);
628 assertEqualInt(pst->st_ctime, 345678);
629 #if ARCHIVE_VERSION_STAMP >= 1009000
630 assertEqualInt(pst->st_dev, 123);
632 assertEqualInt(pst->st_gid, 34);
633 #if ARCHIVE_VERSION_STAMP >= 1009000
634 assertEqualInt(pst->st_ino, 234);
636 assertEqualInt(pst->st_mode, 012345);
637 assertEqualInt(pst->st_mtime, 234567);
638 #if ARCHIVE_VERSION_STAMP >= 1009000
639 assertEqualInt(pst->st_nlink, 345);
641 assertEqualInt(pst->st_size, 123456789);
642 assertEqualInt(pst->st_uid, 23);
644 /* On FreeBSD, high-res timestamp data should come through. */
645 assertEqualInt(pst->st_atimespec.tv_nsec, 321);
646 assertEqualInt(pst->st_ctimespec.tv_nsec, 432);
647 assertEqualInt(pst->st_mtimespec.tv_nsec, 543);
650 /* Changing any one value should update struct stat. */
651 archive_entry_set_atime(e, 456788, 0);
652 assert((pst = archive_entry_stat(e)) != NULL);
653 assertEqualInt(pst->st_atime, 456788);
654 archive_entry_set_ctime(e, 345677, 431);
655 assert((pst = archive_entry_stat(e)) != NULL);
656 assertEqualInt(pst->st_ctime, 345677);
657 #if ARCHIVE_VERSION_STAMP >= 1009000
658 archive_entry_set_dev(e, 122);
659 assert((pst = archive_entry_stat(e)) != NULL);
660 assertEqualInt(pst->st_dev, 122);
662 archive_entry_set_gid(e, 33);
663 assert((pst = archive_entry_stat(e)) != NULL);
664 assertEqualInt(pst->st_gid, 33);
665 #if ARCHIVE_VERSION_STAMP >= 1009000
666 archive_entry_set_ino(e, 233);
667 assert((pst = archive_entry_stat(e)) != NULL);
668 assertEqualInt(pst->st_ino, 233);
670 archive_entry_set_mode(e, 012344);
671 assert((pst = archive_entry_stat(e)) != NULL);
672 assertEqualInt(pst->st_mode, 012344);
673 archive_entry_set_mtime(e, 234566, 542);
674 assert((pst = archive_entry_stat(e)) != NULL);
675 assertEqualInt(pst->st_mtime, 234566);
676 #if ARCHIVE_VERSION_STAMP >= 1009000
677 archive_entry_set_nlink(e, 344);
678 assert((pst = archive_entry_stat(e)) != NULL);
679 assertEqualInt(pst->st_nlink, 344);
681 archive_entry_set_size(e, 123456788);
682 assert((pst = archive_entry_stat(e)) != NULL);
683 assertEqualInt(pst->st_size, 123456788);
684 archive_entry_set_uid(e, 22);
685 assert((pst = archive_entry_stat(e)) != NULL);
686 assertEqualInt(pst->st_uid, 22);
687 /* We don't need to check high-res fields here. */
690 * Test dev/major/minor interfaces. Setting 'dev' or 'rdev'
691 * should change the corresponding major/minor values, and
694 * The test here is system-specific because it assumes that
695 * makedev(), major(), and minor() are defined in sys/stat.h.
696 * I'm not too worried about it, though, because the code is
697 * simple. If it works on FreeBSD, it's unlikely to be broken
698 * anywhere else. Note: The functionality is present on every
699 * platform even if these tests only run some places;
700 * libarchive's more extensive configuration logic should find
701 * the necessary definitions on every platform.
704 #if ARCHIVE_VERSION_STAMP >= 1009000
705 archive_entry_set_dev(e, 0x12345678);
706 assertEqualInt(archive_entry_devmajor(e), major(0x12345678));
707 assertEqualInt(archive_entry_devminor(e), minor(0x12345678));
708 assertEqualInt(archive_entry_dev(e), 0x12345678);
709 archive_entry_set_devmajor(e, 0xfe);
710 archive_entry_set_devminor(e, 0xdcba98);
711 assertEqualInt(archive_entry_devmajor(e), 0xfe);
712 assertEqualInt(archive_entry_devminor(e), 0xdcba98);
713 assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98));
714 archive_entry_set_rdev(e, 0x12345678);
715 assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678));
716 assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678));
717 assertEqualInt(archive_entry_rdev(e), 0x12345678);
718 archive_entry_set_rdevmajor(e, 0xfe);
719 archive_entry_set_rdevminor(e, 0xdcba98);
720 assertEqualInt(archive_entry_rdevmajor(e), 0xfe);
721 assertEqualInt(archive_entry_rdevminor(e), 0xdcba98);
722 assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98));
727 * Exercise the character-conversion logic, if we can.
729 failure("Can't exercise charset-conversion logic.");
730 if (assert(NULL != setlocale(LC_ALL, "de_DE.UTF-8"))) {
731 /* A filename that cannot be converted to wide characters. */
732 archive_entry_copy_pathname(e, "abc\314\214mno\374xyz");
733 failure("Converting invalid chars to Unicode should fail.");
734 assert(NULL == archive_entry_pathname_w(e));
735 //failure("Converting invalid chars to UTF-8 should fail.");
736 //assert(NULL == archive_entry_pathname_utf8(e));
738 /* A group name that cannot be converted. */
739 archive_entry_copy_gname(e, "abc\314\214mno\374xyz");
740 failure("Converting invalid chars to Unicode should fail.");
741 assert(NULL == archive_entry_gname_w(e));
743 /* A user name that cannot be converted. */
744 archive_entry_copy_uname(e, "abc\314\214mno\374xyz");
745 failure("Converting invalid chars to Unicode should fail.");
746 assert(NULL == archive_entry_uname_w(e));
748 /* A hardlink target that cannot be converted. */
749 archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz");
750 failure("Converting invalid chars to Unicode should fail.");
751 assert(NULL == archive_entry_hardlink_w(e));
753 /* A symlink target that cannot be converted. */
754 archive_entry_copy_symlink(e, "abc\314\214mno\374xyz");
755 failure("Converting invalid chars to Unicode should fail.");
756 assert(NULL == archive_entry_symlink_w(e));
759 /* Release the experimental entry. */
760 archive_entry_free(e);