From 9e0a2398a6d947f08b8e9e516c704ccc686b115f Mon Sep 17 00:00:00 2001 From: Madhu K Date: Wed, 2 Aug 2000 19:53:47 +0000 Subject: [PATCH] ICU-447 Added tests for ucol_getDefaultRulesArray X-SVN-Rev: 2100 --- icu4c/source/test/cintltst/capitst.c | 76 +++++++++++++++++++++++++--- icu4c/source/test/cintltst/capitst.h | 4 ++ 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/icu4c/source/test/cintltst/capitst.c b/icu4c/source/test/cintltst/capitst.c index d8710de915..ce73a22d02 100644 --- a/icu4c/source/test/cintltst/capitst.c +++ b/icu4c/source/test/cintltst/capitst.c @@ -20,16 +20,23 @@ #include "cintltst.h" #include "capitst.h" #include "unicode/ustring.h" +#include "unicode/ures.h" + + +U_CAPI const UChar * U_EXPORT2 ucol_getDefaultRulesArray(uint32_t *size); + + void addCollAPITest(TestNode** root) { - addTest(root, &TestProperty, "tscoll/capitst/TestProperty"); - addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl"); - addTest(root, &TestCompare, "tscoll/capitst/TestCompare"); - addTest(root, &TestSortKey, "tscoll/capitst/TestSortKey"); - addTest(root, &TestHashCode, "tscoll/capitst/TestHashCode"); - addTest(root, &TestElemIter, "tscoll/capitst/TestElemIter"); + addTest(root, &TestProperty, "tscoll/capitst/TestProperty"); + addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl"); + addTest(root, &TestCompare, "tscoll/capitst/TestCompare"); + addTest(root, &TestSortKey, "tscoll/capitst/TestSortKey"); + addTest(root, &TestHashCode, "tscoll/capitst/TestHashCode"); + addTest(root, &TestElemIter, "tscoll/capitst/TestElemIter"); addTest(root, &TestGetAll, "tscoll/capitst/TestGetAll"); + addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules"); } @@ -39,6 +46,62 @@ static void doAssert(int condition, const char *message) log_err("ERROR : %s\n", message); } } +void TestGetDefaultRules(){ + int32_t size=0; + UErrorCode status=U_ZERO_ERROR; + UCollator *coll=NULL; + UCollator *coll2=NULL; + int32_t len1 = 0, len2=0; + uint8_t *binColData = NULL; + + UResourceBundle *res = NULL; + UResourceBundle *binColl = NULL; + uint8_t *binResult = NULL; + UChar *rules=NULL; + + + + const UChar * defaultRulesArray=ucol_getDefaultRulesArray(&size); + log_verbose("Test the function ucol_getDefaultRulesArray()\n"); + + coll = ucol_openRules(defaultRulesArray, size, UCOL_DECOMP_CAN, 0, &status); + ucol_setNormalization(coll, UCOL_DEFAULT_NORMALIZATION); + if(U_SUCCESS(status) && coll !=NULL) { + binColData = (uint8_t*)ucol_cloneRuleData(coll, &len1, &status); + + } + + + status=U_ZERO_ERROR; + res=ures_open(NULL, "root", &status); + if(U_FAILURE(status)){ + log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status)); + return; + } + binColl=ures_getByKey(res, "%%Collation", binColl, &status); + if(U_SUCCESS(status)){ + binResult=(uint8_t*)ures_getBinary(binColl, &len2, &status); + if(U_FAILURE(status)){ + log_err("ERROR: ures_getBinary() failed\n"); + } + }else{ + log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed"); + } + + + if(len1 != len2){ + log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n"); + } + if(memcmp(binColData, binResult, len1) != 0){ + log_err("Error: ucol_getDefaultRulesArray() failed\n"); + } + + ures_close(res); + ucol_close(coll); + + +} + /* Collator Properties ucol_open, ucol_strcoll, getStrength/setStrength @@ -171,6 +234,7 @@ void TestProperty() log_verbose("the display name for french collation in german: %s\n", austrdup(disName) ); log_verbose("Default collation getDisplayName ended.\n"); free(disName); + diff --git a/icu4c/source/test/cintltst/capitst.h b/icu4c/source/test/cintltst/capitst.h index 895c646be1..d7872ec56f 100644 --- a/icu4c/source/test/cintltst/capitst.h +++ b/icu4c/source/test/cintltst/capitst.h @@ -57,6 +57,10 @@ * Test ucol_getAvailable and ucol_countAvailable() **/ void TestGetAll(void); + /** + * Test ucol_GetDefaultRules () + **/ + void TestGetDefaultRules(void);