Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / contrib / idn / idnkit-1.0-src / lib / tests / delimitermap.tsy
blob5858b5585c1a7c9c3111a6cc17419e24d7abf773
1 #ifndef lint
2 static char *rcsid = "Id: delimitermap.tsy,v 1.1 2003/06/04 00:26:53 marka Exp ";
3 #endif
5 /*
6  * Copyright (c) 2002 Japan Network Information Center.
7  * All rights reserved.
8  *  
9  * By using this file, you agree to the terms and conditions set forth bellow.
10  * 
11  *                      LICENSE TERMS AND CONDITIONS 
12  * 
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.
17  * 
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.
21  * 
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.
24  * 
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."
30  * 
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
33  *    JPNIC.
34  * 
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.
46  */
48 #include <stddef.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <stdarg.h>
52 #include <idn/delimitermap.h>
53 #include <idn/ucs4.h>
54 #include <idn/log.h>
55 #include "testutil.h"
58  * Codepoions to test the add() function.
59  */
60 #define ADDITIONAL_DELIMITER0   0xe0
61 #define ADDITIONAL_DELIMITER1   0xe1
64  * Sample string for `from' argument of map(),
65  * and its expected outputs.
66  */
67 static const unsigned long from[] = {
68         0x002e, /* full stop */
69         0x3002, /* ideographic full stop */
70         0xff0e, /* fullwidth full stop */
71         0xff61, /* halfwidth ideographic full stop */
72         ADDITIONAL_DELIMITER0,
73         ADDITIONAL_DELIMITER1,
74         0x0000
77 static const unsigned long expected_default[] = {
78         0x002e, /* full stop */
79         0x002e, /* full stop */
80         0x002e, /* full stop */
81         0x002e, /* full stop */
82         ADDITIONAL_DELIMITER0,
83         ADDITIONAL_DELIMITER1,
84         0x0000
87 static const unsigned long expected_add[] = {
88         0x002e, /* full stop */
89         0x002e, /* full stop */
90         0x002e, /* full stop */
91         0x002e, /* full stop */
92         0x002e, /* full stop */
93         ADDITIONAL_DELIMITER1,
94         0x0000
97 static const unsigned long expected_addall[] = {
98         0x002e, /* full stop */
99         0x002e, /* full stop */
100         0x002e, /* full stop */
101         0x002e, /* full stop */
102         0x002e, /* full stop */
103         0x002e, /* full stop */
104         0x0000
107 //--------------------------------------------------------------------
108 // Setups and Teardowns.
109 //--------------------------------------------------------------------
111 //# SETUP
112 //      group: generic-init
114         idn_result_t r;
115         idn_delimitermap_t ctx;
116         unsigned long to[256];
118         r = idn_delimitermap_create(&ctx);
119         ASSERT_RESULT(r, idn_success);
122 //# TEARDOWN
123 //      group: generic-init
125         if (ctx != NULL)
126                 idn_delimitermap_destroy(ctx);
129 //# SETUP
130 //      group: quiet
132         int saved_log_level;
134         saved_log_level = idn_log_getlevel();
135         idn_log_setlevel(idn_log_level_fatal);
138 //# TEARDOWN
139 //      group: quiet
141         idn_log_setlevel(saved_log_level);
144 //--------------------------------------------------------------------
145 // Testcases.
146 //--------------------------------------------------------------------
148 //# TESTCASE
149 //      title: call create()
150 //      group: generic-init
154 //# TESTCASE
155 //      title: call map() without additional delimiters
156 //      group: generic-init
158         r = idn_delimitermap_map(ctx, from, to, sizeof(to) / sizeof(*to));
159         ASSERT_RESULT(r, idn_success);
160         ASSERT_UCS4STRING(to, expected_default);
163 //# TESTCASE
164 //      title: call add() and map()
165 //      group: generic-init
167         r = idn_delimitermap_add(ctx, ADDITIONAL_DELIMITER0);
168         ASSERT_RESULT(r, idn_success);
170         r = idn_delimitermap_map(ctx, from, to, sizeof(to) / sizeof(*to));
171         ASSERT_RESULT(r, idn_success);
172         ASSERT_UCS4STRING(to, expected_add);
175 //# TESTCASE
176 //      title: call addall()
177 //      group: generic-init
179         unsigned long delimiters[2];
181         delimiters[0] = ADDITIONAL_DELIMITER0;
182         delimiters[1] = ADDITIONAL_DELIMITER1;
183         r = idn_delimitermap_addall(ctx, delimiters, 2);
184         ASSERT_RESULT(r, idn_success);
186         r = idn_delimitermap_map(ctx, from, to, sizeof(to) / sizeof(*to));
187         ASSERT_RESULT(r, idn_success);
188         ASSERT_UCS4STRING(to, expected_addall);
191 //# TESTCASE
192 //      title: call addall() with nnames=0
193 //      group: generic-init
195         unsigned long delimiters[2];
197         r = idn_delimitermap_addall(ctx, delimiters, 0);
198         ASSERT_RESULT(r, idn_success);
200         r = idn_delimitermap_map(ctx, from, to, sizeof(to) / sizeof(*to));
201         ASSERT_RESULT(r, idn_success);
202         ASSERT_UCS4STRING(to, expected_default);
205 //# TESTCASE
206 //      title: call add() with invalid codepoint
207 //      group: generic-init quiet
209         r = idn_delimitermap_add(ctx, 0x0000);  /* NUL */
210         ASSERT_RESULT(r, idn_invalid_codepoint);
212         r = idn_delimitermap_add(ctx, 0xd800);  /* surrogate */
213         ASSERT_RESULT(r, idn_invalid_codepoint);
215         r = idn_delimitermap_add(ctx, 0x110000); /* out of range */
216         ASSERT_RESULT(r, idn_invalid_codepoint);
219 //# TESTCASE
220 //      title: call addall() with invalid codepoint
221 //      group: generic-init quiet
223         unsigned long delimiters[1];
225         delimiters[0] = 0x0000;  /* NUL */
226         r = idn_delimitermap_addall(ctx, delimiters, 1);
227         ASSERT_RESULT(r, idn_invalid_codepoint);
229         delimiters[0] = 0xd800;  /* surrogate */
230         r = idn_delimitermap_addall(ctx, delimiters, 1);
231         ASSERT_RESULT(r, idn_invalid_codepoint);
233         delimiters[0] = 0x110000;  /* out of range */
234         r = idn_delimitermap_addall(ctx, delimiters, 1);
235         ASSERT_RESULT(r, idn_invalid_codepoint);
238 //# TESTCASE
239 //      title: overrun test for arg `to' of map()
240 //      group: generic-init
242         r = idn_delimitermap_map(ctx, from, to,
243                                  idn_ucs4_strlen(expected_default) + 1);
244         ASSERT_RESULT(r, idn_success);
245         ASSERT_UCS4STRING(to, expected_default);
246         r = idn_delimitermap_map(ctx, from, to,
247                                  idn_ucs4_strlen(expected_default));
248         ASSERT_RESULT(r, idn_buffer_overflow);
251 //# TESTCASE
252 //      title: call map() with tolen=0
253 //      group: generic-init
255         r = idn_delimitermap_map(ctx, from, to, 0);
256         ASSERT_RESULT(r, idn_buffer_overflow);