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 Andrewsstatic void run_internal(idn_testsuite_t ctx, char *titles[]);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic char *make_hex_string(const char *string);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic char *make_hex_ucs4string(const unsigned long *string);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic void put_failure_message(idn_testsuite_t ctx, const char *msg,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic void idn_testsuite_msgtostderr(const char *msg);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ctx = (idn_testsuite_t) malloc(sizeof(struct idn_testsuite));
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews ctx->testcases = (idn_testcase_t) malloc(sizeof(struct idn_testcase)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_addtestcase(idn_testsuite_t ctx, const char *title,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews assert(ctx != NULL && title != NULL && proc != NULL);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews new_size = ctx->testcase_size + INITIAL_TESTCASE_SIZE;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews new_testcase = ctx->testcases + ctx->ntestcases;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_unsetverbose(idn_testsuite_t ctx) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsrun_internal(idn_testsuite_t ctx, char *titles[]) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews fprintf(stderr, "start testcase %d: %s\n", i + 1,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews status = idn_teststatus_tostring(ctx->current_status);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews fprintf(stderr, "end testcase %d: %s\n", i + 1,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_run(idn_testsuite_t ctx, char *titles[]) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_setstatus(idn_testsuite_t ctx, idn_teststatus_t status) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_teststatus_tostring(idn_teststatus_t status) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews return "pass";
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews return "failed";
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews return "skipped";
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews return "unknown";
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_assert(idn_testsuite_t ctx, const char *msg,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews assert(ctx != NULL && msg != NULL && file != NULL);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_assertint(idn_testsuite_t ctx, int gotten, int expected,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews sprintf(msg, "`%d' expected, but got `%d'", expected, gotten);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews assert(ctx != NULL && gotten != NULL && expected != NULL &&
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews msg = (char *)malloc(strlen(expected) * 4 + strlen(gotten) * 4 + 32);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (msg == NULL || expected_hex == NULL || gotten_hex == NULL) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_assertptr(idn_testsuite_t ctx, const void *gotten,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const void *expected, const char *file, int lineno) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_result_tostring(expected), idn_result_tostring(gotten));
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsidn_testsuite_assertucs4string(idn_testsuite_t ctx,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *gotten,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const unsigned long *expected,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews assert(ctx != NULL && gotten != NULL && expected != NULL &&
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (idn_testsuite_getstatus(ctx) != idn_teststatus_pass)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews idn_testsuite_setstatus(ctx, idn_teststatus_fail);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews msg = (char *)malloc(idn_ucs4_strlen(expected) * 8 +
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (msg == NULL || expected_hex == NULL || gotten_hex == NULL) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic char *
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews static const char hex[] = {"0123456789abcdef"};
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews hex_string = (char *)malloc((strlen(string)) * 4 + 1);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews for (src = string, dst = hex_string; *src != '\0'; src++) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (0x20 <= *src && *src <= 0x7e && *src != '\\') {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews *dst++ = hex[*(const unsigned char *)src >> 4];
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic char *
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsmake_hex_ucs4string(const unsigned long *string) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews static const char hex[] = {"0123456789abcdef"};
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews hex_string = (char *)malloc((idn_ucs4_strlen(string)) * 8 + 1);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews for (src = string, dst = hex_string; *src != '\0'; src++) {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews if (0x20 <= *src && *src <= 0x7e && *src != '\\') {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsput_failure_message(idn_testsuite_t ctx, const char *msg, const char *file,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews sprintf(buffer, "%.100s: In test `%.100s':", file, title);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews sprintf(buffer, "%.100s:%d: failed (%.100s)", file, lineno, msg);