2 static char *rcsid = "Id: nameprep.tsy,v 1.1 2003/06/04 00:26:56 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/nameprep.h>
56 #define UCS4_NAME 0x304C /* hiragana letter ga */
59 * Sample string for `from' argument for map(),
60 * and its expected outputs.
62 static const unsigned long map_from[] = {
63 0x0041, /* latin capital letter a */
64 0x0042, /* latin capital letter b */
69 static const unsigned long map_expected[] = {
70 0x0061, /* latin small letter a */
71 0x0062, /* latin small letter b */
77 * Sample string for `from' argument for isprohibited().
79 static const unsigned long check_from[4] = {
81 0x00A0, /* no-break space: prohibited character */
82 0x0221, /* unassigned character */
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().
93 static const unsigned long check_from2[4] = {
95 0x0221, /* unassigned character */
96 0x00A0, /* no-break space: prohibited character */
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.)
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 */
114 #define BIDIFROM_OFFSET 1
119 static const unsigned long ucs4_nullstr[] = {
123 //--------------------------------------------------------------------
124 // Setups and Teardowns.
125 //--------------------------------------------------------------------
133 idn_nameprep_t handle = NULL;
140 // Initialize the module and create contexts.
143 idn_nameprep_t handle11 = NULL;
145 r = idn_nameprep_create("RFC3491", &handle11);
146 ASSERT_RESULT(r, idn_success);
154 if (handle11 != NULL) {
155 idn_nameprep_destroy(handle11);
162 // Set log level to `fatal' to supress log messages.
166 saved_log_level = idn_log_getlevel();
167 idn_log_setlevel(idn_log_level_fatal);
173 // Restore log level.
175 idn_log_setlevel(saved_log_level);
178 //--------------------------------------------------------------------
180 //--------------------------------------------------------------------
183 // title: idn_nameprep_create() - boundary condition
184 // group: generic quiet
186 r = idn_nameprep_create("", &handle);
187 ASSERT_RESULT(r, idn_notfound);
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);
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);
228 // title: idn_nameprep_create() - RFC3491
231 r = idn_nameprep_create("RFC3491", &handle);
232 ASSERT_RESULT(r, idn_success);
233 idn_nameprep_destroy(handle);
237 // title: idn_nameprep_map() - boundary condition
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);
250 // title: idn_nameprep_map() - RFC3491
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);
265 // title: idn_nameprep_isunassigned() - boundary condition
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);
276 // title: idn_nameprep_isunassigned() - RFC3491
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);
291 // title: idn_nameprep_isprohibited() - boundary condition
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);
302 // title: idn_nameprep_isprohibited() - RFC3491
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);
317 // title: idn_nameprep_isvalidbidi() - boundary condition
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);
328 // title: idn_nameprep_isvalidbidi() - RFC3491
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);