X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftst_icu_I18N.c;h=bbdc9937e386150f9876dbe0227365d1a67fa299;hp=17c5a697dea82cc541135c1ea17aca5d9549fb14;hb=4adcf3fecf9b8d2880ee0b671c9f9d20da18ca49;hpb=46f99a24bc67de00bcbb33458b9c187c7525b1b0 diff --git a/test/tst_icu_I18N.c b/test/tst_icu_I18N.c index 17c5a69..bbdc993 100644 --- a/test/tst_icu_I18N.c +++ b/test/tst_icu_I18N.c @@ -1,9 +1,6 @@ -/* - * Copyright (C) 2005-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: tst_icu_I18N.c,v 1.13 2007-11-08 09:03:11 adam Exp $ - * */ /* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ @@ -26,9 +23,6 @@ #include #include -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - - #define MAX_KEY_SIZE 256 struct icu_termmap { @@ -37,7 +31,6 @@ struct icu_termmap }; - int icu_termmap_cmp(const void *vp1, const void *vp2) { struct icu_termmap *itmp1 = *(struct icu_termmap **) vp1; @@ -48,9 +41,7 @@ int icu_termmap_cmp(const void *vp1, const void *vp2) cmp = strcmp((const char *)itmp1->sort_key, (const char *)itmp2->sort_key); return cmp; -}; - - +} int test_icu_casemap(const char * locale, char action, @@ -76,9 +67,7 @@ int test_icu_casemap(const char * locale, char action, /* converting to UTF8 */ icu_utf16_to_utf8(dest8, dest16, &status); - - /* determine success */ if (dest8->utf8 && (dest8->utf8_len == strlen(chk8cstr)) @@ -101,18 +90,12 @@ int test_icu_casemap(const char * locale, char action, icu_buf_utf8_destroy(dest8); icu_buf_utf16_destroy(src16); icu_buf_utf16_destroy(dest16); - - + return success; } - - -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - void test_icu_I18N_casemap(int argc, char **argv) { - /* Locale 'en' */ /* successful tests */ @@ -132,7 +115,6 @@ void test_icu_I18N_casemap(int argc, char **argv) "A ReD fOx hunTS sQUirriLs", "A Red Fox Hunts Squirrils")); - /* Locale 'da' */ /* success expected */ @@ -173,9 +155,6 @@ void test_icu_I18N_casemap(int argc, char **argv) } - -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - int test_icu_sortmap(const char * locale, int src_list_len, const char ** src_list, const char ** chk_list) { @@ -197,39 +176,39 @@ int test_icu_sortmap(const char * locale, int src_list_len, return 0; /* assigning display terms and sort keys using buf 8 and buf16 */ - for( i = 0; i < src_list_len; i++) - { + 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); - } - + /* assigning sortkeys */ + memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len); + } /* do the sorting */ - qsort(list, src_list_len, - sizeof(struct icu_termmap *), icu_termmap_cmp); + qsort(list, src_list_len, sizeof(struct icu_termmap *), icu_termmap_cmp); /* checking correct sorting */ - for (i = 0; i < src_list_len; i++){ + for (i = 0; i < src_list_len; i++) + { if (0 != strcmp(list[i]->disp_term, chk_list[i])){ success = 0; } } - if(!success){ + if (!success) + { printf("\nERROR\n"); printf("Input str: '%s' : ", locale); for (i = 0; i < src_list_len; i++) { @@ -248,12 +227,9 @@ int test_icu_sortmap(const char * locale, int src_list_len, printf("\n"); } - - - for( i = 0; i < src_list_len; i++) + for (i = 0; i < src_list_len; i++) free(list[i]); - - + ucol_close(coll); icu_buf_utf8_destroy(buf8); @@ -262,12 +238,8 @@ int test_icu_sortmap(const char * locale, int src_list_len, return success; } - -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - void test_icu_I18N_sortmap(int argc, char **argv) { - /* successful tests */ size_t en_1_len = 6; const char * en_1_src[6] = {"z", "K", "a", "A", "Z", "k"}; @@ -298,15 +270,9 @@ void test_icu_I18N_sortmap(int argc, char **argv) } - -/* 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) + const char * src8cstr, + const char * chk8cstr) { int success = 0; @@ -315,14 +281,14 @@ int test_icu_normalizer(const char * rules8cstr, 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); + struct icu_transform * transform + = icu_transform_create(rules8cstr, 'f', 0, &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_transform_trans(transform, dest16, src16, &status); icu_check_status(status); icu_utf16_to_utf8(dest8, dest16, &status); @@ -332,7 +298,8 @@ int test_icu_normalizer(const char * rules8cstr, if(!strcmp((const char *) dest8->utf8, (const char *) chk8cstr)) success = 1; - else { + else + { success = 0; printf("Normalization\n"); printf("Rules: '%s'\n", rules8cstr); @@ -340,22 +307,17 @@ int test_icu_normalizer(const char * rules8cstr, printf("Normalized: '%s'\n", dest8->utf8); printf("Expected: '%s'\n", chk8cstr); } - - icu_normalizer_destroy(normalizer); + icu_transform_destroy(transform); 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")); @@ -381,18 +343,13 @@ void test_icu_I18N_normalizer(int argc, char **argv) " 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) + const char * src8cstr, int count) { int success = 1; @@ -440,13 +397,8 @@ int test_icu_tokenizer(const char * locale, char action, 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?"; @@ -455,8 +407,6 @@ void test_icu_I18N_tokenizer(int argc, char **argv) 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. " @@ -467,10 +417,8 @@ void test_icu_I18N_tokenizer(int argc, char **argv) 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 @@ -479,11 +427,10 @@ void test_icu_I18N_chain(int argc, char **argv) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - - const char * xml_str = "" - "" + const char * xml_str = "" + "" "" - "" + "" "" "" ""; @@ -493,20 +440,20 @@ void test_icu_I18N_chain(int argc, char **argv) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &status)); - while (icu_chain_next_token(chain, &status)){ + 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)); */ + icu_chain_token_number(chain), + icu_chain_token_norm(chain), + icu_chain_token_display(chain)); */ } YAZ_CHECK_EQ(icu_chain_token_number(chain), 7); @@ -514,12 +461,13 @@ void test_icu_I18N_chain(int argc, char **argv) YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status)); - while (icu_chain_next_token(chain, &status)){ + 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)); */ + icu_chain_token_number(chain), + icu_chain_token_norm(chain), + icu_chain_token_display(chain)); */ } @@ -534,14 +482,14 @@ void test_bug_1140(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" /* if the first rule is normalize instead. Then it works */ #if 0 - "" + "" #endif "" - "" + "" "" "" ""; @@ -551,7 +499,7 @@ void test_bug_1140(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -560,13 +508,13 @@ void test_bug_1140(void) chain, "O Romeo, Romeo! wherefore art thou\t Romeo?", &status)); - while (icu_chain_next_token(chain, &status)){ + 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)); */ - + icu_chain_token_number(chain), + icu_chain_token_norm(chain), + icu_chain_token_display(chain)); */ } @@ -574,12 +522,13 @@ void test_bug_1140(void) YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status)); - 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)); */ + 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)); */ } /* we expect 'what' 'is' 'this', i.e. 3 tokens */ @@ -589,22 +538,21 @@ void test_bug_1140(void) } - void test_chain_empty_token(void) { UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" "" - "" + "" ""; 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); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -613,12 +561,13 @@ void test_chain_empty_token(void) chain, "a string with 15 tokenss and 8 displays", &status)); - while (icu_chain_next_token(chain, &status)){ + 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)); */ + icu_chain_token_number(chain), + icu_chain_token_norm(chain), + icu_chain_token_display(chain)); */ } YAZ_CHECK_EQ(icu_chain_token_number(chain), 15); @@ -631,7 +580,7 @@ void test_chain_empty_chain(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" ""; const char * src8 = "some 5487 weired !¤%&(/& sTuFf"; @@ -641,7 +590,7 @@ void test_chain_empty_chain(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -650,12 +599,13 @@ void test_chain_empty_chain(void) chain, src8, &status)); - while (icu_chain_next_token(chain, &status)){ + 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)); */ + icu_chain_token_number(chain), + icu_chain_token_norm(chain), + icu_chain_token_display(chain)); */ } YAZ_CHECK_EQ(icu_chain_token_number(chain), 1); @@ -663,17 +613,13 @@ void test_chain_empty_chain(void) dest8 = (char *) icu_chain_token_norm(chain); YAZ_CHECK_EQ(strcmp(src8, dest8), 0); - icu_chain_destroy(chain); } #endif /* YAZ_HAVE_ICU */ -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - int main(int argc, char **argv) { - YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); @@ -699,15 +645,12 @@ int main(int argc, char **argv) YAZ_CHECK_TERM; } - -/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */ - - - /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +