From b1303f5c86113dcccc256519cb0cf8423b75b8ba Mon Sep 17 00:00:00 2001 From: Alan Liu Date: Sat, 24 Apr 2004 03:00:12 +0000 Subject: [PATCH] ICU-3549 add tests of getAvailableLocales, getKeywords, and getKeywordValues X-SVN-Rev: 15044 --- icu4c/source/test/intltest/svccoll.cpp | 112 +++++++++++++++++++++++-- icu4c/source/test/intltest/svccoll.h | 17 +++- 2 files changed, 120 insertions(+), 9 deletions(-) diff --git a/icu4c/source/test/intltest/svccoll.cpp b/icu4c/source/test/intltest/svccoll.cpp index c5fcf044b6f..60323de12ba 100644 --- a/icu4c/source/test/intltest/svccoll.cpp +++ b/icu4c/source/test/intltest/svccoll.cpp @@ -13,10 +13,22 @@ #include "unicode/coll.h" #include "unicode/strenum.h" #include "hash.h" +#include "uassert.h" #include "ucol_imp.h" // internal api needed to test ucollator equality #include "cstring.h" // internal api used to compare locale strings +void CollationServiceTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par */) +{ + if (exec) logln("TestSuite CollationServiceTest: "); + switch (index) { + TESTCASE(0, TestRegister); + TESTCASE(1, TestRegisterFactory); + TESTCASE(2, TestSeparateTree); + default: name = ""; break; + } +} + void CollationServiceTest::TestRegister() { // register a singleton @@ -320,6 +332,7 @@ char TestFactory::gClassID = 0; void CollationServiceTest::TestRegisterFactory(void) { + int32_t n1, n2, n3; Locale fu_FU("fu", "FU", ""); Locale fu_FU_FOO("fu", "FU", "FOO"); @@ -369,7 +382,13 @@ void CollationServiceTest::TestRegisterFactory(void) Collator* fucol = Collator::createInstance(fu_FU, status); { + n1 = checkAvailable("before registerFactory"); + URegistryKey key = Collator::registerFactory(factory, status); + + n2 = checkAvailable("after registerFactory"); + assertTrue("count after > count before", n2 > n1); + Collator* ncol = Collator::createInstance(Locale::getUS(), status); if (*frcol != *ncol) { errln("frcoll for en_US failed"); @@ -429,21 +448,98 @@ void CollationServiceTest::TestRegisterFactory(void) if (*fucol != *ncol) { errln("collator after unregister does not match original fu_FU"); } - delete ncol; + delete ncol; + + n3 = checkAvailable("after unregister"); + assertTrue("count after unregister == count before register", n3 == n1); } delete fucol; delete uscol; } -void CollationServiceTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par */) -{ - if (exec) logln("TestSuite CollationServiceTest: "); - switch (index) { - TESTCASE(0, TestRegister); - TESTCASE(1, TestRegisterFactory); - default: name = ""; break; +/** + * Iterate through the given iterator, checking to see that all the strings + * in the expected array are present. + * @param expected array of strings we expect to see, or NULL + * @param expectedCount number of elements of expected, or 0 + */ +int32_t CollationServiceTest::checkStringEnumeration(const char* msg, + StringEnumeration& iter, + const char** expected, + int32_t expectedCount) { + UErrorCode ec = U_ZERO_ERROR; + U_ASSERT(expectedCount >= 0 && expectedCount < 31); // [sic] 31 not 32 + int32_t i = 0, n = iter.count(ec); + assertSuccess("count", ec); + UnicodeString buf; + int32_t seenMask = 0; + for (;; ++i) { + const UnicodeString* s = iter.snext(ec); + if (!assertSuccess("snext", ec) || s == NULL) break; + if (i != 0) buf.append(", "); + buf.append(*s); + // check expected list + for (int32_t j=0, bit=1; j