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$");
29 * Most of these tests are system-independent, though a few depend on
30 * features of the local system. Such tests are conditionalized on
31 * the platform name. On unsupported platforms, only the
32 * system-independent features will be tested.
34 * No, I don't want to use config.h in the test files because I want
35 * the tests to also serve as a check on the correctness of config.h.
36 * A mis-configured library build should cause tests to fail.
39 DEFINE_TEST(test_entry)
44 struct archive_entry *e, *e2;
45 const struct stat *pst;
46 unsigned long set, clear; /* For fflag testing. */
47 int type, permset, tag, qual; /* For ACL testing. */
48 const char *name; /* For ACL testing. */
49 const char *xname; /* For xattr tests. */
50 const void *xval; /* For xattr tests. */
51 size_t xsize; /* For xattr tests. */
53 assert((e = archive_entry_new()) != NULL);
56 * Basic set/read tests for all fields.
57 * We should be able to set any field and read
58 * back the same value.
60 * For methods that "copy" a string, we should be able
61 * to overwrite the original passed-in string without
62 * changing the value in the entry.
64 * The following tests are ordered alphabetically by the
68 archive_entry_set_atime(e, 13579, 24680);
69 assertEqualInt(archive_entry_atime(e), 13579);
70 assertEqualInt(archive_entry_atime_nsec(e), 24680);
72 archive_entry_set_ctime(e, 13580, 24681);
73 assertEqualInt(archive_entry_ctime(e), 13580);
74 assertEqualInt(archive_entry_ctime_nsec(e), 24681);
76 archive_entry_set_dev(e, 235);
77 assertEqualInt(archive_entry_dev(e), 235);
78 /* devmajor/devminor are tested specially below. */
80 archive_entry_set_filetype(e, AE_IFREG);
81 assertEqualInt(archive_entry_filetype(e), AE_IFREG);
82 /* fflags are tested specially below */
84 archive_entry_set_gid(e, 204);
85 assertEqualInt(archive_entry_gid(e), 204);
87 archive_entry_set_gname(e, "group");
88 assertEqualString(archive_entry_gname(e), "group");
89 wcscpy(wbuff, L"wgroup");
90 archive_entry_copy_gname_w(e, wbuff);
91 assertEqualWString(archive_entry_gname_w(e), L"wgroup");
92 memset(wbuff, 0, sizeof(wbuff));
93 assertEqualWString(archive_entry_gname_w(e), L"wgroup");
95 archive_entry_set_hardlink(e, "hardlinkname");
96 assertEqualString(archive_entry_hardlink(e), "hardlinkname");
97 strcpy(buff, "hardlinkname2");
98 archive_entry_copy_hardlink(e, buff);
99 assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
100 memset(buff, 0, sizeof(buff));
101 assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
102 wcscpy(wbuff, L"whardlink");
103 archive_entry_copy_hardlink_w(e, wbuff);
104 assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
105 memset(wbuff, 0, sizeof(wbuff));
106 assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
108 archive_entry_set_ino(e, 8593);
109 assertEqualInt(archive_entry_ino(e), 8593);
111 /* TODO: implement these tests. */
113 archive_entry_set_mode(e, 0123456);
114 assertEqualInt(archive_entry_mode(e), 0123456);
116 archive_entry_set_mtime(e, 13581, 24682);
117 assertEqualInt(archive_entry_mtime(e), 13581);
118 assertEqualInt(archive_entry_mtime_nsec(e), 24682);
120 archive_entry_set_nlink(e, 736);
121 assertEqualInt(archive_entry_nlink(e), 736);
123 archive_entry_set_pathname(e, "path");
124 assertEqualString(archive_entry_pathname(e), "path");
125 archive_entry_set_pathname(e, "path");
126 assertEqualString(archive_entry_pathname(e), "path");
127 strcpy(buff, "path2");
128 archive_entry_copy_pathname(e, buff);
129 assertEqualString(archive_entry_pathname(e), "path2");
130 memset(buff, 0, sizeof(buff));
131 assertEqualString(archive_entry_pathname(e), "path2");
132 wcscpy(wbuff, L"wpath");
133 archive_entry_copy_pathname_w(e, wbuff);
134 assertEqualWString(archive_entry_pathname_w(e), L"wpath");
135 memset(wbuff, 0, sizeof(wbuff));
136 assertEqualWString(archive_entry_pathname_w(e), L"wpath");
138 archive_entry_set_rdev(e, 532);
139 assertEqualInt(archive_entry_rdev(e), 532);
140 /* rdevmajor/rdevminor are tested specially below. */
142 archive_entry_set_size(e, 987654321);
143 assertEqualInt(archive_entry_size(e), 987654321);
145 archive_entry_set_symlink(e, "symlinkname");
146 assertEqualString(archive_entry_symlink(e), "symlinkname");
147 strcpy(buff, "symlinkname2");
148 archive_entry_copy_symlink(e, buff);
149 assertEqualString(archive_entry_symlink(e), "symlinkname2");
150 memset(buff, 0, sizeof(buff));
151 assertEqualString(archive_entry_symlink(e), "symlinkname2");
152 archive_entry_copy_symlink_w(e, L"wsymlink");
153 assertEqualWString(archive_entry_symlink_w(e), L"wsymlink");
155 archive_entry_set_uid(e, 83);
156 assertEqualInt(archive_entry_uid(e), 83);
158 archive_entry_set_uname(e, "user");
159 assertEqualString(archive_entry_uname(e), "user");
160 wcscpy(wbuff, L"wuser");
161 archive_entry_copy_gname_w(e, wbuff);
162 assertEqualWString(archive_entry_gname_w(e), L"wuser");
163 memset(wbuff, 0, sizeof(wbuff));
164 assertEqualWString(archive_entry_gname_w(e), L"wuser");
166 /* Test fflags interface. */
167 archive_entry_set_fflags(e, 0x55, 0xAA);
168 archive_entry_fflags(e, &set, &clear);
169 failure("Testing set/get of fflags data.");
170 assertEqualInt(set, 0x55);
171 failure("Testing set/get of fflags data.");
172 assertEqualInt(clear, 0xAA);
174 /* Converting fflags bitmap to string is currently system-dependent. */
175 /* TODO: Make this system-independent. */
176 assertEqualString(archive_entry_fflags_text(e),
177 "uappnd,nouchg,nodump,noopaque,uunlnk");
178 /* TODO: Test archive_entry_copy_fflags_text_w() */
181 /* See test_acl_basic.c for tests of ACL set/get consistency. */
183 /* Test xattrs set/get consistency. */
184 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
185 assertEqualInt(1, archive_entry_xattr_reset(e));
186 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
187 assertEqualString(xname, "xattr1");
188 assertEqualString(xval, "xattrvalue1");
189 assertEqualInt(xsize, 12);
190 assertEqualInt(1, archive_entry_xattr_count(e));
191 assertEqualInt(ARCHIVE_WARN,
192 archive_entry_xattr_next(e, &xname, &xval, &xsize));
193 archive_entry_xattr_clear(e);
194 assertEqualInt(0, archive_entry_xattr_reset(e));
195 assertEqualInt(ARCHIVE_WARN,
196 archive_entry_xattr_next(e, &xname, &xval, &xsize));
197 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
198 assertEqualInt(1, archive_entry_xattr_reset(e));
199 archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12);
200 assertEqualInt(2, archive_entry_xattr_reset(e));
201 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
202 assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
203 assertEqualInt(ARCHIVE_WARN,
204 archive_entry_xattr_next(e, &xname, &xval, &xsize));
208 * Test clone() implementation.
211 /* Set values in 'e' */
212 archive_entry_clear(e);
213 archive_entry_set_atime(e, 13579, 24680);
214 archive_entry_set_ctime(e, 13580, 24681);
215 archive_entry_set_dev(e, 235);
216 archive_entry_set_fflags(e, 0x55, 0xAA);
217 archive_entry_set_gid(e, 204);
218 archive_entry_set_gname(e, "group");
219 archive_entry_set_hardlink(e, "hardlinkname");
220 archive_entry_set_ino(e, 8593);
221 archive_entry_set_mode(e, 0123456);
222 archive_entry_set_mtime(e, 13581, 24682);
223 archive_entry_set_nlink(e, 736);
224 archive_entry_set_pathname(e, "path");
225 archive_entry_set_rdev(e, 532);
226 archive_entry_set_size(e, 987654321);
227 archive_entry_set_symlink(e, "symlinkname");
228 archive_entry_set_uid(e, 83);
229 archive_entry_set_uname(e, "user");
230 /* Add an ACL entry. */
231 archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
232 ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77");
233 /* Add an extended attribute. */
234 archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11);
237 e2 = archive_entry_clone(e);
239 /* Clone should have same contents. */
240 assertEqualInt(archive_entry_atime(e2), 13579);
241 assertEqualInt(archive_entry_atime_nsec(e2), 24680);
242 assertEqualInt(archive_entry_ctime(e2), 13580);
243 assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
244 assertEqualInt(archive_entry_dev(e2), 235);
245 archive_entry_fflags(e, &set, &clear);
246 assertEqualInt(clear, 0xAA);
247 assertEqualInt(set, 0x55);
248 assertEqualInt(archive_entry_gid(e2), 204);
249 assertEqualString(archive_entry_gname(e2), "group");
250 assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
251 assertEqualInt(archive_entry_ino(e2), 8593);
252 assertEqualInt(archive_entry_mode(e2), 0123456);
253 assertEqualInt(archive_entry_mtime(e2), 13581);
254 assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
255 assertEqualInt(archive_entry_nlink(e2), 736);
256 assertEqualString(archive_entry_pathname(e2), "path");
257 assertEqualInt(archive_entry_rdev(e2), 532);
258 assertEqualInt(archive_entry_size(e2), 987654321);
259 assertEqualString(archive_entry_symlink(e2), "symlinkname");
260 assertEqualInt(archive_entry_uid(e2), 83);
261 assertEqualString(archive_entry_uname(e2), "user");
262 /* Verify ACL was copied. */
263 assertEqualInt(4, archive_entry_acl_reset(e2,
264 ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
265 /* First three are standard permission bits. */
266 assertEqualInt(0, archive_entry_acl_next(e2,
267 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
268 &type, &permset, &tag, &qual, &name));
269 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
270 assertEqualInt(permset, 4);
271 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
272 assertEqualInt(qual, -1);
273 assertEqualString(name, NULL);
274 assertEqualInt(0, archive_entry_acl_next(e2,
275 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
276 &type, &permset, &tag, &qual, &name));
277 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
278 assertEqualInt(permset, 5);
279 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
280 assertEqualInt(qual, -1);
281 assertEqualString(name, NULL);
282 assertEqualInt(0, archive_entry_acl_next(e2,
283 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
284 &type, &permset, &tag, &qual, &name));
285 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
286 assertEqualInt(permset, 6);
287 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
288 assertEqualInt(qual, -1);
289 assertEqualString(name, NULL);
290 /* Fourth is custom one. */
291 assertEqualInt(0, archive_entry_acl_next(e2,
292 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
293 &type, &permset, &tag, &qual, &name));
294 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
295 assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
296 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
297 assertEqualInt(qual, 77);
298 assertEqualString(name, "user77");
299 /* Verify xattr was copied. */
300 assertEqualInt(1, archive_entry_xattr_reset(e2));
301 assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize));
302 assertEqualString(xname, "xattr1");
303 assertEqualString(xval, "xattrvalue");
304 assertEqualInt(xsize, 11);
306 /* Change the original */
307 archive_entry_set_atime(e, 13580, 24690);
308 archive_entry_set_ctime(e, 13590, 24691);
309 archive_entry_set_dev(e, 245);
310 archive_entry_set_fflags(e, 0x85, 0xDA);
311 archive_entry_set_filetype(e, AE_IFLNK);
312 archive_entry_set_gid(e, 214);
313 archive_entry_set_gname(e, "grouper");
314 archive_entry_set_hardlink(e, "hardlinkpath");
315 archive_entry_set_ino(e, 8763);
316 archive_entry_set_mode(e, 0123654);
317 archive_entry_set_mtime(e, 18351, 28642);
318 archive_entry_set_nlink(e, 73);
319 archive_entry_set_pathname(e, "pathest");
320 archive_entry_set_rdev(e, 132);
321 archive_entry_set_size(e, 987456321);
322 archive_entry_set_symlink(e, "symlinkpath");
323 archive_entry_set_uid(e, 93);
324 archive_entry_set_uname(e, "username");
325 archive_entry_acl_clear(e);
326 archive_entry_xattr_clear(e);
328 /* Clone should still have same contents. */
329 assertEqualInt(archive_entry_atime(e2), 13579);
330 assertEqualInt(archive_entry_atime_nsec(e2), 24680);
331 assertEqualInt(archive_entry_ctime(e2), 13580);
332 assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
333 assertEqualInt(archive_entry_dev(e2), 235);
334 archive_entry_fflags(e2, &set, &clear);
335 assertEqualInt(clear, 0xAA);
336 assertEqualInt(set, 0x55);
337 assertEqualInt(archive_entry_gid(e2), 204);
338 assertEqualString(archive_entry_gname(e2), "group");
339 assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
340 assertEqualInt(archive_entry_ino(e2), 8593);
341 assertEqualInt(archive_entry_mode(e2), 0123456);
342 assertEqualInt(archive_entry_mtime(e2), 13581);
343 assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
344 assertEqualInt(archive_entry_nlink(e2), 736);
345 assertEqualString(archive_entry_pathname(e2), "path");
346 assertEqualInt(archive_entry_rdev(e2), 532);
347 assertEqualInt(archive_entry_size(e2), 987654321);
348 assertEqualString(archive_entry_symlink(e2), "symlinkname");
349 assertEqualInt(archive_entry_uid(e2), 83);
350 assertEqualString(archive_entry_uname(e2), "user");
351 /* Verify ACL was unchanged. */
352 assertEqualInt(4, archive_entry_acl_reset(e2,
353 ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
354 /* First three are standard permission bits. */
355 assertEqualInt(0, archive_entry_acl_next(e2,
356 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
357 &type, &permset, &tag, &qual, &name));
358 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
359 assertEqualInt(permset, 4);
360 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
361 assertEqualInt(qual, -1);
362 assertEqualString(name, NULL);
363 assertEqualInt(0, archive_entry_acl_next(e2,
364 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
365 &type, &permset, &tag, &qual, &name));
366 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
367 assertEqualInt(permset, 5);
368 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
369 assertEqualInt(qual, -1);
370 assertEqualString(name, NULL);
371 assertEqualInt(0, archive_entry_acl_next(e2,
372 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
373 &type, &permset, &tag, &qual, &name));
374 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
375 assertEqualInt(permset, 6);
376 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
377 assertEqualInt(qual, -1);
378 assertEqualString(name, NULL);
379 /* Fourth is custom one. */
380 assertEqualInt(0, archive_entry_acl_next(e2,
381 ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
382 &type, &permset, &tag, &qual, &name));
383 assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
384 assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
385 assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
386 assertEqualInt(qual, 77);
387 assertEqualString(name, "user77");
388 /* Verify xattr was unchanged. */
389 assertEqualInt(1, archive_entry_xattr_reset(e2));
392 archive_entry_free(e2);
395 * Test clear() implementation.
397 archive_entry_clear(e);
398 assertEqualInt(archive_entry_atime(e), 0);
399 assertEqualInt(archive_entry_atime_nsec(e), 0);
400 assertEqualInt(archive_entry_ctime(e), 0);
401 assertEqualInt(archive_entry_ctime_nsec(e), 0);
402 assertEqualInt(archive_entry_dev(e), 0);
403 archive_entry_fflags(e, &set, &clear);
404 assertEqualInt(clear, 0);
405 assertEqualInt(set, 0);
406 assertEqualInt(archive_entry_filetype(e), 0);
407 assertEqualInt(archive_entry_gid(e), 0);
408 assertEqualString(archive_entry_gname(e), NULL);
409 assertEqualString(archive_entry_hardlink(e), NULL);
410 assertEqualInt(archive_entry_ino(e), 0);
411 assertEqualInt(archive_entry_mode(e), 0);
412 assertEqualInt(archive_entry_mtime(e), 0);
413 assertEqualInt(archive_entry_mtime_nsec(e), 0);
414 assertEqualInt(archive_entry_nlink(e), 0);
415 assertEqualString(archive_entry_pathname(e), NULL);
416 assertEqualInt(archive_entry_rdev(e), 0);
417 assertEqualInt(archive_entry_size(e), 0);
418 assertEqualString(archive_entry_symlink(e), NULL);
419 assertEqualInt(archive_entry_uid(e), 0);
420 assertEqualString(archive_entry_uname(e), NULL);
421 /* ACLs should be cleared. */
422 assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0);
423 assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0);
424 /* Extended attributes should be cleared. */
425 assertEqualInt(archive_entry_xattr_count(e), 0);
428 * Test archive_entry_copy_stat().
430 memset(&st, 0, sizeof(st));
431 /* Set all of the standard 'struct stat' fields. */
432 st.st_atime = 456789;
433 st.st_ctime = 345678;
438 st.st_mtime = 234567;
440 st.st_size = 123456789;
443 /* On FreeBSD, high-res timestamp data should come through. */
444 st.st_atimespec.tv_nsec = 6543210;
445 st.st_ctimespec.tv_nsec = 5432109;
446 st.st_mtimespec.tv_nsec = 3210987;
448 /* Copy them into the entry. */
449 archive_entry_copy_stat(e, &st);
450 /* Read each one back separately and compare. */
451 assertEqualInt(archive_entry_atime(e), 456789);
452 assertEqualInt(archive_entry_ctime(e), 345678);
453 assertEqualInt(archive_entry_dev(e), 123);
454 assertEqualInt(archive_entry_gid(e), 34);
455 assertEqualInt(archive_entry_ino(e), 234);
456 assertEqualInt(archive_entry_mode(e), 077777);
457 assertEqualInt(archive_entry_mtime(e), 234567);
458 assertEqualInt(archive_entry_nlink(e), 345);
459 assertEqualInt(archive_entry_size(e), 123456789);
460 assertEqualInt(archive_entry_uid(e), 23);
462 /* On FreeBSD, high-res timestamp data should come through. */
463 assertEqualInt(archive_entry_atime_nsec(e), 6543210);
464 assertEqualInt(archive_entry_ctime_nsec(e), 5432109);
465 assertEqualInt(archive_entry_mtime_nsec(e), 3210987);
469 * Test archive_entry_stat().
471 /* First, clear out any existing stat data. */
472 memset(&st, 0, sizeof(st));
473 archive_entry_copy_stat(e, &st);
474 /* Set a bunch of fields individually. */
475 archive_entry_set_atime(e, 456789, 321);
476 archive_entry_set_ctime(e, 345678, 432);
477 archive_entry_set_dev(e, 123);
478 archive_entry_set_gid(e, 34);
479 archive_entry_set_ino(e, 234);
480 archive_entry_set_mode(e, 012345);
481 archive_entry_set_mode(e, 012345);
482 archive_entry_set_mtime(e, 234567, 543);
483 archive_entry_set_nlink(e, 345);
484 archive_entry_set_size(e, 123456789);
485 archive_entry_set_uid(e, 23);
486 /* Retrieve a stat structure. */
487 assert((pst = archive_entry_stat(e)) != NULL);
488 /* Check that the values match. */
489 assertEqualInt(pst->st_atime, 456789);
490 assertEqualInt(pst->st_ctime, 345678);
491 assertEqualInt(pst->st_dev, 123);
492 assertEqualInt(pst->st_gid, 34);
493 assertEqualInt(pst->st_ino, 234);
494 assertEqualInt(pst->st_mode, 012345);
495 assertEqualInt(pst->st_mtime, 234567);
496 assertEqualInt(pst->st_nlink, 345);
497 assertEqualInt(pst->st_size, 123456789);
498 assertEqualInt(pst->st_uid, 23);
500 /* On FreeBSD, high-res timestamp data should come through. */
501 assertEqualInt(pst->st_atimespec.tv_nsec, 321);
502 assertEqualInt(pst->st_ctimespec.tv_nsec, 432);
503 assertEqualInt(pst->st_mtimespec.tv_nsec, 543);
506 /* Changing any one value should update struct stat. */
507 archive_entry_set_atime(e, 456788, 0);
508 assert((pst = archive_entry_stat(e)) != NULL);
509 assertEqualInt(pst->st_atime, 456788);
510 archive_entry_set_ctime(e, 345677, 431);
511 assert((pst = archive_entry_stat(e)) != NULL);
512 assertEqualInt(pst->st_ctime, 345677);
513 archive_entry_set_dev(e, 122);
514 assert((pst = archive_entry_stat(e)) != NULL);
515 assertEqualInt(pst->st_dev, 122);
516 archive_entry_set_gid(e, 33);
517 assert((pst = archive_entry_stat(e)) != NULL);
518 assertEqualInt(pst->st_gid, 33);
519 archive_entry_set_ino(e, 233);
520 assert((pst = archive_entry_stat(e)) != NULL);
521 assertEqualInt(pst->st_ino, 233);
522 archive_entry_set_mode(e, 012344);
523 assert((pst = archive_entry_stat(e)) != NULL);
524 assertEqualInt(pst->st_mode, 012344);
525 archive_entry_set_mtime(e, 234566, 542);
526 assert((pst = archive_entry_stat(e)) != NULL);
527 assertEqualInt(pst->st_mtime, 234566);
528 archive_entry_set_nlink(e, 344);
529 assert((pst = archive_entry_stat(e)) != NULL);
530 assertEqualInt(pst->st_nlink, 344);
531 archive_entry_set_size(e, 123456788);
532 assert((pst = archive_entry_stat(e)) != NULL);
533 assertEqualInt(pst->st_size, 123456788);
534 archive_entry_set_uid(e, 22);
535 assert((pst = archive_entry_stat(e)) != NULL);
536 assertEqualInt(pst->st_uid, 22);
537 /* We don't need to check high-res fields here. */
540 * Test dev/major/minor interfaces. Setting 'dev' or 'rdev'
541 * should change the corresponding major/minor values, and
544 * The test here is system-specific because it assumes that
545 * makedev(), major(), and minor() are defined in sys/stat.h.
546 * I'm not too worried about it, though, because the code is
547 * simple. If it works on FreeBSD, it's unlikely to be broken
548 * anywhere else. Note: The functionality is present on every
549 * platform even if these tests only run some places;
550 * libarchive's more extensive configuration logic should find
551 * the necessary definitions on every platform.
554 archive_entry_set_dev(e, 0x12345678);
555 assertEqualInt(archive_entry_devmajor(e), major(0x12345678));
556 assertEqualInt(archive_entry_devminor(e), minor(0x12345678));
557 assertEqualInt(archive_entry_dev(e), 0x12345678);
558 archive_entry_set_devmajor(e, 0xfe);
559 archive_entry_set_devminor(e, 0xdcba98);
560 assertEqualInt(archive_entry_devmajor(e), 0xfe);
561 assertEqualInt(archive_entry_devminor(e), 0xdcba98);
562 assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98));
563 archive_entry_set_rdev(e, 0x12345678);
564 assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678));
565 assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678));
566 assertEqualInt(archive_entry_rdev(e), 0x12345678);
567 archive_entry_set_rdevmajor(e, 0xfe);
568 archive_entry_set_rdevminor(e, 0xdcba98);
569 assertEqualInt(archive_entry_rdevmajor(e), 0xfe);
570 assertEqualInt(archive_entry_rdevminor(e), 0xdcba98);
571 assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98));
574 /* Release the experimental entry. */
575 archive_entry_free(e);