Test files for libxml2 output
[yaz-moved-to-github.git] / test / tst_icu_I18N.c
index 484e9cc..2ad005c 100644 (file)
@@ -455,11 +455,10 @@ static void check_icu_chain(void)
 
     while (icu_chain_next_token(chain, &status))
     {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
+        yaz_log(YLOG_LOG, "%d '%s' '%s'",
+                icu_chain_token_number(chain),
+                icu_chain_token_norm(chain),
+                icu_chain_token_display(chain));
     }
 
     YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
@@ -469,11 +468,10 @@ static void check_icu_chain(void)
 
     while (icu_chain_next_token(chain, &status))
     {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
+        yaz_log(YLOG_LOG, "%d '%s' '%s'",
+                icu_chain_token_number(chain),
+                icu_chain_token_norm(chain),
+                icu_chain_token_display(chain));
     }
 
 
@@ -627,8 +625,7 @@ static void check_icu_iter1(void)
     UErrorCode status = U_ZERO_ERROR;
     struct icu_chain * chain = 0;
     xmlNode *xml_node;
-    struct icu_iter *iter;
-    struct icu_buf_utf8 *token;
+    yaz_icu_iter_t iter;
 
     const char * xml_str = "<icu locale=\"en\">"
         "<tokenize rule=\"w\"/>"
@@ -649,17 +646,15 @@ static void check_icu_iter1(void)
     xmlFreeDoc(doc);
     YAZ_CHECK(chain);
     
-    iter = icu_iter_create(chain, "a string with 15 tokens and 8 displays");
+    iter = icu_iter_create(chain);
+    icu_iter_first(iter, "a string with 15 tokens and 8 displays");
     YAZ_CHECK(iter);
     if (!iter)
         return;
-    token = icu_buf_utf8_create(0);
-    while (icu_iter_next(iter, token))
+    while (icu_iter_next(iter))
     {
-        yaz_log(YLOG_LOG, "[%.*s]", (int) token->utf8_len, token->utf8);
+        yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
     }
-    icu_buf_utf8_destroy(token);
-
     icu_iter_destroy(iter);
     icu_chain_destroy(chain);
 }
@@ -667,9 +662,9 @@ static void check_icu_iter1(void)
 static int test_iter(struct icu_chain *chain, const char *input,
                      const char *expected)
 {
-    struct icu_iter *iter = icu_iter_create(chain, input);
-    WRBUF result;
-    struct icu_buf_utf8 *token;
+    yaz_icu_iter_t iter = icu_iter_create(chain);
+    WRBUF result, second;
+    int success = 1;
 
     if (!iter)
     {
@@ -677,15 +672,29 @@ static int test_iter(struct icu_chain *chain, const char *input,
         return 0;
     }
 
-    token = icu_buf_utf8_create(0);
+    if (icu_iter_next(iter))
+    {
+        yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
+        return 0;
+    }
+
     result = wrbuf_alloc();
-    while (icu_iter_next(iter, token))
+    icu_iter_first(iter, input);
+    while (icu_iter_next(iter))
     {
         wrbuf_puts(result, "[");
-        wrbuf_write(result, (const char *) token->utf8, (int) token->utf8_len);
+        wrbuf_puts(result, icu_iter_get_norm(iter));
         wrbuf_puts(result, "]");
     }
-    icu_buf_utf8_destroy(token);
+
+    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);
 
@@ -693,11 +702,19 @@ static int test_iter(struct icu_chain *chain, const char *input,
     {
         yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
                 input, expected, wrbuf_cstr(result));
-        wrbuf_destroy(result);
-        return 0;
+        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);
-    return 1;
+    wrbuf_destroy(second);
+    return success;
 }
 
 static void *iter_thread(void *p)