aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/test/test_entry.c
blob: f20576490a5f4e495fd01fc6cdf4cdd241f9ea1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
/*-
 * Copyright (c) 2003-2007 Tim Kientzle
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_entry.c 201247 2009-12-30 05:59:21Z kientzle $");

#include <locale.h>

#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h>   /* for Linux file flags */
#endif

#ifndef HAVE_WCSCPY
static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
{
	wchar_t *dest = s1;
	while ((*s1 = *s2) != L'\0')
		++s1, ++s2;
	return dest;
}
#endif

/*
 * Most of these tests are system-independent, though a few depend on
 * features of the local system.  Such tests are conditionalized on
 * the platform name.  On unsupported platforms, only the
 * system-independent features will be tested.
 *
 * No, I don't want to use config.h in the test files because I want
 * the tests to also serve as a check on the correctness of config.h.
 * A mis-configured library build should cause tests to fail.
 */

DEFINE_TEST(test_entry)
{
	char buff[128];
	wchar_t wbuff[128];
	struct stat st;
	struct archive_entry *e, *e2;
	const struct stat *pst;
	unsigned long set, clear; /* For fflag testing. */
	int type, permset, tag, qual; /* For ACL testing. */
	const char *name; /* For ACL testing. */
	const char *xname; /* For xattr tests. */
	const void *xval; /* For xattr tests. */
	size_t xsize; /* For xattr tests. */
	wchar_t wc;
	long l;
	int i;

	assert((e = archive_entry_new()) != NULL);

	/*
	 * Verify that the AE_IF* defines match S_IF* defines
	 * on this platform. See comments in archive_entry.h.
	 */
#ifdef S_IFREG
	assertEqualInt(S_IFREG, AE_IFREG);
#endif
#ifdef S_IFLNK
	assertEqualInt(S_IFLNK, AE_IFLNK);
#endif
#ifdef S_IFSOCK
	assertEqualInt(S_IFSOCK, AE_IFSOCK);
#endif
#ifdef S_IFCHR
	assertEqualInt(S_IFCHR, AE_IFCHR);
#endif
/* Work around MinGW, which defines S_IFBLK wrong. */
/* sourceforge.net/tracker/?func=detail&atid=102435&aid=1942809&group_id=2435 */
#if defined(S_IFBLK) && !defined(_WIN32)
	assertEqualInt(S_IFBLK, AE_IFBLK);
#endif
#ifdef S_IFDIR
	assertEqualInt(S_IFDIR, AE_IFDIR);
#endif
#ifdef S_IFIFO
	assertEqualInt(S_IFIFO, AE_IFIFO);
#endif

	/*
	 * Basic set/read tests for all fields.
	 * We should be able to set any field and read
	 * back the same value.
	 *
	 * For methods that "copy" a string, we should be able
	 * to overwrite the original passed-in string without
	 * changing the value in the entry.
	 *
	 * The following tests are ordered alphabetically by the
	 * name of the field.
	 */

	/* atime */
	archive_entry_set_atime(e, 13579, 24680);
	assertEqualInt(archive_entry_atime(e), 13579);
	assertEqualInt(archive_entry_atime_nsec(e), 24680);
	archive_entry_set_atime(e, 13580, 1000000001L);
	assertEqualInt(archive_entry_atime(e), 13581);
	assertEqualInt(archive_entry_atime_nsec(e), 1);
	archive_entry_set_atime(e, 13580, -7);
	assertEqualInt(archive_entry_atime(e), 13579);
	assertEqualInt(archive_entry_atime_nsec(e), 999999993);
	archive_entry_unset_atime(e);
	assertEqualInt(archive_entry_atime(e), 0);
	assertEqualInt(archive_entry_atime_nsec(e), 0);
	assert(!archive_entry_atime_is_set(e));

	/* birthtime */
	archive_entry_set_birthtime(e, 17579, 24990);
	assertEqualInt(archive_entry_birthtime(e), 17579);
	assertEqualInt(archive_entry_birthtime_nsec(e), 24990);
	archive_entry_set_birthtime(e, 17580, 1234567890L);
	assertEqualInt(archive_entry_birthtime(e), 17581);
	assertEqualInt(archive_entry_birthtime_nsec(e), 234567890);
	archive_entry_set_birthtime(e, 17581, -24990);
	assertEqualInt(archive_entry_birthtime(e), 17580);
	assertEqualInt(archive_entry_birthtime_nsec(e), 999975010);
	archive_entry_unset_birthtime(e);
	assertEqualInt(archive_entry_birthtime(e), 0);
	assertEqualInt(archive_entry_birthtime_nsec(e), 0);
	assert(!archive_entry_birthtime_is_set(e));

	/* ctime */
	archive_entry_set_ctime(e, 13580, 24681);
	assertEqualInt(archive_entry_ctime(e), 13580);
	assertEqualInt(archive_entry_ctime_nsec(e), 24681);
	archive_entry_set_ctime(e, 13581, 2008182348L);
	assertEqualInt(archive_entry_ctime(e), 13583);
	assertEqualInt(archive_entry_ctime_nsec(e), 8182348);
	archive_entry_set_ctime(e, 13582, -24681);
	assertEqualInt(archive_entry_ctime(e), 13581);
	assertEqualInt(archive_entry_ctime_nsec(e), 999975319);
	archive_entry_unset_ctime(e);
	assertEqualInt(archive_entry_ctime(e), 0);
	assertEqualInt(archive_entry_ctime_nsec(e), 0);
	assert(!archive_entry_ctime_is_set(e));

	/* dev */
	assert(!archive_entry_dev_is_set(e));
	archive_entry_set_dev(e, 235);
	assert(archive_entry_dev_is_set(e));
	assertEqualInt(archive_entry_dev(e), 235);
	/* devmajor/devminor are tested specially below. */

	/* filetype */
	archive_entry_set_filetype(e, AE_IFREG);
	assertEqualInt(archive_entry_filetype(e), AE_IFREG);

	/* fflags are tested specially below */

	/* gid */
	archive_entry_set_gid(e, 204);
	assertEqualInt(archive_entry_gid(e), 204);

	/* gname */
	archive_entry_set_gname(e, "group");
	assertEqualString(archive_entry_gname(e), "group");
	assertEqualString(archive_entry_gname_utf8(e), "group");
	assertEqualWString(archive_entry_gname_w(e), L"group");
	wcscpy(wbuff, L"wgroup");
	archive_entry_copy_gname_w(e, wbuff);
	assertEqualWString(archive_entry_gname_w(e), L"wgroup");
	memset(wbuff, 0, sizeof(wbuff));
	assertEqualWString(archive_entry_gname_w(e), L"wgroup");
	assertEqualString(archive_entry_gname_utf8(e), "wgroup");
	assertEqualString(archive_entry_gname(e), "wgroup");
	archive_entry_set_gname_utf8(e, "group");
	assertEqualString(archive_entry_gname_utf8(e), "group");
	assertEqualWString(archive_entry_gname_w(e), L"group");
	assertEqualString(archive_entry_gname(e), "group");
	archive_entry_update_gname_utf8(e, "group2");
	assertEqualString(archive_entry_gname_utf8(e), "group2");
	assertEqualWString(archive_entry_gname_w(e), L"group2");
	assertEqualString(archive_entry_gname(e), "group2");

	/* hardlink */
	archive_entry_set_hardlink(e, "hardlinkname");
	assertEqualString(archive_entry_hardlink(e), "hardlinkname");
	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname");
	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname");
	strcpy(buff, "hardlinkname2");
	archive_entry_copy_hardlink(e, buff);
	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
	memset(buff, 0, sizeof(buff));
	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
	archive_entry_copy_hardlink(e, NULL);
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualWString(archive_entry_hardlink_w(e), NULL);
	assertEqualString(archive_entry_hardlink_utf8(e), NULL);
	wcscpy(wbuff, L"whardlink");
	archive_entry_copy_hardlink_w(e, wbuff);
	assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
	assertEqualString(archive_entry_hardlink_utf8(e), "whardlink");
	assertEqualString(archive_entry_hardlink(e), "whardlink");
	memset(wbuff, 0, sizeof(wbuff));
	assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
	archive_entry_copy_hardlink_w(e, NULL);
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualWString(archive_entry_hardlink_w(e), NULL);
	archive_entry_set_hardlink_utf8(e, "hardlinkname");
	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname");
	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname");
	assertEqualString(archive_entry_hardlink(e), "hardlinkname");
	archive_entry_update_hardlink_utf8(e, "hardlinkname2");
	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");

	/* ino */
	assert(!archive_entry_ino_is_set(e));
	archive_entry_set_ino(e, 8593);
	assert(archive_entry_ino_is_set(e));
	assertEqualInt(archive_entry_ino(e), 8593);
	assertEqualInt(archive_entry_ino64(e), 8593);
	archive_entry_set_ino64(e, 8594);
	assert(archive_entry_ino_is_set(e));
	assertEqualInt(archive_entry_ino(e), 8594);
	assertEqualInt(archive_entry_ino64(e), 8594);

	/* link */
	archive_entry_set_hardlink(e, "hardlinkname");
	archive_entry_set_symlink(e, NULL);
	archive_entry_set_link(e, "link");
	assertEqualString(archive_entry_hardlink(e), "link");
	assertEqualString(archive_entry_symlink(e), NULL);
	archive_entry_copy_link(e, "link2");
	assertEqualString(archive_entry_hardlink(e), "link2");
	assertEqualString(archive_entry_symlink(e), NULL);
	archive_entry_copy_link_w(e, L"link3");
	assertEqualString(archive_entry_hardlink(e), "link3");
	assertEqualString(archive_entry_symlink(e), NULL);
	archive_entry_set_hardlink(e, NULL);
	archive_entry_set_symlink(e, "symlink");
	archive_entry_set_link(e, "link");
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualString(archive_entry_symlink(e), "link");
	archive_entry_copy_link(e, "link2");
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualString(archive_entry_symlink(e), "link2");
	archive_entry_copy_link_w(e, L"link3");
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualString(archive_entry_symlink(e), "link3");
	/* Arbitrarily override symlink if both hardlink and symlink set. */
	archive_entry_set_hardlink(e, "hardlink");
	archive_entry_set_symlink(e, "symlink");
	archive_entry_set_link(e, "link");
	assertEqualString(archive_entry_hardlink(e), "hardlink");
	assertEqualString(archive_entry_symlink(e), "link");

	/* mode */
	archive_entry_set_mode(e, 0123456);
	assertEqualInt(archive_entry_mode(e), 0123456);

	/* mtime */
	archive_entry_set_mtime(e, 13581, 24682);
	assertEqualInt(archive_entry_mtime(e), 13581);
	assertEqualInt(archive_entry_mtime_nsec(e), 24682);
	archive_entry_set_mtime(e, 13582, 1358297468);
	assertEqualInt(archive_entry_mtime(e), 13583);
	assertEqualInt(archive_entry_mtime_nsec(e), 358297468);
	archive_entry_set_mtime(e, 13583, -24682);
	assertEqualInt(archive_entry_mtime(e), 13582);
	assertEqualInt(archive_entry_mtime_nsec(e), 999975318);
	archive_entry_unset_mtime(e);
	assertEqualInt(archive_entry_mtime(e), 0);
	assertEqualInt(archive_entry_mtime_nsec(e), 0);
	assert(!archive_entry_mtime_is_set(e));

	/* nlink */
	archive_entry_set_nlink(e, 736);
	assertEqualInt(archive_entry_nlink(e), 736);

	/* pathname */
	archive_entry_set_pathname(e, "path");
	assertEqualString(archive_entry_pathname(e), "path");
	assertEqualString(archive_entry_pathname_utf8(e), "path");
	assertEqualWString(archive_entry_pathname_w(e), L"path");
	archive_entry_set_pathname(e, "path");
	assertEqualString(archive_entry_pathname(e), "path");
	assertEqualWString(archive_entry_pathname_w(e), L"path");
	assertEqualString(archive_entry_pathname_utf8(e), "path");
	strcpy(buff, "path2");
	archive_entry_copy_pathname(e, buff);
	assertEqualString(archive_entry_pathname(e), "path2");
	assertEqualWString(archive_entry_pathname_w(e), L"path2");
	assertEqualString(archive_entry_pathname_utf8(e), "path2");
	memset(buff, 0, sizeof(buff));
	assertEqualString(archive_entry_pathname(e), "path2");
	assertEqualString(archive_entry_pathname_utf8(e), "path2");
	assertEqualWString(archive_entry_pathname_w(e), L"path2");
	wcscpy(wbuff, L"wpath");
	archive_entry_copy_pathname_w(e, wbuff);
	assertEqualWString(archive_entry_pathname_w(e), L"wpath");
	assertEqualString(archive_entry_pathname_utf8(e), "wpath");
	assertEqualString(archive_entry_pathname(e), "wpath");
	memset(wbuff, 0, sizeof(wbuff));
	assertEqualWString(archive_entry_pathname_w(e), L"wpath");
	assertEqualString(archive_entry_pathname(e), "wpath");
	assertEqualString(archive_entry_pathname_utf8(e), "wpath");
	archive_entry_set_pathname_utf8(e, "path");
	assertEqualWString(archive_entry_pathname_w(e), L"path");
	assertEqualString(archive_entry_pathname(e), "path");
	assertEqualString(archive_entry_pathname_utf8(e), "path");
	archive_entry_update_pathname_utf8(e, "path2");
	assertEqualWString(archive_entry_pathname_w(e), L"path2");
	assertEqualString(archive_entry_pathname(e), "path2");
	assertEqualString(archive_entry_pathname_utf8(e), "path2");

	/* rdev */
	archive_entry_set_rdev(e, 532);
	assertEqualInt(archive_entry_rdev(e), 532);
	/* rdevmajor/rdevminor are tested specially below. */

	/* size */
	archive_entry_set_size(e, 987654321);
	assertEqualInt(archive_entry_size(e), 987654321);
	archive_entry_unset_size(e);
	assertEqualInt(archive_entry_size(e), 0);
	assert(!archive_entry_size_is_set(e));

	/* sourcepath */
	archive_entry_copy_sourcepath(e, "path1");
	assertEqualString(archive_entry_sourcepath(e), "path1");

	/* symlink */
	archive_entry_set_symlink(e, "symlinkname");
	assertEqualString(archive_entry_symlink(e), "symlinkname");
	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname");
	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname");
	strcpy(buff, "symlinkname2");
	archive_entry_copy_symlink(e, buff);
	assertEqualString(archive_entry_symlink(e), "symlinkname2");
	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");
	memset(buff, 0, sizeof(buff));
	assertEqualString(archive_entry_symlink(e), "symlinkname2");
	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");
	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
	archive_entry_copy_symlink_w(e, NULL);
	assertEqualWString(archive_entry_symlink_w(e), NULL);
	assertEqualString(archive_entry_symlink(e), NULL);
	assertEqualString(archive_entry_symlink_utf8(e), NULL);
	archive_entry_copy_symlink_w(e, L"wsymlink");
	assertEqualWString(archive_entry_symlink_w(e), L"wsymlink");
	assertEqualString(archive_entry_symlink_utf8(e), "wsymlink");
	assertEqualString(archive_entry_symlink(e), "wsymlink");
	archive_entry_copy_symlink(e, NULL);
	assertEqualWString(archive_entry_symlink_w(e), NULL);
	assertEqualString(archive_entry_symlink(e), NULL);
	assertEqualString(archive_entry_symlink_utf8(e), NULL);
	archive_entry_set_symlink_utf8(e, "symlinkname");
	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname");
	assertEqualString(archive_entry_symlink(e), "symlinkname");
	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname");
	archive_entry_update_symlink_utf8(e, "symlinkname2");
	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
	assertEqualString(archive_entry_symlink(e), "symlinkname2");
	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");

	/* uid */
	archive_entry_set_uid(e, 83);
	assertEqualInt(archive_entry_uid(e), 83);

	/* uname */
	archive_entry_set_uname(e, "user");
	assertEqualString(archive_entry_uname(e), "user");
	assertEqualString(archive_entry_uname_utf8(e), "user");
	assertEqualWString(archive_entry_uname_w(e), L"user");
	wcscpy(wbuff, L"wuser");
	archive_entry_copy_uname_w(e, wbuff);
	assertEqualWString(archive_entry_uname_w(e), L"wuser");
	memset(wbuff, 0, sizeof(wbuff));
	assertEqualWString(archive_entry_uname_w(e), L"wuser");
	assertEqualString(archive_entry_uname_utf8(e), "wuser");
	assertEqualString(archive_entry_uname(e), "wuser");
	archive_entry_set_uname_utf8(e, "user");
	assertEqualString(archive_entry_uname_utf8(e), "user");
	assertEqualWString(archive_entry_uname_w(e), L"user");
	assertEqualString(archive_entry_uname(e), "user");
	archive_entry_set_uname_utf8(e, "user");
	assertEqualWString(archive_entry_uname_w(e), L"user");
	assertEqualString(archive_entry_uname(e), "user");
	assertEqualString(archive_entry_uname_utf8(e), "user");
	archive_entry_update_uname_utf8(e, "user2");
	assertEqualWString(archive_entry_uname_w(e), L"user2");
	assertEqualString(archive_entry_uname(e), "user2");
	assertEqualString(archive_entry_uname_utf8(e), "user2");

	/* Test fflags interface. */
	archive_entry_set_fflags(e, 0x55, 0xAA);
	archive_entry_fflags(e, &set, &clear);
	failure("Testing set/get of fflags data.");
	assertEqualInt(set, 0x55);
	failure("Testing set/get of fflags data.");
	assertEqualInt(clear, 0xAA);
#ifdef __FreeBSD__
	/* Converting fflags bitmap to string is currently system-dependent. */
	/* TODO: Make this system-independent. */
	assertEqualString(archive_entry_fflags_text(e),
	    "uappnd,nouchg,nodump,noopaque,uunlnk,nosystem");
#endif

#if defined(__FreeBSD__) || defined(__APPLE__)
	/* Test archive_entry_copy_fflags_text_w() */
	archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,hidden");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(UF_HIDDEN, set);
	assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
	/* Test archive_entry_copy_fflags_text() */
	archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,hidden");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(UF_HIDDEN, set);
	assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
#elif defined(_WIN32) && !defined(CYGWIN)
	archive_entry_copy_fflags_text_w(e, L"rdonly,hidden,nosystem");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
	assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
	archive_entry_copy_fflags_text(e, "rdonly,hidden,nosystem");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
	assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
#elif defined FS_IOC_GETFLAGS /* Linux */
	archive_entry_copy_fflags_text_w(e, L"sappnd,schg,dump,noundel");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
	assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
	archive_entry_copy_fflags_text(e, "sappnd,schg,dump,noundel");
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
	assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
#endif

	/* See test_acl_basic.c for tests of ACL set/get consistency. */

	/* Test xattrs set/get consistency. */
	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
	assertEqualInt(1, archive_entry_xattr_reset(e));
	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualString(xname, "xattr1");
	assertEqualString(xval, "xattrvalue1");
	assertEqualInt((int)xsize, 12);
	assertEqualInt(1, archive_entry_xattr_count(e));
	assertEqualInt(ARCHIVE_WARN,
	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualString(xname, NULL);
	assertEqualString(xval, NULL);
	assertEqualInt((int)xsize, 0);
	archive_entry_xattr_clear(e);
	assertEqualInt(0, archive_entry_xattr_reset(e));
	assertEqualInt(ARCHIVE_WARN,
	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualString(xname, NULL);
	assertEqualString(xval, NULL);
	assertEqualInt((int)xsize, 0);
	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
	assertEqualInt(1, archive_entry_xattr_reset(e));
	archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12);
	assertEqualInt(2, archive_entry_xattr_reset(e));
	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualInt(ARCHIVE_WARN,
	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
	assertEqualString(xname, NULL);
	assertEqualString(xval, NULL);
	assertEqualInt((int)xsize, 0);


	/*
	 * Test clone() implementation.
	 */

	/* Set values in 'e' */
	archive_entry_clear(e);
	archive_entry_set_atime(e, 13579, 24680);
	archive_entry_set_birthtime(e, 13779, 24990);
	archive_entry_set_ctime(e, 13580, 24681);
	archive_entry_set_dev(e, 235);
	archive_entry_set_fflags(e, 0x55, 0xAA);
	archive_entry_set_gid(e, 204);
	archive_entry_set_gname(e, "group");
	archive_entry_set_hardlink(e, "hardlinkname");
	archive_entry_set_ino(e, 8593);
	archive_entry_set_mode(e, 0123456);
	archive_entry_set_mtime(e, 13581, 24682);
	archive_entry_set_nlink(e, 736);
	archive_entry_set_pathname(e, "path");
	archive_entry_set_rdev(e, 532);
	archive_entry_set_size(e, 987654321);
	archive_entry_copy_sourcepath(e, "source");
	archive_entry_set_symlink(e, "symlinkname");
	archive_entry_set_uid(e, 83);
	archive_entry_set_uname(e, "user");
	/* Add an ACL entry. */
	archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
	    ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77");
	/* Add an extended attribute. */
	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11);

	/* Make a clone. */
	e2 = archive_entry_clone(e);

	/* Clone should have same contents. */
	assertEqualInt(archive_entry_atime(e2), 13579);
	assertEqualInt(archive_entry_atime_nsec(e2), 24680);
	assertEqualInt(archive_entry_birthtime(e2), 13779);
	assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
	assertEqualInt(archive_entry_ctime(e2), 13580);
	assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
	assertEqualInt(archive_entry_dev(e2), 235);
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(clear, 0xAA);
	assertEqualInt(set, 0x55);
	assertEqualInt(archive_entry_gid(e2), 204);
	assertEqualString(archive_entry_gname(e2), "group");
	assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
	assertEqualInt(archive_entry_ino(e2), 8593);
	assertEqualInt(archive_entry_mode(e2), 0123456);
	assertEqualInt(archive_entry_mtime(e2), 13581);
	assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
	assertEqualInt(archive_entry_nlink(e2), 736);
	assertEqualString(archive_entry_pathname(e2), "path");
	assertEqualInt(archive_entry_rdev(e2), 532);
	assertEqualInt(archive_entry_size(e2), 987654321);
	assertEqualString(archive_entry_sourcepath(e2), "source");
	assertEqualString(archive_entry_symlink(e2), "symlinkname");
	assertEqualInt(archive_entry_uid(e2), 83);
	assertEqualString(archive_entry_uname(e2), "user");

	/* Verify ACL was copied. */
	assertEqualInt(4, archive_entry_acl_reset(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
	/* First three are standard permission bits. */
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 4);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 5);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 6);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	/* Fourth is custom one. */
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
	assertEqualInt(qual, 77);
	assertEqualString(name, "user77");

	/* Verify xattr was copied. */
	assertEqualInt(1, archive_entry_xattr_reset(e2));
	assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize));
	assertEqualString(xname, "xattr1");
	assertEqualString(xval, "xattrvalue");
	assertEqualInt((int)xsize, 11);
	assertEqualInt(ARCHIVE_WARN,
	    archive_entry_xattr_next(e2, &xname, &xval, &xsize));
	assertEqualString(xname, NULL);
	assertEqualString(xval, NULL);
	assertEqualInt((int)xsize, 0);

	/* Change the original */
	archive_entry_set_atime(e, 13580, 24690);
	archive_entry_set_birthtime(e, 13980, 24999);
	archive_entry_set_ctime(e, 13590, 24691);
	archive_entry_set_dev(e, 245);
	archive_entry_set_fflags(e, 0x85, 0xDA);
	archive_entry_set_filetype(e, AE_IFLNK);
	archive_entry_set_gid(e, 214);
	archive_entry_set_gname(e, "grouper");
	archive_entry_set_hardlink(e, "hardlinkpath");
	archive_entry_set_ino(e, 8763);
	archive_entry_set_mode(e, 0123654);
	archive_entry_set_mtime(e, 18351, 28642);
	archive_entry_set_nlink(e, 73);
	archive_entry_set_pathname(e, "pathest");
	archive_entry_set_rdev(e, 132);
	archive_entry_set_size(e, 987456321);
	archive_entry_copy_sourcepath(e, "source2");
	archive_entry_set_symlink(e, "symlinkpath");
	archive_entry_set_uid(e, 93);
	archive_entry_set_uname(e, "username");
	archive_entry_acl_clear(e);
	archive_entry_xattr_clear(e);

	/* Clone should still have same contents. */
	assertEqualInt(archive_entry_atime(e2), 13579);
	assertEqualInt(archive_entry_atime_nsec(e2), 24680);
	assertEqualInt(archive_entry_birthtime(e2), 13779);
	assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
	assertEqualInt(archive_entry_ctime(e2), 13580);
	assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
	assertEqualInt(archive_entry_dev(e2), 235);
	archive_entry_fflags(e2, &set, &clear);
	assertEqualInt(clear, 0xAA);
	assertEqualInt(set, 0x55);
	assertEqualInt(archive_entry_gid(e2), 204);
	assertEqualString(archive_entry_gname(e2), "group");
	assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
	assertEqualInt(archive_entry_ino(e2), 8593);
	assertEqualInt(archive_entry_mode(e2), 0123456);
	assertEqualInt(archive_entry_mtime(e2), 13581);
	assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
	assertEqualInt(archive_entry_nlink(e2), 736);
	assertEqualString(archive_entry_pathname(e2), "path");
	assertEqualInt(archive_entry_rdev(e2), 532);
	assertEqualInt(archive_entry_size(e2), 987654321);
	assertEqualString(archive_entry_sourcepath(e2), "source");
	assertEqualString(archive_entry_symlink(e2), "symlinkname");
	assertEqualInt(archive_entry_uid(e2), 83);
	assertEqualString(archive_entry_uname(e2), "user");

	/* Verify ACL was unchanged. */
	assertEqualInt(4, archive_entry_acl_reset(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
	/* First three are standard permission bits. */
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 4);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 5);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, 6);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);
	/* Fourth is custom one. */
	assertEqualInt(0, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
	assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
	assertEqualInt(qual, 77);
	assertEqualString(name, "user77");
	assertEqualInt(1, archive_entry_acl_next(e2,
			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
			   &type, &permset, &tag, &qual, &name));
	assertEqualInt(type, 0);
	assertEqualInt(permset, 0);
	assertEqualInt(tag, 0);
	assertEqualInt(qual, -1);
	assertEqualString(name, NULL);

	/* Verify xattr was unchanged. */
	assertEqualInt(1, archive_entry_xattr_reset(e2));

	/* Release clone. */
	archive_entry_free(e2);

	/*
	 * Test clear() implementation.
	 */
	archive_entry_clear(e);
	assertEqualInt(archive_entry_atime(e), 0);
	assertEqualInt(archive_entry_atime_nsec(e), 0);
	assertEqualInt(archive_entry_birthtime(e), 0);
	assertEqualInt(archive_entry_birthtime_nsec(e), 0);
	assertEqualInt(archive_entry_ctime(e), 0);
	assertEqualInt(archive_entry_ctime_nsec(e), 0);
	assertEqualInt(archive_entry_dev(e), 0);
	archive_entry_fflags(e, &set, &clear);
	assertEqualInt(clear, 0);
	assertEqualInt(set, 0);
	assertEqualInt(archive_entry_filetype(e), 0);
	assertEqualInt(archive_entry_gid(e), 0);
	assertEqualString(archive_entry_gname(e), NULL);
	assertEqualString(archive_entry_hardlink(e), NULL);
	assertEqualInt(archive_entry_ino(e), 0);
	assertEqualInt(archive_entry_mode(e), 0);
	assertEqualInt(archive_entry_mtime(e), 0);
	assertEqualInt(archive_entry_mtime_nsec(e), 0);
	assertEqualInt(archive_entry_nlink(e), 0);
	assertEqualString(archive_entry_pathname(e), NULL);
	assertEqualInt(archive_entry_rdev(e), 0);
	assertEqualInt(archive_entry_size(e), 0);
	assertEqualString(archive_entry_symlink(e), NULL);
	assertEqualInt(archive_entry_uid(e), 0);
	assertEqualString(archive_entry_uname(e), NULL);
	/* ACLs should be cleared. */
	assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0);
	assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0);
	/* Extended attributes should be cleared. */
	assertEqualInt(archive_entry_xattr_count(e), 0);

	/*
	 * Test archive_entry_copy_stat().
	 */
	memset(&st, 0, sizeof(st));
	/* Set all of the standard 'struct stat' fields. */
	st.st_atime = 456789;
	st.st_ctime = 345678;
	st.st_dev = 123;
	st.st_gid = 34;
	st.st_ino = 234;
	st.st_mode = 077777;
	st.st_mtime = 234567;
	st.st_nlink = 345;
	st.st_size = 123456789;
	st.st_uid = 23;
