etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / contrib / idn / idnkit-1.0-src / lib / tests / nameprep.tsy
blob5e9391f00f168afa0e3e8430242debda9405fc63
1 #ifndef lint
2 static char *rcsid = "Id: nameprep.tsy,v 1.1 2003/06/04 00:26:56 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 <string.h>
52 #include <idn/nameprep.h>
53 #include <idn/log.h>
54 #include "testutil.h"
56 #define UCS4_NAME       0x304C  /* hiragana letter ga */
57 #define BUF_SIZE        4
59  * Sample string for `from' argument for map(),
60  * and its expected outputs.
61  */
62 static const unsigned long map_from[] = {
63         0x0041,         /* latin capital letter a */
64         0x0042,         /* latin capital letter b */
65         UCS4_NAME,
66         0x0000
69 static const unsigned long map_expected[] = {
70         0x0061,         /* latin small letter a */
71         0x0062,         /* latin small letter b */
72         UCS4_NAME,
73         0x0000
77  * Sample string for `from' argument for isprohibited().
78  */
79 static const unsigned long check_from[4] = {
80         UCS4_NAME,
81         0x00A0, /* no-break space: prohibited character */
82         0x0221, /* unassigned character */
83         0x0000
86 #define FROM_UCS4NAME_OFFSET    0
87 #define FROM_PROH_OFFSET        1
88 #define FROM_UNAS_OFFSET        2
91  * Sample string for `from' argument for isunassigned().
92  */
93 static const unsigned long check_from2[4] = {
94         UCS4_NAME,
95         0x0221, /* unassigned character */
96         0x00A0, /* no-break space: prohibited character */
97         0x0000
100 #define FROM2_UCS4NAME_OFFSET   0
101 #define FROM2_PROH_OFFSET       2
102 #define FROM2_UNAS_OFFSET       1
105  * Sample string for `from' argument for isvalidbidi().
106  * (It is not a valid bidi label.)
107  */
108 static const unsigned long bidi_from[4] = {
109         0x05BE, /* hebrew punctuation maqaf */
110         0x0041, /* latin capital letter a */
111         0xFEFC, /* arabic ligature lam with alef final form */
112         0x0000
114 #define BIDIFROM_OFFSET         1
117  * Empty string.
118  */
119 static const unsigned long ucs4_nullstr[] = {
120         0x0000
123 //--------------------------------------------------------------------
124 // Setups and Teardowns.
125 //--------------------------------------------------------------------
127 //# SETUP
128 //      group: generic
129 //--
130 //      Nothing happens.
132         idn_result_t r;
133         idn_nameprep_t handle = NULL;
137 //# SETUP
138 //      group: check
139 //--
140 //      Initialize the module and create contexts.
142         idn_result_t r;
143         idn_nameprep_t handle11 = NULL;
145         r = idn_nameprep_create("RFC3491", &handle11);
146         ASSERT_RESULT(r, idn_success);
149 //# TEARDOWN
150 //      group: check
151 //--
152 //      Destroy contexts.
154         if (handle11 != NULL) {
155                 idn_nameprep_destroy(handle11);
156         }
159 //# SETUP
160 //      group: quiet
161 //--
162 //      Set log level to `fatal' to supress log messages.
164         int saved_log_level;
166         saved_log_level = idn_log_getlevel();
167         idn_log_setlevel(idn_log_level_fatal);
170 //# TEARDOWN
171 //      group: quiet
172 //--
173 //      Restore log level.
175         idn_log_setlevel(saved_log_level);
178 //--------------------------------------------------------------------
179 // Testcases.
180 //--------------------------------------------------------------------
182 //# TESTCASE
183 //      title: idn_nameprep_create() - boundary condition
184 //      group: generic quiet
186         r = idn_nameprep_create("", &handle);
187         ASSERT_RESULT(r, idn_notfound);
190 //# TESTCASE
191 //      title: idn_nameprep_create() - version is NULL (current nameprep)
192 //      group: generic quiet
194         unsigned long to[BUF_SIZE];
195         const unsigned long *found;
197         r = idn_nameprep_create(NULL, &handle);
198         ASSERT_RESULT(r, idn_success);
200         r = idn_nameprep_map(handle, map_from, to, BUF_SIZE);
201         ASSERT_RESULT(r, idn_success);
202         ASSERT_UCS4STRING(to, map_expected);
204         r = idn_nameprep_isunassigned(handle, check_from, &found);
205         ASSERT_RESULT(r, idn_success);
206         ASSERT_PTR(found, check_from + FROM_UNAS_OFFSET);
208         r = idn_nameprep_isprohibited(handle, check_from, &found);
209         ASSERT_RESULT(r, idn_success);
210         ASSERT_PTR(found, check_from + FROM_PROH_OFFSET);
212         r = idn_nameprep_isvalidbidi(handle, bidi_from, &found);
213         ASSERT_RESULT(r, idn_success);
214         ASSERT_PTR(found, bidi_from + BIDIFROM_OFFSET);
216         idn_nameprep_destroy(handle);
219 //# TESTCASE
220 //      title: idn_nameprep_create() - nameprep-01
221 //      group: generic quiet
223         r = idn_nameprep_create("nameprep-01", &handle);
224         ASSERT_RESULT(r, idn_notfound);
227 //# TESTCASE
228 //      title: idn_nameprep_create() - RFC3491
229 //      group: generic
231         r = idn_nameprep_create("RFC3491", &handle);
232         ASSERT_RESULT(r, idn_success);
233         idn_nameprep_destroy(handle);
236 //# TESTCASE
237 //      title: idn_nameprep_map() - boundary condition
238 //      group: check
240         unsigned long to[BUF_SIZE];
242         r = idn_nameprep_map(handle11, ucs4_nullstr, to, 0);
243         ASSERT_RESULT(r, idn_buffer_overflow);
244         r = idn_nameprep_map(handle11, ucs4_nullstr, to, 1);
245         ASSERT_RESULT(r, idn_success);
246         ASSERT_UCS4STRING(to, ucs4_nullstr);
249 //# TESTCASE
250 //      title: idn_nameprep_map() - RFC3491
251 //      group: check
253         unsigned long to[BUF_SIZE];
255         r = idn_nameprep_map(handle11, map_from, to, 0);
256         ASSERT_RESULT(r, idn_buffer_overflow);
257         r = idn_nameprep_map(handle11, map_from, to, BUF_SIZE - 1);
258         ASSERT_RESULT(r, idn_buffer_overflow);
259         r = idn_nameprep_map(handle11, map_from, to, BUF_SIZE);
260         ASSERT_RESULT(r, idn_success);
261         ASSERT_UCS4STRING(to, map_expected);
264 //# TESTCASE
265 //      title: idn_nameprep_isunassigned() - boundary condition
266 //      group: check
268         const unsigned long *found;
270         r = idn_nameprep_isunassigned(handle11, ucs4_nullstr, &found);
271         ASSERT_RESULT(r, idn_success);
272         ASSERT_PTR(found, NULL);
275 //# TESTCASE
276 //      title: idn_nameprep_isunassigned() - RFC3491
277 //      group: check
279         const unsigned long *found;
281         r = idn_nameprep_isunassigned(handle11, check_from, &found);
282         ASSERT_RESULT(r, idn_success);
283         ASSERT_PTR(found, check_from + FROM_UNAS_OFFSET);
285         r = idn_nameprep_isunassigned(handle11, check_from2, &found);
286         ASSERT_RESULT(r, idn_success);
287         ASSERT_PTR(found, check_from2 + FROM2_UNAS_OFFSET);
290 //# TESTCASE
291 //      title: idn_nameprep_isprohibited() - boundary condition
292 //      group: check
294         const unsigned long *found;
296         r = idn_nameprep_isprohibited(handle11, ucs4_nullstr, &found);
297         ASSERT_RESULT(r, idn_success);
298         ASSERT_PTR(found, NULL);
301 //# TESTCASE
302 //      title: idn_nameprep_isprohibited() - RFC3491
303 //      group: check
305         const unsigned long *found;
307         r = idn_nameprep_isprohibited(handle11, check_from, &found);
308         ASSERT_RESULT(r, idn_success);
309         ASSERT_PTR(found, check_from + FROM_PROH_OFFSET);
311         r = idn_nameprep_isprohibited(handle11, check_from2, &found);
312         ASSERT_RESULT(r, idn_success);
313         ASSERT_PTR(found, check_from2 + FROM2_PROH_OFFSET);
316 //# TESTCASE
317 //      title: idn_nameprep_isvalidbidi() - boundary condition
318 //      group: check
320         const unsigned long *found;
322         r = idn_nameprep_isvalidbidi(handle11, ucs4_nullstr, &found);
323         ASSERT_RESULT(r, idn_success);
324         ASSERT_PTR(found, NULL);
327 //# TESTCASE
328 //      title: idn_nameprep_isvalidbidi() - RFC3491
329 //      group: check
331         const unsigned long *found;
333         r = idn_nameprep_isvalidbidi(handle11, bidi_from, &found);
334         ASSERT_RESULT(r, idn_success);
335         ASSERT_PTR(found, bidi_from + BIDIFROM_OFFSET);
337         r = idn_nameprep_isvalidbidi(handle11, check_from2, &found);
338         ASSERT_RESULT(r, idn_success);
339         ASSERT_PTR(found, NULL);