This source file includes following definitions.
- test_u32_grapheme_breaks
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include <unigbrk.h>
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "macros.h"
30
31 static void
32 test_u32_grapheme_breaks (const char *expected, ...)
33 {
34 size_t n = strlen (expected);
35 uint32_t s[16];
36 va_list args;
37 char breaks[16];
38 size_t i;
39
40 ASSERT (n <= 16);
41
42 memset (breaks, 0xcc, n);
43
44 va_start (args, expected);
45 for (i = 0; i < n; i++)
46 {
47 int unit = va_arg (args, int);
48 ASSERT (unit >= 0);
49 s[i] = unit;
50 }
51 ASSERT (va_arg (args, int) == -1);
52 va_end (args);
53
54 u32_grapheme_breaks (s, n, breaks);
55 for (i = 0; i < n; i++)
56 if (breaks[i] != (expected[i] == '#'))
57 {
58 size_t j;
59
60 fprintf (stderr, "wrong grapheme breaks:\n");
61
62 fprintf (stderr, " input:");
63 for (j = 0; j < n; j++)
64 fprintf (stderr, " %02x", s[j]);
65 putc ('\n', stderr);
66
67 fprintf (stderr, "expected:");
68 for (j = 0; j < n; j++)
69 fprintf (stderr, " %d", expected[j] == '#');
70 putc ('\n', stderr);
71
72 fprintf (stderr, " actual:");
73 for (j = 0; j < n; j++)
74 fprintf (stderr, " %d", breaks[j]);
75 putc ('\n', stderr);
76
77 abort ();
78 }
79 }
80
81 int
82 main (void)
83 {
84
85 test_u32_grapheme_breaks ("#", 'a', -1);
86 test_u32_grapheme_breaks ("##", 'a', 'b', -1);
87 test_u32_grapheme_breaks ("###", 'a', 'b', 'c', -1);
88
89 #define HIRAGANA_A 0x3042
90 test_u32_grapheme_breaks ("#", HIRAGANA_A, -1);
91 test_u32_grapheme_breaks ("##", HIRAGANA_A, 'x', -1);
92 test_u32_grapheme_breaks ("##", HIRAGANA_A, HIRAGANA_A, -1);
93
94
95 #define GRAVE 0x0300
96 #define ACUTE 0x0301
97 test_u32_grapheme_breaks ("#_", 'e', ACUTE, -1);
98 test_u32_grapheme_breaks ("#__", 'e', ACUTE, GRAVE, -1);
99 test_u32_grapheme_breaks ("#_#", 'e', ACUTE, 'x', -1);
100 test_u32_grapheme_breaks ("#_#_", 'e', ACUTE, 'e', GRAVE, -1);
101
102 return 0;
103 }