#ifdef __FreeBSD__
	/* On FreeBSD, high-res timestamp data should come through. */
	st.st_atimespec.tv_nsec = 6543210;
	st.st_ctimespec.tv_nsec = 5432109;
	st.st_mtimespec.tv_nsec = 3210987;
	st.st_birthtimespec.tv_nsec = 7459386;
#endif
	/* Copy them into the entry. */
	archive_entry_copy_stat(e, &st);
	/* Read each one back separately and compare. */
	assertEqualInt(archive_entry_atime(e), 456789);
	assertEqualInt(archive_entry_ctime(e), 345678);
	assertEqualInt(archive_entry_dev(e), 123);
	assertEqualInt(archive_entry_gid(e), 34);
	assertEqualInt(archive_entry_ino(e), 234);
	assertEqualInt(archive_entry_mode(e), 077777);
	assertEqualInt(archive_entry_mtime(e), 234567);
	assertEqualInt(archive_entry_nlink(e), 345);
	assertEqualInt(archive_entry_size(e), 123456789);
	assertEqualInt(archive_entry_uid(e), 23);
#if __FreeBSD__
	/* On FreeBSD, high-res timestamp data should come through. */
	assertEqualInt(archive_entry_atime_nsec(e), 6543210);
	assertEqualInt(archive_entry_ctime_nsec(e), 5432109);
	assertEqualInt(archive_entry_mtime_nsec(e), 3210987);
	assertEqualInt(archive_entry_birthtime_nsec(e), 7459386);
