/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************* * * File CRESTST.C * * Modification History: * Name Date Description * Madhu Katragadda 05/09/2000 Ported Tests for New ResourceBundle API * Madhu Katragadda 05/24/2000 Added new tests to test RES_BINARY for collationElements ******************************************************************************** */ #include #include "unicode/utypes.h" #include "cintltst.h" #include "unicode/putil.h" #include "unicode/ustring.h" #include "unicode/ucnv.h" #include "string.h" #include "cstring.h" #include "unicode/uchar.h" #include "ucol_imp.h" /* for U_ICUDATA_COLL */ #include "ubrkimpl.h" /* for U_ICUDATA_BRKITR */ #define RESTEST_HEAP_CHECK 0 #include "unicode/uloc.h" #include "unicode/ulocdata.h" #include "uresimp.h" #include "creststn.h" #include "unicode/ctest.h" #include "ucbuf.h" #include "ureslocs.h" static int32_t pass; static int32_t fail; /*****************************************************************************/ /** * Return a random unsigned long l where 0N <= l <= ULONG_MAX. */ static uint32_t randul() { uint32_t l=0; int32_t i; static UBool initialized = FALSE; if (!initialized) { srand((unsigned)time(NULL)); initialized = TRUE; } /* Assume rand has at least 12 bits of precision */ for (i=0; i> 4); return l; } /** * Return a random double x where 0.0 <= x < 1.0. */ static double randd() { return ((double)randul()) / UINT32_MAX; } /** * Return a random integer i where 0 <= i < n. */ static int32_t randi(int32_t n) { return (int32_t)(randd() * n); } /***************************************************************************************/ /** * Convert an integer, positive or negative, to a character string radix 10. */ static char* itoa1(int32_t i, char* buf) { char *p = 0; char* result = buf; /* Handle negative */ if(i < 0) { *buf++ = '-'; i = -i; } /* Output digits in reverse order */ p = buf; do { *p++ = (char)('0' + (i % 10)); i /= 10; } while(i); *p-- = 0; /* Reverse the string */ while(buf < p) { char c = *buf; *buf++ = *p; *p-- = c; } return result; } static const int32_t kERROR_COUNT = -1234567; static const UChar kERROR[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/, 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/}; /*****************************************************************************/ enum E_Where { e_Root, e_te, e_te_IN, e_Where_count }; typedef enum E_Where E_Where; /*****************************************************************************/ #define CONFIRM_EQ(actual,expected) if (u_strcmp(expected,actual)==0){ record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, austrdup(actual), austrdup(expected)); } #define CONFIRM_INT_EQ(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of %d\n", action, actual, expected); } #define CONFIRM_INT_GE(actual,expected) if ((actual)>=(expected)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x >= %d\n", action, actual, expected); } #define CONFIRM_INT_NE(actual,expected) if ((expected)!=(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x != %d\n", action, actual, expected); } /*#define CONFIRM_ErrorCode(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); } */ static void CONFIRM_ErrorCode(UErrorCode actual,UErrorCode expected) { if ((expected)==(actual)) { record_pass(); } else { record_fail(); /*log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); */ log_err("returned %s instead of %s\n", myErrorName(actual), myErrorName(expected)); } } /* Array of our test objects */ static struct { const char* name; UErrorCode expected_constructor_status; E_Where where; UBool like[e_Where_count]; UBool inherits[e_Where_count]; } param[] = { /* "te" means test */ /* "IN" means inherits */ /* "NE" or "ne" means "does not exist" */ { "root", U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }, { "te", U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, { "te_IN", U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, { "te_NE", U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } }, { "te_IN_NE", U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } }, { "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } } }; static int32_t bundles_count = sizeof(param) / sizeof(param[0]); /*static void printUChars(UChar*);*/ static void TestDecodedBundle(void); static void TestGetKeywordValues(void); static void TestGetFunctionalEquivalent(void); static void TestCLDRStyleAliases(void); static void TestFallbackCodes(void); static void TestGetUTF8String(void); static void TestCLDRVersion(void); /***************************************************************************************/ /* Array of our test objects */ void addNEWResourceBundleTest(TestNode** root) { addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes"); #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle"); addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1"); addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundles"); addTest(root, &TestNewTypes, "tsutil/creststn/TestNewTypes"); addTest(root, &TestEmptyTypes, "tsutil/creststn/TestEmptyTypes"); addTest(root, &TestBinaryCollationData, "tsutil/creststn/TestBinaryCollationData"); addTest(root, &TestAPI, "tsutil/creststn/TestAPI"); addTest(root, &TestErrorConditions, "tsutil/creststn/TestErrorConditions"); addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle"); addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing"); addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess"); addTest(root, &TestXPath, "tsutil/creststn/TestXPath"); addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases"); addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes"); addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String"); addTest(root, &TestCLDRVersion, "tsutil/creststn/TestCLDRVersion"); #endif addTest(root, &TestFallback, "tsutil/creststn/TestFallback"); addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion"); addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl"); addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict"); addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues"); addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent"); addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763"); addTest(root, &TestStackReuse, "tsutil/creststn/TestStackReuse"); } /***************************************************************************************/ static const char* norwayNames[] = { "no_NO_NY", "no_NO", "no", "nn_NO", "nn", "nb_NO", "nb" }; static const char* norwayLocales[] = { "nn_NO", "nb_NO", "nb", "nn_NO", "nn", "nb_NO", "nb" }; static void checkStatus(int32_t line, UErrorCode expected, UErrorCode status) { if(U_FAILURE(status)) { log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__, line); } if(status != expected) { log_err_status(status, "%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status)); } } static void TestErrorCodes(void) { UErrorCode status = U_USING_DEFAULT_WARNING; UResourceBundle *r = NULL, *r2 = NULL; /* First check with ICUDATA */ /* first bundle should return fallback warning */ r = ures_open(NULL, "ti_ER_ASSAB", &status); checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); ures_close(r); /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; r = ures_open(NULL, "ti_ER", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); /* we look up the resource which is aliased, but it lives in fallback */ if(U_SUCCESS(status) && r != NULL) { status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "LocaleScript", NULL, &status); /* LocaleScript lives in ti */ checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); } ures_close(r); /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; r = ures_open(U_ICUDATA_REGION, "ti", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); /* we look up the resource which is aliased and at our level */ /* TODO: restore the following test when cldrbug 3058: is fixed */ if(U_SUCCESS(status) && r != NULL && isICUVersionAtLeast(50, 1, 0)) { status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "Countries", r2, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } ures_close(r); status = U_USING_FALLBACK_WARNING; r = ures_open(NULL, "nolocale", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); ures_close(r); ures_close(r2); /** Now, with the collation bundle **/ /* first bundle should return fallback warning */ r = ures_open(U_ICUDATA_COLL, "sr_YU_VOJVODINA", &status); checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); ures_close(r); /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_FALLBACK_WARNING; r = ures_open(U_ICUDATA_COLL, "sr", &status); checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); /* we look up the resource which is aliased */ if(U_SUCCESS(status) && r != NULL) { status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "collations", NULL, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } ures_close(r); /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; r = ures_open(U_ICUDATA_COLL, "sr", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); /* we look up the resource which is aliased and at our level */ if(U_SUCCESS(status) && r != NULL) { status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "collations", r2, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } ures_close(r); status = U_USING_FALLBACK_WARNING; r = ures_open(U_ICUDATA_COLL, "nolocale", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); ures_close(r); ures_close(r2); } static void TestAliasConflict(void) { UErrorCode status = U_ZERO_ERROR; UResourceBundle *he = NULL; UResourceBundle *iw = NULL; UResourceBundle *norway = NULL; const UChar *result = NULL; int32_t resultLen; uint32_t size = 0; uint32_t i = 0; const char *realName = NULL; he = ures_open(NULL, "he", &status); iw = ures_open(NULL, "iw", &status); if(U_FAILURE(status)) { log_err_status(status, "Failed to get resource with %s\n", myErrorName(status)); } ures_close(iw); result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status); if(U_FAILURE(status) || result == NULL) { log_err_status(status, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status)); } ures_close(he); size = sizeof(norwayNames)/sizeof(norwayNames[0]); for(i = 0; i < size; i++) { status = U_ZERO_ERROR; norway = ures_open(NULL, norwayNames[i], &status); if(U_FAILURE(status)) { log_err_status(status, "Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]); continue; } realName = ures_getLocale(norway, &status); log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames[i], realName); if(realName == NULL || strcmp(norwayLocales[i], realName) != 0) { log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames[i], norwayLocales[i], realName); } ures_close(norway); } } static void TestDecodedBundle(){ UErrorCode error = U_ZERO_ERROR; UResourceBundle* resB; const UChar* srcFromRes; int32_t len; static const UChar uSrc[] = { 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F, 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928, 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A, 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938, 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020, 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938, 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947, 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020, 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915, 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E, 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917, 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D, 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020, 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915, 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B, 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E, 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902, 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932, 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F, 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938, 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930, 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020, 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020, 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F, 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C, 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941, 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917, 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E, 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930, 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E, 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935, 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020, 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935, 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915, 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F, 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033, 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F, 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915, 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020, 0 }; /* pre-flight */ int32_t num =0; const char *testdatapath = loadTestData(&error); resB = ures_open(testdatapath, "iscii", &error); srcFromRes=tres_getString(resB,-1,"str",&len,&error); if(U_FAILURE(error)){ #if UCONFIG_NO_LEGACY_CONVERSION log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n"); #else log_data_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error)); #endif ures_close(resB); return; } if(u_strncmp(srcFromRes,uSrc,len)!=0){ log_err("Genrb produced res files after decoding failed\n"); } while(num= 0) { locName = uloc_getAvailable(j); } log_verbose("Testing version number for locale %s\n", locName); resB = ures_open(NULL,locName, &status); if (U_FAILURE(status)) { log_err_status(status, "Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status)); ures_close(resB); return; } ures_getVersion(resB, versionArray); for (i=0; i<4; ++i) { if (versionArray[i] < minVersionArray[i] || versionArray[i] > maxVersionArray[i]) { log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); break; } } ures_close(resB); } } static void TestGetVersionColl(){ UVersionInfo minVersionArray = {0x00, 0x00, 0x00, 0x00}; UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf}; UVersionInfo versionArray; UErrorCode status= U_ZERO_ERROR; UResourceBundle* resB = NULL; UEnumeration *locs= NULL; int i=0; const char *locName = "root"; int32_t locLen; const UChar* rules =NULL; int32_t len = 0; log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL); locs = ures_openAvailableLocales(U_ICUDATA_COLL, &status); if (U_FAILURE(status)) { log_err_status(status, "enumeration of %s failed.: %s\n", U_ICUDATA_COLL, myErrorName(status)); return; } do{ log_verbose("Testing version number for locale %s\n", locName); resB = ures_open(U_ICUDATA_COLL,locName, &status); if (U_FAILURE(status)) { log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL, locName, myErrorName(status)); ures_close(resB); return; } /* test NUL termination of UCARules */ rules = tres_getString(resB,-1,"UCARules",&len, &status); if(!rules || U_FAILURE(status)) { log_data_err("Could not load UCARules for locale %s\n", locName); continue; } if(u_strlen(rules) != len){ log_err("UCARules string not nul terminated! \n"); } ures_getVersion(resB, versionArray); for (i=0; i<4; ++i) { if (versionArray[i] < minVersionArray[i] || versionArray[i] > maxVersionArray[i]) { log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); break; } } ures_close(resB); } while((locName = uenum_next(locs,&locLen,&status))&&U_SUCCESS(status)); if(U_FAILURE(status)) { log_err("Err %s testing Collation locales.\n", u_errorName(status)); } uenum_close(locs); } static void TestResourceBundles() { UErrorCode status = U_ZERO_ERROR; loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status)); return; } testTag("only_in_Root", TRUE, FALSE, FALSE); testTag("in_Root_te", TRUE, TRUE, FALSE); testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); testTag("in_Root_te_IN", TRUE, FALSE, TRUE); testTag("only_in_te", FALSE, TRUE, FALSE); testTag("only_in_te_IN", FALSE, FALSE, TRUE); testTag("in_te_te_IN", FALSE, TRUE, TRUE); testTag("nonexistent", FALSE, FALSE, FALSE); log_verbose("Passed:= %d Failed= %d \n", pass, fail); } static void TestConstruction1() { UResourceBundle *test1 = 0, *test2 = 0,*empty = 0; const UChar *result1, *result2; UErrorCode status= U_ZERO_ERROR; UErrorCode err = U_ZERO_ERROR; const char* locale="te_IN"; const char* testdatapath; int32_t len1=0; int32_t len2=0; UVersionInfo versionInfo; char versionString[256]; char verboseOutput[256]; U_STRING_DECL(rootVal, "ROOT", 4); U_STRING_DECL(te_inVal, "TE_IN", 5); U_STRING_INIT(rootVal, "ROOT", 4); U_STRING_INIT(te_inVal, "TE_IN", 5); testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } log_verbose("Testing ures_open()......\n"); empty = ures_open(testdatapath, "testempty", &status); if(empty == NULL || U_FAILURE(status)) { log_err("opening empty failed!\n"); } ures_close(empty); test1=ures_open(testdatapath, NULL, &err); if(U_FAILURE(err)) { log_err("construction of NULL did not succeed : %s \n", myErrorName(status)); return; } test2=ures_open(testdatapath, locale, &err); if(U_FAILURE(err)) { log_err("construction of %s did not succeed : %s \n", locale, myErrorName(status)); return; } result1= tres_getString(test1, -1, "string_in_Root_te_te_IN", &len1, &err); result2= tres_getString(test2, -1, "string_in_Root_te_te_IN", &len2, &err); if (U_FAILURE(err) || len1==0 || len2==0) { log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status)); return; } log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput, result1)); log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput, result2)); if(u_strcmp(result1, rootVal) !=0 || u_strcmp(result2, te_inVal) !=0 ){ log_err("construction test failed. Run Verbose for more information"); } /* Test getVersionNumber*/ log_verbose("Testing version number\n"); log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1)); log_verbose("Testing version \n"); ures_getVersion(test1, versionInfo); u_versionToString(versionInfo, versionString); log_verbose("for getVersion : %s\n", versionString); if(strcmp(versionString, ures_getVersionNumber(test1)) != 0) { log_err("Versions differ: %s vs %s\n", versionString, ures_getVersionNumber(test1)); } ures_close(test1); ures_close(test2); } /*****************************************************************************/ /*****************************************************************************/ static UBool testTag(const char* frag, UBool in_Root, UBool in_te, UBool in_te_IN) { int32_t failNum = fail; /* Make array from input params */ UBool is_in[3]; const char *NAME[] = { "ROOT", "TE", "TE_IN" }; /* Now try to load the desired items */ UResourceBundle* theBundle = NULL; char tag[99]; char action[256]; UErrorCode expected_status,status = U_ZERO_ERROR,expected_resource_status = U_ZERO_ERROR; UChar* base = NULL; UChar* expected_string = NULL; const UChar* string = NULL; char buf[5]; char item_tag[10]; int32_t i,j,row,col, len; int32_t actual_bundle; int32_t count = 0; int32_t row_count=0; int32_t column_count=0; int32_t index = 0; int32_t tag_count= 0; const char* testdatapath; char verboseOutput[256]; UResourceBundle* array=NULL; UResourceBundle* array2d=NULL; UResourceBundle* tags=NULL; UResourceBundle* arrayItem1=NULL; testdatapath = loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return FALSE; } is_in[0] = in_Root; is_in[1] = in_te; is_in[2] = in_te_IN; strcpy(item_tag, "tag"); for (i=0; i default */ else if(i == 3) actual_bundle = 1; /* te_NE -> te */ else if(i == 4) actual_bundle = 2; /* te_IN_NE -> te_IN */ else actual_bundle = i; expected_resource_status = U_MISSING_RESOURCE_ERROR; for (j=e_te_IN; j>=e_Root; --j) { if (is_in[j] && param[i].inherits[j]) { if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */ expected_resource_status = U_ZERO_ERROR; else if(j == 0) expected_resource_status = U_USING_DEFAULT_WARNING; else expected_resource_status = U_USING_FALLBACK_WARNING; log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n", param[i].name, i, frag, j, is_in[j]?"Yes":"No", j, param[i].inherits[j]?"Yes":"No", param[actual_bundle].name); break; } } for (j=param[i].where; j>=0; --j) { if (is_in[j]) { if(base != NULL) { free(base); base = NULL; } base=(UChar*)malloc(sizeof(UChar)*(strlen(NAME[j]) + 1)); u_uastrcpy(base,NAME[j]); break; } else { if(base != NULL) { free(base); base = NULL; } base = (UChar*) malloc(sizeof(UChar) * 1); *base = 0x0000; } } /*----string---------------------------------------------------------------- */ strcpy(tag,"string_"); strcat(tag,frag); strcpy(action,param[i].name); strcat(action, ".ures_getStringByKey(" ); strcat(action,tag); strcat(action, ")"); status = U_ZERO_ERROR; len=0; string=tres_getString(theBundle, -1, tag, &len, &status); if(U_SUCCESS(status)) { expected_string=(UChar*)malloc(sizeof(UChar)*(u_strlen(base) + 4)); u_strcpy(expected_string,base); CONFIRM_INT_EQ(len, u_strlen(expected_string)); }else{ expected_string = (UChar*)malloc(sizeof(UChar)*(u_strlen(kERROR) + 1)); u_strcpy(expected_string,kERROR); string=kERROR; } log_verbose("%s got %d, expected %d\n", action, status, expected_resource_status); CONFIRM_ErrorCode(status, expected_resource_status); CONFIRM_EQ(string, expected_string); /*--------------array------------------------------------------------- */ strcpy(tag,"array_"); strcat(tag,frag); strcpy(action,param[i].name); strcat(action, ".ures_getByKey(" ); strcat(action,tag); strcat(action, ")"); len=0; count = kERROR_COUNT; status = U_ZERO_ERROR; array=ures_getByKey(theBundle, tag, array, &status); CONFIRM_ErrorCode(status,expected_resource_status); if (U_SUCCESS(status)) { /*confirm the resource type is an array*/ CONFIRM_INT_EQ(ures_getType(array), URES_ARRAY); /*confirm the size*/ count=ures_getSize(array); CONFIRM_INT_GE(count,1); for (j=0; j= 0 && index < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR; CONFIRM_ErrorCode(status,expected_status); CONFIRM_EQ(string,expected_string); } /*--------------2dArray------------------------------------------------- */ strcpy(tag,"array_2d_"); strcat(tag,frag); strcpy(action,param[i].name); strcat(action, ".ures_getByKey(" ); strcat(action,tag); strcat(action, ")"); row_count = kERROR_COUNT, column_count = kERROR_COUNT; status = U_ZERO_ERROR; array2d=ures_getByKey(theBundle, tag, array2d, &status); CONFIRM_ErrorCode(status,expected_resource_status); if (U_SUCCESS(status)) { /*confirm the resource type is an 2darray*/ CONFIRM_INT_EQ(ures_getType(array2d), URES_ARRAY); row_count=ures_getSize(array2d); CONFIRM_INT_GE(row_count,1); for(row=0; row= 0 && row < row_count && col >= 0 && col < column_count) ? expected_resource_status: U_MISSING_RESOURCE_ERROR; CONFIRM_ErrorCode(status,expected_status); if (U_SUCCESS(status)){ UChar element[3]; u_strcpy(expected_string, base); u_uastrcpy(element, itoa1(row, buf)); u_strcat(expected_string, element); u_uastrcpy(element, itoa1(col, buf)); u_strcat(expected_string, element); } else { u_strcpy(expected_string,kERROR); } CONFIRM_EQ(string,expected_string); } /*--------------taggedArray----------------------------------------------- */ strcpy(tag,"tagged_array_"); strcat(tag,frag); strcpy(action,param[i].name); strcat(action,".ures_getByKey("); strcat(action, tag); strcat(action,")"); status = U_ZERO_ERROR; tag_count=0; tags=ures_getByKey(theBundle, tag, tags, &status); CONFIRM_ErrorCode(status, expected_resource_status); if (U_SUCCESS(status)) { UResType bundleType=ures_getType(tags); CONFIRM_INT_EQ(bundleType, URES_TABLE); tag_count=ures_getSize(tags); CONFIRM_INT_GE((int32_t)tag_count, (int32_t)0); for(index=0; index loc=%s\n", gotAvail?'t':'f', equivLocale, i/3, expectAvail?'t':'f', inLocale, expectLocale); } } } } static void TestGetFunctionalEquivalent(void) { static const char * const collCases[] = { /* avail locale equiv */ "f", "de_US_CALIFORNIA", "de", "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */ "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke", "f", "de_CN@collation=pinyin", "de", "t", "zh@collation=pinyin", "zh", "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */ "t", "zh_Hans_CN@collation=pinyin", "zh", "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */ "t", "zh_Hant_HK@collation=pinyin", "zh", "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */ "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke", "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */ "t", "zh_Hant_HK", "zh@collation=stroke", "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */ "t", "zh_Hant_MO", "zh@collation=stroke", "f", "zh_TW_STROKE", "zh@collation=stroke", "f", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han", "f", "de_CN@calendar=japanese", "de", "t", "de@calendar=japanese", "de", "f", "zh_TW@collation=big5han", "zh@collation=big5han", /* alias of zh_Hant_TW */ "t", "zh_Hant_TW@collation=big5han", "zh@collation=big5han", "f", "zh_TW@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hant_TW */ "t", "zh_Hant_TW@collation=gb2312han", "zh@collation=gb2312han", "f", "zh_CN@collation=big5han", "zh@collation=big5han", /* alias of zh_Hans_CN */ "t", "zh_Hans_CN@collation=big5han", "zh@collation=big5han", "f", "zh_CN@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hans_CN */ "t", "zh_Hans_CN@collation=gb2312han", "zh@collation=gb2312han", "t", "zh@collation=big5han", "zh@collation=big5han", "t", "zh@collation=gb2312han", "zh@collation=gb2312han", "t", "hi@collation=standard", "hi", "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi", "t", "de_DE@collation=pinyin", "de", /* bug 4582 tests */ "f", "de_DE_BONN@collation=pinyin", "de", "t", "nl", "root", "t", "nl_NL", "root", "f", "nl_NL_EEXT", "root", "t", "nl@collation=stroke", "root", "t", "nl_NL@collation=stroke", "root", "f", "nl_NL_EEXT@collation=stroke", "root", NULL }; static const char *calCases[] = { /* avail locale equiv */ "t", "en_US_POSIX", "en@calendar=gregorian", "f", "ja_JP_TOKYO", "ja@calendar=gregorian", "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese", "t", "sr@calendar=gregorian", "sr@calendar=gregorian", "t", "en", "en@calendar=gregorian", NULL }; #if !UCONFIG_NO_COLLATION TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases); #endif TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases); #if !UCONFIG_NO_COLLATION log_verbose("Testing error conditions:\n"); { char equivLocale[256] = "???"; int32_t len; UErrorCode status = U_ZERO_ERROR; UBool gotAvail = FALSE; len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL, "calendar", "calendar", "ar_EG@calendar=islamic", &gotAvail, FALSE, &status); if(status == U_MISSING_RESOURCE_ERROR) { log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n"); } else { log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n", equivLocale, gotAvail?'t':'f', u_errorName(status)); } } #endif } static void TestXPath(void) { UErrorCode status = U_ZERO_ERROR; UResourceBundle *rb = NULL, *alias = NULL; int32_t len = 0; const UChar* result = NULL; const UChar expResult[] = { 0x0063, 0x006F, 0x0072, 0x0072, 0x0065, 0x0063, 0x0074, 0x0000 }; /* "correct" */ /*const UChar expResult[] = { 0x0074, 0x0065, 0x0069, 0x006E, 0x0064, 0x0065, 0x0073, 0x0074, 0x0000 }; *//*teindest*/ const char *testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } log_verbose("Testing ures_open()......\n"); rb = ures_open(testdatapath, "te_IN", &status); if(U_FAILURE(status)) { log_err("Could not open te_IN (%s)\n", myErrorName(status)); return; } alias = ures_getByKey(rb, "rootAliasClient", alias, &status); if(U_FAILURE(status)) { log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); ures_close(rb); return; } result = tres_getString(alias, -1, NULL, &len, &status); if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); } alias = ures_getByKey(rb, "aliasClient", alias, &status); if(U_FAILURE(status)) { log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); ures_close(rb); return; } result = tres_getString(alias, -1, NULL, &len, &status); if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); } alias = ures_getByKey(rb, "nestedRootAliasClient", alias, &status); if(U_FAILURE(status)) { log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status)); ures_close(rb); return; } result = tres_getString(alias, -1, NULL, &len, &status); if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) { log_err("Couldn't get correct string value (%s)\n", myErrorName(status)); } ures_close(alias); ures_close(rb); } static void TestCLDRStyleAliases(void) { UErrorCode status = U_ZERO_ERROR; UResourceBundle *rb = NULL, *alias = NULL, *a=NULL; int32_t i, len; char resource[256]; const UChar *result = NULL; UChar expected[256]; const char *expects[7] = { "", "a41", "a12", "a03", "ar4" }; const char *testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } log_verbose("Testing CLDR style aliases......\n"); rb = ures_open(testdatapath, "te_IN_REVISED", &status); if(U_FAILURE(status)) { log_err("Could not open te_IN (%s)\n", myErrorName(status)); return; } alias = ures_getByKey(rb, "a", alias, &status); if(U_FAILURE(status)) { log_err("Couldn't find the aliased with name \"a\" resource (%s)\n", myErrorName(status)); ures_close(rb); return; } for(i = 1; i < 5 ; i++) { resource[0]='a'; resource[1]='0'+i; resource[2]=0; /* instead of sprintf(resource, "a%i", i); */ a = ures_getByKeyWithFallback(alias, resource, a, &status); result = tres_getString(a, -1, NULL, &len, &status); u_charsToUChars(expects[i], expected, strlen(expects[i])+1); if(U_FAILURE(status) || !result || u_strcmp(result, expected)) { log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource, expects[i], result, myErrorName(status)); status = U_ZERO_ERROR; } } ures_close(a); ures_close(alias); ures_close(rb); } static void TestFallbackCodes(void) { UErrorCode status = U_ZERO_ERROR; const char *testdatapath=loadTestData(&status); UResourceBundle *res = ures_open(testdatapath, "te_IN", &status); UResourceBundle *r = NULL, *fall = NULL; r = ures_getByKey(res, "tagged_array_in_Root_te_te_IN", r, &status); status = U_ZERO_ERROR; fall = ures_getByKeyWithFallback(r, "tag2", fall, &status); if(status != U_ZERO_ERROR) { log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status)); status = U_ZERO_ERROR; } fall = ures_getByKeyWithFallback(r, "tag7", fall, &status); if(status != U_USING_FALLBACK_WARNING) { log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status)); } status = U_ZERO_ERROR; fall = ures_getByKeyWithFallback(r, "tag1", fall, &status); if(status != U_USING_DEFAULT_WARNING) { log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status)); } status = U_ZERO_ERROR; ures_close(fall); ures_close(r); ures_close(res); } /* This test will crash if this doesn't work. Results don't need testing. */ static void TestStackReuse(void) { UResourceBundle table; UErrorCode errorCode = U_ZERO_ERROR; UResourceBundle *rb = ures_open(NULL, "en_US", &errorCode); if(U_FAILURE(errorCode)) { log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode)); return; } ures_initStackObject(&table); ures_getByKeyWithFallback(rb, "Types", &table, &errorCode); ures_getByKeyWithFallback(&table, "collation", &table, &errorCode); ures_close(rb); ures_close(&table); } /* Test ures_getUTF8StringXYZ() --------------------------------------------- */ /* * Replace most ures_getStringXYZ() with this function which wraps the * desired call and also calls the UTF-8 variant and checks that it works. */ extern const UChar * tres_getString(const UResourceBundle *resB, int32_t index, const char *key, int32_t *length, UErrorCode *status) { char buffer8[16]; char *p8; const UChar *s16; const char *s8; UChar32 c16, c8; int32_t length16, length8, i16, i8; UBool forceCopy; if(length == NULL) { length = &length16; } if(index >= 0) { s16 = ures_getStringByIndex(resB, index, length, status); } else if(key != NULL) { s16 = ures_getStringByKey(resB, key, length, status); } else { s16 = ures_getString(resB, length, status); } if(U_FAILURE(*status)) { return s16; } length16 = *length; /* try the UTF-8 variant of ures_getStringXYZ() */ for(forceCopy = FALSE; forceCopy <= TRUE; ++forceCopy) { p8 = buffer8; length8 = (int32_t)sizeof(buffer8); if(index >= 0) { s8 = ures_getUTF8StringByIndex(resB, index, p8, &length8, forceCopy, status); } else if(key != NULL) { s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); } else { s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status); } if(*status == U_INVALID_CHAR_FOUND) { /* the UTF-16 string contains an unpaired surrogate, can't test UTF-8 variant */ return s16; } if(*status == U_BUFFER_OVERFLOW_ERROR) { *status = U_ZERO_ERROR; p8 = (char *)malloc(++length8); if(p8 == NULL) { return s16; } if(index >= 0) { s8 = ures_getUTF8StringByIndex(resB, index, p8, &length8, forceCopy, status); } else if(key != NULL) { s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); } else { s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status); } } if(U_FAILURE(*status)) { /* something unexpected happened */ if(p8 != buffer8) { free(p8); } return s16; } if(forceCopy && s8 != p8) { log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n", resB, (long)index, key); } /* verify NUL-termination */ if((p8 != buffer8 || length8 < sizeof(buffer8)) && s8[length8] != 0) { log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n", resB, (long)index, key); } /* verify correct string */ i16 = i8 = 0; while(i16 < length16 && i8 < length8) { U16_NEXT(s16, i16, length16, c16); U8_NEXT(s8, i8, length8, c8); if(c16 != c8) { log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n", resB, (long)index, key, (long)c16, (long)c8, (long)i16); } } /* verify correct length */ if(i16 < length16) { log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n", resB, (long)index, key, (long)length8, (long)length16); } if(i8 < length8) { log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n", resB, (long)index, key, (long)length8, (long)length16); } /* clean up */ if(p8 != buffer8) { free(p8); } } return s16; } /* * API tests for ures_getUTF8String(). * Most cases are handled by tres_getString(), which leaves argument checking * to be tested here. * Since the variants share most of their implementation, we only need to test * one of them. * We also need not test for checking arguments which will be checked by the * UTF-16 ures_getStringXYZ() that are called internally. */ static void TestGetUTF8String() { UResourceBundle *res; const char *testdatapath; char buffer8[16]; const char *s8; int32_t length8; UErrorCode status; status = U_ZERO_ERROR; testdatapath = loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); return; } res = ures_open(testdatapath, "", &status); if(U_FAILURE(status)) { log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status)); return; } /* one good call */ status = U_ZERO_ERROR; length8 = (int32_t)sizeof(buffer8); s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status); if(status != U_ZERO_ERROR) { log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status)); } /* negative capacity */ status = U_ZERO_ERROR; length8 = -1; s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status); if(status != U_ILLEGAL_ARGUMENT_ERROR) { log_err("ures_getUTF8StringByKey(capacity<0) malfunctioned - %s\n", u_errorName(status)); } /* capacity>0 but dest=NULL */ status = U_ZERO_ERROR; length8 = (int32_t)sizeof(buffer8); s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", NULL, &length8, FALSE, &status); if(status != U_ILLEGAL_ARGUMENT_ERROR) { log_err("ures_getUTF8StringByKey(dest=NULL capacity>0) malfunctioned - %s\n", u_errorName(status)); } ures_close(res); } static void TestCLDRVersion(void) { UVersionInfo zeroVersion; UVersionInfo testExpect; UVersionInfo testCurrent; UVersionInfo cldrVersion; char tmp[200]; UErrorCode status = U_ZERO_ERROR; /* setup the constant value */ u_versionFromString(zeroVersion, "0.0.0.0"); /* test CLDR value from API */ ulocdata_getCLDRVersion(cldrVersion, &status); if(U_FAILURE(status)) { /* the show is pretty much over at this point */ log_err_status(status, "FAIL: ulocdata_getCLDRVersion() returned %s\n", u_errorName(status)); return; } else { u_versionToString(cldrVersion, tmp); log_info("ulocdata_getCLDRVersion() returned: '%s'\n", tmp); } /* setup from resource bundle */ { UResourceBundle *res; const char *testdatapath; status = U_ZERO_ERROR; testdatapath = loadTestData(&status); if(U_FAILURE(status)) { log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); return; } res = ures_openDirect(testdatapath, "root", &status); if(U_FAILURE(status)) { log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status )); return; } ures_getVersionByKey(res, "ExpectCLDRVersionAtLeast", testExpect, &status); ures_getVersionByKey(res, "CurrentCLDRVersion", testCurrent, &status); ures_close(res); if(U_FAILURE(status)) { log_err("Unable to get test data for CLDR version - %s\n", u_errorName(status)); } } if(U_FAILURE(status)) return; u_versionToString(testExpect,tmp); log_verbose("(data) ExpectCLDRVersionAtLeast { %s }\n", tmp); if(memcmp(cldrVersion, testExpect, sizeof(UVersionInfo)) < 0) { log_data_err("CLDR version is too old, expect at least %s.", tmp); } u_versionToString(testCurrent,tmp); log_verbose("(data) CurrentCLDRVersion { %s }\n", tmp); switch(memcmp(cldrVersion, testCurrent, sizeof(UVersionInfo))) { case 0: break; /* OK- current. */ case -1: log_info("CLDR version is behind 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; case 1: log_info("CLDR version is ahead of 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; } }