1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
26
27#include <locale.h>
28
29#ifdef HAVE_LINUX_FS_H
30#include <linux/fs.h>   /* for Linux file flags */
31#endif
32
33#ifndef HAVE_WCSCPY
34static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
35{
36	wchar_t *dest = s1;
37	while ((*s1 = *s2) != L'\0')
38		++s1, ++s2;
39	return dest;
40}
41#endif
42
43/*
44 * Most of these tests are system-independent, though a few depend on
45 * features of the local system.  Such tests are conditionalized on
46 * the platform name.  On unsupported platforms, only the
47 * system-independent features will be tested.
48 *
49 * No, I don't want to use config.h in the test files because I want
50 * the tests to also serve as a check on the correctness of config.h.
51 * A mis-configured library build should cause tests to fail.
52 */
53
54DEFINE_TEST(test_entry)
55{
56	char buff[128];
57	wchar_t wbuff[128];
58	struct stat st;
59	struct archive_entry *e, *e2;
60	const struct stat *pst;
61	unsigned long set, clear; /* For fflag testing. */
62	int type, permset, tag, qual; /* For ACL testing. */
63	const char *name; /* For ACL testing. */
64	const char *xname; /* For xattr tests. */
65	const void *xval; /* For xattr tests. */
66	size_t xsize; /* For xattr tests. */
67	wchar_t wc;
68	long l;
69	int i;
70
71	assert((e = archive_entry_new()) != NULL);
72
73	/*
74	 * Verify that the AE_IF* defines match S_IF* defines
75	 * on this platform. See comments in archive_entry.h.
76	 */
77#ifdef S_IFREG
78	assertEqualInt(S_IFREG, AE_IFREG);
79#endif
80#ifdef S_IFLNK
81	assertEqualInt(S_IFLNK, AE_IFLNK);
82#endif
83#ifdef S_IFSOCK
84	assertEqualInt(S_IFSOCK, AE_IFSOCK);
85#endif
86#ifdef S_IFCHR
87	assertEqualInt(S_IFCHR, AE_IFCHR);
88#endif
89/* Work around MinGW, which defines S_IFBLK wrong. */
90/* sourceforge.net/tracker/?func=detail&atid=102435&aid=1942809&group_id=2435 */
91#if defined(S_IFBLK) && !defined(_WIN32)
92	assertEqualInt(S_IFBLK, AE_IFBLK);
93#endif
94#ifdef S_IFDIR
95	assertEqualInt(S_IFDIR, AE_IFDIR);
96#endif
97#ifdef S_IFIFO
98	assertEqualInt(S_IFIFO, AE_IFIFO);
99#endif
100
101	/*
102	 * Basic set/read tests for all fields.
103	 * We should be able to set any field and read
104	 * back the same value.
105	 *
106	 * For methods that "copy" a string, we should be able
107	 * to overwrite the original passed-in string without
108	 * changing the value in the entry.
109	 *
110	 * The following tests are ordered alphabetically by the
111	 * name of the field.
112	 */
113
114	/* atime */
115	archive_entry_set_atime(e, 13579, 24680);
116	assertEqualInt(archive_entry_atime(e), 13579);
117	assertEqualInt(archive_entry_atime_nsec(e), 24680);
118	archive_entry_set_atime(e, 13580, 1000000001L);
119	assertEqualInt(archive_entry_atime(e), 13581);
120	assertEqualInt(archive_entry_atime_nsec(e), 1);
121	archive_entry_set_atime(e, 13580, -7);
122	assertEqualInt(archive_entry_atime(e), 13579);
123	assertEqualInt(archive_entry_atime_nsec(e), 999999993);
124	archive_entry_unset_atime(e);
125	assertEqualInt(archive_entry_atime(e), 0);
126	assertEqualInt(archive_entry_atime_nsec(e), 0);
127	assert(!archive_entry_atime_is_set(e));
128
129	/* birthtime */
130	archive_entry_set_birthtime(e, 17579, 24990);
131	assertEqualInt(archive_entry_birthtime(e), 17579);
132	assertEqualInt(archive_entry_birthtime_nsec(e), 24990);
133	archive_entry_set_birthtime(e, 17580, 1234567890L);
134	assertEqualInt(archive_entry_birthtime(e), 17581);
135	assertEqualInt(archive_entry_birthtime_nsec(e), 234567890);
136	archive_entry_set_birthtime(e, 17581, -24990);
137	assertEqualInt(archive_entry_birthtime(e), 17580);
138	assertEqualInt(archive_entry_birthtime_nsec(e), 999975010);
139	archive_entry_unset_birthtime(e);
140	assertEqualInt(archive_entry_birthtime(e), 0);
141	assertEqualInt(archive_entry_birthtime_nsec(e), 0);
142	assert(!archive_entry_birthtime_is_set(e));
143
144	/* ctime */
145	archive_entry_set_ctime(e, 13580, 24681);
146	assertEqualInt(archive_entry_ctime(e), 13580);
147	assertEqualInt(archive_entry_ctime_nsec(e), 24681);
148	archive_entry_set_ctime(e, 13581, 2008182348L);
149	assertEqualInt(archive_entry_ctime(e), 13583);
150	assertEqualInt(archive_entry_ctime_nsec(e), 8182348);
151	archive_entry_set_ctime(e, 13582, -24681);
152	assertEqualInt(archive_entry_ctime(e), 13581);
153	assertEqualInt(archive_entry_ctime_nsec(e), 999975319);
154	archive_entry_unset_ctime(e);
155	assertEqualInt(archive_entry_ctime(e), 0);
156	assertEqualInt(archive_entry_ctime_nsec(e), 0);
157	assert(!archive_entry_ctime_is_set(e));
158
159	/* dev */
160	assert(!archive_entry_dev_is_set(e));
161	archive_entry_set_dev(e, 235);
162	assert(archive_entry_dev_is_set(e));
163	assertEqualInt(archive_entry_dev(e), 235);
164	/* devmajor/devminor are tested specially below. */
165
166	/* filetype */
167	archive_entry_set_filetype(e, AE_IFREG);
168	assertEqualInt(archive_entry_filetype(e), AE_IFREG);
169
170	/* fflags are tested specially below */
171
172	/* gid */
173	archive_entry_set_gid(e, 204);
174	assertEqualInt(archive_entry_gid(e), 204);
175
176	/* gname */
177	archive_entry_set_gname(e, "group");
178	assertEqualString(archive_entry_gname(e), "group");
179	assertEqualString(archive_entry_gname_utf8(e), "group");
180	assertEqualWString(archive_entry_gname_w(e), L"group");
181	wcscpy(wbuff, L"wgroup");
182	archive_entry_copy_gname_w(e, wbuff);
183	assertEqualWString(archive_entry_gname_w(e), L"wgroup");
184	memset(wbuff, 0, sizeof(wbuff));
185	assertEqualWString(archive_entry_gname_w(e), L"wgroup");
186	assertEqualString(archive_entry_gname_utf8(e), "wgroup");
187	assertEqualString(archive_entry_gname(e), "wgroup");
188	archive_entry_set_gname_utf8(e, "group");
189	assertEqualString(archive_entry_gname_utf8(e), "group");
190	assertEqualWString(archive_entry_gname_w(e), L"group");
191	assertEqualString(archive_entry_gname(e), "group");
192	archive_entry_update_gname_utf8(e, "group2");
193	assertEqualString(archive_entry_gname_utf8(e), "group2");
194	assertEqualWString(archive_entry_gname_w(e), L"group2");
195	assertEqualString(archive_entry_gname(e), "group2");
196
197	/* hardlink */
198	archive_entry_set_hardlink(e, "hardlinkname");
199	assertEqualString(archive_entry_hardlink(e), "hardlinkname");
200	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname");
201	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname");
202	strcpy(buff, "hardlinkname2");
203	archive_entry_copy_hardlink(e, buff);
204	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
205	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
206	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
207	memset(buff, 0, sizeof(buff));
208	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
209	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
210	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
211	archive_entry_copy_hardlink(e, NULL);
212	assertEqualString(archive_entry_hardlink(e), NULL);
213	assertEqualWString(archive_entry_hardlink_w(e), NULL);
214	assertEqualString(archive_entry_hardlink_utf8(e), NULL);
215	wcscpy(wbuff, L"whardlink");
216	archive_entry_copy_hardlink_w(e, wbuff);
217	assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
218	assertEqualString(archive_entry_hardlink_utf8(e), "whardlink");
219	assertEqualString(archive_entry_hardlink(e), "whardlink");
220	memset(wbuff, 0, sizeof(wbuff));
221	assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
222	archive_entry_copy_hardlink_w(e, NULL);
223	assertEqualString(archive_entry_hardlink(e), NULL);
224	assertEqualWString(archive_entry_hardlink_w(e), NULL);
225	archive_entry_set_hardlink_utf8(e, "hardlinkname");
226	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname");
227	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname");
228	assertEqualString(archive_entry_hardlink(e), "hardlinkname");
229	archive_entry_update_hardlink_utf8(e, "hardlinkname2");
230	assertEqualString(archive_entry_hardlink_utf8(e), "hardlinkname2");
231	assertEqualWString(archive_entry_hardlink_w(e), L"hardlinkname2");
232	assertEqualString(archive_entry_hardlink(e), "hardlinkname2");
233
234	/* ino */
235	assert(!archive_entry_ino_is_set(e));
236	archive_entry_set_ino(e, 8593);
237	assert(archive_entry_ino_is_set(e));
238	assertEqualInt(archive_entry_ino(e), 8593);
239	assertEqualInt(archive_entry_ino64(e), 8593);
240	archive_entry_set_ino64(e, 8594);
241	assert(archive_entry_ino_is_set(e));
242	assertEqualInt(archive_entry_ino(e), 8594);
243	assertEqualInt(archive_entry_ino64(e), 8594);
244
245	/* link */
246	archive_entry_set_hardlink(e, "hardlinkname");
247	archive_entry_set_symlink(e, NULL);
248	archive_entry_set_link(e, "link");
249	assertEqualString(archive_entry_hardlink(e), "link");
250	assertEqualString(archive_entry_symlink(e), NULL);
251	archive_entry_copy_link(e, "link2");
252	assertEqualString(archive_entry_hardlink(e), "link2");
253	assertEqualString(archive_entry_symlink(e), NULL);
254	archive_entry_copy_link_w(e, L"link3");
255	assertEqualString(archive_entry_hardlink(e), "link3");
256	assertEqualString(archive_entry_symlink(e), NULL);
257	archive_entry_set_hardlink(e, NULL);
258	archive_entry_set_symlink(e, "symlink");
259	archive_entry_set_link(e, "link");
260	assertEqualString(archive_entry_hardlink(e), NULL);
261	assertEqualString(archive_entry_symlink(e), "link");
262	archive_entry_copy_link(e, "link2");
263	assertEqualString(archive_entry_hardlink(e), NULL);
264	assertEqualString(archive_entry_symlink(e), "link2");
265	archive_entry_copy_link_w(e, L"link3");
266	assertEqualString(archive_entry_hardlink(e), NULL);
267	assertEqualString(archive_entry_symlink(e), "link3");
268	/* Arbitrarily override symlink if both hardlink and symlink set. */
269	archive_entry_set_hardlink(e, "hardlink");
270	archive_entry_set_symlink(e, "symlink");
271	archive_entry_set_link(e, "link");
272	assertEqualString(archive_entry_hardlink(e), "hardlink");
273	assertEqualString(archive_entry_symlink(e), "link");
274
275	/* mode */
276	archive_entry_set_mode(e, 0123456);
277	assertEqualInt(archive_entry_mode(e), 0123456);
278
279	/* mtime */
280	archive_entry_set_mtime(e, 13581, 24682);
281	assertEqualInt(archive_entry_mtime(e), 13581);
282	assertEqualInt(archive_entry_mtime_nsec(e), 24682);
283	archive_entry_set_mtime(e, 13582, 1358297468);
284	assertEqualInt(archive_entry_mtime(e), 13583);
285	assertEqualInt(archive_entry_mtime_nsec(e), 358297468);
286	archive_entry_set_mtime(e, 13583, -24682);
287	assertEqualInt(archive_entry_mtime(e), 13582);
288	assertEqualInt(archive_entry_mtime_nsec(e), 999975318);
289	archive_entry_unset_mtime(e);
290	assertEqualInt(archive_entry_mtime(e), 0);
291	assertEqualInt(archive_entry_mtime_nsec(e), 0);
292	assert(!archive_entry_mtime_is_set(e));
293
294	/* nlink */
295	archive_entry_set_nlink(e, 736);
296	assertEqualInt(archive_entry_nlink(e), 736);
297
298	/* pathname */
299	archive_entry_set_pathname(e, "path");
300	assertEqualString(archive_entry_pathname(e), "path");
301	assertEqualString(archive_entry_pathname_utf8(e), "path");
302	assertEqualWString(archive_entry_pathname_w(e), L"path");
303	archive_entry_set_pathname(e, "path");
304	assertEqualString(archive_entry_pathname(e), "path");
305	assertEqualWString(archive_entry_pathname_w(e), L"path");
306	assertEqualString(archive_entry_pathname_utf8(e), "path");
307	strcpy(buff, "path2");
308	archive_entry_copy_pathname(e, buff);
309	assertEqualString(archive_entry_pathname(e), "path2");
310	assertEqualWString(archive_entry_pathname_w(e), L"path2");
311	assertEqualString(archive_entry_pathname_utf8(e), "path2");
312	memset(buff, 0, sizeof(buff));
313	assertEqualString(archive_entry_pathname(e), "path2");
314	assertEqualString(archive_entry_pathname_utf8(e), "path2");
315	assertEqualWString(archive_entry_pathname_w(e), L"path2");
316	wcscpy(wbuff, L"wpath");
317	archive_entry_copy_pathname_w(e, wbuff);
318	assertEqualWString(archive_entry_pathname_w(e), L"wpath");
319	assertEqualString(archive_entry_pathname_utf8(e), "wpath");
320	assertEqualString(archive_entry_pathname(e), "wpath");
321	memset(wbuff, 0, sizeof(wbuff));
322	assertEqualWString(archive_entry_pathname_w(e), L"wpath");
323	assertEqualString(archive_entry_pathname(e), "wpath");
324	assertEqualString(archive_entry_pathname_utf8(e), "wpath");
325	archive_entry_set_pathname_utf8(e, "path");
326	assertEqualWString(archive_entry_pathname_w(e), L"path");
327	assertEqualString(archive_entry_pathname(e), "path");
328	assertEqualString(archive_entry_pathname_utf8(e), "path");
329	archive_entry_update_pathname_utf8(e, "path2");
330	assertEqualWString(archive_entry_pathname_w(e), L"path2");
331	assertEqualString(archive_entry_pathname(e), "path2");
332	assertEqualString(archive_entry_pathname_utf8(e), "path2");
333
334	/* rdev */
335	archive_entry_set_rdev(e, 532);
336	assertEqualInt(archive_entry_rdev(e), 532);
337	/* rdevmajor/rdevminor are tested specially below. */
338
339	/* size */
340	archive_entry_set_size(e, 987654321);
341	assertEqualInt(archive_entry_size(e), 987654321);
342	archive_entry_unset_size(e);
343	assertEqualInt(archive_entry_size(e), 0);
344	assert(!archive_entry_size_is_set(e));
345
346	/* sourcepath */
347	archive_entry_copy_sourcepath(e, "path1");
348	assertEqualString(archive_entry_sourcepath(e), "path1");
349
350	/* symlink */
351	archive_entry_set_symlink(e, "symlinkname");
352	assertEqualString(archive_entry_symlink(e), "symlinkname");
353	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname");
354	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname");
355	strcpy(buff, "symlinkname2");
356	archive_entry_copy_symlink(e, buff);
357	assertEqualString(archive_entry_symlink(e), "symlinkname2");
358	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
359	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");
360	memset(buff, 0, sizeof(buff));
361	assertEqualString(archive_entry_symlink(e), "symlinkname2");
362	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");
363	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
364	archive_entry_copy_symlink_w(e, NULL);
365	assertEqualWString(archive_entry_symlink_w(e), NULL);
366	assertEqualString(archive_entry_symlink(e), NULL);
367	assertEqualString(archive_entry_symlink_utf8(e), NULL);
368	archive_entry_copy_symlink_w(e, L"wsymlink");
369	assertEqualWString(archive_entry_symlink_w(e), L"wsymlink");
370	assertEqualString(archive_entry_symlink_utf8(e), "wsymlink");
371	assertEqualString(archive_entry_symlink(e), "wsymlink");
372	archive_entry_copy_symlink(e, NULL);
373	assertEqualWString(archive_entry_symlink_w(e), NULL);
374	assertEqualString(archive_entry_symlink(e), NULL);
375	assertEqualString(archive_entry_symlink_utf8(e), NULL);
376	archive_entry_set_symlink_utf8(e, "symlinkname");
377	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname");
378	assertEqualString(archive_entry_symlink(e), "symlinkname");
379	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname");
380	archive_entry_update_symlink_utf8(e, "symlinkname2");
381	assertEqualWString(archive_entry_symlink_w(e), L"symlinkname2");
382	assertEqualString(archive_entry_symlink(e), "symlinkname2");
383	assertEqualString(archive_entry_symlink_utf8(e), "symlinkname2");
384
385	/* uid */
386	archive_entry_set_uid(e, 83);
387	assertEqualInt(archive_entry_uid(e), 83);
388
389	/* uname */
390	archive_entry_set_uname(e, "user");
391	assertEqualString(archive_entry_uname(e), "user");
392	assertEqualString(archive_entry_uname_utf8(e), "user");
393	assertEqualWString(archive_entry_uname_w(e), L"user");
394	wcscpy(wbuff, L"wuser");
395	archive_entry_copy_uname_w(e, wbuff);
396	assertEqualWString(archive_entry_uname_w(e), L"wuser");
397	memset(wbuff, 0, sizeof(wbuff));
398	assertEqualWString(archive_entry_uname_w(e), L"wuser");
399	assertEqualString(archive_entry_uname_utf8(e), "wuser");
400	assertEqualString(archive_entry_uname(e), "wuser");
401	archive_entry_set_uname_utf8(e, "user");
402	assertEqualString(archive_entry_uname_utf8(e), "user");
403	assertEqualWString(archive_entry_uname_w(e), L"user");
404	assertEqualString(archive_entry_uname(e), "user");
405	archive_entry_set_uname_utf8(e, "user");
406	assertEqualWString(archive_entry_uname_w(e), L"user");
407	assertEqualString(archive_entry_uname(e), "user");
408	assertEqualString(archive_entry_uname_utf8(e), "user");
409	archive_entry_update_uname_utf8(e, "user2");
410	assertEqualWString(archive_entry_uname_w(e), L"user2");
411	assertEqualString(archive_entry_uname(e), "user2");
412	assertEqualString(archive_entry_uname_utf8(e), "user2");
413
414	/* Test fflags interface. */
415	archive_entry_set_fflags(e, 0x55, 0xAA);
416	archive_entry_fflags(e, &set, &clear);
417	failure("Testing set/get of fflags data.");
418	assertEqualInt(set, 0x55);
419	failure("Testing set/get of fflags data.");
420	assertEqualInt(clear, 0xAA);
421#ifdef __FreeBSD__
422	/* Converting fflags bitmap to string is currently system-dependent. */
423	/* TODO: Make this system-independent. */
424	assertEqualString(archive_entry_fflags_text(e),
425	    "uappnd,nouchg,nodump,noopaque,uunlnk,nosystem");
426#endif
427
428#if defined(__FreeBSD__) || defined(__APPLE__)
429	/* Test archive_entry_copy_fflags_text_w() */
430	archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,hidden");
431	archive_entry_fflags(e, &set, &clear);
432	assertEqualInt(UF_HIDDEN, set);
433	assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
434	/* Test archive_entry_copy_fflags_text() */
435	archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,hidden");
436	archive_entry_fflags(e, &set, &clear);
437	assertEqualInt(UF_HIDDEN, set);
438	assertEqualInt(UF_NODUMP | UF_IMMUTABLE | UF_APPEND, clear);
439#elif defined(_WIN32) && !defined(CYGWIN)
440	archive_entry_copy_fflags_text_w(e, L"rdonly,hidden,nosystem");
441	archive_entry_fflags(e, &set, &clear);
442	assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
443	assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
444	archive_entry_copy_fflags_text(e, "rdonly,hidden,nosystem");
445	archive_entry_fflags(e, &set, &clear);
446	assertEqualInt(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, set);
447	assertEqualInt(FILE_ATTRIBUTE_SYSTEM, clear);
448#elif defined FS_IOC_GETFLAGS /* Linux */
449	archive_entry_copy_fflags_text_w(e, L"sappnd,schg,dump,noundel");
450	archive_entry_fflags(e, &set, &clear);
451	assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
452	assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
453	archive_entry_copy_fflags_text(e, "sappnd,schg,dump,noundel");
454	archive_entry_fflags(e, &set, &clear);
455	assertEqualInt(FS_APPEND_FL | FS_IMMUTABLE_FL, set);
456	assertEqualInt(FS_NODUMP_FL | FS_UNRM_FL, clear);
457#endif
458
459	/* See test_acl_basic.c for tests of ACL set/get consistency. */
460
461	/* Test xattrs set/get consistency. */
462	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
463	assertEqualInt(1, archive_entry_xattr_reset(e));
464	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
465	assertEqualString(xname, "xattr1");
466	assertEqualString(xval, "xattrvalue1");
467	assertEqualInt((int)xsize, 12);
468	assertEqualInt(1, archive_entry_xattr_count(e));
469	assertEqualInt(ARCHIVE_WARN,
470	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
471	assertEqualString(xname, NULL);
472	assertEqualString(xval, NULL);
473	assertEqualInt((int)xsize, 0);
474	archive_entry_xattr_clear(e);
475	assertEqualInt(0, archive_entry_xattr_reset(e));
476	assertEqualInt(ARCHIVE_WARN,
477	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
478	assertEqualString(xname, NULL);
479	assertEqualString(xval, NULL);
480	assertEqualInt((int)xsize, 0);
481	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12);
482	assertEqualInt(1, archive_entry_xattr_reset(e));
483	archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12);
484	assertEqualInt(2, archive_entry_xattr_reset(e));
485	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
486	assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize));
487	assertEqualInt(ARCHIVE_WARN,
488	    archive_entry_xattr_next(e, &xname, &xval, &xsize));
489	assertEqualString(xname, NULL);
490	assertEqualString(xval, NULL);
491	assertEqualInt((int)xsize, 0);
492
493
494	/*
495	 * Test clone() implementation.
496	 */
497
498	/* Set values in 'e' */
499	archive_entry_clear(e);
500	archive_entry_set_atime(e, 13579, 24680);
501	archive_entry_set_birthtime(e, 13779, 24990);
502	archive_entry_set_ctime(e, 13580, 24681);
503	archive_entry_set_dev(e, 235);
504	archive_entry_set_fflags(e, 0x55, 0xAA);
505	archive_entry_set_gid(e, 204);
506	archive_entry_set_gname(e, "group");
507	archive_entry_set_hardlink(e, "hardlinkname");
508	archive_entry_set_ino(e, 8593);
509	archive_entry_set_mode(e, 0123456);
510	archive_entry_set_mtime(e, 13581, 24682);
511	archive_entry_set_nlink(e, 736);
512	archive_entry_set_pathname(e, "path");
513	archive_entry_set_rdev(e, 532);
514	archive_entry_set_size(e, 987654321);
515	archive_entry_copy_sourcepath(e, "source");
516	archive_entry_set_symlink(e, "symlinkname");
517	archive_entry_set_uid(e, 83);
518	archive_entry_set_uname(e, "user");
519	/* Add an ACL entry. */
520	archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
521	    ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77");
522	/* Add an extended attribute. */
523	archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11);
524
525	/* Make a clone. */
526	e2 = archive_entry_clone(e);
527
528	/* Clone should have same contents. */
529	assertEqualInt(archive_entry_atime(e2), 13579);
530	assertEqualInt(archive_entry_atime_nsec(e2), 24680);
531	assertEqualInt(archive_entry_birthtime(e2), 13779);
532	assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
533	assertEqualInt(archive_entry_ctime(e2), 13580);
534	assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
535	assertEqualInt(archive_entry_dev(e2), 235);
536	archive_entry_fflags(e, &set, &clear);
537	assertEqualInt(clear, 0xAA);
538	assertEqualInt(set, 0x55);
539	assertEqualInt(archive_entry_gid(e2), 204);
540	assertEqualString(archive_entry_gname(e2), "group");
541	assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
542	assertEqualInt(archive_entry_ino(e2), 8593);
543	assertEqualInt(archive_entry_mode(e2), 0123456);
544	assertEqualInt(archive_entry_mtime(e2), 13581);
545	assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
546	assertEqualInt(archive_entry_nlink(e2), 736);
547	assertEqualString(archive_entry_pathname(e2), "path");
548	assertEqualInt(archive_entry_rdev(e2), 532);
549	assertEqualInt(archive_entry_size(e2), 987654321);
550	assertEqualString(archive_entry_sourcepath(e2), "source");
551	assertEqualString(archive_entry_symlink(e2), "symlinkname");
552	assertEqualInt(archive_entry_uid(e2), 83);
553	assertEqualString(archive_entry_uname(e2), "user");
554
555	/* Verify ACL was copied. */
556	assertEqualInt(4, archive_entry_acl_reset(e2,
557			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
558	/* First three are standard permission bits. */
559	assertEqualInt(0, archive_entry_acl_next(e2,
560			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
561			   &type, &permset, &tag, &qual, &name));
562	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
563	assertEqualInt(permset, 4);
564	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
565	assertEqualInt(qual, -1);
566	assertEqualString(name, NULL);
567	assertEqualInt(0, archive_entry_acl_next(e2,
568			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
569			   &type, &permset, &tag, &qual, &name));
570	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
571	assertEqualInt(permset, 5);
572	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
573	assertEqualInt(qual, -1);
574	assertEqualString(name, NULL);
575	assertEqualInt(0, archive_entry_acl_next(e2,
576			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
577			   &type, &permset, &tag, &qual, &name));
578	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
579	assertEqualInt(permset, 6);
580	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
581	assertEqualInt(qual, -1);
582	assertEqualString(name, NULL);
583	/* Fourth is custom one. */
584	assertEqualInt(0, archive_entry_acl_next(e2,
585			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
586			   &type, &permset, &tag, &qual, &name));
587	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
588	assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
589	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
590	assertEqualInt(qual, 77);
591	assertEqualString(name, "user77");
592
593	/* Verify xattr was copied. */
594	assertEqualInt(1, archive_entry_xattr_reset(e2));
595	assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize));
596	assertEqualString(xname, "xattr1");
597	assertEqualString(xval, "xattrvalue");
598	assertEqualInt((int)xsize, 11);
599	assertEqualInt(ARCHIVE_WARN,
600	    archive_entry_xattr_next(e2, &xname, &xval, &xsize));
601	assertEqualString(xname, NULL);
602	assertEqualString(xval, NULL);
603	assertEqualInt((int)xsize, 0);
604
605	/* Change the original */
606	archive_entry_set_atime(e, 13580, 24690);
607	archive_entry_set_birthtime(e, 13980, 24999);
608	archive_entry_set_ctime(e, 13590, 24691);
609	archive_entry_set_dev(e, 245);
610	archive_entry_set_fflags(e, 0x85, 0xDA);
611	archive_entry_set_filetype(e, AE_IFLNK);
612	archive_entry_set_gid(e, 214);
613	archive_entry_set_gname(e, "grouper");
614	archive_entry_set_hardlink(e, "hardlinkpath");
615	archive_entry_set_ino(e, 8763);
616	archive_entry_set_mode(e, 0123654);
617	archive_entry_set_mtime(e, 18351, 28642);
618	archive_entry_set_nlink(e, 73);
619	archive_entry_set_pathname(e, "pathest");
620	archive_entry_set_rdev(e, 132);
621	archive_entry_set_size(e, 987456321);
622	archive_entry_copy_sourcepath(e, "source2");
623	archive_entry_set_symlink(e, "symlinkpath");
624	archive_entry_set_uid(e, 93);
625	archive_entry_set_uname(e, "username");
626	archive_entry_acl_clear(e);
627	archive_entry_xattr_clear(e);
628
629	/* Clone should still have same contents. */
630	assertEqualInt(archive_entry_atime(e2), 13579);
631	assertEqualInt(archive_entry_atime_nsec(e2), 24680);
632	assertEqualInt(archive_entry_birthtime(e2), 13779);
633	assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
634	assertEqualInt(archive_entry_ctime(e2), 13580);
635	assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
636	assertEqualInt(archive_entry_dev(e2), 235);
637	archive_entry_fflags(e2, &set, &clear);
638	assertEqualInt(clear, 0xAA);
639	assertEqualInt(set, 0x55);
640	assertEqualInt(archive_entry_gid(e2), 204);
641	assertEqualString(archive_entry_gname(e2), "group");
642	assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
643	assertEqualInt(archive_entry_ino(e2), 8593);
644	assertEqualInt(archive_entry_mode(e2), 0123456);
645	assertEqualInt(archive_entry_mtime(e2), 13581);
646	assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
647	assertEqualInt(archive_entry_nlink(e2), 736);
648	assertEqualString(archive_entry_pathname(e2), "path");
649	assertEqualInt(archive_entry_rdev(e2), 532);
650	assertEqualInt(archive_entry_size(e2), 987654321);
651	assertEqualString(archive_entry_sourcepath(e2), "source");
652	assertEqualString(archive_entry_symlink(e2), "symlinkname");
653	assertEqualInt(archive_entry_uid(e2), 83);
654	assertEqualString(archive_entry_uname(e2), "user");
655
656	/* Verify ACL was unchanged. */
657	assertEqualInt(4, archive_entry_acl_reset(e2,
658			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
659	/* First three are standard permission bits. */
660	assertEqualInt(0, archive_entry_acl_next(e2,
661			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
662			   &type, &permset, &tag, &qual, &name));
663	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
664	assertEqualInt(permset, 4);
665	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ);
666	assertEqualInt(qual, -1);
667	assertEqualString(name, NULL);
668	assertEqualInt(0, archive_entry_acl_next(e2,
669			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
670			   &type, &permset, &tag, &qual, &name));
671	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
672	assertEqualInt(permset, 5);
673	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ);
674	assertEqualInt(qual, -1);
675	assertEqualString(name, NULL);
676	assertEqualInt(0, archive_entry_acl_next(e2,
677			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
678			   &type, &permset, &tag, &qual, &name));
679	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
680	assertEqualInt(permset, 6);
681	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER);
682	assertEqualInt(qual, -1);
683	assertEqualString(name, NULL);
684	/* Fourth is custom one. */
685	assertEqualInt(0, archive_entry_acl_next(e2,
686			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
687			   &type, &permset, &tag, &qual, &name));
688	assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
689	assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ);
690	assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
691	assertEqualInt(qual, 77);
692	assertEqualString(name, "user77");
693	assertEqualInt(1, archive_entry_acl_next(e2,
694			   ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
695			   &type, &permset, &tag, &qual, &name));
696	assertEqualInt(type, 0);
697	assertEqualInt(permset, 0);
698	assertEqualInt(tag, 0);
699	assertEqualInt(qual, -1);
700	assertEqualString(name, NULL);
701
702	/* Verify xattr was unchanged. */
703	assertEqualInt(1, archive_entry_xattr_reset(e2));
704
705	/* Release clone. */
706	archive_entry_free(e2);
707
708	/*
709	 * Test clear() implementation.
710	 */
711	archive_entry_clear(e);
712	assertEqualInt(archive_entry_atime(e), 0);
713	assertEqualInt(archive_entry_atime_nsec(e), 0);
714	assertEqualInt(archive_entry_birthtime(e), 0);
715	assertEqualInt(archive_entry_birthtime_nsec(e), 0);
716	assertEqualInt(archive_entry_ctime(e), 0);
717	assertEqualInt(archive_entry_ctime_nsec(e), 0);
718	assertEqualInt(archive_entry_dev(e), 0);
719	archive_entry_fflags(e, &set, &clear);
720	assertEqualInt(clear, 0);
721	assertEqualInt(set, 0);
722	assertEqualInt(archive_entry_filetype(e), 0);
723	assertEqualInt(archive_entry_gid(e), 0);
724	assertEqualString(archive_entry_gname(e), NULL);
725	assertEqualString(archive_entry_hardlink(e), NULL);
726	assertEqualInt(archive_entry_ino(e), 0);
727	assertEqualInt(archive_entry_mode(e), 0);
728	assertEqualInt(archive_entry_mtime(e), 0);
729	assertEqualInt(archive_entry_mtime_nsec(e), 0);
730	assertEqualInt(archive_entry_nlink(e), 0);
731	assertEqualString(archive_entry_pathname(e), NULL);
732	assertEqualInt(archive_entry_rdev(e), 0);
733	assertEqualInt(archive_entry_size(e), 0);
734	assertEqualString(archive_entry_symlink(e), NULL);
735	assertEqualInt(archive_entry_uid(e), 0);
736	assertEqualString(archive_entry_uname(e), NULL);
737	/* ACLs should be cleared. */
738	assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0);
739	assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0);
740	/* Extended attributes should be cleared. */
741	assertEqualInt(archive_entry_xattr_count(e), 0);
742
743	/*
744	 * Test archive_entry_copy_stat().
745	 */
746	memset(&st, 0, sizeof(st));
747	/* Set all of the standard 'struct stat' fields. */
748	st.st_atime = 456789;
749	st.st_ctime = 345678;
750	st.st_dev = 123;
751	st.st_gid = 34;
752	st.st_ino = 234;
753	st.st_mode = 077777;
754	st.st_mtime = 234567;
755	st.st_nlink = 345;
756	st.st_size = 123456789;
757	st.st_uid = 23;
758#ifdef __FreeBSD__
759	/* On FreeBSD, high-res timestamp data should come through. */
760	st.st_atimespec.tv_nsec = 6543210;
761	st.st_ctimespec.tv_nsec = 5432109;
762	st.st_mtimespec.tv_nsec = 3210987;
763	st.st_birthtimespec.tv_nsec = 7459386;
764#endif
765	/* Copy them into the entry. */
766	archive_entry_copy_stat(e, &st);
767	/* Read each one back separately and compare. */
768	assertEqualInt(archive_entry_atime(e), 456789);
769	assertEqualInt(archive_entry_ctime(e), 345678);
770	assertEqualInt(archive_entry_dev(e), 123);
771	assertEqualInt(archive_entry_gid(e), 34);
772	assertEqualInt(archive_entry_ino(e), 234);
773	assertEqualInt(archive_entry_mode(e), 077777);
774	assertEqualInt(archive_entry_mtime(e), 234567);
775	assertEqualInt(archive_entry_nlink(e), 345);
776	assertEqualInt(archive_entry_size(e), 123456789);
777	assertEqualInt(archive_entry_uid(e), 23);
778#if __FreeBSD__
779	/* On FreeBSD, high-res timestamp data should come through. */
780	assertEqualInt(archive_entry_atime_nsec(e), 6543210);
781	assertEqualInt(archive_entry_ctime_nsec(e), 5432109);
782	assertEqualInt(archive_entry_mtime_nsec(e), 3210987);
783	assertEqualInt(archive_entry_birthtime_nsec(e), 7459386);
784#endif
785
786	/*
787	 * Test archive_entry_stat().
788	 */
789	/* First, clear out any existing stat data. */
790	memset(&st, 0, sizeof(st));
791	archive_entry_copy_stat(e, &st);
792	/* Set a bunch of fields individually. */
793	archive_entry_set_atime(e, 456789, 321);
794	archive_entry_set_ctime(e, 345678, 432);
795	archive_entry_set_dev(e, 123);
796	archive_entry_set_gid(e, 34);
797	archive_entry_set_ino(e, 234);
798	archive_entry_set_mode(e, 012345);
799	archive_entry_set_mode(e, 012345);
800	archive_entry_set_mtime(e, 234567, 543);
801	archive_entry_set_nlink(e, 345);
802	archive_entry_set_size(e, 123456789);
803	archive_entry_set_uid(e, 23);
804	/* Retrieve a stat structure. */
805	assert((pst = archive_entry_stat(e)) != NULL);
806	if (pst == NULL)
807		return;
808	/* Check that the values match. */
809	assertEqualInt(pst->st_atime, 456789);
810	assertEqualInt(pst->st_ctime, 345678);
811	assertEqualInt(pst->st_dev, 123);
812	assertEqualInt(pst->st_gid, 34);
813	assertEqualInt(pst->st_ino, 234);
814	assertEqualInt(pst->st_mode, 012345);
815	assertEqualInt(pst->st_mtime, 234567);
816	assertEqualInt(pst->st_nlink, 345);
817	assertEqualInt(pst->st_size, 123456789);
818	assertEqualInt(pst->st_uid, 23);
819#ifdef __FreeBSD__
820	/* On FreeBSD, high-res timestamp data should come through. */
821	assertEqualInt(pst->st_atimespec.tv_nsec, 321);
822	assertEqualInt(pst->st_ctimespec.tv_nsec, 432);
823	assertEqualInt(pst->st_mtimespec.tv_nsec, 543);
824#endif
825
826	/* Changing any one value should update struct stat. */
827	archive_entry_set_atime(e, 456788, 0);
828	assert((pst = archive_entry_stat(e)) != NULL);
829	if (pst == NULL)
830		return;
831	assertEqualInt(pst->st_atime, 456788);
832	archive_entry_set_ctime(e, 345677, 431);
833	assert((pst = archive_entry_stat(e)) != NULL);
834	if (pst == NULL)
835		return;
836	assertEqualInt(pst->st_ctime, 345677);
837	archive_entry_set_dev(e, 122);
838	assert((pst = archive_entry_stat(e)) != NULL);
839	if (pst == NULL)
840		return;
841	assertEqualInt(pst->st_dev, 122);
842	archive_entry_set_gid(e, 33);
843	assert((pst = archive_entry_stat(e)) != NULL);
844	if (pst == NULL)
845		return;
846	assertEqualInt(pst->st_gid, 33);
847	archive_entry_set_ino(e, 233);
848	assert((pst = archive_entry_stat(e)) != NULL);
849	if (pst == NULL)
850		return;
851	assertEqualInt(pst->st_ino, 233);
852	archive_entry_set_mode(e, 012344);
853	assert((pst = archive_entry_stat(e)) != NULL);
854	if (pst == NULL)
855		return;
856	assertEqualInt(pst->st_mode, 012344);
857	archive_entry_set_mtime(e, 234566, 542);
858	assert((pst = archive_entry_stat(e)) != NULL);
859	if (pst == NULL)
860		return;
861	assertEqualInt(pst->st_mtime, 234566);
862	archive_entry_set_nlink(e, 344);
863	assert((pst = archive_entry_stat(e)) != NULL);
864	if (pst == NULL)
865		return;
866	assertEqualInt(pst->st_nlink, 344);
867	archive_entry_set_size(e, 123456788);
868	assert((pst = archive_entry_stat(e)) != NULL);
869	if (pst == NULL)
870		return;
871	assertEqualInt(pst->st_size, 123456788);
872	archive_entry_set_uid(e, 22);
873	assert((pst = archive_entry_stat(e)) != NULL);
874	if (pst == NULL)
875		return;
876	assertEqualInt(pst->st_uid, 22);
877	/* We don't need to check high-res fields here. */
878
879	/*
880	 * Test dev/major/minor interfaces.  Setting 'dev' or 'rdev'
881	 * should change the corresponding major/minor values, and
882	 * vice versa.
883	 *
884	 * The test here is system-specific because it assumes that
885	 * makedev(), major(), and minor() are defined in sys/stat.h.
886	 * I'm not too worried about it, though, because the code is
887	 * simple.  If it works on FreeBSD, it's unlikely to be broken
888	 * anywhere else.  Note: The functionality is present on every
889	 * platform even if these tests only run some places;
890	 * libarchive's more extensive configuration logic should find
891	 * the necessary definitions on every platform.
892	 */
893#if __FreeBSD__
894	archive_entry_set_dev(e, 0x12345678);
895	assertEqualInt(archive_entry_devmajor(e), major(0x12345678));
896	assertEqualInt(archive_entry_devminor(e), minor(0x12345678));
897	assertEqualInt(archive_entry_dev(e), 0x12345678);
898	archive_entry_set_devmajor(e, 0xfe);
899	archive_entry_set_devminor(e, 0xdcba98);
900	assertEqualInt(archive_entry_devmajor(e), 0xfe);
901	assertEqualInt(archive_entry_devminor(e), 0xdcba98);
902	assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98));
903	archive_entry_set_rdev(e, 0x12345678);
904	assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678));
905	assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678));
906	assertEqualInt(archive_entry_rdev(e), 0x12345678);
907	archive_entry_set_rdevmajor(e, 0xfe);
908	archive_entry_set_rdevminor(e, 0xdcba98);
909	assertEqualInt(archive_entry_rdevmajor(e), 0xfe);
910	assertEqualInt(archive_entry_rdevminor(e), 0xdcba98);
911	assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98));
912#endif
913
914	/*
915	 * Exercise the character-conversion logic, if we can.
916	 */
917	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
918		skipping("Can't exercise charset-conversion logic without"
919			" a suitable locale.");
920	} else {
921		/* A filename that cannot be converted to wide characters. */
922		archive_entry_copy_pathname(e, "abc\314\214mno\374xyz");
923		failure("Converting invalid chars to Unicode should fail.");
924		assert(NULL == archive_entry_pathname_w(e));
925		/*
926		  failure("Converting invalid chars to UTF-8 should fail.");
927		  assert(NULL == archive_entry_pathname_utf8(e));
928		*/
929
930		/* A group name that cannot be converted. */
931		archive_entry_copy_gname(e, "abc\314\214mno\374xyz");
932		failure("Converting invalid chars to Unicode should fail.");
933		assert(NULL == archive_entry_gname_w(e));
934
935		/* A user name that cannot be converted. */
936		archive_entry_copy_uname(e, "abc\314\214mno\374xyz");
937		failure("Converting invalid chars to Unicode should fail.");
938		assert(NULL == archive_entry_uname_w(e));
939
940		/* A hardlink target that cannot be converted. */
941		archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz");
942		failure("Converting invalid chars to Unicode should fail.");
943		assert(NULL == archive_entry_hardlink_w(e));
944
945		/* A symlink target that cannot be converted. */
946		archive_entry_copy_symlink(e, "abc\314\214mno\374xyz");
947		failure("Converting invalid chars to Unicode should fail.");
948		assert(NULL == archive_entry_symlink_w(e));
949	}
950
951	l = 0x12345678L;
952	wc = (wchar_t)l; /* Wide character too big for UTF-8. */
953	if (NULL == setlocale(LC_ALL, "C") || (long)wc != l) {
954		skipping("Testing charset conversion failure requires 32-bit wchar_t and support for \"C\" locale.");
955	} else {
956		/*
957		 * Build the string L"xxx\U12345678yyy\u5678zzz" without
958		 * using wcscpy or C99 \u#### syntax.
959		 */
960		name = "xxxAyyyBzzz";
961		for (i = 0; i < (int)strlen(name); ++i)
962			wbuff[i] = name[i];
963		wbuff[3] = (wchar_t)0x12345678;
964		wbuff[7] = (wchar_t)0x5678;
965		/* A Unicode filename that cannot be converted to UTF-8. */
966		archive_entry_copy_pathname_w(e, wbuff);
967		failure("Converting wide characters from Unicode should fail.");
968		assertEqualString(NULL, archive_entry_pathname(e));
969	}
970
971	/* Release the experimental entry. */
972	archive_entry_free(e);
973}
974