From: Marc Cromme Date: Tue, 1 May 2007 08:10:26 +0000 (+0000) Subject: cleaned ICU case folding/mapping tests X-Git-Tag: PAZPAR2.1.0.0~186 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=c282ecc45c1410291d816aa184b470f10fc1b42e;p=pazpar2-moved-to-github.git cleaned ICU case folding/mapping tests --- diff --git a/src/test_icu_I18N.c b/src/test_icu_I18N.c index a667425..c8862f6 100644 --- a/src/test_icu_I18N.c +++ b/src/test_icu_I18N.c @@ -1,4 +1,4 @@ -/* $Id: test_icu_I18N.c,v 1.3 2007-05-01 07:58:43 adam Exp $ +/* $Id: test_icu_I18N.c,v 1.4 2007-05-01 08:10:26 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -19,6 +19,9 @@ 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 + + #if HAVE_CONFIG_H #include "cconfig.h" #endif @@ -36,175 +39,109 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "icu_I18N.h" #include "string.h" -void test_icu_I18N_casemap_en(int argc, char **argv) -{ +// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 + +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; - NMEM nmem = nmem_create(); - char * dest8 = 0; + //size_t src8_len = strlen(src8); + int sucess = 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); + //printf("original string: '%s' (%d)\n", src8, (int) src8_len); //these shall succeed dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "en", 'l'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'en:l' '%s' (%d)\n", dest8, (int) dest8_len); - - - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "en", 'u'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'en:u' '%s' (%d)\n", dest8, (int) dest8_len); - - - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "en", 'f'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'en:f' '%s' (%d)\n", dest8, (int) dest8_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); - + 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); - YAZ_CHECK(0 == 0); - //YAZ_CHECK_EQ(0, 1); + return sucess; } -void test_icu_I18N_casemap_da(int argc, char **argv) +// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 + +void test_icu_I18N_casemap(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; + // Locale 'en' - const char * src8 = "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN"; - size_t src8_len = strlen(src8); + // sucessful tests + YAZ_CHECK(test_icu_casemap("en", 'l', + "A ReD fOx hunTS sQUirriLs", + "a red fox hunts squirrils")); - printf("original string: '%s' (%d)\n", src8, (int) src8_len); - - //these shall succeed - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'l'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:l' '%s' (%d)\n", dest8, (int) dest8_len); - - - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'u'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:u' '%s' (%d)\n", dest8, (int) dest8_len); - - - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'f'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:f' '%s' (%d)\n", dest8, (int) dest8_len); - - - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 't'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:t' '%s' (%d)\n", dest8, (int) dest8_len); - - nmem_destroy(nmem); - - YAZ_CHECK(0 == 0); - //YAZ_CHECK_EQ(0, 1); -} + YAZ_CHECK(test_icu_casemap("en", 'u', + "A ReD fOx hunTS sQUirriLs", + "A RED FOX HUNTS SQUIRRILS")); + + YAZ_CHECK(test_icu_casemap("en", 'f', + "A ReD fOx hunTS sQUirriLs", + "a red fox hunts squirrils")); + + // this one fails and needs more investigation .. + YAZ_CHECK(0 == test_icu_casemap("en", 't', + "A ReD fOx hunTS sQUirriLs", + "A Red Fox Hunts Squirrils")); -void test_icu_I18N_casemap_de(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; + // Locale 'da' - const char * src8 = "zWÖlf ärgerliche Würste rollen ÜBer die StRAße"; - size_t src8_len = strlen(src8); - - printf("original string: '%s' (%d)\n", src8, (int) src8_len); + // sucess expected + YAZ_CHECK(test_icu_casemap("da", 'l', + "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", + "åh æble, øs fløde i åen efter blåbærgrøden")); - //these shall succeed - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'l'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:l' '%s' (%d)\n", dest8, (int) dest8_len); + YAZ_CHECK(test_icu_casemap("da", 'u', + "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", + "ÅH ÆBLE, ØS FLØDE I ÅEN EFTER BLÅBÆRGRØDEN")); + YAZ_CHECK(test_icu_casemap("da", 'f', + "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", + "åh æble, øs fløde i åen efter blåbærgrøden")); - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'u'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:u' '%s' (%d)\n", dest8, (int) dest8_len); + YAZ_CHECK(test_icu_casemap("da", 't', + "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", + "Åh Æble, Øs Fløde I Åen Efter Blåbærgrøden")); + // Locale 'de' - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 'f'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:f' '%s' (%d)\n", dest8, (int) dest8_len); + // 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")); + 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")); - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "da", 't'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'da:t' '%s' (%d)\n", dest8, (int) dest8_len); + 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")); - nmem_destroy(nmem); + 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")); - YAZ_CHECK(0 == 0); - //YAZ_CHECK_EQ(0, 1); } -void test_icu_I18N_casemap_el(int argc, char **argv) -{ - -#if 0 +void test_icu_I18N_casemap_failures(int argc, char **argv) +{ size_t buf_cap = 128; char buf[buf_cap]; @@ -212,46 +149,51 @@ void test_icu_I18N_casemap_el(int argc, char **argv) NMEM nmem = nmem_create(); char * dest8 = 0; - const char * src8 = "" - size_t src8_len = strlen(src8); + const char * src8 = "A ReD fOx hunTS sQUirriLs"; + //size_t src8_len = strlen(src8); - printf("original string: '%s' (%d)\n", src8, (int) src8_len); + //printf("original string: '%s' (%d)\n", src8, (int) src8_len); - //these shall succeed + // some calling error needs investigation dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "el", 'l'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'el:l' '%s' (%d)\n", dest8, (int) 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, "el", 'u'); + src8, "zz_abc", 'l'); YAZ_CHECK(dest8_len); - printf("icu_casemap 'el:u' '%s' (%d)\n", dest8, (int) dest8_len); + //printf("icu_casemap 'zz:l' '%s' (%d)\n", dest8, (int) dest8_len); - dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len, - src8, "el", 'f'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'el:f' '%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, "el", 't'); - YAZ_CHECK(dest8_len); - printf("icu_casemap 'el:t' '%s' (%d)\n", dest8, (int) 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); - - YAZ_CHECK(0 == 0); - //YAZ_CHECK_EQ(0, 1); -#endif - } - #endif +// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 + int main(int argc, char **argv) { @@ -260,10 +202,8 @@ int main(int argc, char **argv) #ifdef HAVE_ICU - test_icu_I18N_casemap_en(argc, argv); - test_icu_I18N_casemap_da(argc, argv); - test_icu_I18N_casemap_de(argc, argv); - test_icu_I18N_casemap_el(argc, argv); + test_icu_I18N_casemap_failures(argc, argv); + test_icu_I18N_casemap(argc, argv); #else