+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation and
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*******************************************************************************
#include "unicode/utypes.h"
#include "cintltst.h"
#include "unicode/ustring.h"
+#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
#include <stdlib.h>
#include "crestst.h"
#include "unicode/ctest.h"
-#include "ucol_imp.h" /* collation */
-
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
static void TestOpenDirect(void);
static void TestFallback(void);
static void TestTable32(void);
{ "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
};
-static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
+static int32_t bundles_count = UPRV_LENGTHOF(param);
void addResourceBundleTest(TestNode** root)
{
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
addTest(root, &TestConstruction1, "tsutil/crestst/TestConstruction1");
addTest(root, &TestOpenDirect, "tsutil/crestst/TestOpenDirect");
addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundles");
addTest(root, &TestTable32, "tsutil/crestst/TestTable32");
- addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
- addTest(root, &TestAliasConflict, "tsutil/crestst/TestAliasConflict");
addTest(root, &TestFileStream, "tsutil/crestst/TestFileStream");
addTest(root, &TestGetSize, "tsutil/crestst/TestGetSize");
addTest(root, &TestGetLocaleByType, "tsutil/crestst/TestGetLocaleByType");
+#endif
+ addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
+ addTest(root, &TestAliasConflict, "tsutil/crestst/TestAliasConflict");
+
}
he = ures_open(NULL, "he", &status);
iw = ures_open(NULL, "iw", &status);
if(U_FAILURE(status)) {
- log_err("Failed to get resource with %s\n", myErrorName(status));
+ log_err_status(status, "Failed to get resource with %s\n", myErrorName(status));
}
ures_close(iw);
- result = ures_getStringByKey(he, "localPatternChars", &resultLen, &status);
+ result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status);
if(U_FAILURE(status) || result == NULL) {
- log_err("Failed to get resource with %s\n", myErrorName(status));
+ log_err_status(status, "Failed to get resource with %s\n", myErrorName(status));
}
ures_close(he);
}
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);
testdatapath=loadTestData(&err);
if(U_FAILURE(err))
{
- log_err("Could not load testdata.dat %s \n",myErrorName(err));
+ log_data_err("Could not load testdata.dat %s \n",myErrorName(err));
return;
}
int n;
log_err("Construction test failed for ures_open();\n");
- if(!VERBOSITY)
+ if(!getTestOption(VERBOSITY_OPTION))
log_info("(run verbose for more information)\n");
log_verbose("\nGot->");
fr_FR = ures_open(NULL, "fr_FR", &status);
if(U_FAILURE(status))
{
- log_err("Couldn't open fr_FR - %d\n", status);
+ log_err_status(status, "Couldn't open fr_FR - %s\n", u_errorName(status));
return;
}
/* clear it out.. just do some calls to get the gears turning */
junk = ures_getStringByKey(fr_FR, "LocaleID", &resultLen, &status);
+ (void)junk; /* Suppress set but not used warning. */
status = U_ZERO_ERROR;
junk = ures_getStringByKey(fr_FR, "LocaleString", &resultLen, &status);
status = U_ZERO_ERROR;
status = U_ZERO_ERROR;
/* OK first one. This should be a Default value. */
- subResource = ures_getByKey(fr_FR, "MeasurementSystem", NULL, &status);
+ subResource = ures_getByKey(fr_FR, "layout", NULL, &status);
if(status != U_USING_DEFAULT_WARNING)
{
- log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get CurrencyMap from fr_FR, got %s\n",
+ log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get layout from fr_FR, got %s\n",
u_errorName(status));
}
ures_close(subResource);
status = U_ZERO_ERROR;
/* and this is a Fallback, to fr */
- junk = ures_getStringByKey(fr_FR, "Countries", &resultLen, &status);
+ junk = ures_getStringByKey(fr_FR, "ExemplarCharacters", &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 %s\n",
+ log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get ExemplarCharacters from fr_FR, got %s\n",
u_errorName(status));
}
static void
TestOpenDirect(void) {
- UResourceBundle *idna_rules, *item;
+ UResourceBundle *idna_rules, *casing, *te_IN, *ne, *item;
UErrorCode errorCode;
/*
* from root or similar
*/
errorCode=U_ZERO_ERROR;
- idna_rules=ures_openDirect("testdata", "idna_rules", &errorCode);
+ idna_rules=ures_openDirect(loadTestData(&errorCode), "idna_rules", &errorCode);
if(U_FAILURE(errorCode)) {
- log_err("ures_openDirect(\"idna_rules\") failed: %s\n", u_errorName(errorCode));
+ log_data_err("ures_openDirect(\"idna_rules\") failed: %s\n", u_errorName(errorCode));
return;
}
}
/* try an item in root, must fail */
- item=ures_getByKey(idna_rules, "Languages", NULL, &errorCode);
+ item=ures_getByKey(idna_rules, "ShortLanguage", NULL, &errorCode);
if(U_FAILURE(errorCode)) {
errorCode=U_ZERO_ERROR;
} else {
errorCode = U_USING_FALLBACK_WARNING;;
idna_rules=ures_openDirect("testdata", "idna_rules", &errorCode);
if(U_FAILURE(errorCode)) {
- log_err("ures_openDirect(\"idna_rules\") failed when U_USING_FALLBACK_WARNING was set prior to call: %s\n", u_errorName(errorCode));
+ log_data_err("ures_openDirect(\"idna_rules\") failed when U_USING_FALLBACK_WARNING was set prior to call: %s\n", u_errorName(errorCode));
return;
}
ures_close(idna_rules);
+
+ /*
+ * ICU 3.6 has new resource bundle syntax and data for bundles that do not
+ * participate in locale fallback. Now,
+ * - ures_open() works like ures_openDirect() on a bundle with a top-level
+ * type of ":table(nofallback)" _if_ the bundle exists
+ * - ures_open() will continue to find a root bundle if the requested one
+ * does not exist, unlike ures_openDirect()
+ *
+ * Test with a different bundle than above to avoid confusion in the cache.
+ */
+
+ /*
+ * verify that ures_open("casing"), which now has a nofallback declaration,
+ * does not enable fallbacks
+ */
+ errorCode=U_ZERO_ERROR;
+ casing=ures_open("testdata", "casing", &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_data_err("ures_open(\"casing\") failed: %s\n", u_errorName(errorCode));
+ return;
+ }
+
+ errorCode=U_ZERO_ERROR;
+ item=ures_getByKey(casing, "Info", NULL, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("casing.getByKey(Info) failed - %s\n", u_errorName(errorCode));
+ } else {
+ ures_close(item);
+ }
+
+ errorCode=U_ZERO_ERROR;
+ item=ures_getByKey(casing, "ShortLanguage", NULL, &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("casing.getByKey(root key) succeeded despite nofallback declaration - %s\n", u_errorName(errorCode));
+ ures_close(item);
+ }
+ ures_close(casing);
+
+ /*
+ * verify that ures_open("ne") finds the root bundle but
+ * ures_openDirect("ne") does not
+ */
+ errorCode=U_ZERO_ERROR;
+ ne=ures_open("testdata", "ne", &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_data_err("ures_open(\"ne\") failed (expected to get root): %s\n", u_errorName(errorCode));
+ }
+ if(errorCode!=U_USING_DEFAULT_WARNING || 0!=uprv_strcmp("root", ures_getLocale(ne, &errorCode))) {
+ log_err("ures_open(\"ne\") found something other than \"root\" - %s\n", u_errorName(errorCode));
+ }
+ ures_close(ne);
+
+ errorCode=U_ZERO_ERROR;
+ ne=ures_openDirect("testdata", "ne", &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_data_err("ures_openDirect(\"ne\") succeeded unexpectedly\n");
+ ures_close(ne);
+ }
+
+ /* verify that ures_openDirect("te_IN") does not enable fallbacks */
+ errorCode=U_ZERO_ERROR;
+ te_IN=ures_openDirect("testdata", "te_IN", &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_data_err("ures_open(\"te_IN\") failed: %s\n", u_errorName(errorCode));
+ return;
+ }
+ errorCode=U_ZERO_ERROR;
+ item=ures_getByKey(te_IN, "ShortLanguage", NULL, &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("te_IN.getByKey(root key) succeeded despite use of ures_openDirect() - %s\n", u_errorName(errorCode));
+ ures_close(item);
+ }
+ ures_close(te_IN);
}
static int32_t
}
/* search for some items by key */
- for(i=0; i<LENGTHOF(testcases); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(testcases); ++i) {
item=ures_getByKey(res, testcases[i].key, item, &errorCode);
if(U_FAILURE(errorCode)) {
log_err("unable to find the key \"%s\" in testdata/testtable32.res - %s\n",
if(U_FAILURE(status))
{
- log_err("Could not load testdata.dat %s\n", u_errorName(status));
+ log_data_err("Could not load testdata.dat %s\n", u_errorName(status));
return;
}
return;
}
- for(i = 0; i < sizeof(test)/sizeof(test[0]); i++) {
+ for(i = 0; i < UPRV_LENGTHOF(test); i++) {
res = ures_getByKey(rb, test[i].key, res, &status);
if(U_FAILURE(status))
{
if(U_FAILURE(status))
{
- log_err("Could not load testdata.dat %s\n", u_errorName(status));
+ log_data_err("Could not load testdata.dat %s\n", u_errorName(status));
return;
}
- for(i = 0; i < sizeof(test)/sizeof(test[0]); i++) {
+ for(i = 0; i < UPRV_LENGTHOF(test); i++) {
rb = ures_open(testdatapath, test[i].requestedLocale, &status);
if(U_FAILURE(status))
{
status = U_ZERO_ERROR;
continue;
}
-
+
locale = ures_getLocaleByType(res, ULOC_REQUESTED_LOCALE, &status);
- if(locale) {
+ if(U_SUCCESS(status) && locale != NULL) {
log_err("Requested locale should return NULL\n");
}
+ status = U_ZERO_ERROR;
locale = ures_getLocaleByType(res, ULOC_VALID_LOCALE, &status);
if(!locale || strcmp(locale, test[i].validLocale) != 0) {
log_err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale);
}
ures_close(res);
}
-