X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..73c04bcfe1096173b00431f0cdc742894b15eef0:/icuSources/test/intltest/restest.cpp diff --git a/icuSources/test/intltest/restest.cpp b/icuSources/test/intltest/restest.cpp index 8afa73af..72dc7c28 100644 --- a/icuSources/test/intltest/restest.cpp +++ b/icuSources/test/intltest/restest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -85,7 +85,7 @@ itoa(int32_t i, char* buf) // Array of our test objects -struct +static struct { const char* name; Locale *locale; @@ -108,7 +108,7 @@ param[] = { "ne", NULL, U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } } }; -int32_t bundles_count = sizeof(param) / sizeof(param[0]); +static const int32_t bundles_count = sizeof(param) / sizeof(param[0]); //*************************************************************************************** @@ -156,8 +156,7 @@ int32_t randi(int32_t n) */ ResourceBundleTest::ResourceBundleTest() : pass(0), - fail(0), - OUT(it_out) + fail(0) { if (param[5].locale == NULL) { param[0].locale = new Locale("root"); @@ -187,6 +186,8 @@ void ResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const char* case 0: name = "TestResourceBundles"; if (exec) TestResourceBundles(); break; case 1: name = "TestConstruction"; if (exec) TestConstruction(); break; case 2: name = "TestExemplar"; if (exec) TestExemplar(); break; + case 3: name = "TestGetSize"; if (exec) TestGetSize(); break; + case 4: name = "TestGetLocaleByType"; if (exec) TestGetLocaleByType(); break; default: name = ""; break; //needed to end loop } } @@ -479,6 +480,124 @@ ResourceBundleTest::TestExemplar(){ logln("Number of installed locales with exemplar characters that could be tested: %d",num); } - + +void +ResourceBundleTest::TestGetSize(void) +{ + const struct { + const char* key; + int32_t size; + } test[] = { + { "zerotest", 1}, + { "one", 1}, + { "importtest", 1}, + { "integerarray", 1}, + { "emptyarray", 0}, + { "emptytable", 0}, + { "emptystring", 1}, /* empty string is still a string */ + { "emptyint", 1}, + { "emptybin", 1}, + { "testinclude", 1}, + { "collations", 1}, /* not 2 - there is hidden %%CollationBin */ + }; + + UErrorCode status = U_ZERO_ERROR; + + const char* testdatapath = loadTestData(status); + int32_t i = 0, j = 0; + int32_t size = 0; + + if(U_FAILURE(status)) + { + err("Could not load testdata.dat %s\n", u_errorName(status)); + return; + } + + ResourceBundle rb(testdatapath, "testtypes", status); + if(U_FAILURE(status)) + { + err("Could not testtypes resource bundle %s\n", u_errorName(status)); + return; + } + + for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) { + ResourceBundle res = rb.get(test[i].key, status); + if(U_FAILURE(status)) + { + err("Couldn't find the key %s. Error: %s\n", u_errorName(status)); + return; + } + size = res.getSize(); + if(size != test[i].size) { + err("Expected size %i, got size %i for key %s\n", test[i].size, size, test[i].key); + for(j = 0; j < size; j++) { + ResourceBundle helper = res.get(j, status); + err("%s\n", helper.getKey()); + } + } + } +} + +void +ResourceBundleTest::TestGetLocaleByType(void) +{ + const struct { + const char *requestedLocale; + const char *resourceKey; + const char *validLocale; + const char *actualLocale; + } test[] = { + { "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" }, + { "te_IN_BLAH", "string_only_in_te", "te_IN", "te" }, + { "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" }, + { "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" }, + { "te_IN_BLAH@currency=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" }, + { "te_IN_BLAH@calendar=thai;collation=phonebook", "array_2d_only_in_te", "te_IN", "te" } + }; + + UErrorCode status = U_ZERO_ERROR; + + const char* testdatapath = loadTestData(status); + int32_t i = 0; + Locale locale; + + if(U_FAILURE(status)) + { + err("Could not load testdata.dat %s\n", u_errorName(status)); + return; + } + + for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) { + ResourceBundle rb(testdatapath, test[i].requestedLocale, status); + if(U_FAILURE(status)) + { + err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status)); + status = U_ZERO_ERROR; + continue; + } + + ResourceBundle res = rb.get(test[i].resourceKey, status); + if(U_FAILURE(status)) + { + err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status)); + status = U_ZERO_ERROR; + continue; + } + + locale = res.getLocale(ULOC_REQUESTED_LOCALE, status); + if(locale != Locale::getDefault()) { + err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); + } + locale = res.getLocale(ULOC_VALID_LOCALE, status); + if(strcmp(locale.getName(), test[i].validLocale) != 0) { + err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); + } + locale = res.getLocale(ULOC_ACTUAL_LOCALE, status); + if(strcmp(locale.getName(), test[i].actualLocale) != 0) { + err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); + } + } +} + //eof