X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..b331163bffd790ced0e88b73f44f86d49ccc48a5:/icuSources/test/cintltst/cucdapi.c diff --git a/icuSources/test/cintltst/cucdapi.c b/icuSources/test/cintltst/cucdapi.c index 4a919c40..155f0e49 100644 --- a/icuSources/test/cintltst/cucdapi.c +++ b/icuSources/test/cintltst/cucdapi.c @@ -1,7 +1,6 @@ /******************************************************************** - * COPYRIGHT: - * Copyright (c) 1997-2006, International Business Machines Corporation and - * others. All Rights Reserved. + * Copyright (c) 1997-2014, International Business Machines + * Corporation and others. All Rights Reserved. ********************************************************************/ #include @@ -10,8 +9,39 @@ #include "unicode/uchar.h" #include "cintltst.h" #include "cucdapi.h" +#include "cmemory.h" -#define ARRAY_SIZE(array) (int32_t)(sizeof array / sizeof array[0]) +static void scriptsToString(const UScriptCode scripts[], int32_t length, char s[]) { + int32_t i; + if(length == 0) { + strcpy(s, "(no scripts)"); + return; + } + s[0] = 0; + for(i = 0; i < length; ++i) { + if(i > 0) { + strcat(s, " "); + } + strcat(s, uscript_getShortName(scripts[i])); + } +} + +static void assertEqualScripts(const char *msg, + const UScriptCode scripts1[], int32_t length1, + const UScriptCode scripts2[], int32_t length2, + UErrorCode errorCode) { + char s1[80]; + char s2[80]; + if(U_FAILURE(errorCode)) { + log_err("Failed: %s - %s\n", msg, u_errorName(errorCode)); + return; + } + scriptsToString(scripts1, length1, s1); + scriptsToString(scripts2, length2, s2); + if(0!=strcmp(s1, s2)) { + log_data_err("Failed: %s: expected %s but got %s\n", msg, s1, s2); + } +} void TestUScriptCodeAPI(){ int i =0; @@ -40,7 +70,7 @@ void TestUScriptCodeAPI(){ "asfdasd", "5464", "12235", /* test the last index */ "zyyy", "YI", - '\0' + NULL }; UScriptCode expected[] ={ /* locales should return */ @@ -69,11 +99,11 @@ void TestUScriptCodeAPI(){ const int32_t capacity = 10; - for( ; testNames[i]!='\0'; i++){ + for( ; testNames[i]!=NULL; i++){ UScriptCode script[10]={USCRIPT_INVALID_CODE}; uscript_getCode(testNames[i],script,capacity, &err); if( script[0] != expected[i]){ - log_err("Error getting script code Got: %i Expected: %i for name %s\n", + log_data_err("Error getting script code Got: %i Expected: %i for name %s (Error code does not propagate if data is not present. Are you missing data?)\n", script[0],expected[i],testNames[i]); numErrors++; } @@ -86,6 +116,7 @@ void TestUScriptCodeAPI(){ { UErrorCode err = U_ZERO_ERROR; int32_t capacity=0; + int32_t j; UScriptCode jaCode[]={USCRIPT_KATAKANA, USCRIPT_HIRAGANA, USCRIPT_HAN }; UScriptCode script[10]={USCRIPT_INVALID_CODE}; int32_t num = uscript_getCode("ja",script,capacity, &err); @@ -94,8 +125,17 @@ void TestUScriptCodeAPI(){ err = U_ZERO_ERROR; capacity = 10; num = uscript_getCode("ja",script,capacity, &err); - if(num!=(sizeof(jaCode)/sizeof(UScriptCode)) || script[0]!=jaCode[0] || script[1]!=jaCode[1]){ - log_err("Errors uscript_getScriptCode() for Japaneese locale \n"); + if(num!=(sizeof(jaCode)/sizeof(UScriptCode))){ + log_err("Errors uscript_getScriptCode() for Japanese locale: num=%d, expected %d \n", + num, (sizeof(jaCode)/sizeof(UScriptCode))); + } + for(j=0;j