#endif

	/*
	 * Test archive_entry_stat().
	 */
	/* First, clear out any existing stat data. */
	memset(&st, 0, sizeof(st));
	archive_entry_copy_stat(e, &st);
	/* Set a bunch of fields individually. */
	archive_entry_set_atime(e, 456789, 321);
	archive_entry_set_ctime(e, 345678, 432);
	archive_entry_set_dev(e, 123);
	archive_entry_set_gid(e, 34);
	archive_entry_set_ino(e, 234);
	archive_entry_set_mode(e, 012345);
	archive_entry_set_mode(e, 012345);
	archive_entry_set_mtime(e, 234567, 543);
	archive_entry_set_nlink(e, 345);
	archive_entry_set_size(e, 123456789);
	archive_entry_set_uid(e, 23);
	/* Retrieve a stat structure. */
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	/* Check that the values match. */
	assertEqualInt(pst->st_atime, 456789);
	assertEqualInt(pst->st_ctime, 345678);
	assertEqualInt(pst->st_dev, 123);
	assertEqualInt(pst->st_gid, 34);
	assertEqualInt(pst->st_ino, 234);
	assertEqualInt(pst->st_mode, 012345);
	assertEqualInt(pst->st_mtime, 234567);
	assertEqualInt(pst->st_nlink, 345);
	assertEqualInt(pst->st_size, 123456789);
	assertEqualInt(pst->st_uid, 23);
