21 #include "test_unicode.h"
40 #define BUFSIZE (size_t) 16
47 #define BUFSIZE_UTF8 (BUFSIZE * (size_t) 4 + (size_t) 2)
49 #include "uc_test_nfc.c"
74 static int test_unicode_conformance(
size_t record,
const char* src_utf8,
78 int res = POSIX_EXIT_SUCCESS;
79 const char* buf1 = NULL;
80 const char* buf2 = NULL;
81 const char* buf3 = NULL;
83 const char* input = NULL;
84 const char* err = NULL;
88 printf(
"================\nrecord: %u\n", (
unsigned int) record);
89 printf(
"src_utf8: %s\n", src_utf8);
90 printf(
"nfc_utf8: %s\n", nfc_utf8);
91 printf(
"nfd_utf8: %s\n", nfd_utf8);
92 printf(
"================\n"),
101 res = POSIX_EXIT_FAILURE;
103 else if(strcmp(nfc_utf8, buf1))
107 res = POSIX_EXIT_FAILURE;
111 if(POSIX_EXIT_SUCCESS == res)
118 res = POSIX_EXIT_FAILURE;
120 else if(strcmp(nfc_utf8, buf2))
124 res = POSIX_EXIT_FAILURE;
129 if(POSIX_EXIT_SUCCESS == res)
136 res = POSIX_EXIT_FAILURE;
138 else if(strcmp(nfc_utf8, buf3))
142 res = POSIX_EXIT_FAILURE;
147 if(POSIX_EXIT_SUCCESS != res && NULL != err)
149 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
150 loc = posix_setlocale(POSIX_LC_CTYPE,
"");
156 print_error(
"Setting locale for debug messages failed");
161 if(NULL == strstr(loc,
"UTF") && NULL == strstr(loc,
"utf"))
164 "Debug messages can't be printed with current locale");
168 fprintf(stderr,
TEST_TAB "Record number in test data file: %lu\n",
169 (
unsigned long int) record);
170 fprintf(stderr,
TEST_TAB "Input data: \"%s\"\n", input);
171 fprintf(stderr,
TEST_TAB "Result is : \"%s\"\n", err);
172 fprintf(stderr,
TEST_TAB "Should be : \"%s\"\n", nfc_utf8);
178 if(buf1 != src_utf8) {
enc_free((
void*) buf1); }
179 if(buf2 != nfc_utf8) {
enc_free((
void*) buf2); }
180 if(buf3 != nfd_utf8) {
enc_free((
void*) buf3); }
194 static int test_unicode_part2(
void)
196 int res = POSIX_EXIT_SUCCESS;
199 enum sm_state state = SM_SRC;
200 long int src[BUFSIZE];
201 long int nfc[BUFSIZE];
202 long int nfd[BUFSIZE];
206 char src_utf8[BUFSIZE_UTF8];
207 char nfc_utf8[BUFSIZE_UTF8];
208 char nfd_utf8[BUFSIZE_UTF8];
213 while(POSIX_EXIT_SUCCESS == res && -1 != (ucp = uc_test_nfc_table[i++]))
220 if(-2L == ucp) { state = SM_NFC; }
224 res = POSIX_EXIT_FAILURE;
231 res = POSIX_EXIT_FAILURE;
233 else { src[src_i++] = ucp; }
239 if(-2L == ucp) { state = SM_NFD; }
243 res = POSIX_EXIT_FAILURE;
250 res = POSIX_EXIT_FAILURE;
252 else { nfc[nfc_i++] = ucp; }
261 src_utf8[0] =
' '; utf8_i = 1;
263 src_utf8[utf8_i] = 0;
264 nfc_utf8[0] =
' '; utf8_i = 1;
266 nfc_utf8[utf8_i] = 0;
267 nfd_utf8[0] =
' '; utf8_i = 1;
269 nfd_utf8[utf8_i] = 0;
270 if(src_i || nfc_i || nfd_i)
273 res = POSIX_EXIT_FAILURE;
278 res = test_unicode_conformance(rec++,
279 src_utf8, nfc_utf8, nfd_utf8);
287 res = POSIX_EXIT_FAILURE;
294 res = POSIX_EXIT_FAILURE;
296 else { nfd[nfd_i++] = ucp; }
303 res = POSIX_EXIT_FAILURE;
349 #define TS_NUM (size_t) 11
350 #define TS_UTF7 (size_t) 8
351 static const char* ts[TS_NUM] =
354 "This is an ASCII string",
355 "This is an Unicode string: \xC3\xA4word",
356 "This is an Unicode string: \xE0\xAD\x9Cword",
357 "This is an Unicode string: a\xCC\x88word",
358 "This is an Unicode string: start\xCE\xB1\xCC\x94\xCC\x81\xCD\x85word",
359 "This is an Unicode string: start\xCE\xB1\xCC\x81\xCC\x94\xCD\x85word",
360 "This is an Unicode string: \xE2\x84\xA6word",
361 "Composition of hangul jamo: \xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6",
363 "This is an Unicode string: hundertf+AHUDCA-nfzig",
364 "This is an Unicode string: Violinschl+APw-ssel (+2DTdHg-)",
365 "Shift sequence terminated by SP or end-of-data: A+AMQ- O+ANY U+ANw"
367 static const char* rs[TS_NUM] = {
369 "This is an ASCII string",
370 "This is an Unicode string: \xC3\xA4word",
371 "This is an Unicode string: \xE0\xAC\xA1\xE0\xAC\xBCword",
372 "This is an Unicode string: \xC3\xA4word",
373 "This is an Unicode string: start\xE1\xBE\x85word",
374 "This is an Unicode string: start\xE1\xBE\xB4\xCC\x94word",
375 "This is an Unicode string: \xCE\xA9word",
376 "Composition of hangul jamo: \xED\x93\x9B",
378 "This is an Unicode string: hundertf\xC3\xBCnfzig",
379 "This is an Unicode string: Violinschl\xC3\xBCssel (\xF0\x9D\x84\x9E)",
380 "Shift sequence terminated by SP or end-of-data: A\xC3\x84 O\xC3\x96 U\xC3\x9C"
382 int res = POSIX_EXIT_SUCCESS;
388 for(i = 0; i < TS_NUM; ++i)
401 res = POSIX_EXIT_FAILURE;
404 if(strcmp(rs[i], buf))
408 #if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
409 loc = posix_setlocale(POSIX_LC_CTYPE,
"");
415 print_error(
"Setting locale for debug messages failed");
420 if(NULL == strstr(loc,
"UTF") && NULL == strstr(loc,
"utf"))
423 "Debug messages can't be printed with current locale");
427 fprintf(stderr,
TEST_TAB "Input data: \"%s\"\n", ts[i]);
428 fprintf(stderr,
TEST_TAB "Result is : \"%s\"\n", buf);
429 fprintf(stderr,
TEST_TAB "Should be : \"%s\"\n", rs[i]);
432 res = POSIX_EXIT_FAILURE;
435 if(buf != ts[i]) {
enc_free((
void*) buf); }
439 if(POSIX_EXIT_SUCCESS == res)
441 res = test_unicode_part2();