added special case with an empty ICU chain for 'raw' index processing without call...
[yaz-moved-to-github.git] / test / tst_icu_I18N.c
index cbef9e8..a00e15c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tst_icu_I18N.c,v 1.8 2007-10-25 08:42:21 marc Exp $
+/* $Id: tst_icu_I18N.c,v 1.9 2007-10-25 10:04:33 marc Exp $
    Copyright (c) 2006-2007, Index Data.
 
    This file is part of Pazpar2.
@@ -641,6 +641,47 @@ void test_chain_empty_token(void)
     icu_chain_destroy(chain);
 }
 
+void test_chain_empty_chain(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+
+    const char * xml_str = "<icu>"
+        "</icu>";
+    
+    const char * src8 = "some 5487 weired !ยค%&(/& sTuFf";
+    char * dest8 = 0;
+
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+    chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    YAZ_CHECK(icu_chain_assign_cstr(
+                  chain,  src8,
+                  &status));
+
+    while (icu_chain_next_token(chain, &status)){
+        ;
+        //printf("%d '%s' '%s'\n",
+        //       icu_chain_get_token_count(chain),
+        //       icu_chain_get_norm(chain),
+        //       icu_chain_get_display(chain));
+    }
+
+    YAZ_CHECK_EQ(icu_chain_get_token_count(chain), 1);
+
+    dest8 = icu_chain_get_norm(chain);
+    YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
+    
+
+    icu_chain_destroy(chain);
+}
+
 #endif // HAVE_ICU
 
 /* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
@@ -659,6 +700,7 @@ int main(int argc, char **argv)
     test_icu_I18N_tokenizer(argc, argv);
     test_icu_I18N_chain(argc, argv);
     test_chain_empty_token();
+    test_chain_empty_chain();
     test_bug_1140();
 
 #else /* HAVE_ICU */