#ifdef __FreeBSD__
	/* On FreeBSD, high-res timestamp data should come through. */
	assertEqualInt(pst->st_atimespec.tv_nsec, 321);
	assertEqualInt(pst->st_ctimespec.tv_nsec, 432);
	assertEqualInt(pst->st_mtimespec.tv_nsec, 543);
#endif

	/* Changing any one value should update struct stat. */
	archive_entry_set_atime(e, 456788, 0);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_atime, 456788);
	archive_entry_set_ctime(e, 345677, 431);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_ctime, 345677);
	archive_entry_set_dev(e, 122);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_dev, 122);
	archive_entry_set_gid(e, 33);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_gid, 33);
	archive_entry_set_ino(e, 233);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_ino, 233);
	archive_entry_set_mode(e, 012344);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_mode, 012344);
	archive_entry_set_mtime(e, 234566, 542);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_mtime, 234566);
	archive_entry_set_nlink(e, 344);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_nlink, 344);
	archive_entry_set_size(e, 123456788);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_size, 123456788);
	archive_entry_set_uid(e, 22);
	assert((pst = archive_entry_stat(e)) != NULL);
	if (pst == NULL)
		return;
	assertEqualInt(pst->st_uid, 22);
	/* We don't need to check high-res fields here. */

	/*
	 * Test dev/major/minor interfaces.  Setting 'dev' or 'rdev'
	 * should change the corresponding major/minor values, and
	 * vice versa.
	 *
	 * The test here is system-specific because it assumes that
	 * makedev(), major(), and minor() are defined in sys/stat.h.
	 * I'm not too worried about it, though, because the code is
	 * simple.  If it works on FreeBSD, it's unlikely to be broken
	 * anywhere else.  Note: The functionality is present on every
	 * platform even if these tests only run some places;
	 * libarchive's more extensive configuration logic should find
	 * the necessary definitions on every platform.
	 */
