-/* $Id: test_icu_I18N.c,v 1.4 2007-05-01 08:10:26 marc Exp $
+/* $Id: test_icu_I18N.c,v 1.7 2007-05-02 14:01:36 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
#ifdef HAVE_ICU
#include "icu_I18N.h"
-#include "string.h"
+#include <string.h>
+#include <stdlib.h>
// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
}
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
void test_icu_I18N_casemap_failures(int argc, char **argv)
{
nmem_destroy(nmem);
}
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+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;
+}
+
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+void test_icu_I18N_sortmap(int argc, char **argv)
+{
+
+ // sucessful tests
+ size_t en_1_len = 6;
+ const char * en_1_src[6] = {"z", "K", "a", "A", "Z", "k"};
+ const char * en_1_cck[6] = {"a", "A", "K", "k", "z", "Z"};
+ YAZ_CHECK(test_icu_sortmap("en", en_1_len, en_1_src, en_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("en_AU", en_1_len, en_1_src, en_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("en_CA", en_1_len, en_1_src, en_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("en_GB", en_1_len, en_1_src, en_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("en_US", en_1_len, en_1_src, en_1_cck));
+
+ // sucessful tests - this one fails and should not!!!
+ size_t da_1_len = 6;
+ const char * da_1_src[6] = {"z", "å", "o", "æ", "a", "ø"};
+ const char * da_1_cck[6] = {"a", "o", "z", "æ", "ø", "å"};
+ YAZ_CHECK(0 == test_icu_sortmap("da", da_1_len, da_1_src, da_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("da_DK", da_1_len, da_1_src, da_1_cck));
+
+ // sucessful tests
+ size_t de_1_len = 9;
+ const char * de_1_src[9] = {"u", "ä", "o", "t", "s", "ß", "ü", "ö", "a"};
+ const char * de_1_cck[9] = {"ä", "a", "o", "ö", "s", "ß", "t", "u", "ü"};
+ YAZ_CHECK(test_icu_sortmap("de", de_1_len, de_1_src, de_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("de_AT", de_1_len, de_1_src, de_1_cck));
+ YAZ_CHECK(0 == test_icu_sortmap("de_DE", de_1_len, de_1_src, de_1_cck));
+
+}
+
+
#endif
// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
test_icu_I18N_casemap_failures(argc, argv);
test_icu_I18N_casemap(argc, argv);
+ test_icu_I18N_sortmap(argc, argv);
#else
}
-
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
/*
* Local variables: