Remove building with NOCRYPTO option
[minix3.git] / tests / lib / libc / locale / t_io.c
blob782bed8f9e8af04ac809cd3f157b90cee1ac7eb9
1 /* $NetBSD: t_io.c,v 1.4 2014/01/21 00:32:16 yamt 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.4 2014/01/21 00:32:16 yamt 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 /* XXX implementation detail knowledge (wchar_t encoding) */
57 wchar_t ibuf[] = { 0xcf10, 0 };
58 setlocale(LC_CTYPE, "zh_TW.Big5");
59 ATF_REQUIRE_ERRNO(EILSEQ, wprintf(L"%ls\n", ibuf) < 0);
60 ATF_REQUIRE(ferror(stdout));
63 ATF_TC(bad_big5_swprintf);
64 ATF_TC_HEAD(bad_big5_swprintf, tc)
66 atf_tc_set_md_var(tc, "descr", "Test bad big5 wchar swprintf");
69 ATF_TC_BODY(bad_big5_swprintf, tc)
71 /* XXX implementation detail knowledge (wchar_t encoding) */
72 wchar_t ibuf[] = { 0xcf10, 0 };
73 wchar_t obuf[20];
74 setlocale(LC_CTYPE, "zh_TW.Big5");
75 ATF_REQUIRE_ERRNO(EILSEQ,
76 swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf) < 0);
79 ATF_TC(good_big5_wprintf);
80 ATF_TC_HEAD(good_big5_wprintf, tc)
82 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar wprintf");
85 ATF_TC_BODY(good_big5_wprintf, tc)
87 /* XXX implementation detail knowledge (wchar_t encoding) */
88 wchar_t ibuf[] = { 0xcf40, 0 };
89 setlocale(LC_CTYPE, "zh_TW.Big5");
90 ATF_REQUIRE_EQ(wprintf(L"%ls\n", ibuf), 2);
93 ATF_TC(good_big5_swprintf);
94 ATF_TC_HEAD(good_big5_swprintf, tc)
96 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar swprintf");
99 ATF_TC_BODY(good_big5_swprintf, tc)
101 /* XXX implementation detail knowledge (wchar_t encoding) */
102 wchar_t ibuf[] = { 0xcf40, 0 };
103 wchar_t obuf[20];
104 setlocale(LC_CTYPE, "zh_TW.Big5");
105 ATF_REQUIRE_EQ(swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf), 2);
108 struct ibuf {
109 off_t off;
110 size_t buflen;
111 const char *buf;
114 static int
115 readfn(void *vp, char *buf, int len)
117 struct ibuf *ib = vp;
118 size_t todo = MIN((size_t)len, ib->buflen - ib->off);
120 memcpy(buf, ib->buf + ib->off, todo);
121 ib->off += todo;
122 return todo;
125 ATF_TC(good_big5_getwc);
126 ATF_TC_HEAD(good_big5_getwc, tc)
128 atf_tc_set_md_var(tc, "descr", "Test good big5 wchar getwc");
131 ATF_TC_BODY(good_big5_getwc, tc)
133 const char buf[] = { 0xcf, 0x40 };
134 struct ibuf ib = {
135 .buf = buf,
136 .buflen = sizeof(buf),
138 FILE *fp = funopen(&ib, readfn, NULL, NULL, NULL);
140 ATF_REQUIRE(fp != NULL);
141 setlocale(LC_CTYPE, "zh_TW.Big5");
142 /* XXX implementation detail knowledge (wchar_t encoding) */
143 ATF_REQUIRE_EQ(getwc(fp), 0xcf40);
144 fclose(fp);
147 ATF_TC(bad_big5_getwc);
148 ATF_TC_HEAD(bad_big5_getwc, tc)
150 atf_tc_set_md_var(tc, "descr", "Test bad big5 wchar getwc");
153 ATF_TC_BODY(bad_big5_getwc, tc)
155 const char buf[] = { 0xcf, 0x20 };
156 struct ibuf ib = {
157 .buf = buf,
158 .buflen = sizeof(buf),
160 FILE *fp = funopen(&ib, readfn, NULL, NULL, NULL);
162 ATF_REQUIRE(fp != NULL);
163 setlocale(LC_CTYPE, "zh_TW.Big5");
164 ATF_REQUIRE_EQ(getwc(fp), WEOF);
165 fclose(fp);
168 ATF_TP_ADD_TCS(tp)
170 ATF_TP_ADD_TC(tp, bad_big5_wprintf);
171 ATF_TP_ADD_TC(tp, bad_big5_swprintf);
172 ATF_TP_ADD_TC(tp, good_big5_wprintf);
173 ATF_TP_ADD_TC(tp, good_big5_swprintf);
174 ATF_TP_ADD_TC(tp, good_big5_getwc);
175 ATF_TP_ADD_TC(tp, bad_big5_getwc);
177 return atf_no_error();