xref: /freebsd/contrib/libarchive/unzip/test/test_I.c (revision 397e83df75e0fcd0d3fcb95ae4d794cb7600fc89)
1 /*
2  * Copyright (c) 2023 Aaron Lindros
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  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #include "test.h"
27 
28 #ifdef HAVE_LOCALE_H
29 #include <locale.h>
30 #endif
31 
32 /* Test I arg - file name encoding */
33 DEFINE_TEST(test_I)
34 {
35 	const char *reffile = "test_I.zip";
36 	const char *lang;
37 	int r;
38 
39 #if HAVE_SETLOCALE
40 	if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) {
41 		skipping("en_US.UTF-8 locale not available on this system.");
42 		return;
43 	}
44 #else
45 	skipping("setlocale() not available on this system.");
46 #endif
47 
48 	lang = getenv("LANG");
49 	setenv("LANG", "en_US.UTF-8", 1);
50 	extract_reference_file(reffile);
51 	r = systemf("%s -I UTF-8 %s >test.out 2>test.err", testprog, reffile);
52 	assertEqualInt(0, r);
53 	assertNonEmptyFile("test.out");
54 	assertEmptyFile("test.err");
55 
56 	assertTextFileContents("Hello, World!\n", "Γειά σου Κόσμε.txt");
57 
58 	if (lang == NULL)
59 		unsetenv("LANG");
60 	else
61 		setenv("LANG", lang, 1);
62 }
63