1 /* $NetBSD: t_io.c,v 1.2 2013/03/17 05:02:13 jmmv Exp $ */
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
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 };
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 };
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));
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);
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
);
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
);
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();