+ xmlFreeDoc(doc);
+ YAZ_CHECK(chain);
+
+ iter = icu_iter_create(chain);
+ icu_iter_first(iter, "a string with 15 tokens and 8 displays");
+ YAZ_CHECK(iter);
+ if (!iter)
+ return;
+ while (icu_iter_next(iter))
+ {
+ yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
+ }
+ icu_iter_destroy(iter);
+ icu_chain_destroy(chain);
+}
+
+static int test_iter(struct icu_chain *chain, const char *input,
+ const char *expected)
+{
+ yaz_icu_iter_t iter = icu_iter_create(chain);
+ WRBUF result, second;
+ int success = 1;
+
+ if (!iter)
+ {
+ yaz_log(YLOG_WARN, "test_iter: input=%s !iter", input);
+ return 0;
+ }
+
+ if (icu_iter_next(iter))
+ {
+ yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
+ return 0;
+ }
+
+ result = wrbuf_alloc();
+ icu_iter_first(iter, input);
+ while (icu_iter_next(iter))
+ {
+ wrbuf_puts(result, "[");
+ wrbuf_puts(result, icu_iter_get_norm(iter));
+ wrbuf_puts(result, "]");
+ }
+
+ second = wrbuf_alloc();
+ icu_iter_first(iter, input);
+ while (icu_iter_next(iter))
+ {
+ wrbuf_puts(second, "[");
+ wrbuf_puts(second, icu_iter_get_norm(iter));
+ wrbuf_puts(second, "]");
+ }
+
+ icu_iter_destroy(iter);
+
+ if (strcmp(expected, wrbuf_cstr(result)))
+ {
+ yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
+ input, expected, wrbuf_cstr(result));
+ success = 0;
+ }
+
+ if (strcmp(expected, wrbuf_cstr(second)))
+ {
+ yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s (2nd)",
+ input, expected, wrbuf_cstr(second));
+ success = 0;
+ }
+
+ wrbuf_destroy(result);
+ wrbuf_destroy(second);
+ return success;
+}
+
+static void *iter_thread(void *p)
+{
+ struct icu_chain *chain = (struct icu_chain *) p;
+ int i;
+
+ for (i = 0; i < 10000; i++)
+ {
+ YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
+ "[adobe][acrobat][reader][1991][][1999][]"));
+ }
+ return 0;
+}
+
+static void check_iter_threads(struct icu_chain *chain)
+{
+#if YAZ_POSIX_THREADS
+#define NO_THREADS 1
+
+ pthread_t t[NO_THREADS];
+ int i;
+
+ for (i = 0; i < NO_THREADS; i++)
+ pthread_create(t + i, 0, iter_thread, chain);
+
+ for (i = 0; i < NO_THREADS; i++)
+ pthread_join(t[i], 0);
+#endif
+}
+static void check_icu_iter2(void)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ struct icu_chain * chain = 0;
+ xmlNode *xml_node;
+
+ const char * xml_str = "<icu locale=\"en\">"
+ "<transform rule=\"[:Control:] Any-Remove\"/>"
+ "<tokenize rule=\"l\"/>"
+ "<tokenize rule=\"w\"/>"
+ "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+ "<display/>"
+ "<casemap rule=\"l\"/>"
+ "</icu>";
+
+ xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+ YAZ_CHECK(doc);
+ if (!doc)
+ return;
+ xml_node = xmlDocGetRootElement(doc);
+ YAZ_CHECK(xml_node);
+ if (!xml_node)
+ return ;
+
+ chain = icu_chain_xml_config(xml_node, 0, &status);
+
+ xmlFreeDoc(doc);
+ YAZ_CHECK(chain);
+
+ YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
+ "[adobe][acrobat][reader][1991][][1999][]"));
+
+ check_iter_threads(chain);
+
+ icu_chain_destroy(chain);
+}
+
+#endif /* YAZ_HAVE_ICU */
+
+int main(int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_LOG();
+
+#if YAZ_HAVE_ICU
+
+ check_icu_casemap();
+ check_icu_sortmap();
+ check_icu_normalizer();
+ check_icu_tokenizer();
+ check_icu_chain();
+ check_chain_empty_token();
+ check_chain_empty_chain();
+ check_icu_iter1();
+ check_icu_iter2();
+
+ check_bug_1140();
+
+#else /* YAZ_HAVE_ICU */
+
+ yaz_log(YLOG_LOG, "ICU unit tests omitted");
+ YAZ_CHECK(0 == 0);
+
+#endif /* YAZ_HAVE_ICU */
+
+ YAZ_CHECK_TERM;
+}