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