2 static char *rcsid = "Id: ucs4.tsy,v 1.1 2003/06/04 00:27:04 marka Exp ";
6 * Copyright (c) 2002 Japan Network Information Center.
9 * By using this file, you agree to the terms and conditions set forth bellow.
11 * LICENSE TERMS AND CONDITIONS
13 * The following License Terms and Conditions apply, unless a different
14 * license is obtained from Japan Network Information Center ("JPNIC"),
15 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
16 * Chiyoda-ku, Tokyo 101-0047, Japan.
18 * 1. Use, Modification and Redistribution (including distribution of any
19 * modified or derived work) in source and/or binary forms is permitted
20 * under this License Terms and Conditions.
22 * 2. Redistribution of source code must retain the copyright notices as they
23 * appear in each source code file, this License Terms and Conditions.
25 * 3. Redistribution in binary form must reproduce the Copyright Notice,
26 * this License Terms and Conditions, in the documentation and/or other
27 * materials provided with the distribution. For the purposes of binary
28 * distribution the "Copyright Notice" refers to the following language:
29 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
31 * 4. The name of JPNIC may not be used to endorse or promote products
32 * derived from this Software without specific prior written approval of
35 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
36 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
44 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
45 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
58 * Sample UTF8 and UCS4 strings.
60 static const char *utf8_string =
61 "\x7f" /* 0x0000007f */
62 "\xdf\xbf" /* 0x000007ff */
63 "\xef\xbf\xbf" /* 0x0000ffff */
64 "\xf7\xbf\xbf\xbf" /* 0x001fffff */
65 "\xfb\xbf\xbf\xbf\xbf" /* 0x03ffffff */
66 "\xfd\xbf\xbf\xbf\xbf\xbf"; /* 0x7fffffff */
68 static const unsigned long ucs4_string[] = {
78 //--------------------------------------------------------------------
79 // Setups and Teardowns.
80 //--------------------------------------------------------------------
85 unsigned long to[256];
103 saved_log_level = idn_log_getlevel();
104 idn_log_setlevel(idn_log_level_fatal);
110 idn_log_setlevel(saved_log_level);
113 //--------------------------------------------------------------------
115 //--------------------------------------------------------------------
118 // title: call utf8toucs4()
121 r = idn_ucs4_utf8toucs4(utf8_string, to, tolen);
122 ASSERT_RESULT(r, idn_success);
123 ASSERT_UCS4STRING(to, ucs4_string);
127 // title: call ucs4toutf8()
130 r = idn_ucs4_ucs4toutf8(ucs4_string, to, tolen);
131 ASSERT_RESULT(r, idn_success);
132 ASSERT_STRING(to, utf8_string);
136 // title: call utf8toucs4() with empty from
139 static unsigned long empty_ucs4_string[] = {0};
141 r = idn_ucs4_utf8toucs4("", to, tolen);
142 ASSERT_RESULT(r, idn_success);
143 ASSERT_UCS4STRING(to, empty_ucs4_string);
147 // title: call ucs4toutf8() with empty from
150 static unsigned long empty_ucs4_string[] = {0};
152 r = idn_ucs4_ucs4toutf8(empty_ucs4_string, to, tolen);
153 ASSERT_RESULT(r, idn_success);
154 ASSERT_STRING(to, "");
158 // title: call utf8toucs4() with broken string
159 // group: utf8-init quiet
161 /* "\xfe" as the 1st byte is out of range. */
162 r = idn_ucs4_utf8toucs4("\xfe\xbf\xbf\xbf\xbf\xbf\xbf", to, tolen);
163 ASSERT_RESULT(r, idn_invalid_encoding);
165 /* "\x7f" as the 2nd byte is out of range. */
166 r = idn_ucs4_utf8toucs4("\xdf\x7f", to, tolen);
167 ASSERT_RESULT(r, idn_invalid_encoding);
169 /* "\xc0" as the 2nd byte is out of range. */
170 r = idn_ucs4_utf8toucs4("\xdf\xc0", to, tolen);
171 ASSERT_RESULT(r, idn_invalid_encoding);
173 /* "\x7f" as the 3rd byte is out of range. */
174 r = idn_ucs4_utf8toucs4("\xef\xbf\x7f", to, tolen);
175 ASSERT_RESULT(r, idn_invalid_encoding);
177 /* "\xc0" as the 3rd byte is out of range. */
178 r = idn_ucs4_utf8toucs4("\xef\xbf\xc0", to, tolen);
179 ASSERT_RESULT(r, idn_invalid_encoding);
181 /* "\x7f" as the 4th byte is out of range. */
182 r = idn_ucs4_utf8toucs4("\xf7\xbf\xbf\x7f", to, tolen);
183 ASSERT_RESULT(r, idn_invalid_encoding);
185 /* "\xc0" as the 4th byte is out of range. */
186 r = idn_ucs4_utf8toucs4("\xf7\xbf\xbf\xc0", to, tolen);
187 ASSERT_RESULT(r, idn_invalid_encoding);
189 /* "\x7f" as the 5th byte is out of range. */
190 r = idn_ucs4_utf8toucs4("\xfb\xbf\xbf\xbf\x7f", to, tolen);
191 ASSERT_RESULT(r, idn_invalid_encoding);
193 /* "\xc0" as the 5th byte is out of range. */
194 r = idn_ucs4_utf8toucs4("\xfb\xbf\xbf\xbf\xc0", to, tolen);
195 ASSERT_RESULT(r, idn_invalid_encoding);
197 /* "\x7f" as the 6th byte is out of range. */
198 r = idn_ucs4_utf8toucs4("\xfd\xbf\xbf\xbf\xbf\x7f", to, tolen);
199 ASSERT_RESULT(r, idn_invalid_encoding);
201 /* "\xc0" as the 6th byte is out of range. */
202 r = idn_ucs4_utf8toucs4("\xfd\xbf\xbf\xbf\xbf\xc0", to, tolen);
203 ASSERT_RESULT(r, idn_invalid_encoding);
205 /* `from' contains surrogate pair */
206 r = idn_ucs4_utf8toucs4("\xed\xa0\x80\xed\xbf\xbf", to, tolen);
207 ASSERT_RESULT(r, idn_invalid_encoding);
211 // title: call ucs4toutf8() with broken string
212 // group: ucs4-init quiet
214 static unsigned long invalid_ucs4_string0[] = {0x80000000, 0};
215 static unsigned long invalid_ucs4_string1[] = {0xd800, 0xdfff, 0};
217 /* 0x80000000 is out of range */
218 r = idn_ucs4_ucs4toutf8(invalid_ucs4_string0, to, tolen);
219 ASSERT_RESULT(r, idn_invalid_encoding);
221 /* `from' contains surrogate pair */
222 r = idn_ucs4_ucs4toutf8(invalid_ucs4_string1, to, tolen);
223 ASSERT_RESULT(r, idn_invalid_encoding);
227 // title: buffer overrun test for utf8toucs4()
230 r = idn_ucs4_utf8toucs4(utf8_string, to,
231 idn_ucs4_strlen(ucs4_string) + 1);
232 ASSERT_RESULT(r, idn_success);
233 ASSERT_UCS4STRING(to, ucs4_string);
235 r = idn_ucs4_utf8toucs4(utf8_string, to,
236 idn_ucs4_strlen(ucs4_string));
237 ASSERT_RESULT(r, idn_buffer_overflow);
239 r = idn_ucs4_utf8toucs4(utf8_string, to, 0);
240 ASSERT_RESULT(r, idn_buffer_overflow);
244 // title: buffer overrun test for ucs4toutf8()
247 r = idn_ucs4_ucs4toutf8(ucs4_string, to, strlen(utf8_string) + 1);
248 ASSERT_RESULT(r, idn_success);
249 ASSERT_STRING(to, utf8_string);
251 r = idn_ucs4_ucs4toutf8(ucs4_string, to, strlen(utf8_string));
252 ASSERT_RESULT(r, idn_buffer_overflow);
254 r = idn_ucs4_ucs4toutf8(ucs4_string, to, 0);
255 ASSERT_RESULT(r, idn_buffer_overflow);