X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Funiname%2Ftest-uninames.c;h=21163513b4239d0458ec50fbd87ba8c286a92f65;hb=fe9ecba865a2015187a862f25ada175a5d3d8aa8;hp=492e786db7a469e9f54208f55ef7b1433f9f97e7;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/tests/uniname/test-uninames.c b/tests/uniname/test-uninames.c index 492e786db..21163513b 100644 --- a/tests/uniname/test-uninames.c +++ b/tests/uniname/test-uninames.c @@ -1,5 +1,6 @@ /* Test the Unicode character name functions. - Copyright (C) 2000-2003, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2005, 2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,6 +23,7 @@ #include "xalloc.h" #include "uniname.h" +#include "progname.h" /* The names according to the UnicodeData.txt file, modified to contain the Hangul syllable names, as described in the Unicode 3.0 book. */ @@ -43,10 +45,10 @@ getfield (FILE *stream, char *buffer, int delim) { /* Put c into the buffer. */ if (++count >= FIELDLEN - 1) - { - fprintf (stderr, "field too long\n"); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "field too long\n"); + exit (EXIT_FAILURE); + } *buffer++ = c; } @@ -87,21 +89,21 @@ fill_names (const char *unicodedata_filename) n = getfield (stream, field0, ';'); n += getfield (stream, field1, ';'); if (n == 0) - break; + break; if (n != 2) - { - fprintf (stderr, "short line in '%s':%d\n", - unicodedata_filename, lineno); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "short line in '%s':%d\n", + unicodedata_filename, lineno); + exit (EXIT_FAILURE); + } for (; (c = getc (stream)), (c != EOF && c != '\n'); ) - ; + ; i = strtoul (field0, NULL, 16); if (i >= 0x110000) - { - fprintf (stderr, "index too large\n"); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "index too large\n"); + exit (EXIT_FAILURE); + } unicode_names[i] = xstrdup (field1); } if (ferror (stream) || fclose (stream)) @@ -124,28 +126,28 @@ test_name_lookup () char *result = unicode_character_name (i, buf); if (unicode_names[i] != NULL) - { - if (result == NULL) - { - fprintf (stderr, "\\u%04X name lookup failed!\n", i); - error = 1; - } - else if (strcmp (result, unicode_names[i]) != 0) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } - } + { + if (result == NULL) + { + fprintf (stderr, "\\u%04X name lookup failed!\n", i); + error = 1; + } + else if (strcmp (result, unicode_names[i]) != 0) + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } + } else - { - if (result != NULL) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } - } + { + if (result != NULL) + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } + } } for (i = 0x110000; i < 0x1000000; i++) @@ -153,11 +155,11 @@ test_name_lookup () char *result = unicode_character_name (i, buf); if (result != NULL) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } } return error; @@ -174,18 +176,18 @@ test_inverse_lookup () for (i = 0; i < 0x110000; i++) if (unicode_names[i] != NULL) { - unsigned int result = unicode_name_character (unicode_names[i]); - if (result != i) - { - if (result == UNINAME_INVALID) - fprintf (stderr, "inverse name lookup of \"%s\" failed\n", - unicode_names[i]); - else - fprintf (stderr, - "inverse name lookup of \"%s\" returned 0x%04X\n", - unicode_names[i], result); - error = 1; - } + unsigned int result = unicode_name_character (unicode_names[i]); + if (result != i) + { + if (result == UNINAME_INVALID) + fprintf (stderr, "inverse name lookup of \"%s\" failed\n", + unicode_names[i]); + else + fprintf (stderr, + "inverse name lookup of \"%s\" returned 0x%04X\n", + unicode_names[i], result); + error = 1; + } } /* Second, generate random but likely names and verify they are not @@ -200,13 +202,13 @@ test_inverse_lookup () unsigned int result; do i1 = ((rand () % 0x11) << 16) - + ((rand () & 0xff) << 8) - + (rand () & 0xff); + + ((rand () & 0xff) << 8) + + (rand () & 0xff); while (unicode_names[i1] == NULL); do i2 = ((rand () % 0x11) << 16) - + ((rand () & 0xff) << 8) - + (rand () & 0xff); + + ((rand () & 0xff) << 8) + + (rand () & 0xff); while (unicode_names[i2] == NULL); s1 = unicode_names[i1]; @@ -216,25 +218,25 @@ test_inverse_lookup () /* Concatenate a starting piece of s1 with an ending piece of s2. */ for (j1 = 1; j1 <= l1; j1++) - if (j1 == l1 || s1[j1] == ' ') - for (j2 = 0; j2 < l2; j2++) - if (j2 == 0 || s2[j2-1] == ' ') - { - memcpy (buf, s1, j1); - buf[j1] = ' '; - memcpy (buf + j1 + 1, s2 + j2, l2 - j2 + 1); - - result = unicode_name_character (buf); - if (result != UNINAME_INVALID - && !(unicode_names[result] != NULL - && strcmp (unicode_names[result], buf) == 0)) - { - fprintf (stderr, - "inverse name lookup of \"%s\" returned 0x%04X\n", - unicode_names[i], result); - error = 1; - } - } + if (j1 == l1 || s1[j1] == ' ') + for (j2 = 0; j2 < l2; j2++) + if (j2 == 0 || s2[j2-1] == ' ') + { + memcpy (buf, s1, j1); + buf[j1] = ' '; + memcpy (buf + j1 + 1, s2 + j2, l2 - j2 + 1); + + result = unicode_name_character (buf); + if (result != UNINAME_INVALID + && !(unicode_names[result] != NULL + && strcmp (unicode_names[result], buf) == 0)) + { + fprintf (stderr, + "inverse name lookup of \"%s\" returned 0x%04X\n", + unicode_names[i], result); + error = 1; + } + } } /* Third, some extreme case that used to loop. */ @@ -249,6 +251,8 @@ main (int argc, char *argv[]) { int error = 0; + set_program_name (argv[0]); + fill_names (argv[1]); error |= test_name_lookup ();