1 | /* |
---|
2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Obere Lagerstr. 30 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "tmacros.h" |
---|
20 | |
---|
21 | #include <string.h> |
---|
22 | #include <utf8proc/utf8proc.h> |
---|
23 | |
---|
24 | const char rtems_test_name[] = "UTF8PROC 1"; |
---|
25 | |
---|
26 | static void |
---|
27 | test_utf8proc_errmsg ( void ) |
---|
28 | { |
---|
29 | int error; |
---|
30 | size_t string_length; |
---|
31 | const char* err_msg; |
---|
32 | |
---|
33 | for ( error = 0; error >= UTF8PROC_ERROR_INVALIDOPTS - 1; --error ) { |
---|
34 | err_msg = utf8proc_errmsg ( error ); |
---|
35 | rtems_test_assert ( err_msg != NULL ); |
---|
36 | |
---|
37 | string_length = strlen (err_msg ); |
---|
38 | rtems_test_assert ( string_length > 0 ); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | static void |
---|
43 | test_utf8proc_version ( void ) |
---|
44 | { |
---|
45 | const char* version; |
---|
46 | size_t string_length; |
---|
47 | |
---|
48 | version = utf8proc_version ( ); |
---|
49 | rtems_test_assert ( version != NULL ); |
---|
50 | |
---|
51 | string_length = strlen ( version ); |
---|
52 | rtems_test_assert ( string_length > 0 ); |
---|
53 | |
---|
54 | rtems_test_assert (0 == strcmp ( version, "1.1.5" ) ); |
---|
55 | } |
---|
56 | |
---|
57 | static void |
---|
58 | test_utf8proc_iterate ( void ) |
---|
59 | { |
---|
60 | char utf8_str_simple[] = "The quick brown.fox"; |
---|
61 | uint8_t *utf8_str_simple_ptr = (uint8_t*)(&utf8_str_simple[0]); |
---|
62 | size_t length_simple_string = strlen ( utf8_str_simple ); |
---|
63 | int32_t unicode_char; |
---|
64 | unsigned int index; |
---|
65 | ssize_t bytes_read; |
---|
66 | |
---|
67 | for (index = 0; index < length_simple_string; ++index) { |
---|
68 | bytes_read = utf8proc_iterate ( |
---|
69 | &utf8_str_simple_ptr[index], |
---|
70 | length_simple_string - index, |
---|
71 | &unicode_char ); |
---|
72 | rtems_test_assert ( bytes_read == 1 ); |
---|
73 | rtems_test_assert ( (uint8_t)unicode_char == utf8_str_simple_ptr[index]); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | static void |
---|
78 | test_utf8proc_encode_char ( void ) |
---|
79 | { |
---|
80 | uint8_t utf8_str[4]; |
---|
81 | int32_t unicode_char; |
---|
82 | ssize_t bytes_written; |
---|
83 | |
---|
84 | for ( unicode_char = 0; unicode_char < 128; ++unicode_char ) { |
---|
85 | bytes_written = utf8proc_encode_char ( unicode_char, utf8_str ); |
---|
86 | |
---|
87 | rtems_test_assert ( bytes_written == 1 ); |
---|
88 | rtems_test_assert ( utf8_str[0] == (uint8_t)unicode_char ); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | test_utf8proc_get_property ( void ) |
---|
94 | { |
---|
95 | int32_t unicode_char; |
---|
96 | const utf8proc_property_t* properties; |
---|
97 | |
---|
98 | for ( unicode_char = 0x0000; unicode_char <= 0x10FFFF; ++unicode_char ) { |
---|
99 | properties = utf8proc_get_property ( unicode_char ); |
---|
100 | rtems_test_assert ( NULL != properties ); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | static void |
---|
105 | test_utf8proc_decompose_char ( void ) |
---|
106 | { |
---|
107 | int32_t unicode_char; |
---|
108 | int32_t unicode_char_decomposed[4]; |
---|
109 | ssize_t chars_written; |
---|
110 | |
---|
111 | for ( unicode_char = 0x0000; unicode_char <= 0x10FFFF; ++unicode_char ) { |
---|
112 | chars_written = utf8proc_decompose_char ( |
---|
113 | unicode_char, |
---|
114 | unicode_char_decomposed, |
---|
115 | sizeof ( unicode_char_decomposed ) / sizeof ( unicode_char_decomposed[0] ), |
---|
116 | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE, |
---|
117 | 0); |
---|
118 | if ( unicode_char < 0x80 ) { |
---|
119 | rtems_test_assert ( chars_written == 1 ); |
---|
120 | rtems_test_assert ( unicode_char_decomposed[0] == unicode_char); |
---|
121 | } |
---|
122 | else |
---|
123 | rtems_test_assert ( chars_written > 0 ); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | static void |
---|
128 | test_utf8proc_decompose ( void ) |
---|
129 | { |
---|
130 | char string_simple[] = "The quick brown.fox"; |
---|
131 | uint8_t *string_simple_utf8 = (uint8_t*)(&string_simple[0]); |
---|
132 | int32_t string_decomposed[sizeof ( string_simple ) * 4]; |
---|
133 | ssize_t chars_written; |
---|
134 | unsigned int index; |
---|
135 | |
---|
136 | memset (&string_decomposed[0], 0, sizeof ( string_decomposed ) ); |
---|
137 | |
---|
138 | chars_written = utf8proc_decompose ( |
---|
139 | string_simple_utf8, |
---|
140 | sizeof ( string_simple ), |
---|
141 | &string_decomposed[0], |
---|
142 | sizeof ( string_decomposed ), |
---|
143 | UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE ); |
---|
144 | rtems_test_assert ( chars_written == strlen ( string_simple ) ); |
---|
145 | /* Our source string contains only very simple characters. Thus the above |
---|
146 | * decomposition should result in exactly the same string |
---|
147 | */ |
---|
148 | for ( index = 0; index < sizeof ( string_simple ); ++index ) { |
---|
149 | rtems_test_assert ( string_simple_utf8[index] == (uint8_t)string_decomposed[index] ); |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | static void |
---|
154 | test_utf8proc_reencode ( void ) |
---|
155 | { |
---|
156 | char string_simple[] = "The quick brown.fox"; |
---|
157 | uint8_t *string_simple_utf8 = (uint8_t*)(&string_simple[0]); |
---|
158 | int32_t string_decomposed[sizeof ( string_simple ) * 4]; |
---|
159 | uint8_t *string_reencoded = (uint8_t*)(&string_decomposed[0]); |
---|
160 | ssize_t chars_written; |
---|
161 | unsigned int index; |
---|
162 | |
---|
163 | memset (&string_decomposed[0], 0, sizeof ( string_decomposed ) ); |
---|
164 | |
---|
165 | chars_written = utf8proc_decompose ( |
---|
166 | string_simple_utf8, |
---|
167 | sizeof ( string_simple ), |
---|
168 | &string_decomposed[0], |
---|
169 | sizeof ( string_decomposed ), |
---|
170 | UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE ); |
---|
171 | rtems_test_assert ( chars_written == strlen ( string_simple ) ); |
---|
172 | |
---|
173 | chars_written = utf8proc_reencode ( |
---|
174 | &string_decomposed[0], |
---|
175 | chars_written, |
---|
176 | UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE ); |
---|
177 | rtems_test_assert ( chars_written == strlen ( string_simple ) ); |
---|
178 | /* Our source string contains only very simple characters. Thus the above |
---|
179 | * decomposition should result in exactly the same string |
---|
180 | */ |
---|
181 | for ( index = 0; index < sizeof ( string_simple ); ++index ) { |
---|
182 | rtems_test_assert ( string_simple_utf8[index] == string_reencoded[index] ); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | static void |
---|
187 | test_utf8proc_map ( void ) |
---|
188 | { |
---|
189 | char string_simple[] = "The quick brown.fox"; |
---|
190 | uint8_t *string_simple_utf8 = (uint8_t*)(&string_simple[0]); |
---|
191 | uint8_t *dest = NULL; |
---|
192 | ssize_t chars_written; |
---|
193 | unsigned int index; |
---|
194 | |
---|
195 | chars_written = utf8proc_map( |
---|
196 | string_simple_utf8, |
---|
197 | sizeof ( string_simple ), |
---|
198 | &dest, |
---|
199 | UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE ); |
---|
200 | rtems_test_assert ( chars_written == strlen ( string_simple ) ); |
---|
201 | rtems_test_assert ( dest != NULL); |
---|
202 | |
---|
203 | /* Our source string contains only very simple characters. Thus the above |
---|
204 | * decomposition should result in exactly the same string |
---|
205 | */ |
---|
206 | for ( index = 0; index < chars_written; ++index ) { |
---|
207 | rtems_test_assert ( string_simple_utf8[index] == dest[index] ); |
---|
208 | } |
---|
209 | free ( dest ); |
---|
210 | } |
---|
211 | |
---|
212 | typedef uint8_t* (*normalization_method)(const uint8_t* str); |
---|
213 | |
---|
214 | static void |
---|
215 | test_utf8proc_normalize ( const normalization_method test_sample ) |
---|
216 | { |
---|
217 | char string_simple[] = "The quick brown.fox"; |
---|
218 | uint8_t *string_simple_utf8 = (uint8_t*)(&string_simple[0]); |
---|
219 | uint8_t *dest = NULL; |
---|
220 | unsigned int index; |
---|
221 | |
---|
222 | dest = test_sample ( string_simple_utf8 ); |
---|
223 | rtems_test_assert ( dest != NULL); |
---|
224 | |
---|
225 | /* Our source string contains only very simple characters. Thus the above |
---|
226 | * decomposition should result in exactly the same string |
---|
227 | */ |
---|
228 | for ( index = 0; index < sizeof ( string_simple ); ++index ) { |
---|
229 | rtems_test_assert ( string_simple_utf8[index] == dest[index] ); |
---|
230 | } |
---|
231 | free ( dest ); |
---|
232 | } |
---|
233 | |
---|
234 | static void test ( void ) |
---|
235 | { |
---|
236 | test_utf8proc_errmsg ( ); |
---|
237 | test_utf8proc_version ( ); |
---|
238 | test_utf8proc_iterate ( ); |
---|
239 | test_utf8proc_encode_char ( ); |
---|
240 | test_utf8proc_get_property ( ); |
---|
241 | test_utf8proc_decompose_char ( ); |
---|
242 | test_utf8proc_decompose ( ); |
---|
243 | test_utf8proc_reencode ( ); |
---|
244 | test_utf8proc_map ( ); |
---|
245 | test_utf8proc_normalize ( utf8proc_NFD ); |
---|
246 | test_utf8proc_normalize ( utf8proc_NFC ); |
---|
247 | test_utf8proc_normalize ( utf8proc_NFKD ); |
---|
248 | test_utf8proc_normalize ( utf8proc_NFKC ); |
---|
249 | } |
---|
250 | |
---|
251 | static void Init ( rtems_task_argument arg ) |
---|
252 | { |
---|
253 | TEST_BEGIN(); |
---|
254 | |
---|
255 | test ( ); |
---|
256 | |
---|
257 | TEST_END(); |
---|
258 | |
---|
259 | rtems_test_exit ( 0 ); |
---|
260 | } |
---|
261 | |
---|
262 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
263 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
264 | |
---|
265 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
266 | |
---|
267 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
268 | |
---|
269 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
270 | |
---|
271 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
272 | |
---|
273 | #define CONFIGURE_INIT |
---|
274 | |
---|
275 | #include <rtems/confdefs.h> |
---|