#if __FreeBSD__
	archive_entry_set_dev(e, 0x12345678);
	assertEqualInt(archive_entry_devmajor(e), major(0x12345678));
	assertEqualInt(archive_entry_devminor(e), minor(0x12345678));
	assertEqualInt(archive_entry_dev(e), 0x12345678);
	archive_entry_set_devmajor(e, 0xfe);
	archive_entry_set_devminor(e, 0xdcba98);
	assertEqualInt(archive_entry_devmajor(e), 0xfe);
	assertEqualInt(archive_entry_devminor(e), 0xdcba98);
	assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98));
	archive_entry_set_rdev(e, 0x12345678);
	assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678));
	assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678));
	assertEqualInt(archive_entry_rdev(e), 0x12345678);
	archive_entry_set_rdevmajor(e, 0xfe);
	archive_entry_set_rdevminor(e, 0xdcba98);
	assertEqualInt(archive_entry_rdevmajor(e), 0xfe);
	assertEqualInt(archive_entry_rdevminor(e), 0xdcba98);
	assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98));
#endif

	/*
	 * Exercise the character-conversion logic, if we can.
	 */
	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
		skipping("Can't exercise charset-conversion logic without"
			" a suitable locale.");
	} else {
		/* A filename that cannot be converted to wide characters. */
		archive_entry_copy_pathname(e, "abc\314\214mno\374xyz");
		failure("Converting invalid chars to Unicode should fail.");
		assert(NULL == archive_entry_pathname_w(e));
		/*
		  failure("Converting invalid chars to UTF-8 should fail.");
		  assert(NULL == archive_entry_pathname_utf8(e));
		*/

		/* A group name that cannot be converted. */
		archive_entry_copy_gname(e, "abc\314\214mno\374xyz");
		failure("Converting invalid chars to Unicode should fail.");
		assert(NULL == archive_entry_gname_w(e));

		/* A user name that cannot be converted. */
		archive_entry_copy_uname(e, "abc\314\214mno\374xyz");
		failure("Converting invalid chars to Unicode should fail.");
		assert(NULL == archive_entry_uname_w(e));

		/* A hardlink target that cannot be converted. */
		archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz");
		failure("Converting invalid chars to Unicode should fail.");
		assert(NULL == archive_entry_hardlink_w(e));

		/* A symlink target that cannot be converted. */
		archive_entry_copy_symlink(e, "abc\314\214mno\374xyz");
		failure("Converting invalid chars to Unicode should fail.");
		assert(NULL == archive_entry_symlink_w(e));
	}

	l = 0x12345678L;
	wc = (wchar_t)l; /* Wide character too big for UTF-8. */
	if (NULL == setlocale(LC_ALL, "C") || (long)wc != l) {
		skipping("Testing charset conversion failure requires 32-bit wchar_t and support for \"C\" locale.");
	} else {
		/*
		 * Build the string L"xxx\U12345678yyy\u5678zzz" without
		 * using wcscpy or C99 \u#### syntax.
		 */
		name = "xxxAyyyBzzz";
		for (i = 0; i < (int)strlen(name); ++i)
			wbuff[i] = name[i];
		wbuff[3] = (wchar_t)0x12345678;
		wbuff[7] = (wchar_t)0x5678;
		/* A Unicode filename that cannot be converted to UTF-8. */
		archive_entry_copy_pathname_w(e, wbuff);
		failure("Converting wide characters from Unicode should fail.");
		assertEqualString(NULL, archive_entry_pathname(e));
	}

	/* Release the experimental entry. */
	archive_entry_free(e);
}