OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2014, International Business Machines Corporation and | 3 * Copyright (c) 1997-2015, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ********************************************************************/ | 5 ********************************************************************/ |
6 //==============================================================================
= | 6 //==============================================================================
= |
7 // | 7 // |
8 // File apicoll.cpp | 8 // File apicoll.cpp |
9 // | 9 // |
10 // | 10 // |
11 // | 11 // |
12 // Created by: Helena Shih | 12 // Created by: Helena Shih |
13 // | 13 // |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 col->setStrength(Collator::PRIMARY); | 184 col->setStrength(Collator::PRIMARY); |
185 logln("testing Collator::getStrength() method again ..."); | 185 logln("testing Collator::getStrength() method again ..."); |
186 doAssert((col->getStrength() != Collator::TERTIARY), "collation object has t
he wrong strength"); | 186 doAssert((col->getStrength() != Collator::TERTIARY), "collation object has t
he wrong strength"); |
187 doAssert((col->getStrength() == Collator::PRIMARY), "collation object's stre
ngth is not primary difference"); | 187 doAssert((col->getStrength() == Collator::PRIMARY), "collation object's stre
ngth is not primary difference"); |
188 | 188 |
189 logln("testing French Collator::setStrength() method ..."); | 189 logln("testing French Collator::setStrength() method ..."); |
190 col->setStrength(Collator::TERTIARY); | 190 col->setStrength(Collator::TERTIARY); |
191 doAssert((col->getStrength() == Collator::TERTIARY), "collation object's str
ength is not tertiary difference"); | 191 doAssert((col->getStrength() == Collator::TERTIARY), "collation object's str
ength is not tertiary difference"); |
192 doAssert((col->getStrength() != Collator::PRIMARY), "collation object's stre
ngth is primary difference"); | 192 doAssert((col->getStrength() != Collator::PRIMARY), "collation object's stre
ngth is primary difference"); |
193 doAssert((col->getStrength() != Collator::SECONDARY), "collation object's st
rength is secondary difference"); | 193 doAssert((col->getStrength() != Collator::SECONDARY), "collation object's st
rength is secondary difference"); |
| 194 delete col; |
194 | 195 |
195 logln("Create junk collation: "); | 196 logln("Create junk collation: "); |
196 Locale abcd("ab", "CD", ""); | 197 Locale abcd("ab", "CD", ""); |
197 success = U_ZERO_ERROR; | 198 success = U_ZERO_ERROR; |
198 Collator *junk = 0; | 199 Collator *junk = 0; |
199 junk = Collator::createInstance(abcd, success); | 200 junk = Collator::createInstance(abcd, success); |
200 | 201 |
201 if (U_FAILURE(success)) | 202 if (U_FAILURE(success)) |
202 { | 203 { |
203 errln("Junk collation creation failed, should at least return default.")
; | 204 errln("Junk collation creation failed, should at least return default.")
; |
204 delete col; | |
205 return; | 205 return; |
206 } | 206 } |
207 | 207 |
208 delete col; | 208 doAssert(((RuleBasedCollator *)junk)->getRules().isEmpty(), |
209 col = Collator::createInstance(success); | 209 "The root collation should be returned for an unsupported languag
e."); |
210 if (U_FAILURE(success)) | |
211 { | |
212 errln("Creating default collator failed."); | |
213 delete junk; | |
214 return; | |
215 } | |
216 | |
217 doAssert(((RuleBasedCollator *)col)->getRules() == ((RuleBasedCollator *)jun
k)->getRules(), | |
218 "The default collation should be returned."); | |
219 Collator *frCol = Collator::createInstance(Locale::getCanadaFrench(), succes
s); | 210 Collator *frCol = Collator::createInstance(Locale::getCanadaFrench(), succes
s); |
220 if (U_FAILURE(success)) | 211 if (U_FAILURE(success)) |
221 { | 212 { |
222 errln("Creating fr_CA collator failed."); | 213 errln("Creating fr_CA collator failed."); |
223 delete col; | |
224 delete junk; | 214 delete junk; |
225 return; | 215 return; |
226 } | 216 } |
227 | 217 |
228 // If the default locale isn't French, the French and non-French collators | 218 // If the default locale isn't French, the French and non-French collators |
229 // should be different | 219 // should be different |
230 if (frCol->getLocale(ULOC_ACTUAL_LOCALE, success) != Locale::getCanadaFrench
()) { | 220 if (frCol->getLocale(ULOC_ACTUAL_LOCALE, success) != Locale::getCanadaFrench
()) { |
231 doAssert((*frCol != *junk), "The junk is the same as the fr_CA collator.
"); | 221 doAssert((*frCol != *junk), "The junk is the same as the fr_CA collator.
"); |
232 } | 222 } |
233 Collator *aFrCol = frCol->clone(); | 223 Collator *aFrCol = frCol->clone(); |
234 doAssert((*frCol == *aFrCol), "The cloning of a fr_CA collator failed."); | 224 doAssert((*frCol == *aFrCol), "The cloning of a fr_CA collator failed."); |
235 logln("Collator property test ended."); | 225 logln("Collator property test ended."); |
236 | 226 |
237 delete col; | |
238 delete frCol; | 227 delete frCol; |
239 delete aFrCol; | 228 delete aFrCol; |
240 delete junk; | 229 delete junk; |
241 } | 230 } |
242 | 231 |
243 void | 232 void |
244 CollationAPITest::TestRuleBasedColl() | 233 CollationAPITest::TestRuleBasedColl() |
245 { | 234 { |
246 RuleBasedCollator *col1, *col2, *col3, *col4; | 235 RuleBasedCollator *col1, *col2, *col3, *col4; |
247 UErrorCode status = U_ZERO_ERROR; | 236 UErrorCode status = U_ZERO_ERROR; |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 | 990 |
1002 | 991 |
1003 | 992 |
1004 logln("The compare tests end."); | 993 logln("The compare tests end."); |
1005 delete col; | 994 delete col; |
1006 } | 995 } |
1007 | 996 |
1008 void | 997 void |
1009 CollationAPITest::TestGetAll(/* char* par */) | 998 CollationAPITest::TestGetAll(/* char* par */) |
1010 { | 999 { |
1011 if (logKnownIssue("10774","Side effects from utility/LocaleTest/TestGetLocal
e")) { | |
1012 return; | |
1013 } | |
1014 int32_t count1, count2; | 1000 int32_t count1, count2; |
1015 UErrorCode status = U_ZERO_ERROR; | 1001 UErrorCode status = U_ZERO_ERROR; |
1016 | 1002 |
1017 logln("Trying Collator::getAvailableLocales(int&)"); | 1003 logln("Trying Collator::getAvailableLocales(int&)"); |
1018 | 1004 |
1019 const Locale* list = Collator::getAvailableLocales(count1); | 1005 const Locale* list = Collator::getAvailableLocales(count1); |
1020 for (int32_t i = 0; i < count1; ++i) { | 1006 for (int32_t i = 0; i < count1; ++i) { |
1021 UnicodeString dispName; | 1007 UnicodeString dispName; |
1022 logln(UnicodeString("Locale name: ") | 1008 logln(UnicodeString("Locale name: ") |
1023 + UnicodeString(list[i].getName()) | 1009 + UnicodeString(list[i].getName()) |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 vt[0] = 0x0041; | 1530 vt[0] = 0x0041; |
1545 | 1531 |
1546 (void)coll->setVariableTop(vt, 1, status); | 1532 (void)coll->setVariableTop(vt, 1, status); |
1547 if(status != U_ILLEGAL_ARGUMENT_ERROR) { | 1533 if(status != U_ILLEGAL_ARGUMENT_ERROR) { |
1548 errln("setVariableTop(letter) did not detect illegal argument - %s", u_error
Name(status)); | 1534 errln("setVariableTop(letter) did not detect illegal argument - %s", u_error
Name(status)); |
1549 } | 1535 } |
1550 | 1536 |
1551 status = U_ZERO_ERROR; | 1537 status = U_ZERO_ERROR; |
1552 vt[0] = 0x24; // dollar sign (currency symbol) | 1538 vt[0] = 0x24; // dollar sign (currency symbol) |
1553 uint32_t newVarTop = coll->setVariableTop(vt, 1, status); | 1539 uint32_t newVarTop = coll->setVariableTop(vt, 1, status); |
1554 | 1540 if(U_FAILURE(status)) { |
| 1541 errln("setVariableTop(dollar sign) failed: %s", u_errorName(status)); |
| 1542 return; |
| 1543 } |
1555 if(newVarTop != coll->getVariableTop(status)) { | 1544 if(newVarTop != coll->getVariableTop(status)) { |
1556 errln("setVariableTop(dollar sign) != following getVariableTop()"); | 1545 errln("setVariableTop(dollar sign) != following getVariableTop()"); |
1557 } | 1546 } |
1558 | 1547 |
1559 UnicodeString dollar((UChar)0x24); | 1548 UnicodeString dollar((UChar)0x24); |
1560 UnicodeString euro((UChar)0x20AC); | 1549 UnicodeString euro((UChar)0x20AC); |
1561 uint32_t newVarTop2 = coll->setVariableTop(euro, status); | 1550 uint32_t newVarTop2 = coll->setVariableTop(euro, status); |
1562 assertEquals("setVariableTop(Euro sign) == following getVariableTop()", | 1551 assertEquals("setVariableTop(Euro sign) == following getVariableTop()", |
1563 (int64_t)newVarTop2, (int64_t)coll->getVariableTop(status)); | 1552 (int64_t)newVarTop2, (int64_t)coll->getVariableTop(status)); |
1564 assertEquals("setVariableTop(Euro sign) == setVariableTop(dollar sign) (should
pin to top of currency group)", | 1553 assertEquals("setVariableTop(Euro sign) == setVariableTop(dollar sign) (should
pin to top of currency group)", |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 errln("[Coll actual \"%s\"]: Error in actual locale, got different one:
\"%s\"", | 1689 errln("[Coll actual \"%s\"]: Error in actual locale, got different one:
\"%s\"", |
1701 locale.getName(), actual2.getName()); | 1690 locale.getName(), actual2.getName()); |
1702 } | 1691 } |
1703 if(*coll2 != *coll) { | 1692 if(*coll2 != *coll) { |
1704 errln("[Coll actual \"%s\"]: Got different collator than before", locale
.getName()); | 1693 errln("[Coll actual \"%s\"]: Got different collator than before", locale
.getName()); |
1705 } | 1694 } |
1706 } | 1695 } |
1707 delete coll; | 1696 delete coll; |
1708 } | 1697 } |
1709 | 1698 |
1710 /* completely non-existant locale for collator should get a default collator *
/ | 1699 /* completely non-existent locale for collator should get a root collator */ |
1711 { | 1700 { |
1712 Collator *defaultColl = Collator::createInstance((const Locale)NULL, status)
; | 1701 LocalPointer<Collator> coll(Collator::createInstance("blahaha", status)); |
1713 coll = Collator::createInstance("blahaha", status); | |
1714 if(U_FAILURE(status)) { | 1702 if(U_FAILURE(status)) { |
1715 errln("Failed to open collator with %s", u_errorName(status)); | 1703 errln("Failed to open collator with %s", u_errorName(status)); |
1716 delete coll; | |
1717 delete defaultColl; | |
1718 return; | 1704 return; |
1719 } | 1705 } |
1720 if(coll->getLocale(ULOC_VALID_LOCALE, status) != | 1706 Locale valid = coll->getLocale(ULOC_VALID_LOCALE, status); |
1721 defaultColl->getLocale(ULOC_VALID_LOCALE, status)) { | 1707 const char *name = valid.getName(); |
1722 errln("Valid locale for nonexisting locale locale collator differs " | 1708 if(*name != 0 && strcmp(name, "root") != 0) { |
1723 "from valid locale for default collator"); | 1709 errln("Valid locale for nonexisting-locale collator is \"%s\" not root", n
ame); |
1724 } | 1710 } |
1725 if(coll->getLocale(ULOC_ACTUAL_LOCALE, status) != | 1711 Locale actual = coll->getLocale(ULOC_ACTUAL_LOCALE, status); |
1726 defaultColl->getLocale(ULOC_ACTUAL_LOCALE, status)) { | 1712 name = actual.getName(); |
1727 errln("Actual locale for nonexisting locale locale collator differs " | 1713 if(*name != 0 && strcmp(name, "root") != 0) { |
1728 "from actual locale for default collator"); | 1714 errln("Actual locale for nonexisting-locale collator is \"%s\" not root",
name); |
1729 } | 1715 } |
1730 delete coll; | |
1731 delete defaultColl; | |
1732 } | 1716 } |
1733 | 1717 |
1734 | 1718 |
1735 | 1719 |
1736 /* collator instantiated from rules should have all three locales NULL */ | 1720 /* collator instantiated from rules should have all three locales NULL */ |
1737 coll = new RuleBasedCollator(rlz, status); | 1721 coll = new RuleBasedCollator(rlz, status); |
1738 locale = coll->getLocale(ULOC_REQUESTED_LOCALE, status); | 1722 locale = coll->getLocale(ULOC_REQUESTED_LOCALE, status); |
1739 if(U_SUCCESS(status) && !locale.isBogus()) { | 1723 if(U_SUCCESS(status) && !locale.isBogus()) { |
1740 errln("For collator instantiated from rules, requested locale %s is not bogu
s", locale.getName()); | 1724 errln("For collator instantiated from rules, requested locale %s is not bogu
s", locale.getName()); |
1741 } | 1725 } |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2505 TESTCASE_AUTO(TestSubclass); | 2489 TESTCASE_AUTO(TestSubclass); |
2506 TESTCASE_AUTO(TestNULLCharTailoring); | 2490 TESTCASE_AUTO(TestNULLCharTailoring); |
2507 TESTCASE_AUTO(TestClone); | 2491 TESTCASE_AUTO(TestClone); |
2508 TESTCASE_AUTO(TestCloneBinary); | 2492 TESTCASE_AUTO(TestCloneBinary); |
2509 TESTCASE_AUTO(TestIterNumeric); | 2493 TESTCASE_AUTO(TestIterNumeric); |
2510 TESTCASE_AUTO(TestBadKeywords); | 2494 TESTCASE_AUTO(TestBadKeywords); |
2511 TESTCASE_AUTO_END; | 2495 TESTCASE_AUTO_END; |
2512 } | 2496 } |
2513 | 2497 |
2514 #endif /* #if !UCONFIG_NO_COLLATION */ | 2498 #endif /* #if !UCONFIG_NO_COLLATION */ |
OLD | NEW |