Mercurial > gnulib
annotate tests/uninorm/test-u32-normalize-big.c @ 40226:5b87a9bf7240
uninorm tests: Free allocated memory.
* tests/uninorm/test-u32-normalize-big.h
(struct normalization_test_file): Remove 'const' from allocated member.
(free_normalization_test_file): New declaration.
* tests/uninorm/test-u32-normalize-big.c (test_other): Free allocated
memory.
(free_normalization_test_file): New function.
* tests/uninorm/test-u32-nfc-big.c (main): Free allocated
'struct normalization_test_file' contents.
* tests/uninorm/test-u32-nfd-big.c (main): Likewise.
* tests/uninorm/test-u32-nfkc-big.c (main): Likewise.
* tests/uninorm/test-u32-nfkd-big.c (main): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 10 Mar 2019 15:14:01 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
11193 | 1 /* Test of Unicode compliance of normalization of UTF-32 strings. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11193 | 3 |
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. | |
8 | |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
11193 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 /* Specification. */ | |
22 #include "test-u32-normalize-big.h" | |
23 | |
13073
03de1efbfdd3
Resolve conflict between the two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
24 #if GNULIB_TEST_UNINORM_U32_NORMALIZE |
11193 | 25 |
26 #include <stdio.h> | |
27 #include <stdlib.h> | |
28 | |
29 #include "xalloc.h" | |
30 #include "unistr.h" | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
31 #include "macros.h" |
11193 | 32 |
33 #define ASSERT_WITH_LINE(expr, file, line) \ | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
34 do \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
35 { \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
36 if (!(expr)) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
37 { \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
38 fprintf (stderr, "%s:%d: assertion failed for %s:%u\n", \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
39 __FILE__, __LINE__, file, line); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
40 fflush (stderr); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
41 abort (); \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
42 } \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
43 } \ |
11193 | 44 while (0) |
45 | |
46 static int | |
47 cmp_ucs4_t (const void *a, const void *b) | |
48 { | |
49 ucs4_t a_value = *(const ucs4_t *)a; | |
50 ucs4_t b_value = *(const ucs4_t *)b; | |
51 return (a_value < b_value ? -1 : a_value > b_value ? 1 : 0); | |
52 } | |
53 | |
54 void | |
55 read_normalization_test_file (const char *filename, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
56 struct normalization_test_file *file) |
11193 | 57 { |
58 FILE *stream; | |
59 unsigned int lineno; | |
60 int part_index; | |
61 struct normalization_test_line *lines; | |
62 size_t lines_length; | |
63 size_t lines_allocated; | |
64 | |
65 stream = fopen (filename, "r"); | |
66 if (stream == NULL) | |
67 { | |
68 fprintf (stderr, "error during fopen of '%s'\n", filename); | |
69 exit (1); | |
70 } | |
71 | |
72 for (part_index = 0; part_index < 4; part_index++) | |
73 { | |
74 file->parts[part_index].lines = NULL; | |
75 file->parts[part_index].lines_length = 0; | |
76 } | |
77 | |
78 lineno = 0; | |
79 | |
80 part_index = -1; | |
81 lines = NULL; | |
82 lines_length = 0; | |
83 lines_allocated = 0; | |
84 | |
85 for (;;) | |
86 { | |
87 char buf[1000+1]; | |
88 char *ptr; | |
89 int c; | |
90 struct normalization_test_line line; | |
91 size_t sequence_index; | |
92 | |
93 lineno++; | |
94 | |
95 /* Read a line. */ | |
96 ptr = buf; | |
97 do | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
98 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
99 c = getc (stream); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
100 if (c == EOF || c == '\n') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
101 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
102 *ptr++ = c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
103 } |
11193 | 104 while (ptr < buf + 1000); |
105 *ptr = '\0'; | |
106 if (c == EOF) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
107 break; |
11193 | 108 |
109 /* Ignore empty lines and comment lines. */ | |
110 if (buf[0] == '\0' || buf[0] == '#') | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
111 continue; |
11193 | 112 |
113 /* Handle lines that introduce a new part. */ | |
114 if (buf[0] == '@') | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
115 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
116 /* Switch to the next part. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
117 if (part_index >= 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
118 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
119 lines = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
120 (struct normalization_test_line *) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
121 xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
122 file->parts[part_index].lines = lines; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
123 file->parts[part_index].lines_length = lines_length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
124 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
125 part_index++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
126 lines = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
127 lines_length = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
128 lines_allocated = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
129 continue; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
130 } |
11193 | 131 |
132 /* It's a line containing 5 sequences of Unicode characters. | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
133 Parse it and append it to the current part. */ |
11193 | 134 if (!(part_index >= 0 && part_index < 4)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
135 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
136 fprintf (stderr, "unexpected structure of '%s'\n", filename); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
137 exit (1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
138 } |
11193 | 139 ptr = buf; |
140 line.lineno = lineno; | |
141 for (sequence_index = 0; sequence_index < 5; sequence_index++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
142 line.sequences[sequence_index] = NULL; |
11193 | 143 for (sequence_index = 0; sequence_index < 5; sequence_index++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
144 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
145 uint32_t *sequence = XNMALLOC (1, uint32_t); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
146 size_t sequence_length = 0; |
11193 | 147 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
148 for (;;) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
149 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
150 char *endptr; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
151 unsigned int uc; |
11193 | 152 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
153 uc = strtoul (ptr, &endptr, 16); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
154 if (endptr == ptr) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
155 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
156 ptr = endptr; |
11193 | 157 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
158 /* Append uc to the sequence. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
159 sequence = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
160 (uint32_t *) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
161 xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
162 sequence[sequence_length] = uc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
163 sequence_length++; |
11193 | 164 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
165 if (*ptr == ' ') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
166 ptr++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
167 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
168 if (sequence_length == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
169 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
170 fprintf (stderr, "empty character sequence in '%s'\n", filename); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
171 exit (1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
172 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
173 sequence[sequence_length] = 0; /* terminator */ |
11193 | 174 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
175 line.sequences[sequence_index] = sequence; |
11193 | 176 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
177 if (*ptr != ';') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
178 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
179 fprintf (stderr, "error parsing '%s'\n", filename); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
180 exit (1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
181 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
182 ptr++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
183 } |
11193 | 184 |
185 /* Append the line to the current part. */ | |
186 if (lines_length == lines_allocated) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
187 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
188 lines_allocated = 2 * lines_allocated; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
189 if (lines_allocated < 7) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
190 lines_allocated = 7; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
191 lines = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
192 (struct normalization_test_line *) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
193 xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
194 } |
11193 | 195 lines[lines_length] = line; |
196 lines_length++; | |
197 } | |
198 | |
199 if (part_index >= 0) | |
200 { | |
201 lines = | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
202 (struct normalization_test_line *) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
203 xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); |
11193 | 204 file->parts[part_index].lines = lines; |
205 file->parts[part_index].lines_length = lines_length; | |
206 } | |
207 | |
208 { | |
209 /* Collect all c1 values from the part 1 in an array. */ | |
210 const struct normalization_test_part *p = &file->parts[1]; | |
211 ucs4_t *c1_array = XNMALLOC (p->lines_length + 1, ucs4_t); | |
212 size_t line_index; | |
213 | |
214 for (line_index = 0; line_index < p->lines_length; line_index++) | |
215 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
216 const uint32_t *sequence = p->lines[line_index].sequences[0]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
217 /* In part 1, every sequences[0] consists of a single character. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
218 if (!(sequence[0] != 0 && sequence[1] == 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
219 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
220 c1_array[line_index] = sequence[0]; |
11193 | 221 } |
222 | |
223 /* Sort this array. */ | |
224 qsort (c1_array, p->lines_length, sizeof (ucs4_t), cmp_ucs4_t); | |
225 | |
226 /* Add the sentinel at the end. */ | |
227 c1_array[p->lines_length] = 0x110000; | |
228 | |
229 file->part1_c1_sorted = c1_array; | |
230 } | |
231 | |
232 file->filename = xstrdup (filename); | |
233 | |
234 if (ferror (stream) || fclose (stream)) | |
235 { | |
236 fprintf (stderr, "error reading from '%s'\n", filename); | |
237 exit (1); | |
238 } | |
239 } | |
240 | |
241 void | |
242 test_specific (const struct normalization_test_file *file, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
243 int (*check) (const uint32_t *c1, size_t c1_length, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
244 const uint32_t *c2, size_t c2_length, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
245 const uint32_t *c3, size_t c3_length, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
246 const uint32_t *c4, size_t c4_length, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
247 const uint32_t *c5, size_t c5_length)) |
11193 | 248 { |
249 size_t part_index; | |
250 | |
251 for (part_index = 0; part_index < 4; part_index++) | |
252 { | |
253 const struct normalization_test_part *p = &file->parts[part_index]; | |
254 size_t line_index; | |
255 | |
256 for (line_index = 0; line_index < p->lines_length; line_index++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
257 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
258 const struct normalization_test_line *l = &p->lines[line_index]; |
11193 | 259 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
260 ASSERT_WITH_LINE (check (l->sequences[0], u32_strlen (l->sequences[0]), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
261 l->sequences[1], u32_strlen (l->sequences[1]), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
262 l->sequences[2], u32_strlen (l->sequences[2]), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
263 l->sequences[3], u32_strlen (l->sequences[3]), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
264 l->sequences[4], u32_strlen (l->sequences[4])) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
265 == 0, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
266 file->filename, l->lineno); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
267 } |
11193 | 268 } |
269 } | |
270 | |
271 void | |
272 test_other (const struct normalization_test_file *file, uninorm_t nf) | |
273 { | |
274 /* Check that for every character not listed in part 1 of the | |
275 NormalizationTest.txt file, the character maps to itself in each | |
276 of the four normalization forms. */ | |
277 const ucs4_t *p = file->part1_c1_sorted; | |
278 ucs4_t uc; | |
279 | |
280 for (uc = 0; uc < 0x110000; uc++) | |
281 { | |
282 if (uc >= 0xD800 && uc < 0xE000) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
283 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
284 /* A surrogate, not a character. Skip uc. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
285 } |
11193 | 286 else if (uc == *p) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
287 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
288 /* Skip uc. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
289 p++; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
290 } |
11193 | 291 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
292 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
293 uint32_t input[1]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
294 size_t length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
295 uint32_t *result; |
11193 | 296 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
297 input[0] = uc; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
298 result = u32_normalize (nf, input, 1, NULL, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
299 ASSERT (result != NULL && length == 1 && result[0] == uc); |
40226
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
300 |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
301 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11488
diff
changeset
|
302 } |
11193 | 303 } |
304 } | |
305 | |
40226
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
306 void |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
307 free_normalization_test_file (struct normalization_test_file *file) |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
308 { |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
309 size_t part_index; |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
310 |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
311 for (part_index = 0; part_index < 4; part_index++) |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
312 { |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
313 const struct normalization_test_part *p = &file->parts[part_index]; |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
314 size_t line_index; |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
315 |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
316 for (line_index = 0; line_index < p->lines_length; line_index++) |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
317 { |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
318 const struct normalization_test_line *l = &p->lines[line_index]; |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
319 size_t sequence_index; |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
320 |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
321 for (sequence_index = 0; sequence_index < 5; sequence_index++) |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
322 free (l->sequences[sequence_index]); |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
323 } |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
324 free (p->lines); |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
325 } |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
326 free (file->part1_c1_sorted); |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
327 free (file->filename); |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
328 } |
5b87a9bf7240
uninorm tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
329 |
11193 | 330 #endif |