/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation and
+ * Copyright (c) 1997-2006, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
#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"
#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)); }
+/*#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 void TestDecodedBundle(void);
static void TestGetKeywordValues(void);
static void TestGetFunctionalEquivalent(void);
+static void TestCLDRStyleAliases(void);
+static void TestFallbackCodes(void);
+static void TestGetUTF8String(void);
/***************************************************************************************/
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");
addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues");
addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent");
addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763");
-
+ 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");
}
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");
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");
}
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);
/* 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);
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");
}
/* 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);
}
}
/* test for jitterbug#2626 */
+#if !UCONFIG_NO_COLLATION
{
UResourceBundle* resB = NULL;
const UChar* str = NULL;
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){
}
ures_close(resB);
}
+#endif
{
const char *sourcePath = ctest_dataSrcDir();
int32_t srcPathLen = (int32_t)strlen(sourcePath);
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)){
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;
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);
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);
const char* testdatapath;
UChar* utestdatapath=NULL;
char convOutput[256];
+ UChar largeBuffer[1025];
UResourceBundle *teRes = NULL;
UResourceBundle *teFillin=NULL;
UResourceBundle *teFillin2=NULL;
utestdatapath = (UChar*) malloc((len+10)*sizeof(UChar));
u_charsToUChars(testdatapath, utestdatapath, (int32_t)strlen(testdatapath)+1);
- /*u_uastrcpy(utestdatapath, testdatapath);*/
+#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) && U_FILE_SEP_CHAR == '\\'
+ {
+ /* Convert all backslashes to forward slashes so that we can make sure that ures_openU
+ can handle invariant characters. */
+ UChar *backslash;
+ while ((backslash = u_strchr(utestdatapath, 0x005C))) {
+ *backslash = 0x002F;
+ }
+ }
+#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));
+ }
+
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ if(ures_openU(NULL, "root", &status) != NULL){
+ log_err("ERROR: ures_openU() worked with error status with %s\n", myErrorName(status));
+ }
+
+ status = U_ZERO_ERROR;
teRes=ures_openU(utestdatapath, "te", &status);
if(U_FAILURE(status)){
- log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath), myErrorName(status));
+ log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status));
return;
}
/*Test ures_getLocale() */
}
key=ures_getKey(teFillin);
/*if(strcmp(key, "%%CollationBin") != 0){*/
- if(strcmp(key, "array_2d_in_Root_te") != 0){
+ /*if(strcmp(key, "array_2d_in_Root_te") != 0){*/ /* added "aliasClient" that goes first */
+ if(strcmp(key, "a") != 0){
log_err("ERROR: ures_getNextResource() failed\n");
}
#endif
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)));
}
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*/
status=U_ZERO_ERROR;
teRes=ures_openU(utestdatapath, "te", &status);
if(U_FAILURE(status)){
- log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath), myErrorName(status));
+ log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status));
return;
}
status=U_ILLEGAL_ARGUMENT_ERROR;
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);
+ log_data_err("Could not load UCARules for locale %s\n", locName);
continue;
}
if(u_strlen(rules) != len){
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;
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);
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);
}
}
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);
}
}
}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;
}
/* 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. */
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",
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, 0};
+ 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);
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;
}
aliasB = ures_open(testdatapath, "testaliases", &status);
-
+
+ if(U_FAILURE(status))
+ {
+ log_err("Could not load testaliases.res %s \n",myErrorName(status));
+ return;
+ }
/* this should fail - circular alias */
tb = ures_getByKey(aliasB, "aaa", tb, &status);
if(status != U_TOO_MANY_ALIASES_ERROR) {
log_err("Failed to detect circular alias\n");
- } else {
+ }
+ else {
status = U_ZERO_ERROR;
}
tb = ures_getByKey(aliasB, "aab", tb, &status);
} else {
status = U_ZERO_ERROR;
}
-
/* testing referencing/composed alias */
uk = ures_findResource("ja/LocaleScript/2", uk, &status);
if((uk == NULL) || U_FAILURE(status)) {
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");
}
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)) {
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 || uprv_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");
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");
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]);
}
}
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);
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;
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;
}
}
- 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");
}
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");
}
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");
}
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);
}
}
"t", "hi@collation=direct", "hi@collation=direct",
"f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
"f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
- NULL
+ "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", "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",
#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_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_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_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_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_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_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);
+}