nameprep.tsy revision 5c526acb82c882e41b655c31f5fa4425c87b671c
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic char *rcsid = "$Id: nameprep.tsy,v 1.1 2003/06/04 00:26:56 marka Exp $";
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Copyright (c) 2002 Japan Network Information Center.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * All rights reserved.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * By using this file, you agree to the terms and conditions set forth bellow.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * LICENSE TERMS AND CONDITIONS
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * The following License Terms and Conditions apply, unless a different
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * license is obtained from Japan Network Information Center ("JPNIC"),
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Chiyoda-ku, Tokyo 101-0047, Japan.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 1. Use, Modification and Redistribution (including distribution of any
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * modified or derived work) in source and/or binary forms is permitted
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * under this License Terms and Conditions.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 2. Redistribution of source code must retain the copyright notices as they
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * appear in each source code file, this License Terms and Conditions.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 3. Redistribution in binary form must reproduce the Copyright Notice,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * this License Terms and Conditions, in the documentation and/or other
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * materials provided with the distribution. For the purposes of binary
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * distribution the "Copyright Notice" refers to the following language:
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 4. The name of JPNIC may not be used to endorse or promote products
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * derived from this Software without specific prior written approval of
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define UCS4_NAME 0x304C /* hiragana letter ga */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define BUF_SIZE 4
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Sample string for `from' argument for map(),
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * and its expected outputs.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long map_from[] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0041, /* latin capital letter a */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0042, /* latin capital letter b */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long map_expected[] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0061, /* latin small letter a */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0062, /* latin small letter b */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Sample string for `from' argument for isprohibited().
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long check_from[4] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x00A0, /* no-break space: prohibited character */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0221, /* unassigned character */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM_UCS4NAME_OFFSET 0
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM_PROH_OFFSET 1
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM_UNAS_OFFSET 2
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Sample string for `from' argument for isunassigned().
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long check_from2[4] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0221, /* unassigned character */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x00A0, /* no-break space: prohibited character */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM2_UCS4NAME_OFFSET 0
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM2_PROH_OFFSET 2
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define FROM2_UNAS_OFFSET 1
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Sample string for `from' argument for isvalidbidi().
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * (It is not a valid bidi label.)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long bidi_from[4] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x05BE, /* hebrew punctuation maqaf */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0x0041, /* latin capital letter a */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews 0xFEFC, /* arabic ligature lam with alef final form */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define BIDIFROM_OFFSET 1
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Empty string.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic const unsigned long ucs4_nullstr[] = {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//--------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Setups and Teardowns.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//--------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: generic
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Nothing happens.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_result_t r;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_nameprep_t handle = NULL;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Initialize the module and create contexts.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_result_t r;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_nameprep_t handle11 = NULL;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_create("RFC3491", &handle11);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Destroy contexts.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (handle11 != NULL) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_nameprep_destroy(handle11);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: quiet
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Set log level to `fatal' to supress log messages.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews int saved_log_level;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews saved_log_level = idn_log_getlevel();
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_log_setlevel(idn_log_level_fatal);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: quiet
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Restore log level.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_log_setlevel(saved_log_level);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//--------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Testcases.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//--------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_create() - boundary condition
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: generic quiet
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_create("", &handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_notfound);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_create() - version is NULL (current nameprep)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: generic quiet
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews unsigned long to[BUF_SIZE];
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_create(NULL, &handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle, map_from, to, BUF_SIZE);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_UCS4STRING(to, map_expected);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isunassigned(handle, check_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from + FROM_UNAS_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isprohibited(handle, check_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from + FROM_PROH_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isvalidbidi(handle, bidi_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, bidi_from + BIDIFROM_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_nameprep_destroy(handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_create() - nameprep-01
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: generic quiet
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_create("nameprep-01", &handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_notfound);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_create() - RFC3491
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: generic
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_create("RFC3491", &handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_nameprep_destroy(handle);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_map() - boundary condition
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews unsigned long to[BUF_SIZE];
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle11, ucs4_nullstr, to, 0);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_buffer_overflow);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle11, ucs4_nullstr, to, 1);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_UCS4STRING(to, ucs4_nullstr);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_map() - RFC3491
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews unsigned long to[BUF_SIZE];
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle11, map_from, to, 0);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_buffer_overflow);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle11, map_from, to, BUF_SIZE - 1);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_buffer_overflow);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_map(handle11, map_from, to, BUF_SIZE);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_UCS4STRING(to, map_expected);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isunassigned() - boundary condition
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isunassigned(handle11, ucs4_nullstr, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, NULL);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isunassigned() - RFC3491
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isunassigned(handle11, check_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from + FROM_UNAS_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isunassigned(handle11, check_from2, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from2 + FROM2_UNAS_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isprohibited() - boundary condition
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isprohibited(handle11, ucs4_nullstr, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, NULL);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isprohibited() - RFC3491
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isprohibited(handle11, check_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from + FROM_PROH_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isprohibited(handle11, check_from2, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, check_from2 + FROM2_PROH_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isvalidbidi() - boundary condition
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isvalidbidi(handle11, ucs4_nullstr, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, NULL);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// title: idn_nameprep_isvalidbidi() - RFC3491
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// group: check
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *found;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isvalidbidi(handle11, bidi_from, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, bidi_from + BIDIFROM_OFFSET);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews r = idn_nameprep_isvalidbidi(handle11, check_from2, &found);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_RESULT(r, idn_success);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ASSERT_PTR(found, NULL);