tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libc / locale / t_io.c
blobae7da422cd850232de64208614a06504ebe79c56
1 /* $NetBSD: t_io.c,v 1.2 2013/03/17 05:02:13 jmmv Exp $ */
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __COPYRIGHT("@(#) Copyright (c) 2011\
34 The NetBSD Foundation, inc. All rights reserved.");
35 __RCSID("$NetBSD: t_io.c,v 1.2 2013/03/17 05:02:13 jmmv Exp $");
37 #include <sys/param.h>
38 #include <errno.h>
39 #include <locale.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <wchar.h>
45 #include <atf-c.h>
48 ATF_TC(bad_big5_wprintf);
49 ATF_TC_HEAD(bad_big5_wprintf, tc)
51 atf_tc_set_md_var(tc, "descr", "Test bad big5 wchar wprintf");
54 ATF_TC_BODY(bad_big5_wprintf, tc)
56 wchar_t ibuf[] = { 0xcf10, 0 };
57 setlocale(LC_CTYPE, "zh_TW.Big5");
58 atf_tc_expect_fail("PR lib/47660");
59 ATF_REQUIRE_EQ(wprintf(L"%ls\n", ibuf), -1);
62 ATF_TC(bad_big5_swprintf);
63 ATF_TC_HEAD(bad_big5_swprintf, tc)
65 atf_tc_set_md_var(tc, "descr", "Test bad big5 wchar swprintf");
68 ATF_TC_BODY(bad_big5_swprintf, tc)
70 wchar_t ibuf[] = { 0xcf10, 0 };
71 wchar_t obuf[20];
72 setlocale(LC_CTYPE, "zh_TW.Big5");
73 ATF_REQUIRE_EQ(swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf), -1);
76 ATF_TC(good_big5_wprintf);
77 ATF_TC_HEAD(good_big5_wprintf, tc)
79 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar wprintf");
82 ATF_TC_BODY(good_big5_wprintf, tc)
84 wchar_t ibuf[] = { 0xcf40, 0 };
85 setlocale(LC_CTYPE, "zh_TW.Big5");
86 // WTF? swprintf() fails, wprintf succeeds?
87 ATF_REQUIRE_EQ(wprintf(L"%ls\n", ibuf), 2);
90 ATF_TC(good_big5_swprintf);
91 ATF_TC_HEAD(good_big5_swprintf, tc)
93 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar swprintf");
96 ATF_TC_BODY(good_big5_swprintf, tc)
98 wchar_t ibuf[] = { 0xcf40, 0 };
99 wchar_t obuf[20];
100 setlocale(LC_CTYPE, "zh_TW.Big5");
101 ATF_REQUIRE_EQ(swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf), 2);
104 static int readfn(void *p, char *buf, int len) {
105 memcpy(buf, p, MIN(len, 2));
106 return 2;
109 ATF_TC(good_big5_getwc);
110 ATF_TC_HEAD(good_big5_getwc, tc)
112 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar getwc");
115 ATF_TC_BODY(good_big5_getwc, tc)
117 char ibuf[] = { 0xcf, 0x40 };
118 FILE *fp = funopen(ibuf, readfn, NULL, NULL, NULL);
120 ATF_REQUIRE(fp != NULL);
121 setlocale(LC_CTYPE, "zh_TW.Big5");
122 ATF_REQUIRE_EQ(getwc(fp), 0xcf40);
123 fclose(fp);
126 ATF_TC(bad_big5_getwc);
127 ATF_TC_HEAD(bad_big5_getwc, tc)
129 atf_tc_set_md_var(tc, "descr", "Test bad big5 wchar getwc");
132 ATF_TC_BODY(bad_big5_getwc, tc)
134 char ibuf[] = { 0xcf, 0x20 };
135 FILE *fp = funopen(ibuf, readfn, NULL, NULL, NULL);
137 ATF_REQUIRE(fp != NULL);
138 setlocale(LC_CTYPE, "zh_TW.Big5");
139 ATF_REQUIRE_EQ(getwc(fp), WEOF);
140 fclose(fp);
143 ATF_TC(bad_eucJP_getwc);
144 ATF_TC_HEAD(bad_eucJP_getwc, tc)
146 atf_tc_set_md_var(tc, "descr", "Test bad eucJP wchar getwc");
149 ATF_TC_BODY(bad_eucJP_getwc, tc)
151 char ibuf[] = { 0xcf, 0x20 };
152 FILE *fp = funopen(ibuf, readfn, NULL, NULL, NULL);
154 ATF_REQUIRE(fp != NULL);
155 setlocale(LC_CTYPE, "ja_JP.eucJP");
156 // WTF? Not even returning what it read?
157 ATF_CHECK_EQ(getwc(fp), 0xcf20);
158 atf_tc_expect_fail("PR lib/47660");
159 ATF_REQUIRE_EQ(getwc(fp), WEOF);
160 fclose(fp);
163 ATF_TP_ADD_TCS(tp)
165 ATF_TP_ADD_TC(tp, bad_big5_wprintf);
166 ATF_TP_ADD_TC(tp, bad_big5_swprintf);
167 ATF_TP_ADD_TC(tp, good_big5_wprintf);
168 ATF_TP_ADD_TC(tp, good_big5_swprintf);
169 ATF_TP_ADD_TC(tp, good_big5_getwc);
170 ATF_TP_ADD_TC(tp, bad_big5_getwc);
171 ATF_TP_ADD_TC(tp, bad_eucJP_getwc);
173 return atf_no_error();