ICU chain XML configuration up and running, used in unit test as well.
[pazpar2-moved-to-github.git] / src / test_icu_I18N.c
index 93428ad..4e976eb 100644 (file)
@@ -1,23 +1,23 @@
-/* $Id: test_icu_I18N.c,v 1.9 2007-05-07 12:18:34 marc Exp $
+/* $Id: test_icu_I18N.c,v 1.23 2007-05-21 10:14:08 marc Exp $
    Copyright (c) 2006-2007, Index Data.
 
-This file is part of Pazpar2.
+   This file is part of Pazpar2.
 
-Pazpar2 is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+   Pazpar2 is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 2, or (at your option) any later
+   version.
 
-Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+   Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
 
-You should have received a copy of the GNU General Public License
-along with Pazpar2; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+   You should have received a copy of the GNU General Public License
+   along with Pazpar2; see the file LICENSE.  If not, write to the
+   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.
+*/
 
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
  
@@ -41,12 +41,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <string.h>
 #include <stdlib.h>
 
-#include <unicode/ustring.h>  
+//#include <unicode/ustring.h>  
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
 
 #define MAX_KEY_SIZE 256
-
 struct icu_termmap
 {
     uint8_t sort_key[MAX_KEY_SIZE]; // standard C string '\0' terminated
@@ -69,88 +68,6 @@ int icu_termmap_cmp(const void *vp1, const void *vp2)
 
 
 
-int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
-                      struct icu_buf_utf16 * src16,
-                      const char *locale, char action,
-                      UErrorCode *status)
-{
-    int32_t dest16_len = 0;
-    
-    switch(action) {    
-    case 'l':    
-        dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
-                                  src16->utf16, src16->utf16_len, 
-                                  locale, status);
-        break;
-    case 'u':    
-        dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
-                                  src16->utf16, src16->utf16_len, 
-                                  locale, status);
-        break;
-    case 't':    
-        dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
-                                  src16->utf16, src16->utf16_len,
-                                  0, locale, status);
-        break;
-    case 'f':    
-        dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
-                                   src16->utf16, src16->utf16_len,
-                                   U_FOLD_CASE_DEFAULT, status);
-        break;
-        
-    default:
-        return U_UNSUPPORTED_ERROR;
-        break;
-    }
-
-    // check for buffer overflow, resize and retry
-    if (*status == U_BUFFER_OVERFLOW_ERROR
-        //|| dest16_len > dest16->utf16_cap
-        ){
-        icu_buf_utf16_resize(dest16, dest16_len * 2);
-        *status = U_ZERO_ERROR;
-
-    
-        switch(action) {    
-        case 'l':    
-            dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
-                                      src16->utf16, src16->utf16_len, 
-                                      locale, status);
-            break;
-        case 'u':    
-            dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
-                                      src16->utf16, src16->utf16_len, 
-                                      locale, status);
-            break;
-        case 't':    
-            dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
-                                      src16->utf16, src16->utf16_len,
-                                      0, locale, status);
-            break;
-        case 'f':    
-        dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
-                                   src16->utf16, src16->utf16_len,
-                                   U_FOLD_CASE_DEFAULT, status);
-        break;
-        
-        default:
-            return U_UNSUPPORTED_ERROR;
-            break;
-        }
-    }
-    
-    if (U_SUCCESS(*status)
-        && dest16_len < dest16->utf16_cap)
-        dest16->utf16_len = dest16_len;
-    else {
-        dest16->utf16[0] = (UChar) 0;
-        dest16->utf16_len = 0;
-    }
-  
-    return *status;
-};
-
-
 
 int test_icu_casemap(const char * locale, char action,
                      const char * src8cstr, const char * chk8cstr)
