2 static char *rcsid = "Id: normalizer.tsy,v 1.1 2003/06/04 00:26:57 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.
52 #include <idn/normalizer.h>
59 #define CONF_FILENAME "test.map"
62 * Sample string for `from' argument of normalize(),
63 * and its expected outputs.
65 static const unsigned long from[4] = {
66 0x304B, /* hiragana letter ka */
67 0x3099, /* combining katakana-hiragana voiced sound mark */
68 0x32D0, /* circled katakana a */
72 static const unsigned long normalized_kc_str[3] = {
73 0x304C, /* hiragana letter ga */
74 0x30A2, /* katakana letter a */
78 static const unsigned long normalized_c_str[3] = {
79 0x304C, /* hiragana letter ga */
80 0x32D0, /* circled katakana a */
85 test_proc(const unsigned long *from, unsigned long *to, size_t tolen)
87 if (tolen > idn_ucs4_strlen(from)) {
88 idn_ucs4_strcpy(to, from);
90 return (idn_buffer_overflow);
96 //--------------------------------------------------------------------
97 // Setups and Teardowns.
98 //--------------------------------------------------------------------
112 // Initialize the module and create context.
115 idn_normalizer_t ctx = NULL;
117 r = idn_normalizer_initialize();
118 ASSERT_RESULT(r, idn_success);
119 r = idn_normalizer_create(&ctx);
120 ASSERT_RESULT(r, idn_success);
128 idn_normalizer_destroy(ctx);
134 // Initialize the module and create context.
137 idn_normalizer_t ctx = NULL;
138 char *names[ARRAY_SIZE];
141 for (i = 0; i < ARRAY_SIZE; i++) {
142 names[i] = malloc(BUF_SIZE);
143 if (names[i] == NULL) {
144 ASSERT("malloc failed\n");
148 strcpy(names[0], "RFC3491");
149 strcpy(names[1], "unicode-form-kc");
150 strcpy(names[2], "unicode-form-kc/3.2.0");
151 strcpy(names[3], "RFC3491");
152 strcpy(names[4], "unicode-form-kc");
153 strcpy(names[5], "unicode-form-kc/3.2.0");
154 strcpy(names[6], "RFC3491");
155 strcpy(names[7], "unicode-form-kc");
156 strcpy(names[8], "unicode-form-kc/3.2.0");
157 strcpy(names[9], "RFC3491");
158 strcpy(names[10], "unicode-form-kc");
159 strcpy(names[11], "unicode-form-kc/3.2.0");
160 strcpy(names[12], "RFC3491");
161 strcpy(names[13], "unicode-form-kc");
162 strcpy(names[14], "unicode-form-kc/3.2.0");
163 strcpy(names[15], "RFC3491");
164 strcpy(names[16], "unicode-form-kc");
165 strcpy(names[17], "unicode-form-kc/3.2.0");
166 strcpy(names[18], "RFC3491");
167 strcpy(names[19], "unicode-form-kc");
169 r = idn_normalizer_initialize();
170 ASSERT_RESULT(r, idn_success);
171 r = idn_normalizer_create(&ctx);
172 ASSERT_RESULT(r, idn_success);
180 idn_normalizer_destroy(ctx);
181 for (i = 0; i < ARRAY_SIZE; i++) {
189 // Set log level to `fatal' to supress log messages.
193 saved_log_level = idn_log_getlevel();
194 idn_log_setlevel(idn_log_level_fatal);
200 // Restore log level.
202 idn_log_setlevel(saved_log_level);
205 //--------------------------------------------------------------------
207 //--------------------------------------------------------------------
210 // title: idn_normalizer_add() - boundary condition
211 // group: generic quiet
213 r = idn_normalizer_add(ctx, "");
214 ASSERT_RESULT(r, idn_invalid_name);
218 // title: idn_normalizer_add() - builtin schemes
219 // group: generic quiet
221 r = idn_normalizer_add(ctx, "RFC3491");
222 ASSERT_RESULT(r, idn_success);
223 r = idn_normalizer_add(ctx, "unicode-form-kc");
224 ASSERT_RESULT(r, idn_success);
225 r = idn_normalizer_add(ctx, "unicode-form-kc/3.2.0");
226 ASSERT_RESULT(r, idn_success);
228 r = idn_normalizer_add(ctx, "nameprep-01");
229 ASSERT_RESULT(r, idn_invalid_name);
233 // title: idn_normalizer_addall() - boundary condition
234 // group: addall quiet
236 strcpy(names[3], "");
237 r = idn_normalizer_addall(ctx, (const char **)names, ARRAY_SIZE);
238 ASSERT_RESULT(r, idn_invalid_name);
242 // title: idn_normalizer_addall() - nschemes is 0
243 // group: addall quiet
245 r = idn_normalizer_addall(ctx, (const char **)names, 0);
246 ASSERT_RESULT(r, idn_success);
250 // title: idn_normalizer_addall() - add a lot of schemes
251 // group: addall quiet
253 unsigned long to[TOBUF_SIZE];
255 r = idn_normalizer_addall(ctx, (const char **)names, ARRAY_SIZE);
256 ASSERT_RESULT(r, idn_success);
257 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
258 ASSERT_RESULT(r, idn_success);
259 ASSERT_UCS4STRING(to, normalized_kc_str);
263 // title: idn_normalizer_addall() - add same scheme repetedly
264 // group: addall quiet
267 unsigned long to[TOBUF_SIZE];
269 for (i = 0; i < ARRAY_SIZE; i++) {
270 strcpy(names[i], "RFC3491");
272 r = idn_normalizer_addall(ctx, (const char **)names, ARRAY_SIZE);
273 ASSERT_RESULT(r, idn_success);
274 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
275 ASSERT_RESULT(r, idn_success);
276 ASSERT_UCS4STRING(to, normalized_kc_str);
280 // title: idn_normalizer_normalize() - schemes check - RFC3491
281 // group: generic quiet
283 unsigned long to[TOBUF_SIZE];
285 r = idn_normalizer_add(ctx, "RFC3491");
286 ASSERT_RESULT(r, idn_success);
287 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
288 ASSERT_RESULT(r, idn_success);
289 ASSERT_UCS4STRING(to, normalized_kc_str);
293 // title: idn_normalizer_normalize() - schemes check - unicode-form-kc/3.2.0
294 // group: generic quiet
296 unsigned long to[TOBUF_SIZE];
298 r = idn_normalizer_add(ctx, "unicode-form-kc/3.2.0");
299 ASSERT_RESULT(r, idn_success);
300 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
301 ASSERT_RESULT(r, idn_success);
302 ASSERT_UCS4STRING(to, normalized_kc_str);
306 // title: idn_normalizer_normalize() - context without procedure
307 // group: generic quiet
309 unsigned long to[TOBUF_SIZE];
311 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
312 ASSERT_RESULT(r, idn_success);
313 ASSERT_UCS4STRING(to, from);
317 // title: idn_normalizer_destroy(), idn_normalizer_incrref()
321 idn_normalizer_t ctx = NULL;
323 r = idn_normalizer_initialize();
324 ASSERT_RESULT(r, idn_success);
325 r = idn_normalizer_create(&ctx);
326 ASSERT_RESULT(r, idn_success);
327 idn_normalizer_incrref(ctx);
328 idn_normalizer_destroy(ctx);
329 idn_normalizer_destroy(ctx);
333 // title: idn_normalizer_register()
334 // group: generic quiet
336 unsigned long to[TOBUF_SIZE];
338 r = idn_normalizer_register("test", test_proc);
339 ASSERT_RESULT(r, idn_success);
340 r = idn_normalizer_add(ctx, "test");
341 ASSERT_RESULT(r, idn_success);
343 r = idn_normalizer_normalize(ctx, from, to, TOBUF_SIZE);
344 ASSERT_RESULT(r, idn_success);
345 ASSERT_UCS4STRING(to, from);