X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/57a6839dcb3bba09e8228b822b290604668416fe..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/test/cintltst/cucdapi.c diff --git a/icuSources/test/cintltst/cucdapi.c b/icuSources/test/cintltst/cucdapi.c index 2370f84e..9b359c7a 100644 --- a/icuSources/test/cintltst/cucdapi.c +++ b/icuSources/test/cintltst/cucdapi.c @@ -1,5 +1,7 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** - * Copyright (c) 1997-2014, International Business Machines + * Copyright (c) 1997-2016, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************/ @@ -9,8 +11,39 @@ #include "unicode/uchar.h" #include "cintltst.h" #include "cucdapi.h" +#include "cmemory.h" -#define LENGTHOF(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; @@ -94,11 +127,11 @@ void TestUScriptCodeAPI(){ err = U_ZERO_ERROR; capacity = 10; num = uscript_getCode("ja",script,capacity, &err); - if(num!=(sizeof(jaCode)/sizeof(UScriptCode))){ + if(num!=UPRV_LENGTHOF(jaCode)){ log_err("Errors uscript_getScriptCode() for Japanese locale: num=%d, expected %d \n", - num, (sizeof(jaCode)/sizeof(UScriptCode))); + num, UPRV_LENGTHOF(jaCode)); } - for(j=0;j