@@ -207,42 +124,6 @@ int test_icu_casemap(const char * locale, char action,
 
 
 
-#if 0
-
-int test_icu_casemap(const char * locale, char action,
-                     const char * src8, const char * check8)
-{
-    NMEM nmem = nmem_create();    
-    size_t buf_cap = 128;
-    char buf[buf_cap];
-    const char * dest8 = 0;
-    size_t dest8_len = 0;
-    //size_t src8_len = strlen(src8);
-    int sucess = 0;
-
-    //printf("original string:   '%s' (%d)\n", src8, (int) src8_len);
-
-    //these shall succeed
-    dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
-                        src8, locale, action);
-
-
-    //printf("icu_casemap '%s:%c' '%s' (%d)\n", 
-    //       locale, action, dest8, (int) dest8_len);
-
-    if (dest8 
-        && (dest8_len == strlen(check8))
-        && !strcmp(check8, dest8))
-        sucess = dest8_len;
-
-    nmem_destroy(nmem);
-
-    return sucess;
-}
-
-#endif
-
-
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
 void test_icu_I18N_casemap(int argc, char **argv)
@@ -291,152 +172,26 @@ void test_icu_I18N_casemap(int argc, char **argv)
 
     // sucess expected    
     YAZ_CHECK(test_icu_casemap("de", 'l',
-                          "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                          "zwölf ärgerliche würste rollen über die straße"));
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "zwölf ärgerliche würste rollen über die straße"));
 
     YAZ_CHECK(test_icu_casemap("de", 'u',
-                           "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                           "ZWÖLF ÄRGERLICHE WÜRSTE ROLLEN ÜBER DIE STRASSE"));
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "ZWÖLF ÄRGERLICHE WÜRSTE ROLLEN ÜBER DIE STRASSE"));
 
     YAZ_CHECK(test_icu_casemap("de", 'f',
-                           "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                           "zwölf ärgerliche würste rollen über die strasse"));
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "zwölf ärgerliche würste rollen über die strasse"));
 
     YAZ_CHECK(test_icu_casemap("de", 't',
-                           "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                           "Zwölf Ärgerliche Würste Rollen Über Die Straße"));
-
-}
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "Zwölf Ärgerliche Würste Rollen Über Die Straße"));
 
-
-#if 0
-
-// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
-
-void test_icu_I18N_casemap_failures(int argc, char **argv)
-{
-
-    size_t buf_cap = 128;
-    char buf[buf_cap];
-    size_t dest8_len = 0;
-    NMEM nmem = nmem_create();
-    char * dest8 = 0;
-
-    const char * src8 =  "A ReD fOx hunTS sQUirriLs";
-    //size_t src8_len = strlen(src8);
-    
-    //printf("original string:   '%s' (%d)\n", src8, (int) src8_len);
-
-    // some calling error needs investigation
-    dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
-                        src8, "en", 't');
-    YAZ_CHECK(0 == dest8_len);
-    //printf("icu_casemap 'en:t' '%s' (%d)\n", dest8, (int) dest8_len);
-
-
-    // attention: does not fail even if no locale 'xy_zz' defined
-    // it seems to default to english locale
-    dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
-                        src8, "zz_abc", 'l');
-    YAZ_CHECK(dest8_len);
-    //printf("icu_casemap 'zz:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
-
-    // shall fail - no buf buffer defined
-    dest8 = icu_casemap(nmem, 0, buf_cap, &dest8_len,
-                        src8, "en", 'l');
-    YAZ_CHECK(0 == dest8_len);
-    //printf("icu_casemap 'en:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
-    // shall fail - no buf_cap  defined
-    dest8 = icu_casemap(nmem, buf, 0, &dest8_len,
-                        src8, "en", 'l');
-    YAZ_CHECK(0 == dest8_len);
-    //printf("icu_casemap 'en:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
-    // shall fail - no action 'x' defined
-    dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
-                        src8, "en", 'x');
-    YAZ_CHECK(0 == dest8_len);
-    //printf("icu_casemap 'en:x' '%s' (%d)\n", dest8, (int) dest8_len);
-
-    nmem_destroy(nmem);
 }
 
 
