Mercurial > hg > octave-kai > gnulib-hg
comparison tests/uninorm/test-u8-nfd.c @ 12421:e8d2c6fc33ad
Use spaces for indentation, not tabs.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 10 Dec 2009 20:28:30 +0100 |
parents | f8e64c4210ee |
children | a48d3d749ca5 |
comparison
equal
deleted
inserted
replaced
12420:5850b9a81029 | 12421:e8d2c6fc33ad |
---|---|
29 | 29 |
30 #include "unistr.h" | 30 #include "unistr.h" |
31 | 31 |
32 #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) | 32 #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) |
33 #define ASSERT(expr) \ | 33 #define ASSERT(expr) \ |
34 do \ | 34 do \ |
35 { \ | 35 { \ |
36 if (!(expr)) \ | 36 if (!(expr)) \ |
37 { \ | 37 { \ |
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ | 38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ |
39 fflush (stderr); \ | 39 fflush (stderr); \ |
40 abort (); \ | 40 abort (); \ |
41 } \ | 41 } \ |
42 } \ | 42 } \ |
43 while (0) | 43 while (0) |
44 | 44 |
45 static int | 45 static int |
46 check (const uint8_t *input, size_t input_length, | 46 check (const uint8_t *input, size_t input_length, |
47 const uint8_t *expected, size_t expected_length) | 47 const uint8_t *expected, size_t expected_length) |
66 | 66 |
67 length = expected_length - 1; | 67 length = expected_length - 1; |
68 preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); | 68 preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); |
69 result = u8_normalize (UNINORM_NFD, input, input_length, preallocated, &length); | 69 result = u8_normalize (UNINORM_NFD, input, input_length, preallocated, &length); |
70 if (!(result != NULL)) | 70 if (!(result != NULL)) |
71 return 4; | 71 return 4; |
72 if (!(result != preallocated)) | 72 if (!(result != preallocated)) |
73 return 5; | 73 return 5; |
74 if (!(length == expected_length)) | 74 if (!(length == expected_length)) |
75 return 6; | 75 return 6; |
76 if (!(u8_cmp (result, expected, expected_length) == 0)) | 76 if (!(u8_cmp (result, expected, expected_length) == 0)) |
77 return 7; | 77 return 7; |
78 free (result); | 78 free (result); |
79 free (preallocated); | 79 free (preallocated); |
80 } | 80 } |
81 | 81 |
82 /* Test return conventions with resultbuf large enough. */ | 82 /* Test return conventions with resultbuf large enough. */ |
228 } | 228 } |
229 | 229 |
230 { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ | 230 { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ |
231 static const uint8_t input[] = | 231 static const uint8_t input[] = |
232 { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', | 232 { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', |
233 ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, | 233 ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, |
234 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, | 234 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, |
235 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, | 235 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, |
236 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', | 236 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', |
237 '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, | 237 '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, |
238 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', | 238 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', |
239 0xED, 0x95, 0x9C, | 239 0xED, 0x95, 0x9C, |
240 0xEA, 0xB8, 0x80, '\n' | 240 0xEA, 0xB8, 0x80, '\n' |
241 }; | 241 }; |
242 static const uint8_t expected[] = | 242 static const uint8_t expected[] = |
243 { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', | 243 { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', |
244 ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, | 244 ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, |
245 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, | 245 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, |
246 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, | 246 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, |
247 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', | 247 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', |
248 '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, | 248 '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, |
249 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', | 249 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', |
250 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, | 250 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, |
251 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' | 251 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' |
252 }; | 252 }; |
253 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); | 253 ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); |
254 } | 254 } |
255 | 255 |
256 #if HAVE_DECL_ALARM | 256 #if HAVE_DECL_ALARM |
263 /* Check that the sorting is not O(n²) but O(n log n). */ | 263 /* Check that the sorting is not O(n²) but O(n log n). */ |
264 { | 264 { |
265 int pass; | 265 int pass; |
266 for (pass = 0; pass < 3; pass++) | 266 for (pass = 0; pass < 3; pass++) |
267 { | 267 { |
268 size_t repeat = 1; | 268 size_t repeat = 1; |
269 size_t m = 100000; | 269 size_t m = 100000; |
270 uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); | 270 uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); |
271 if (input != NULL) | 271 if (input != NULL) |
272 { | 272 { |
273 uint8_t *expected = input + (2 * m - 1); | 273 uint8_t *expected = input + (2 * m - 1); |
274 size_t m1 = m / 2; | 274 size_t m1 = m / 2; |
275 size_t m2 = (m - 1) / 2; | 275 size_t m2 = (m - 1) / 2; |
276 /* NB: m1 + m2 == m - 1. */ | 276 /* NB: m1 + m2 == m - 1. */ |
277 uint8_t *p; | 277 uint8_t *p; |
278 size_t i; | 278 size_t i; |
279 | 279 |
280 input[0] = 0x41; | 280 input[0] = 0x41; |
281 p = input + 1; | 281 p = input + 1; |
282 switch (pass) | 282 switch (pass) |
283 { | 283 { |
284 case 0: | 284 case 0: |
285 for (i = 0; i < m1; i++) | 285 for (i = 0; i < m1; i++) |
286 { | 286 { |
287 *p++ = 0xCC; | 287 *p++ = 0xCC; |
288 *p++ = 0x99; | 288 *p++ = 0x99; |
289 } | 289 } |
290 for (i = 0; i < m2; i++) | 290 for (i = 0; i < m2; i++) |
291 { | 291 { |
292 *p++ = 0xCC; | 292 *p++ = 0xCC; |
293 *p++ = 0x80; | 293 *p++ = 0x80; |
294 } | 294 } |
295 break; | 295 break; |
296 | 296 |
297 case 1: | 297 case 1: |
298 for (i = 0; i < m2; i++) | 298 for (i = 0; i < m2; i++) |
299 { | 299 { |
300 *p++ = 0xCC; | 300 *p++ = 0xCC; |
301 *p++ = 0x80; | 301 *p++ = 0x80; |
302 } | 302 } |
303 for (i = 0; i < m1; i++) | 303 for (i = 0; i < m1; i++) |
304 { | 304 { |
305 *p++ = 0xCC; | 305 *p++ = 0xCC; |
306 *p++ = 0x99; | 306 *p++ = 0x99; |
307 } | 307 } |
308 break; | 308 break; |
309 | 309 |
310 case 2: | 310 case 2: |
311 for (i = 0; i < m2; i++) | 311 for (i = 0; i < m2; i++) |
312 { | 312 { |
313 *p++ = 0xCC; | 313 *p++ = 0xCC; |
314 *p++ = 0x99; | 314 *p++ = 0x99; |
315 *p++ = 0xCC; | 315 *p++ = 0xCC; |
316 *p++ = 0x80; | 316 *p++ = 0x80; |
317 } | 317 } |
318 for (; i < m1; i++) | 318 for (; i < m1; i++) |
319 { | 319 { |
320 *p++ = 0xCC; | 320 *p++ = 0xCC; |
321 *p++ = 0x99; | 321 *p++ = 0x99; |
322 } | 322 } |
323 break; | 323 break; |
324 | 324 |
325 default: | 325 default: |
326 abort (); | 326 abort (); |
327 } | 327 } |
328 | 328 |
329 expected[0] = 0x41; | 329 expected[0] = 0x41; |
330 p = expected + 1; | 330 p = expected + 1; |
331 for (i = 0; i < m1; i++) | 331 for (i = 0; i < m1; i++) |
332 { | 332 { |
333 *p++ = 0xCC; | 333 *p++ = 0xCC; |
334 *p++ = 0x99; | 334 *p++ = 0x99; |
335 } | 335 } |
336 for (i = 0; i < m2; i++) | 336 for (i = 0; i < m2; i++) |
337 { | 337 { |
338 *p++ = 0xCC; | 338 *p++ = 0xCC; |
339 *p++ = 0x80; | 339 *p++ = 0x80; |
340 } | 340 } |
341 | 341 |
342 for (; repeat > 0; repeat--) | 342 for (; repeat > 0; repeat--) |
343 ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); | 343 ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); |
344 | 344 |
345 free (input); | 345 free (input); |
346 } | 346 } |
347 } | 347 } |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 #else | 351 #else |