summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/test/cintltst/creststn.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/icu-xetex/test/cintltst/creststn.c')
-rw-r--r--Build/source/libs/icu-xetex/test/cintltst/creststn.c392
1 files changed, 317 insertions, 75 deletions
diff --git a/Build/source/libs/icu-xetex/test/cintltst/creststn.c b/Build/source/libs/icu-xetex/test/cintltst/creststn.c
index a79fc6232c0..f2cfa9cd727 100644
--- a/Build/source/libs/icu-xetex/test/cintltst/creststn.c
+++ b/Build/source/libs/icu-xetex/test/cintltst/creststn.c
@@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2005, International Business Machines Corporation and
+ * Copyright (c) 1997-2006, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
@@ -25,6 +25,7 @@
#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"
@@ -175,6 +176,8 @@ static void TestGetKeywordValues(void);
static void TestGetFunctionalEquivalent(void);
static void TestCLDRStyleAliases(void);
static void TestFallbackCodes(void);
+static void TestGetUTF8String(void);
+
/***************************************************************************************/
/* Array of our test objects */
@@ -184,7 +187,7 @@ void addNEWResourceBundleTest(TestNode** root)
addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes");
addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle");
addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1");
- addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundle");
+ addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundles");
addTest(root, &TestFallback, "tsutil/creststn/TestFallback");
addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion");
addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl");
@@ -203,6 +206,8 @@ void addNEWResourceBundleTest(TestNode** root)
addTest(root, &TestXPath, "tsutil/creststn/TestXPath");
addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases");
addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes");
+ addTest(root, &TestStackReuse, "tsutil/creststn/TestStackReuse");
+ addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String");
}
@@ -414,7 +419,7 @@ static void TestDecodedBundle(){
int32_t num =0;
const char *testdatapath = loadTestData(&error);
resB = ures_open(testdatapath, "iscii", &error);
- srcFromRes=ures_getStringByKey(resB,"str",&len,&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");
@@ -466,7 +471,7 @@ static void TestNewTypes() {
theBundle = ures_open(testdatapath, "testtypes", &status);
- empty = ures_getStringByKey(theBundle, "emptystring", &len, &status);
+ empty = tres_getString(theBundle, -1, "emptystring", &len, &status);
if(empty && (*empty != 0 || len != 0)) {
log_err("Empty string returned invalid value\n");
}
@@ -483,7 +488,7 @@ static void TestNewTypes() {
res = ures_getByKey(theBundle, "zerotest", res, &status);
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
- zeroString=ures_getString(res, &len, &status);
+ zeroString=tres_getString(res, -1, NULL, &len, &status);
if(U_SUCCESS(status)){
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(len, 7);
@@ -569,7 +574,7 @@ static void TestNewTypes() {
/* this tests if escapes are preserved or not */
{
- const UChar* str = ures_getStringByKey(theBundle,"testescape",&len,&status);
+ const UChar* str = tres_getString(theBundle,-1,"testescape",&len,&status);
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
if(U_SUCCESS(status)){
u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1);
@@ -608,7 +613,7 @@ static void TestNewTypes() {
patternLen = (int32_t)uprv_strlen(pattern);
expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen);
- got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status);
+ got = tres_getString(theBundle,-1,"test_unescaping",&len,&status);
expectedLen = u_unescape(pattern,expectedEscaped,patternLen);
if(got==NULL || u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){
log_err("genrb failed to unescape string\n");
@@ -625,7 +630,7 @@ static void TestNewTypes() {
}
/* test for jitterbug#1435 */
{
- const UChar* str = ures_getStringByKey(theBundle,"test_underscores",&len,&status);
+ const UChar* str = tres_getString(theBundle,-1,"test_underscores",&len,&status);
expect ="test message ....";
u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1);
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
@@ -634,6 +639,7 @@ static void TestNewTypes() {
}
}
/* test for jitterbug#2626 */
+#if !UCONFIG_NO_COLLATION
{
UResourceBundle* resB = NULL;
const UChar* str = NULL;
@@ -642,7 +648,7 @@ static void TestNewTypes() {
status = U_ZERO_ERROR;
resB = ures_getByKey(theBundle, "collations", resB, &status);
resB = ures_getByKey(resB, "standard", resB, &status);
- str = ures_getStringByKey(resB,"Sequence",&strLength,&status);
+ str = tres_getString(resB,-1,"Sequence",&strLength,&status);
if(!str || U_FAILURE(status)) {
log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status));
} else if(u_strcmp(my,str) != 0){
@@ -650,6 +656,7 @@ static void TestNewTypes() {
}
ures_close(resB);
}
+#endif
{
const char *sourcePath = ctest_dataSrcDir();
int32_t srcPathLen = (int32_t)strlen(sourcePath);
@@ -665,7 +672,7 @@ static void TestNewTypes() {
status = U_ZERO_ERROR;
{
int32_t strLen =0;
- const UChar* str = ures_getStringByKey(theBundle, "testincludeUTF",&strLen,&status);
+ const UChar* str = tres_getString(theBundle, -1, "testincludeUTF",&strLen,&status);
strcpy(path, "riwords.txt");
path[strlen("riwords.txt")]=0;
if(U_FAILURE(status)){
@@ -702,7 +709,7 @@ static void TestNewTypes() {
status = U_ZERO_ERROR;
{
int32_t strLen =0;
- const UChar* str = ures_getStringByKey(theBundle, "testinclude",&strLen,&status);
+ const UChar* str = tres_getString(theBundle, -1, "testinclude",&strLen,&status);
strcpy(path, "translit_rules.txt");
path[strlen("translit_rules.txt")]=0;
@@ -775,7 +782,7 @@ static void TestEmptyTypes() {
res = ures_getByKey(theBundle, "emptyexplicitstring", res, &status);
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
- zeroString=ures_getString(res, &len, &status);
+ zeroString=tres_getString(res, -1, NULL, &len, &status);
if(U_SUCCESS(status)){
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(len, 0);
@@ -790,7 +797,7 @@ static void TestEmptyTypes() {
res = ures_getByKey(theBundle, "emptystring", res, &status);
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
- zeroString=ures_getString(res, &len, &status);
+ zeroString=tres_getString(res, -1, NULL, &len, &status);
if(U_SUCCESS(status)){
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
CONFIRM_INT_EQ(len, 0);
@@ -973,6 +980,7 @@ static void TestAPI() {
const char* testdatapath;
UChar* utestdatapath=NULL;
char convOutput[256];
+ UChar largeBuffer[1025];
UResourceBundle *teRes = NULL;
UResourceBundle *teFillin=NULL;
UResourceBundle *teFillin2=NULL;
@@ -1000,8 +1008,18 @@ static void TestAPI() {
}
#endif
+ u_memset(largeBuffer, 0x0030, sizeof(largeBuffer)/sizeof(largeBuffer[0]));
+ largeBuffer[sizeof(largeBuffer)/sizeof(largeBuffer[0])-1] = 0;
+
/*Test ures_openU */
+ status = U_ZERO_ERROR;
+ ures_close(ures_openU(largeBuffer, "root", &status));
+ if(status != U_ILLEGAL_ARGUMENT_ERROR){
+ log_err("ERROR: ures_openU() worked when the path is very large. It returned %s\n", myErrorName(status));
+ }
+
+ status = U_ZERO_ERROR;
ures_close(ures_openU(NULL, "root", &status));
if(U_FAILURE(status)){
log_err("ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status));
@@ -1056,7 +1074,7 @@ static void TestAPI() {
if(U_FAILURE(status)){
log_err("ERROR: ures_getByIndex on string resource failed\n");
}
- if(strcmp(u_austrcpy(convOutput, ures_getString(teFillin2, &len, &status)), "TE") != 0){
+ if(strcmp(u_austrcpy(convOutput, tres_getString(teFillin2, -1, NULL, &len, &status)), "TE") != 0){
status=U_ZERO_ERROR;
log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2, &len, &status)));
}
@@ -1155,8 +1173,8 @@ static void TestErrorConditions(){
log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
status=U_ZERO_ERROR;
ures_openFillIn(NULL, testdatapath, "te", &status);
- if(status != U_INTERNAL_PROGRAM_ERROR){
- log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_INTERNAL_PROGRAM_ERROR, Got: %s\n",
+ if(status != U_ILLEGAL_ARGUMENT_ERROR){
+ log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
myErrorName(status));
}
/*Test ures_getLocale() with status != U_ZERO_ERROR*/
@@ -1409,7 +1427,7 @@ static void TestGetVersionColl(){
return;
}
/* test NUL termination of UCARules */
- rules = ures_getStringByKey(resB,"UCARules",&len, &status);
+ 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;
@@ -1502,8 +1520,8 @@ static void TestConstruction1()
log_err("construction of %s did not succeed : %s \n", locale, myErrorName(status));
return;
}
- result1= ures_getStringByKey(test1, "string_in_Root_te_te_IN", &len1, &err);
- result2= ures_getStringByKey(test2, "string_in_Root_te_te_IN", &len2, &err);
+ 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;
@@ -1670,7 +1688,7 @@ static UBool testTag(const char* frag,
status = U_ZERO_ERROR;
len=0;
- string=ures_getStringByKey(theBundle, tag, &len, &status);
+ 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);
@@ -1716,7 +1734,7 @@ static UBool testTag(const char* frag,
u_strcat(expected_string, element);
arrayItem1=ures_getNextResource(array, arrayItem1, &status);
if(U_SUCCESS(status)){
- CONFIRM_EQ(ures_getString(arrayItem1, &len, &status),expected_string);
+ CONFIRM_EQ(tres_getString(arrayItem1, -1, NULL, &len, &status),expected_string);
}
}
@@ -1808,7 +1826,7 @@ static UBool testTag(const char* frag,
u_strcat(expected_string, element);
arrayItem1=ures_getNextResource(tableRow, arrayItem1, &status);
if(U_SUCCESS(status)){
- const UChar *stringValue=ures_getString(arrayItem1, &len, &status);
+ const UChar *stringValue=tres_getString(arrayItem1, -1, NULL, &len, &status);
CONFIRM_EQ(stringValue, expected_string);
}
}
@@ -1925,7 +1943,7 @@ static UBool testTag(const char* frag,
}else{
record_fail();
}
- t=(UChar*)ures_getString(tagelement, &len, &status);
+ t=(UChar*)tres_getString(tagelement, -1, NULL, &len, &status);
if(!U_FAILURE(status)){
string=t;
}
@@ -1994,11 +2012,11 @@ static void TestFallback()
/* clear it out.. just do some calls to get the gears turning */
- junk = ures_getStringByKey(fr_FR, "LocaleID", &resultLen, &status);
+ junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status);
status = U_ZERO_ERROR;
- junk = ures_getStringByKey(fr_FR, "LocaleString", &resultLen, &status);
+ junk = tres_getString(fr_FR, -1, "LocaleString", &resultLen, &status);
status = U_ZERO_ERROR;
- junk = ures_getStringByKey(fr_FR, "LocaleID", &resultLen, &status);
+ junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status);
status = U_ZERO_ERROR;
/* OK first one. This should be a Default value. */
@@ -2013,7 +2031,7 @@ static void TestFallback()
ures_close(subResource);
/* and this is a Fallback, to fr */
- junk = ures_getStringByKey(fr_FR, "Countries", &resultLen, &status);
+ junk = tres_getString(fr_FR, -1, "Countries", &resultLen, &status);
if(status != U_USING_FALLBACK_WARNING)
{
log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get Countries from fr_FR, got %d\n",
@@ -2030,18 +2048,20 @@ static void TestFallback()
UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err);
UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err);
UResourceBundle* tResB;
- static const UChar versionStr[] = { 0x0031, 0x002E, 0x0032, 0x0037, 0x0000};
+ const UChar* version = NULL;
+ static const UChar versionStr[] = { 0x0031, 0x002E, 0x0033, 0x0037, 0x0000};
if(err != U_ZERO_ERROR){
log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err));
return;
}
- if(u_strcmp(ures_getString(resLocID, &resultLen, &err), versionStr) != 0){
+ version = tres_getString(resLocID, -1, NULL, &resultLen, &err);
+ if(u_strcmp(version, versionStr) != 0){
log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value\n");
}
- tResB = ures_getByKey(myResB, "calendar", NULL, &err);
+ tResB = ures_getByKey(myResB, "zoneStrings", NULL, &err);
if(err != U_USING_FALLBACK_WARNING){
- log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for calendar err=%s\n",u_errorName(err));
+ log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for zoneStrings err=%s\n",u_errorName(err));
}
ures_close(resLocID);
ures_close(myResB);
@@ -2064,8 +2084,8 @@ static void TestResourceLevelAliasing(void) {
UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL;
const char* testdatapath = NULL;
const UChar *string = NULL, *sequence = NULL;
- const uint8_t *binary = NULL, *binSequence = NULL;
- int32_t strLen = 0, seqLen = 0, binLen = 0, binSeqLen = 0;
+ /*const uint8_t *binary = NULL, *binSequence = NULL;*/
+ int32_t strLen = 0, seqLen = 0;/*, binLen = 0, binSeqLen = 0;*/
char buffer[100];
char *s;
@@ -2114,16 +2134,16 @@ static void TestResourceLevelAliasing(void) {
goto cleanup;
}
- sequence = ures_getString(uk, &seqLen, &status);
+ sequence = tres_getString(uk, -1, NULL, &seqLen, &status);
tb = ures_getByKey(aliasB, "referencingalias", tb, &status);
- string = ures_getString(tb, &strLen, &status);
+ string = tres_getString(tb, -1, NULL, &strLen, &status);
if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
log_err("Referencing alias didn't get the right string\n");
}
- string = ures_getStringByKey(aliasB, "referencingalias", &strLen, &status);
+ string = tres_getString(aliasB, -1, "referencingalias", &strLen, &status);
if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
log_err("Referencing alias didn't get the right string\n");
}
@@ -2133,7 +2153,7 @@ static void TestResourceLevelAliasing(void) {
checkStatus(__LINE__, U_ZERO_ERROR, status);
tb = ures_getByIndex(tb, 2, tb, &status);
checkStatus(__LINE__, U_ZERO_ERROR, status);
- string = ures_getString(tb, &strLen, &status);
+ string = tres_getString(tb, -1, NULL, &strLen, &status);
checkStatus(__LINE__, U_ZERO_ERROR, status);
if(U_FAILURE(status)) {
@@ -2142,28 +2162,34 @@ static void TestResourceLevelAliasing(void) {
log_err("Referencing alias didn't get the right string\n");
}
- /* check whether the binary collation data is properly referenced by an alias */
- uk = ures_findResource("th/BreakDictionaryData", uk, &status);
- binSequence = ures_getBinary(uk, &binSeqLen, &status);
-
- tb = ures_getByKey(aliasB, "BreakDictionaryData", tb, &status);
- binary = ures_getBinary(tb, &binLen, &status);
-
- if(U_FAILURE(status)) {
- log_err("%s trying to read binary BreakDictionaryData\n");
- } else if(binSeqLen != binLen || memcmp(binSequence, binary, binSeqLen) != 0) {
- log_err("Referencing alias didn't get the right data\n");
+
+ {
+ UResourceBundle* ja = ures_open(U_ICUDATA_BRKITR,"ja", &status);
+ const UChar *got = NULL, *exp=NULL;
+ int32_t gotLen = 0, expLen=0;
+ ja = ures_getByKey(ja, "boundaries", ja, &status);
+ exp = tres_getString(ja, -1, "word", &expLen, &status);
+
+ tb = ures_getByKey(aliasB, "boundaries", tb, &status);
+ got = tres_getString(tb, -1, "word", &gotLen, &status);
+
+ if(U_FAILURE(status)) {
+ log_err("%s trying to read str boundaries\n");
+ } else if(gotLen != expLen || u_strncmp(exp, got, gotLen) != 0) {
+ log_err("Referencing alias didn't get the right data\n");
+ }
+ ures_close(ja);
+ status = U_ZERO_ERROR;
}
-
/* simple alias */
testtypes = ures_open(testdatapath, "testtypes", &status);
strcpy(buffer, "menu/file/open");
s = buffer;
uk = ures_findSubResource(testtypes, s, uk, &status);
- sequence = ures_getString(uk, &seqLen, &status);
+ sequence = tres_getString(uk, -1, NULL, &seqLen, &status);
tb = ures_getByKey(aliasB, "simplealias", tb, &status);
- string = ures_getString(tb, &strLen, &status);
+ string = tres_getString(tb, -1, NULL, &strLen, &status);
if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
log_err("Referencing alias didn't get the right string\n");
@@ -2173,10 +2199,10 @@ static void TestResourceLevelAliasing(void) {
tb = ures_getByKey(aliasB, "zoneTests", tb, &status);
tb = ures_getByKey(tb, "zoneAlias2", tb, &status);
- string = ures_getString(tb, &strLen, &status);
+ string = tres_getString(tb, -1, NULL, &strLen, &status);
en = ures_findResource("en/zoneStrings/3/0", en, &status);
- sequence = ures_getString(en, &seqLen, &status);
+ sequence = tres_getString(en, -1, NULL, &seqLen, &status);
if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
log_err("Referencing alias didn't get the right string\n");
@@ -2207,23 +2233,35 @@ static void TestResourceLevelAliasing(void) {
log_err("Couldn't get testGetStringByKeyAliasing resource\n");
}
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
- result = ures_getStringByKey(tb, keys[i], &resultLen, &status);
+ result = tres_getString(tb, -1, keys[i], &resultLen, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
+ continue;
+ }
uBufferLen = u_unescape(strings[i], uBuffer, 256);
if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
log_err("Didn't get correct string while accesing alias table by key (%s)\n", keys[i]);
}
}
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
- result = ures_getStringByIndex(tb, i, &resultLen, &status);
+ result = tres_getString(tb, i, NULL, &resultLen, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
+ continue;
+ }
uBufferLen = u_unescape(strings[i], uBuffer, 256);
- if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+ if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
log_err("Didn't get correct string while accesing alias table by index (%s)\n", strings[i]);
}
}
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
result = ures_getNextString(tb, &resultLen, &key, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
+ continue;
+ }
uBufferLen = u_unescape(strings[i], uBuffer, 256);
- if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+ if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
log_err("Didn't get correct string while iterating over alias table (%s)\n", strings[i]);
}
}
@@ -2232,20 +2270,35 @@ static void TestResourceLevelAliasing(void) {
log_err("Couldn't get testGetStringByIndexAliasing resource\n");
}
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
- result = ures_getStringByIndex(tb, i, &resultLen, &status);
+ result = tres_getString(tb, i, NULL, &resultLen, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
+ continue;
+ }
uBufferLen = u_unescape(strings[i], uBuffer, 256);
- if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+ if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]);
}
}
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
result = ures_getNextString(tb, &resultLen, &key, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
+ continue;
+ }
uBufferLen = u_unescape(strings[i], uBuffer, 256);
- if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+ if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings[i]);
}
}
}
+ tb = ures_getByKey(aliasB, "testAliasToTree", tb, &status);
+ if(U_FAILURE(status)){
+ log_err("Fetching the resource with key \"testAliasToTree\" failed. Error: %s\n", u_errorName(status));
+ }
+ if (strcmp(ures_getKey(tb), "collations") != 0) {
+ log_err("ures_getKey(aliasB) unexpectedly returned %s instead of \"collations\"\n", ures_getKey(tb));
+ }
cleanup:
ures_close(aliasB);
ures_close(tb);
@@ -2261,8 +2314,13 @@ static void TestDirectAccess(void) {
char buffer[100];
char *s;
+ /*const char* testdatapath=loadTestData(&status);
+ if(U_FAILURE(status)){
+ log_err("Could not load testdata.dat %s \n",myErrorName(status));
+ return;
+ }*/
- t = ures_findResource("en/zoneStrings/3/2", t, &status);
+ t = ures_findResource("/testdata/te/zoneStrings/3/2", t, &status);
if(U_FAILURE(status)) {
log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
status = U_ZERO_ERROR;
@@ -2272,7 +2330,7 @@ static void TestDirectAccess(void) {
log_err("Got a strange key, expected NULL, got %s\n", key);
}
}
- t = ures_findResource("en/zoneStrings/3", t, &status);
+ t = ures_findResource("en/calendar/gregorian/DateTimePatterns/3", t, &status);
if(U_FAILURE(status)) {
log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
status = U_ZERO_ERROR;
@@ -2316,7 +2374,7 @@ static void TestDirectAccess(void) {
}
}
- t = ures_findResource("root/calendar/islamic-civil/DateTimePatterns", t, &status);
+ t = ures_findResource("root/calendar/islamic-civil/DateTime", t, &status);
if(U_SUCCESS(status)) {
log_err("This resource does not exist. How did it get here?\n");
}
@@ -2333,7 +2391,7 @@ static void TestDirectAccess(void) {
t2 = ures_open(NULL, "he", &status);
t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status);
t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status);
- t2 = ures_getByKeyWithFallback(t2, "DateTimePatterns", t2, &status);
+ t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status);
if(U_SUCCESS(status)) {
log_err("This resource does not exist. How did it get here?\n");
}
@@ -2354,7 +2412,7 @@ static void TestDirectAccess(void) {
t2 = ures_open(NULL, "root", &status);
t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status);
t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status);
- t2 = ures_getByKeyWithFallback(t2, "DateTimePatterns", t2, &status);
+ t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status);
if(U_SUCCESS(status)) {
log_err("This resource does not exist. How did it get here?\n");
}
@@ -2458,10 +2516,10 @@ static void TestGetFunctionalEquivalentOf(const char *path, const char *resName,
log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale);
if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) {
- log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
- gotAvail?'t':'f', equivLocale,
- i/3,
- expectAvail?'t':'f', inLocale, expectLocale);
+ log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
+ gotAvail?'t':'f', equivLocale,
+ i/3,
+ expectAvail?'t':'f', inLocale, expectLocale);
}
}
@@ -2508,8 +2566,8 @@ static void TestGetFunctionalEquivalent(void) {
static const char *calCases[] = {
/* avail locale equiv */
- "t", "en_US", "en@calendar=gregorian",
- "f", "ja_JP_TOKYO", "ja@calendar=gregorian",
+ "t", "en_US_POSIX", "en_US@calendar=gregorian",
+ "f", "ja_JP_TOKYO", "ja_JP@calendar=gregorian",
"f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
"t", "sr@calendar=gregorian", "sr@calendar=gregorian",
"t", "en", "en@calendar=gregorian",
@@ -2572,7 +2630,7 @@ static void TestXPath(void) {
return;
}
- result = ures_getString(alias, &len, &status);
+ 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));
}
@@ -2584,7 +2642,7 @@ static void TestXPath(void) {
return;
}
- result = ures_getString(alias, &len, &status);
+ 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));
}
@@ -2596,7 +2654,7 @@ static void TestXPath(void) {
return;
}
- result = ures_getString(alias, &len, &status);
+ 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));
}
@@ -2636,7 +2694,7 @@ static void TestCLDRStyleAliases(void) {
resource[2]=0;
/* instead of sprintf(resource, "a%i", i); */
a = ures_getByKeyWithFallback(alias, resource, a, &status);
- result = ures_getString(a, &len, &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));
@@ -2685,3 +2743,187 @@ static void TestFallbackCodes(void) {
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_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_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);
+}