ICU-2558 fixed resb code overwriting warning statuses

X-SVN-Rev: 10599
This commit is contained in:
Vladimir Weinstein 2002-12-11 01:39:59 +00:00
parent b094732484
commit 42a9879b66
3 changed files with 62 additions and 4 deletions

View File

@ -279,7 +279,11 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
if(r != NULL) { /* if the entry is already in the hash table */
r->fCountExisting++; /* we just increase it's reference count */
*status = r->fBogus; /* and set returning status */
/* if the resource has a warning */
/* we don't want to overwrite a status with no error */
if(r->fBogus != U_ZERO_ERROR) {
*status = r->fBogus; /* set the returning status */
}
} else { /* otherwise, we'll try to construct a new entry */
UBool result = FALSE;
@ -485,7 +489,9 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID, UEr
umtx_unlock(&resbMutex);
if(U_SUCCESS(*status)) {
*status = intStatus;
if(intStatus != U_ZERO_ERROR) {
*status = intStatus;
}
return r;
} else {
return NULL;
@ -546,8 +552,9 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
/* first, open the bundle with real data */
UResourceBundle *result = resB;
const char* temp = NULL;
UResourceBundle *mainRes = ures_openDirect(path, locale, status);
if(U_SUCCESS(*status)) {
UErrorCode intStatus = U_ZERO_ERROR;
UResourceBundle *mainRes = ures_openDirect(path, locale, &intStatus);
if(U_SUCCESS(intStatus)) {
if(keyPath == NULL) {
/* no key path. This means that we are going to
* to use the corresponding resource from
@ -603,6 +610,8 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
result = resB;
}
}
} else { /* we failed to open the resource we're aliasing to */
*status = intStatus;
}
uprv_free(chAlias);
ures_close(mainRes);

View File

@ -170,6 +170,7 @@ static void TestDecodedBundle(void);
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");
@ -212,6 +213,52 @@ static const char* norwayLocales[] = {
"nb"
};
static void checkStatus(UErrorCode expected, UErrorCode status) {
if(status != expected) {
log_err("Expected error code %s, got error code %s\n", u_errorName(expected), u_errorName(status));
}
}
static void TestErrorCodes(void) {
UErrorCode status = U_USING_DEFAULT_WARNING;
UResourceBundle *r = NULL, *r2 = NULL;
/* first bundle should return fallback warning */
r = ures_open(NULL, "sr_YU_VOJVODINA", &status);
checkStatus(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, "sr_YU", &status);
checkStatus(U_USING_DEFAULT_WARNING, status);
/* we look up the resource which is aliased, but it lives in fallback */
status = U_USING_DEFAULT_WARNING;
r2 = ures_getByKey(r, "CollationElements", NULL, &status);
checkStatus(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, "sr", &status);
checkStatus(U_USING_DEFAULT_WARNING, status);
/* we look up the resource which is aliased and at our level */
status = U_USING_DEFAULT_WARNING;
r2 = ures_getByKey(r, "CollationElements", NULL, &status);
checkStatus(U_USING_DEFAULT_WARNING, status);
ures_close(r);
ures_close(r2);
status = U_USING_FALLBACK_WARNING;
r = ures_open(NULL, "nolocale", &status);
checkStatus(U_USING_DEFAULT_WARNING, status);
ures_close(r);
}
static void TestAliasConflict(void) {
UErrorCode status = U_ZERO_ERROR;
UResourceBundle *he = NULL;

View File

@ -54,6 +54,8 @@ static void TestDirectAccess(void);
static void TestResourceLevelAliasing(void);
static void TestErrorCodes(void);
/**
* extensive subtests called by TestResourceBundles
**/