1 /* Test of compatibility decomposition of UTF-16 strings.
2 Copyright (C) 2009-2016 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009. */
21 #if GNULIB_TEST_UNINORM_U16_NORMALIZE
33 check (const uint16_t *input, size_t input_length,
34 const uint16_t *expected, size_t expected_length)
39 /* Test return conventions with resultbuf == NULL. */
40 result = u16_normalize (UNINORM_NFKD, input, input_length, NULL, &length);
41 if (!(result != NULL))
43 if (!(length == expected_length))
45 if (!(u16_cmp (result, expected, expected_length) == 0))
49 /* Test return conventions with resultbuf too small. */
50 if (expected_length > 0)
52 uint16_t *preallocated;
54 length = expected_length - 1;
55 preallocated = (uint16_t *) malloc (length * sizeof (uint16_t));
56 result = u16_normalize (UNINORM_NFKD, input, input_length, preallocated, &length);
57 if (!(result != NULL))
59 if (!(result != preallocated))
61 if (!(length == expected_length))
63 if (!(u16_cmp (result, expected, expected_length) == 0))
69 /* Test return conventions with resultbuf large enough. */
71 uint16_t *preallocated;
73 length = expected_length;
74 preallocated = (uint16_t *) malloc (length * sizeof (uint16_t));
75 result = u16_normalize (UNINORM_NFKD, input, input_length, preallocated, &length);
76 if (!(result != NULL))
78 if (!(preallocated == NULL || result == preallocated))
80 if (!(length == expected_length))
82 if (!(u16_cmp (result, expected, expected_length) == 0))
94 ASSERT (check (NULL, 0, NULL, 0) == 0);
97 static const uint16_t input[] = { 0x0020 };
98 ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
101 { /* LATIN CAPITAL LETTER A WITH DIAERESIS */
102 static const uint16_t input[] = { 0x00C4 };
103 static const uint16_t expected[] = { 0x0041, 0x0308 };
104 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
107 { /* LATIN CAPITAL LETTER A WITH DIAERESIS AND MACRON */
108 static const uint16_t input[] = { 0x01DE };
109 static const uint16_t expected[] = { 0x0041, 0x0308, 0x0304 };
110 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
113 { /* GREEK DIALYTIKA AND PERISPOMENI */
114 static const uint16_t input[] = { 0x1FC1 };
115 static const uint16_t expected[] = { 0x0020, 0x0308, 0x0342 };
116 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
119 { /* SCRIPT SMALL L */
120 static const uint16_t input[] = { 0x2113 };
121 static const uint16_t expected[] = { 0x006C };
122 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
125 { /* NO-BREAK SPACE */
126 static const uint16_t input[] = { 0x00A0 };
127 static const uint16_t expected[] = { 0x0020 };
128 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
131 { /* ARABIC LETTER VEH INITIAL FORM */
132 static const uint16_t input[] = { 0xFB6C };
133 static const uint16_t expected[] = { 0x06A4 };
134 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
137 { /* ARABIC LETTER VEH MEDIAL FORM */
138 static const uint16_t input[] = { 0xFB6D };
139 static const uint16_t expected[] = { 0x06A4 };
140 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
143 { /* ARABIC LETTER VEH FINAL FORM */
144 static const uint16_t input[] = { 0xFB6B };
145 static const uint16_t expected[] = { 0x06A4 };
146 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
149 { /* ARABIC LETTER VEH ISOLATED FORM */
150 static const uint16_t input[] = { 0xFB6A };
151 static const uint16_t expected[] = { 0x06A4 };
152 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
155 { /* CIRCLED NUMBER FIFTEEN */
156 static const uint16_t input[] = { 0x246E };
157 static const uint16_t expected[] = { 0x0031, 0x0035 };
158 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
161 { /* TRADE MARK SIGN */
162 static const uint16_t input[] = { 0x2122 };
163 static const uint16_t expected[] = { 0x0054, 0x004D };
164 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
167 { /* LATIN SUBSCRIPT SMALL LETTER I */
168 static const uint16_t input[] = { 0x1D62 };
169 static const uint16_t expected[] = { 0x0069 };
170 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
173 { /* PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS */
174 static const uint16_t input[] = { 0xFE35 };
175 static const uint16_t expected[] = { 0x0028 };
176 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
179 { /* FULLWIDTH LATIN CAPITAL LETTER A */
180 static const uint16_t input[] = { 0xFF21 };
181 static const uint16_t expected[] = { 0x0041 };
182 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
185 { /* HALFWIDTH IDEOGRAPHIC COMMA */
186 static const uint16_t input[] = { 0xFF64 };
187 static const uint16_t expected[] = { 0x3001 };
188 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
191 { /* SMALL IDEOGRAPHIC COMMA */
192 static const uint16_t input[] = { 0xFE51 };
193 static const uint16_t expected[] = { 0x3001 };
194 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
198 static const uint16_t input[] = { 0x3392 };
199 static const uint16_t expected[] = { 0x004D, 0x0048, 0x007A };
200 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
203 { /* VULGAR FRACTION THREE EIGHTHS */
204 static const uint16_t input[] = { 0x215C };
205 static const uint16_t expected[] = { 0x0033, 0x2044, 0x0038 };
206 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
210 static const uint16_t input[] = { 0x00B5 };
211 static const uint16_t expected[] = { 0x03BC };
212 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
215 { /* ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM */
216 static const uint16_t input[] = { 0xFDFA };
217 static const uint16_t expected[] =
218 { 0x0635, 0x0644, 0x0649, 0x0020, 0x0627, 0x0644, 0x0644, 0x0647, 0x0020,
219 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645
221 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
224 { /* HANGUL SYLLABLE GEUL */
225 static const uint16_t input[] = { 0xAE00 };
226 static const uint16_t expected[] = { 0x1100, 0x1173, 0x11AF };
227 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
230 { /* HANGUL SYLLABLE GEU */
231 static const uint16_t input[] = { 0xADF8 };
232 static const uint16_t expected[] = { 0x1100, 0x1173 };
233 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
236 { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */
237 static const uint16_t input[] =
238 { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ',
239 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443,
240 0x0439, 0x0442, 0x0435, '!', ' ',
241 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2,
242 '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ',
243 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n'
245 static const uint16_t expected[] =
246 { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ',
247 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443,
248 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ',
249 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032,
250 '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ',
251 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',',
252 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n'
254 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0);
258 /* Declare failure if test takes too long, by using default abort
259 caused by SIGALRM. */
260 signal (SIGALRM, SIG_DFL);
264 /* Check that the sorting is not O(n²) but O(n log n). */
267 for (pass = 0; pass < 3; pass++)
271 uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t));
274 uint16_t *expected = input + m;
276 size_t m2 = (m - 1) / 2;
277 /* NB: m1 + m2 == m - 1. */
286 for (i = 0; i < m1; i++)
288 for (i = 0; i < m2; i++)
293 for (i = 0; i < m2; i++)
295 for (i = 0; i < m1; i++)
300 for (i = 0; i < m2; i++)
313 expected[0] = 0x0041;
315 for (i = 0; i < m1; i++)
317 for (i = 0; i < m2; i++)
320 for (; repeat > 0; repeat--)
321 ASSERT (check (input, m, expected, m) == 0);