-
-#endif
-
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
-#if 0
-int test_icu_sortmap(const char * locale, size_t list_len,
-                     const char ** src8_list, const char ** check8_list)
-{
-    int sucess = 1;
-
-    size_t i = 0;
-
-
-    NMEM nmem = nmem_create();    
-    size_t buf_cap = 128;
-    char buf[buf_cap];
-    struct icu_termmap ** dest8_list 
-        = nmem_malloc(nmem, sizeof(struct icu_termmap *) * list_len);
-    //size_t dest8_len = 0;
-    //size_t src8_len = strlen(src8);
-
-    // initializing icu_termmap
-    for (i = 0; i < list_len; i++){
-        dest8_list[i] = icu_termmap_create(nmem);
-        dest8_list[i]->norm_term = nmem_strdup(nmem, src8_list[i]); 
-        dest8_list[i]->disp_term = nmem_strdup(nmem, src8_list[i]);
-        //dest8_list[i]->sort_key =  nmem_strdup(nmem, src8_list[i]);
-        //dest8_list[i]->sort_len =  strlen(src8_list[i]);
-        dest8_list[i]->sort_key 
-            = icu_sortmap(nmem, buf, buf_cap, 0, src8_list[i], locale);
-        // = icu_sortmap(nmem, buf, buf_cap, &(dest8_list[i]->sort_len),
-        //                  src8_list[i], locale);
-    }
-
-    // do the sorting
-    qsort(dest8_list, list_len, 
-          sizeof(struct icu_termmap *), icu_termmap_cmp);
-
-    // checking correct sorting
-    for (i = 0; i < list_len; i++){
-        if (0 != strcmp(dest8_list[i]->disp_term, check8_list[i])){
-            sucess = 0;
-        }
-    }
-
-    if (1 || !sucess){
-        printf("\n");
-        printf("Input    '%s':", locale);
-        for (i = 0; i < list_len; i++)
-            printf(" '%s'", src8_list[i]);
-        printf("\n");        
-        printf("ICU sort '%s':", locale);
-        for (i = 0; i < list_len; i++)
-            printf(" '%s'", dest8_list[i]->disp_term);
-        if (sucess)
-            printf(" OK");
-        else
-            printf(" ERROR ??");
-        printf("\n");
-        printf("Expected '%s':", locale);
-        for (i = 0; i < list_len; i++)
-            printf(" '%s'", check8_list[i]);
-        printf("\n");        
-    }
-    
-    nmem_destroy(nmem);
-
-    return sucess;
-}
-
-#else
-
 int test_icu_sortmap(const char * locale, int src_list_len,
                      const char ** src_list, const char ** chk_list)
 {
@@ -444,89 +199,89 @@ int test_icu_sortmap(const char * locale, int src_list_len,
 
     UErrorCode status = U_ZERO_ERROR;
 
-  struct icu_buf_utf8 * buf8 = icu_buf_utf8_create(0);
-  struct icu_buf_utf16 * buf16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf8 * buf8 = icu_buf_utf8_create(0);
+    struct icu_buf_utf16 * buf16 = icu_buf_utf16_create(0);
 
-  int i;
+    int i;
 
-  struct icu_termmap * list[src_list_len];
+    struct icu_termmap * list[src_list_len];
 
-  UCollator *coll = ucol_open(locale, &status); 
-  icu_check_status(status);
+    UCollator *coll = ucol_open(locale, &status); 
+    icu_check_status(status);
 
-  if(!U_SUCCESS(status))
-    return 0;
+    if(U_FAILURE(status))
+        return 0;
 
-  // assigning display terms and sort keys using buf 8 and buf16
-  for( i = 0; i < src_list_len; i++) 
-    {
+    // assigning display terms and sort keys using buf 8 and buf16
+    for( i = 0; i < src_list_len; i++) 
+        {
 
-      list[i] = (struct icu_termmap *) malloc(sizeof(struct icu_termmap));
+            list[i] = (struct icu_termmap *) malloc(sizeof(struct icu_termmap));
 
-      // copy display term
-      strcpy(list[i]->disp_term, src_list[i]);    
+            // copy display term
+            strcpy(list[i]->disp_term, src_list[i]);    
 
-      // transforming to UTF16
-      icu_utf16_from_utf8_cstr(buf16, list[i]->disp_term, &status);
-      icu_check_status(status);
+            // transforming to UTF16
+            icu_utf16_from_utf8_cstr(buf16, list[i]->disp_term, &status);
+            icu_check_status(status);
 
-      // computing sortkeys
-      icu_sortkey8_from_utf16(coll, buf8, buf16, &status);
-      icu_check_status(status);
+            // computing sortkeys
+            icu_sortkey8_from_utf16(coll, buf8, buf16, &status);
+            icu_check_status(status);
     
-      // assigning sortkeys
-      memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
-      //strncpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
-      //strcpy((char *) list[i]->sort_key, (const char *) buf8->utf8);
-    } 
+            // assigning sortkeys
+            memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
+            //strncpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
+            //strcpy((char *) list[i]->sort_key, (const char *) buf8->utf8);
+        } 
 
 
-  // do the sorting
-  qsort(list, src_list_len, 
-        sizeof(struct icu_termmap *), icu_termmap_cmp);
+    // do the sorting
+    qsort(list, src_list_len, 
+          sizeof(struct icu_termmap *), icu_termmap_cmp);
 
-  // checking correct sorting
-  for (i = 0; i < src_list_len; i++){
-    if (0 != strcmp(list[i]->disp_term, chk_list[i])){
-      success = 0;
+    // checking correct sorting
+    for (i = 0; i < src_list_len; i++){
+        if (0 != strcmp(list[i]->disp_term, chk_list[i])){
+            success = 0;
+        }
+    }
+
+    if(!success){
+        printf("\nERROR\n"); 
+        printf("Input str: '%s' : ", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            printf(" '%s'", list[i]->disp_term); 
+        }
+        printf("\n");
+        printf("ICU sort:  '%s' : ", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            printf(" '%s'", list[i]->disp_term); 
+            //printf("(%d|%d)", list[i]->sort_key[0],list[i]->sort_key[1]); 
+        }
+        printf("\n"); 
+        printf("Expected:  '%s' : ", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            printf(" '%s'", chk_list[i]); 
+        }
+        printf("\n"); 
     }
-  }
-
-  if(!success){
-  printf("\nERROR\n"); 
-  printf("Input str: '%s' : ", locale); 
-  for (i = 0; i < src_list_len; i++) {
-    printf(" '%s'", list[i]->disp_term); 
-  }
-  printf("\n");
-  printf("ICU sort:  '%s' : ", locale); 
-  for (i = 0; i < src_list_len; i++) {
-    printf(" '%s'", list[i]->disp_term); 
-    //printf("(%d|%d)", list[i]->sort_key[0],list[i]->sort_key[1]); 
-  }
-  printf("\n"); 
-  printf("Expected:  '%s' : ", locale); 
-  for (i = 0; i < src_list_len; i++) {
-    printf(" '%s'", chk_list[i]); 
-  }
-  printf("\n"); 
-  }
-  
   
-  ucol_close(coll);
 
-  icu_buf_utf8_destroy(buf8);
-  icu_buf_utf16_destroy(buf16);
 
+    for( i = 0; i < src_list_len; i++)
+        free(list[i]);
+        
+    
+    ucol_close(coll);
 
+    icu_buf_utf8_destroy(buf8);
+    icu_buf_utf16_destroy(buf16);
 
     return success;  
 }
 
 
-#endif
-
-
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
 void test_icu_I18N_sortmap(int argc, char **argv)
@@ -560,7 +315,268 @@ void test_icu_I18N_sortmap(int argc, char **argv)
 }
 
 
-#endif    
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+
+
+
+int test_icu_normalizer(const char * rules8cstr,
+                            const char * src8cstr,
+                            const char * chk8cstr)
+{
+    int success = 0;
+    
+    UErrorCode status = U_ZERO_ERROR;
+
+    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
+    struct icu_normalizer * normalizer
+        = icu_normalizer_create(rules8cstr, 'f', &status);
+    icu_check_status(status);
+    
+    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+    icu_check_status(status);
+
+    icu_normalizer_normalize(normalizer, dest16, src16, &status);
+    icu_check_status(status);
+
+    icu_utf16_to_utf8(dest8, dest16, &status);
+    icu_check_status(status);
+
+
+    if(!strcmp((const char *) dest8->utf8, 
+               (const char *) chk8cstr))
+        success = 1;
+    else {
+        success = 0;
+        printf("Normalization\n");
+        printf("Rules:      '%s'\n", rules8cstr);
+        printf("Input:      '%s'\n", src8cstr);
+        printf("Normalized: '%s'\n", dest8->utf8);
+        printf("Expected:   '%s'\n", chk8cstr);
+    }
+    
+
+    icu_normalizer_destroy(normalizer);
+    icu_buf_utf16_destroy(src16);
+    icu_buf_utf16_destroy(dest16);
+    icu_buf_utf8_destroy(dest8);
+
+    return success;
+};
+
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+void test_icu_I18N_normalizer(int argc, char **argv)
+{
+
+    YAZ_CHECK(test_icu_normalizer("[:Punctuation:] Any-Remove",
+                                  "Don't shoot!",
+                                  "Dont shoot"));
+    
+    YAZ_CHECK(test_icu_normalizer("[:Control:] Any-Remove",
+                                  "Don't\n shoot!",
+                                  "Don't shoot!"));
+
+    YAZ_CHECK(test_icu_normalizer("[:Decimal_Number:] Any-Remove",
+                                  "This is 4 you!",
+                                  "This is  you!"));
+
+    YAZ_CHECK(test_icu_normalizer("Lower; [:^Letter:] Remove",
+                                  "Don't shoot!",
+                                  "dontshoot"));
+    
+    YAZ_CHECK(test_icu_normalizer("[:^Number:] Remove",
+                                  "Monday 15th of April",
+                                  "15"));
+
+    YAZ_CHECK(test_icu_normalizer("Lower;"
+                                  "[[:WhiteSpace:][:Punctuation:]] Remove",
+                                  " word4you? ",
+                                  "word4you"));
+
+
+    YAZ_CHECK(test_icu_normalizer("NFD; [:Nonspacing Mark:] Remove; NFC",
+                                  "à côté de l'alcôve ovoïde",
+                                  "a cote de l'alcove ovoide"));
+
+}
+
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+int test_icu_tokenizer(const char * locale, char action,
+                     const char * src8cstr, int count)
+{
+    int success = 1;
+
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf16 * tkn16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf8 * tkn8 = icu_buf_utf8_create(0);
+
+    //printf("Input:  '%s'\n", src8cstr);
+
+    // transforming to UTF16
+    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+    icu_check_status(status);
+
+    // set up tokenizer
+    struct icu_tokenizer * tokenizer 
+        = icu_tokenizer_create(locale, action, &status);
+    icu_check_status(status);
+    YAZ_CHECK(tokenizer);
+
+    // attach text buffer to tokenizer
+    icu_tokenizer_attach(tokenizer, src16, &status);    
+    icu_check_status(status);
+    YAZ_CHECK(tokenizer->bi);
+
+    // perform work on tokens
+    //printf("Tokens: ");
+    while(icu_tokenizer_next_token(tokenizer, tkn16, &status)){
+        icu_check_status(status);
+
+        // converting to UTF8
+        icu_utf16_to_utf8(tkn8, tkn16, &status);
+
+        //printf("token %d %d %d %d '%s'\n",
+        //       
+        //       icu_tokenizer_token_start(tokenizer),
+        //       icu_tokenizer_token_end(tokenizer),
+        //       icu_tokenizer_token_length(tokenizer),
+        //       tkn8->utf8);
+    }
+
+    if (count != icu_tokenizer_token_count(tokenizer)){
+        success = 0;
+        printf("\nTokenizer '%s:%c' Error: \n", locale, action);
+        printf("Input:  '%s'\n", src8cstr);
+        printf("Tokens: %d", icu_tokenizer_token_count(tokenizer));
+        printf(", expected: %d\n", count);
+    }
+
+    icu_tokenizer_destroy(tokenizer);
+    icu_buf_utf16_destroy(src16);
+    icu_buf_utf16_destroy(tkn16);
+    icu_buf_utf8_destroy(tkn8);
+        
+    return success;
+}
+
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+void test_icu_I18N_tokenizer(int argc, char **argv)
+{
+
+
+    const char * en_str 
+        = "O Romeo, Romeo! wherefore art thou Romeo?";
+    
+    YAZ_CHECK(test_icu_tokenizer("en", 's', en_str, 2));
+    YAZ_CHECK(test_icu_tokenizer("en", 'l', en_str, 7));
+    YAZ_CHECK(test_icu_tokenizer("en", 'w', en_str, 16));
+    YAZ_CHECK(test_icu_tokenizer("en", 'c', en_str, 41));
+
+
+
+    const char * da_str 
+        = "Blåbærtærte. Denne kage stammer fra Finland. "
+        "Den er med blåbær, men alle sommerens forskellige bær kan bruges.";
+    
+    YAZ_CHECK(test_icu_tokenizer("da", 's', da_str, 3));
+    YAZ_CHECK(test_icu_tokenizer("dar", 'l', da_str, 17));
+    YAZ_CHECK(test_icu_tokenizer("da", 'w', da_str, 37));
+    YAZ_CHECK(test_icu_tokenizer("da", 'c', da_str, 110));
+
+}
+
+
+void test_icu_I18N_chain(int argc, char **argv)
+{
+    const char * en_str 
+        = "O Romeo, Romeo! wherefore art thou\t Romeo?";
+
+    printf("ICU chain:\ninput: '%s'\n", en_str);
+
+    UErrorCode status = U_ZERO_ERROR;
+    //struct icu_chain_step * step = 0;
+    struct icu_chain * chain = 0;
+    
+
+    const char * xml_str = "<icu_chain id=\"en:word\" locale=\"en\">"
+        "<normalize rule=\"[:Control:] Any-Remove\"/>"
+        "<tokenize rule=\"l\"/>"
+        "<normalize rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "<display/>"
+        "<casemap rule=\"l\"/>"
+        "<normal/>"
+        "<sort/>"
+        "</icu_chain>";
+
+    
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+
+    chain = icu_chain_xml_config(xml_node, &status);
+
+#if 0
+    chain  = icu_chain_create((uint8_t *) "en:word", (uint8_t *) "en");
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize,
+                                 (const uint8_t *) "[:Control:] Any-Remove",
+                                 &status);
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
+                                 (const uint8_t *) "s",
+                                 &status);
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
+                                 (const uint8_t *) "l",
+                                 &status);
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize,
+                                 (const uint8_t *)
+                                 "[[:WhiteSpace:][:Punctuation:]] Any-Remove",
+                                 &status);
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
+                                 (const uint8_t *)"",
+                                 &status);
+/*     step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize, */
+/*                                  (const uint8_t *) "Lower", */
+/*                                  &status); */
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap,
+                                 (const uint8_t *) "l",
+                                 &status);
+    step = icu_chain_insert_step(chain, ICU_chain_step_type_norm,
+                                 (const uint8_t *)"",
+                                 &status);
+/*     step = icu_chain_insert_step(chain, ICU_chain_step_type_sort, */
+/*                                  (const uint8_t *)"", */
+/*                                  &status); */
+    
+#endif
+
+    YAZ_CHECK(chain);
+
+    YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &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), 7);
+
+    icu_chain_destroy(chain);
+}
+
+
+
+#endif // HAVE_ICU
 
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
@@ -575,14 +591,17 @@ int main(int argc, char **argv)
     //test_icu_I18N_casemap_failures(argc, argv);
     test_icu_I18N_casemap(argc, argv);
     test_icu_I18N_sortmap(argc, argv);
-#else
+    test_icu_I18N_normalizer(argc, argv);
+    test_icu_I18N_tokenizer(argc, argv);
+    test_icu_I18N_chain(argc, argv);
+
+#else // HAVE_ICU
 
     printf("ICU unit tests omitted.\n"
            "Please install libicu36-dev and icu-doc or similar\n");
     YAZ_CHECK(0 == 0);
 
-#endif    
+#endif // HAVE_ICU
    
     YAZ_CHECK_TERM;
 }
@@ -590,6 +609,8 @@ int main(int argc, char **argv)
 
 // DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
 
+
+
 /*
  * Local variables:
  * c-basic-offset: 4