diff options
author | Andreas Rottmann <a.rottmann@gmx.at> | 2010-05-27 18:23:17 +0200 |
---|---|---|
committer | Andreas Rottmann <a.rottmann@gmx.at> | 2010-05-27 18:23:17 +0200 |
commit | bd6adfa17d453e4c486e36fed4c5779db90a8a0e (patch) | |
tree | 9798677560d5f99061afe9f0db105a8c97f2438a /tests/uninorm/test-u8-nfkc.c | |
parent | 79ca645d222db2e158784642c3b464a47bea26f3 (diff) | |
parent | 3e0814cd9862b89c7a39672672937477bd87ddfb (diff) |
Merge commit 'upstream/0.9.3'
Diffstat (limited to 'tests/uninorm/test-u8-nfkc.c')
-rw-r--r-- | tests/uninorm/test-u8-nfkc.c | 245 |
1 files changed, 116 insertions, 129 deletions
diff --git a/tests/uninorm/test-u8-nfkc.c b/tests/uninorm/test-u8-nfkc.c index 0ea4636..1ca1413 100644 --- a/tests/uninorm/test-u8-nfkc.c +++ b/tests/uninorm/test-u8-nfkc.c @@ -1,5 +1,5 @@ /* Test of compatibility normalization of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 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 @@ -18,29 +18,16 @@ #include <config.h> -#if GNULIB_UNINORM_U8_NORMALIZE +#if GNULIB_TEST_UNINORM_U8_NORMALIZE #include "uninorm.h" #include <signal.h> -#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "unistr.h" - -#define SIZEOF(array) (sizeof (array) / sizeof (array[0])) -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "macros.h" static int check (const uint8_t *input, size_t input_length, @@ -68,13 +55,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_normalize (UNINORM_NFKC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -257,8 +244,8 @@ test_u8_nfkc (void) static const uint8_t input[] = { 0xEF, 0xB7, 0xBA }; static const uint8_t decomposed[] = { 0xD8, 0xB5, 0xD9, 0x84, 0xD9, 0x89, 0x20, 0xD8, 0xA7, 0xD9, 0x84, 0xD9, - 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, - 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 + 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, + 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 }; ASSERT (check (input, SIZEOF (input), decomposed, SIZEOF (decomposed)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), decomposed, SIZEOF (decomposed)) == 0); @@ -282,36 +269,36 @@ test_u8_nfkc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t decomposed[] = { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, - 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, + 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' }; static const uint8_t expected[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), expected, SIZEOF (expected)) == 0); @@ -330,89 +317,89 @@ test_u8_nfkc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); - if (input != NULL) - { - uint8_t *expected = input + (2 * m - 1); - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint8_t *p; - size_t i; - - input[0] = 0x41; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - break; - - case 1: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - *p++ = 0xCC; - *p++ = 0x80; - } - for (; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - default: - abort (); - } - - expected[0] = 0xC3; - expected[1] = 0x80; - p = expected + 2; - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2 - 1; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); - ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); + if (input != NULL) + { + uint8_t *expected = input + (2 * m - 1); + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint8_t *p; + size_t i; + + input[0] = 0x41; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + break; + + case 1: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + *p++ = 0xCC; + *p++ = 0x80; + } + for (; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + default: + abort (); + } + + expected[0] = 0xC3; + expected[1] = 0x80; + p = expected + 2; + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2 - 1; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); + ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); + } + + free (input); + } } } } |