1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
6 /* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
15 #include <yaz/timing.h>
20 #include <yaz/wrbuf.h>
23 #include <yaz/icu_I18N.h>
24 #include <unicode/uclean.h>
31 #include <libxml/xmlmemory.h>
37 #define MAX_KEY_SIZE 256
40 uint8_t sort_key[MAX_KEY_SIZE]; /* standard C string '\0' terminated */
41 char disp_term[MAX_KEY_SIZE]; /* standard C utf-8 string */
45 static int icu_termmap_cmp(const void *vp1, const void *vp2)
47 struct icu_termmap *itmp1 = *(struct icu_termmap **) vp1;
48 struct icu_termmap *itmp2 = *(struct icu_termmap **) vp2;
52 cmp = strcmp((const char *)itmp1->sort_key,
53 (const char *)itmp2->sort_key);
58 static int test_icu_casemap(const char *locale, char action,
59 const char *src8cstr, const char *chk8cstr)
62 UErrorCode status = U_ZERO_ERROR;
64 struct icu_buf_utf8 *src8 = icu_buf_utf8_create(0);
65 struct icu_buf_utf8 *dest8 = icu_buf_utf8_create(0);
66 struct icu_buf_utf16 *src16 = icu_buf_utf16_create(0);
67 struct icu_buf_utf16 *dest16 = icu_buf_utf16_create(0);
70 int src8cstr_len = strlen(src8cstr);
71 int chk8cstr_len = strlen(chk8cstr);
73 /* converting to UTF16 */
74 icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
76 /* perform case mapping */
77 icu_utf16_casemap(dest16, src16, locale, action, &status);
79 /* converting to UTF8 */
80 icu_utf16_to_utf8(dest8, dest16, &status);
82 /* determine success */
84 && (dest8->utf8_len == strlen(chk8cstr))
85 && !strcmp(chk8cstr, (const char *) dest8->utf8))
93 yaz_log(YLOG_WARN, "test_icu_casemap failed");
94 yaz_log(YLOG_LOG, "Original string: '%s' (%d)",
95 src8cstr, src8cstr_len);
96 yaz_log(YLOG_LOG, "icu_casemap '%s:%c' '%s' (%d)",
97 locale, action, dest8->utf8, dest8->utf8_len);
98 yaz_log(YLOG_LOG, "expected string: '%s' (%d)",
99 chk8cstr, chk8cstr_len);
102 /* clean the buffers */
103 icu_buf_utf8_destroy(src8);
104 icu_buf_utf8_destroy(dest8);
105 icu_buf_utf16_destroy(src16);
106 icu_buf_utf16_destroy(dest16);
111 static void check_icu_casemap(void)
115 /* successful tests */
116 YAZ_CHECK(test_icu_casemap("en", 'l',
117 "A ReD fOx hunTS sQUirriLs",
118 "a red fox hunts squirrils"));
120 YAZ_CHECK(test_icu_casemap("en", 'u',
121 "A ReD fOx hunTS sQUirriLs",
122 "A RED FOX HUNTS SQUIRRILS"));
124 YAZ_CHECK(test_icu_casemap("en", 'f',
125 "A ReD fOx hunTS sQUirriLs",
126 "a red fox hunts squirrils"));
128 YAZ_CHECK(test_icu_casemap("en", 't',
129 "A ReD fOx hunTS sQUirriLs",
130 "A Red Fox Hunts Squirrils"));
134 /* success expected */
135 YAZ_CHECK(test_icu_casemap("da", 'l',
136 "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN",
137 "åh æble, øs fløde i åen efter blåbærgrøden"));
139 YAZ_CHECK(test_icu_casemap("da", 'u',
140 "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN",
141 "ÅH ÆBLE, ØS FLØDE I ÅEN EFTER BLÅBÆRGRØDEN"));
143 YAZ_CHECK(test_icu_casemap("da", 'f',
144 "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN",
145 "åh æble, øs fløde i åen efter blåbærgrøden"));
147 YAZ_CHECK(test_icu_casemap("da", 't',
148 "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN",
149 "Åh Æble, Øs Fløde I Åen Efter Blåbærgrøden"));
153 /* success expected */
154 YAZ_CHECK(test_icu_casemap("de", 'l',
155 "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
156 "zwölf ärgerliche würste rollen über die straße"));
158 YAZ_CHECK(test_icu_casemap("de", 'u',
159 "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
160 "ZWÖLF ÄRGERLICHE WÜRSTE ROLLEN ÜBER DIE STRASSE"));
162 YAZ_CHECK(test_icu_casemap("de", 'f',
163 "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
164 "zwölf ärgerliche würste rollen über die strasse"));
166 YAZ_CHECK(test_icu_casemap("de", 't',
167 "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
168 "Zwölf Ärgerliche Würste Rollen Über Die Straße"));
172 static int test_icu_sortmap(const char *locale, int src_list_len,
173 const char **src_list, const char **chk_list)
177 UErrorCode status = U_ZERO_ERROR;
179 struct icu_buf_utf8 *buf8 = icu_buf_utf8_create(0);
180 struct icu_buf_utf16 *buf16 = icu_buf_utf16_create(0);
184 struct icu_termmap *list[src_list_len];
186 UCollator *coll = ucol_open(locale, &status);
187 icu_check_status(status);
189 if (U_FAILURE(status))
192 /* assigning display terms and sort keys using buf 8 and buf16 */
193 for (i = 0; i < src_list_len; i++)
196 list[i] = (struct icu_termmap *) malloc(sizeof(struct icu_termmap));
198 /* copy display term */
199 strcpy(list[i]->disp_term, src_list[i]);
201 /* transforming to UTF16 */
202 icu_utf16_from_utf8_cstr(buf16, list[i]->disp_term, &status);
203 icu_check_status(status);
205 /* computing sortkeys */
206 icu_sortkey8_from_utf16(coll, buf8, buf16, &status);
207 icu_check_status(status);
209 /* assigning sortkeys */
210 memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);
214 qsort(list, src_list_len, sizeof(struct icu_termmap *), icu_termmap_cmp);
216 /* checking correct sorting */
217 for (i = 0; i < src_list_len; i++)
219 if (0 != strcmp(list[i]->disp_term, chk_list[i])){
226 yaz_log(YLOG_LOG, "ERROR");
227 yaz_log(YLOG_LOG, "Input str:'%s':", locale);
228 for (i = 0; i < src_list_len; i++) {
229 yaz_log(YLOG_LOG, " '%s'", list[i]->disp_term);
231 yaz_log(YLOG_LOG, "ICU sort: '%s':", locale);
232 for (i = 0; i < src_list_len; i++) {
233 yaz_log(YLOG_LOG, " '%s'", list[i]->disp_term);
235 yaz_log(YLOG_LOG, "Expected: '%s':", locale);
236 for (i = 0; i < src_list_len; i++) {
237 yaz_log(YLOG_LOG, " '%s'", chk_list[i]);
241 for (i = 0; i < src_list_len; i++)
246 icu_buf_utf8_destroy(buf8);
247 icu_buf_utf16_destroy(buf16);
252 static void check_icu_sortmap(void)
254 /* successful tests */
256 const char *en_1_src[6] = {"z", "K", "a", "A", "Z", "k"};
257 const char *en_1_cck[6] = {"a", "A", "k", "K", "z", "Z"};
258 YAZ_CHECK(test_icu_sortmap("en", en_1_len, en_1_src, en_1_cck));
259 YAZ_CHECK(test_icu_sortmap("en_AU", en_1_len, en_1_src, en_1_cck));
260 YAZ_CHECK(test_icu_sortmap("en_CA", en_1_len, en_1_src, en_1_cck));
261 YAZ_CHECK(test_icu_sortmap("en_GB", en_1_len, en_1_src, en_1_cck));
262 YAZ_CHECK(test_icu_sortmap("en_US", en_1_len, en_1_src, en_1_cck));
264 /* successful tests */
267 const char *da_1_src[6] = {"z", "å", "o", "æ", "a", "ø"};
268 const char *da_1_cck[6] = {"a", "o", "z", "æ", "ø", "å"};
269 YAZ_CHECK(test_icu_sortmap("da", da_1_len, da_1_src, da_1_cck));
270 YAZ_CHECK(test_icu_sortmap("da_DK", da_1_len, da_1_src, da_1_cck));
272 /* successful tests */
275 const char *de_1_src[9] = {"u", "ä", "o", "t", "s", "ß", "ü", "ö", "a"};
276 const char *de_1_cck[9] = {"a","ä", "o", "ö", "s", "ß", "t", "u", "ü"};
277 YAZ_CHECK(test_icu_sortmap("de", de_1_len, de_1_src, de_1_cck));
278 YAZ_CHECK(test_icu_sortmap("de_AT", de_1_len, de_1_src, de_1_cck));
279 YAZ_CHECK(test_icu_sortmap("de_DE", de_1_len, de_1_src, de_1_cck));
283 static int test_icu_normalizer(const char *rules8cstr,
284 const char *src8cstr,
285 const char *chk8cstr)
289 UErrorCode status = U_ZERO_ERROR;
291 struct icu_buf_utf16 *src16 = icu_buf_utf16_create(0);
292 struct icu_buf_utf16 *dest16 = icu_buf_utf16_create(0);
293 struct icu_buf_utf8 *dest8 = icu_buf_utf8_create(0);
294 struct icu_transform *transform
295 = icu_transform_create(rules8cstr, 'f', 0, &status);
296 icu_check_status(status);
298 icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
299 icu_check_status(status);
301 icu_transform_trans(transform, dest16, src16, &status);
302 icu_check_status(status);
304 icu_utf16_to_utf8(dest8, dest16, &status);
305 icu_check_status(status);
308 if (!strcmp((const char *) dest8->utf8,
309 (const char *) chk8cstr))
314 yaz_log(YLOG_LOG, "Normalization");
315 yaz_log(YLOG_LOG, " Rules: '%s'", rules8cstr);
316 yaz_log(YLOG_LOG, " Input: '%s'", src8cstr);
317 yaz_log(YLOG_LOG, " Normalized: '%s'", dest8->utf8);
318 yaz_log(YLOG_LOG, " Expected: '%s'", chk8cstr);
321 icu_transform_destroy(transform);
322 icu_buf_utf16_destroy(src16);
323 icu_buf_utf16_destroy(dest16);
324 icu_buf_utf8_destroy(dest8);
329 static void check_icu_normalizer(void)
331 YAZ_CHECK(test_icu_normalizer("[:Punctuation:] Any-Remove",
335 YAZ_CHECK(test_icu_normalizer("[:Control:] Any-Remove",
339 YAZ_CHECK(test_icu_normalizer("[:Decimal_Number:] Any-Remove",
343 YAZ_CHECK(test_icu_normalizer("Lower; [:^Letter:] Remove",
347 YAZ_CHECK(test_icu_normalizer("[:^Number:] Remove",
348 "Monday 15th of April",
351 YAZ_CHECK(test_icu_normalizer("Lower;"
352 "[[:WhiteSpace:][:Punctuation:]] Remove",
356 YAZ_CHECK(test_icu_normalizer("NFD; [:Nonspacing Mark:] Remove; NFC",
357 "à côté de l'alcôve ovoïde",
358 "a cote de l'alcove ovoide"));
361 static int test_icu_tokenizer(const char *locale, char action,
362 const char *src8cstr, int count)
366 UErrorCode status = U_ZERO_ERROR;
367 struct icu_buf_utf16 *src16 = icu_buf_utf16_create(0);
368 struct icu_buf_utf16 *tkn16 = icu_buf_utf16_create(0);
369 struct icu_buf_utf8 *tkn8 = icu_buf_utf8_create(0);
370 struct icu_tokenizer *tokenizer = 0;
371 size_t org_start, org_len;
373 /* transforming to UTF16 */
374 icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
375 icu_check_status(status);
377 /* set up tokenizer */
378 tokenizer = icu_tokenizer_create(locale, action, &status);
379 icu_check_status(status);
380 YAZ_CHECK(tokenizer);
382 /* attach text buffer to tokenizer */
383 icu_tokenizer_attach(tokenizer, src16, &status);
384 icu_check_status(status);
386 /* perform work on tokens */
387 while (icu_tokenizer_next_token(tokenizer, tkn16, &status,
388 &org_start, &org_len))
390 icu_check_status(status);
392 /* converting to UTF8 */
393 icu_utf16_to_utf8(tkn8, tkn16, &status);
396 if (count != icu_tokenizer_token_count(tokenizer))
399 yaz_log(YLOG_LOG, "Tokenizer '%s:%c' Error:", locale, action);
400 yaz_log(YLOG_LOG, " Input: '%s'", src8cstr);
401 yaz_log(YLOG_LOG, " Tokens: %d", icu_tokenizer_token_count(tokenizer));
402 yaz_log(YLOG_LOG, " Expected: %d", count);
405 icu_tokenizer_destroy(tokenizer);
406 icu_buf_utf16_destroy(src16);
407 icu_buf_utf16_destroy(tkn16);
408 icu_buf_utf8_destroy(tkn8);
413 static void check_icu_tokenizer(void)
416 = "O Romeo, Romeo! wherefore art thou Romeo?";
418 YAZ_CHECK(test_icu_tokenizer("en", 's', en_str, 2));
419 YAZ_CHECK(test_icu_tokenizer("en", 'l', en_str, 7));
420 YAZ_CHECK(test_icu_tokenizer("en", 'w', en_str, 16));
421 YAZ_CHECK(test_icu_tokenizer("en", 'c', en_str, 41));
425 = "Blåbærtærte. Denne kage stammer fra Finland. "
426 "Den er med blåbær, men alle sommerens forskellige bær kan bruges.";
428 YAZ_CHECK(test_icu_tokenizer("da", 's', da_str, 3));
429 YAZ_CHECK(test_icu_tokenizer("dar", 'l', da_str, 17));
430 YAZ_CHECK(test_icu_tokenizer("da", 'w', da_str, 37));
431 YAZ_CHECK(test_icu_tokenizer("da", 'c', da_str, 110));
435 static void check_icu_chain(void)
438 = "O Romeo, Romeo! wherefore art thou\t Romeo?";
440 UErrorCode status = U_ZERO_ERROR;
441 struct icu_chain *chain = 0;
443 const char *xml_str = "<icu locale=\"en\">"
444 "<transform rule=\"[:Control:] Any-Remove\"/>"
445 "<tokenize rule=\"l\"/>"
446 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
448 "<casemap rule=\"l\"/>"
452 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
453 xmlNode *xml_node = xmlDocGetRootElement(doc);
456 chain = icu_chain_xml_config(xml_node, 0, &status);
463 YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &status));
465 while (icu_chain_next_token(chain, &status))
467 yaz_log(YLOG_LOG, "%d '%s' '%s'",
468 icu_chain_token_number(chain),
469 icu_chain_token_norm(chain),
470 icu_chain_token_display(chain));
473 YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
476 YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
478 while (icu_chain_next_token(chain, &status))
480 yaz_log(YLOG_LOG, "%d '%s' '%s'",
481 icu_chain_token_number(chain),
482 icu_chain_token_norm(chain),
483 icu_chain_token_display(chain));
487 YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
489 icu_chain_destroy(chain);
493 static void check_bug_1140(void)
495 UErrorCode status = U_ZERO_ERROR;
496 struct icu_chain *chain = 0;
498 const char *xml_str = "<icu locale=\"en\">"
500 /* if the first rule is normalize instead. Then it works */
502 "<transform rule=\"[:Control:] Any-Remove\"/>"
504 "<tokenize rule=\"l\"/>"
505 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
507 "<casemap rule=\"l\"/>"
511 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
512 xmlNode *xml_node = xmlDocGetRootElement(doc);
515 chain = icu_chain_xml_config(xml_node, 0, &status);
522 YAZ_CHECK(icu_chain_assign_cstr(
523 chain, "O Romeo, Romeo! wherefore art thou\t Romeo?",
526 while (icu_chain_next_token(chain, &status))
529 /* printf("%d '%s' '%s'\n",
530 icu_chain_token_number(chain),
531 icu_chain_token_norm(chain),
532 icu_chain_token_display(chain)); */
536 YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
538 YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
540 while (icu_chain_next_token(chain, &status))
543 /* printf("%d '%s' '%s'\n",
544 icu_chain_token_number(chain),
545 icu_chain_token_norm(chain),
546 icu_chain_token_display(chain)); */
549 /* we expect 'what' 'is' 'this', i.e. 3 tokens */
550 YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
552 icu_chain_destroy(chain);
556 static void check_chain_empty_token(void)
558 UErrorCode status = U_ZERO_ERROR;
559 struct icu_chain *chain = 0;
561 const char *xml_str = "<icu locale=\"en\">"
562 "<tokenize rule=\"w\"/>"
563 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
566 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
567 xmlNode *xml_node = xmlDocGetRootElement(doc);
570 chain = icu_chain_xml_config(xml_node, 0, &status);
575 YAZ_CHECK(icu_chain_assign_cstr(
576 chain, "a string with 15 tokenss and 8 displays",
579 while (icu_chain_next_token(chain, &status))
582 /* printf("%d '%s' '%s'\n",
583 icu_chain_token_number(chain),
584 icu_chain_token_norm(chain),
585 icu_chain_token_display(chain)); */
588 YAZ_CHECK_EQ(icu_chain_token_number(chain), 15);
590 icu_chain_destroy(chain);
593 static void check_chain_empty_chain(void)
595 UErrorCode status = U_ZERO_ERROR;
596 struct icu_chain *chain = 0;
598 const char *xml_str = "<icu locale=\"en\">"
601 const char *src8 = "some 5487 weired !¤%&(/& sTuFf";
604 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
605 xmlNode *xml_node = xmlDocGetRootElement(doc);
608 chain = icu_chain_xml_config(xml_node, 0, &status);
613 YAZ_CHECK(icu_chain_assign_cstr(
617 while (icu_chain_next_token(chain, &status))
620 /* printf("%d '%s' '%s'\n",
621 icu_chain_token_number(chain),
622 icu_chain_token_norm(chain),
623 icu_chain_token_display(chain)); */
626 YAZ_CHECK_EQ(icu_chain_token_number(chain), 1);
628 dest8 = (char *) icu_chain_token_norm(chain);
629 YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
631 icu_chain_destroy(chain);
634 static void check_icu_iter1(void)
636 UErrorCode status = U_ZERO_ERROR;
637 struct icu_chain *chain = 0;
641 const char *xml_str = "<icu locale=\"en\">"
642 "<tokenize rule=\"w\"/>"
643 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
646 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
650 xml_node = xmlDocGetRootElement(doc);
655 chain = icu_chain_xml_config(xml_node, 1, &status);
660 iter = icu_iter_create(chain);
661 icu_iter_first(iter, "a string with 15 tokens and 8 displays");
665 while (icu_iter_next(iter))
667 yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
669 icu_iter_destroy(iter);
670 icu_chain_destroy(chain);
673 static int test_iter(struct icu_chain *chain, const char *input,
674 const char *expected)
676 yaz_icu_iter_t iter = icu_iter_create(chain);
677 WRBUF result, second, sort_result;
682 yaz_log(YLOG_WARN, "test_iter: input=%s !iter", input);
686 if (icu_iter_next(iter))
688 yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
692 sort_result = wrbuf_alloc();
693 result = wrbuf_alloc();
694 icu_iter_first(iter, input);
695 while (icu_iter_next(iter))
697 const char *sort_str = icu_iter_get_sortkey(iter);
700 wrbuf_puts(sort_result, "[");
701 wrbuf_puts_escaped(sort_result, sort_str);
702 wrbuf_puts(sort_result, "]");
706 wrbuf_puts(sort_result, "[NULL]");
708 wrbuf_puts(result, "[");
709 wrbuf_puts(result, icu_iter_get_norm(iter));
710 wrbuf_puts(result, "]");
712 yaz_log(YLOG_LOG, "sortkey=%s", wrbuf_cstr(sort_result));
713 second = wrbuf_alloc();
714 icu_iter_first(iter, input);
715 while (icu_iter_next(iter))
717 wrbuf_puts(second, "[");
718 wrbuf_puts(second, icu_iter_get_norm(iter));
719 wrbuf_puts(second, "]");
722 icu_iter_destroy(iter);
724 if (strcmp(expected, wrbuf_cstr(result)))
726 yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
727 input, expected, wrbuf_cstr(result));
731 if (strcmp(expected, wrbuf_cstr(second)))
733 yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s (2nd)",
734 input, expected, wrbuf_cstr(second));
738 wrbuf_destroy(result);
739 wrbuf_destroy(second);
740 wrbuf_destroy(sort_result);
744 static void *iter_thread(void *p)
746 struct icu_chain *chain = (struct icu_chain *) p;
749 for (i = 0; i < 1000; i++)
751 YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
752 "[adobe][acrobat][reader][1991][][1999][]"));
757 static void check_iter_threads(struct icu_chain *chain)
759 #if YAZ_POSIX_THREADS
762 pthread_t t[NO_THREADS];
765 for (i = 0; i < NO_THREADS; i++)
766 pthread_create(t + i, 0, iter_thread, chain);
768 for (i = 0; i < NO_THREADS; i++)
769 pthread_join(t[i], 0);
773 static void check_icu_iter2(void)
775 UErrorCode status = U_ZERO_ERROR;
776 struct icu_chain *chain = 0;
779 const char *xml_str = "<icu locale=\"en\">"
780 "<transform rule=\"[:Control:] Any-Remove\"/>"
781 "<tokenize rule=\"l\"/>"
782 "<tokenize rule=\"w\"/>"
783 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
785 "<casemap rule=\"l\"/>"
788 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
792 xml_node = xmlDocGetRootElement(doc);
797 chain = icu_chain_xml_config(xml_node, 1, &status);
804 YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
805 "[adobe][acrobat][reader][1991][][1999][]"));
807 YAZ_CHECK(test_iter(chain, "Νόταρης, Γιάννης Σωτ",
808 "[νόταρης][γιάννης][σωτ]"));
810 check_iter_threads(chain);
812 icu_chain_destroy(chain);
815 static void check_icu_iter3(void)
817 UErrorCode status = U_ZERO_ERROR;
818 struct icu_chain *chain = 0;
821 const char *xml_str =
822 "<icu_chain id=\"sort\" locale=\"el\">\n"
823 "<transform rule=\"[:Control:] Any-Remove\"/>\n"
824 "<transform rule=\"[[:Control:][:WhiteSpace:][:Punctuation:]] Remove\"/>\n"
825 "<transform rule=\"NFD; [:Nonspacing Mark:] Remove; NFC\"/>\n"
826 "<casemap rule=\"l\"/>\n"
830 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
834 xml_node = xmlDocGetRootElement(doc);
839 chain = icu_chain_xml_config(xml_node, 1, &status);
846 YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
847 "[adobeacrobatreader19911999]"));
849 YAZ_CHECK(test_iter(chain, "Νόταρης, Γιάννης Σωτ",
850 "[νοταρηςγιαννηςσωτ]"));
852 icu_chain_destroy(chain);
856 static void check_icu_iter4(void)
858 UErrorCode status = U_ZERO_ERROR;
859 struct icu_chain *chain = 0;
862 const char *xml_str = "<icu locale=\"en\">"
863 "<transform rule=\"[:Control:] Any-Remove\"/>"
864 "<tokenize rule=\"l\"/>"
865 "<tokenize rule=\"w\"/>"
866 "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
868 "<casemap rule=\"l\"/>"
872 xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
876 xml_node = xmlDocGetRootElement(doc);
881 chain = icu_chain_xml_config(xml_node, 1, &status);
888 YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
889 "[adobeacrobatreader19911999]"));
891 YAZ_CHECK(test_iter(chain, "Νόταρης, Γιάννης Σωτ",
892 "[νόταρηςγιάννηςσωτ]"));
894 // check_iter_threads(chain);
896 icu_chain_destroy(chain);
900 #endif /* YAZ_HAVE_ICU */
902 int main(int argc, char **argv)
904 YAZ_CHECK_INIT(argc, argv);
911 check_icu_normalizer();
912 check_icu_tokenizer();
914 check_chain_empty_token();
915 check_chain_empty_chain();
928 #else /* YAZ_HAVE_ICU */
930 yaz_log(YLOG_LOG, "ICU unit tests omitted");
933 #endif /* YAZ_HAVE_ICU */
941 * c-file-style: "Stroustrup"
942 * indent-tabs-mode: nil
944 * vim: shiftwidth=4 tabstop=8 expandtab