| OLD | NEW |
| (Empty) |
| 1 /******************************************************************** | |
| 2 * COPYRIGHT: | |
| 3 * Copyright (c) 1997-2009, International Business Machines Corporation and | |
| 4 * others. All Rights Reserved. | |
| 5 ********************************************************************/ | |
| 6 | |
| 7 #include "unicode/utypes.h" | |
| 8 | |
| 9 #if !UCONFIG_NO_COLLATION | |
| 10 | |
| 11 #ifndef _COLL | |
| 12 #include "unicode/coll.h" | |
| 13 #endif | |
| 14 | |
| 15 #ifndef _TBLCOLL | |
| 16 #include "unicode/tblcoll.h" | |
| 17 #endif | |
| 18 | |
| 19 #ifndef _UNISTR | |
| 20 #include "unicode/unistr.h" | |
| 21 #endif | |
| 22 | |
| 23 #ifndef _SORTKEY | |
| 24 #include "unicode/sortkey.h" | |
| 25 #endif | |
| 26 | |
| 27 #ifndef _CURRCOLL | |
| 28 #include "currcoll.h" | |
| 29 #endif | |
| 30 | |
| 31 #include "sfwdchit.h" | |
| 32 | |
| 33 #define ARRAY_LENGTH(array) (sizeof array / sizeof array[0]) | |
| 34 | |
| 35 CollationCurrencyTest::CollationCurrencyTest() | |
| 36 { | |
| 37 } | |
| 38 | |
| 39 CollationCurrencyTest::~CollationCurrencyTest() | |
| 40 { | |
| 41 } | |
| 42 | |
| 43 void CollationCurrencyTest::currencyTest(/*char *par*/) | |
| 44 { | |
| 45 // All the currency symbols, in collation order | |
| 46 static const UChar currency[][2] = | |
| 47 { | |
| 48 { 0x00A4, 0x0000}, /*00A4; L; [14 36, 03, 03] # [082B.0020.0002] # CURR
ENCY SIGN*/ | |
| 49 { 0x00A2, 0x0000}, /*00A2; L; [14 38, 03, 03] # [082C.0020.0002] # CENT
SIGN*/ | |
| 50 { 0xFFE0, 0x0000}, /*FFE0; L; [14 38, 03, 05] # [082C.0020.0003] # FULL
WIDTH CENT SIGN*/ | |
| 51 { 0x0024, 0x0000}, /*0024; L; [14 3A, 03, 03] # [082D.0020.0002] # DOLL
AR SIGN*/ | |
| 52 { 0xFF04, 0x0000}, /*FF04; L; [14 3A, 03, 05] # [082D.0020.0003] # FULL
WIDTH DOLLAR SIGN*/ | |
| 53 { 0xFE69, 0x0000}, /*FE69; L; [14 3A, 03, 1D] # [082D.0020.000F] # SMAL
L DOLLAR SIGN*/ | |
| 54 { 0x00A3, 0x0000}, /*00A3; L; [14 3C, 03, 03] # [082E.0020.0002] # POUN
D SIGN*/ | |
| 55 { 0xFFE1, 0x0000}, /*FFE1; L; [14 3C, 03, 05] # [082E.0020.0003] # FULL
WIDTH POUND SIGN*/ | |
| 56 { 0x00A5, 0x0000}, /*00A5; L; [14 3E, 03, 03] # [082F.0020.0002] # YEN
SIGN*/ | |
| 57 { 0xFFE5, 0x0000}, /*FFE5; L; [14 3E, 03, 05] # [082F.0020.0003] # FULL
WIDTH YEN SIGN*/ | |
| 58 { 0x09F2, 0x0000}, /*09F2; L; [14 40, 03, 03] # [0830.0020.0002] # BENG
ALI RUPEE MARK*/ | |
| 59 { 0x09F3, 0x0000}, /*09F3; L; [14 42, 03, 03] # [0831.0020.0002] # BENG
ALI RUPEE SIGN*/ | |
| 60 { 0x0E3F, 0x0000}, /*0E3F; L; [14 44, 03, 03] # [0832.0020.0002] # THAI
CURRENCY SYMBOL BAHT*/ | |
| 61 { 0x17DB, 0x0000}, /*17DB; L; [14 46, 03, 03] # [0833.0020.0002] # KHME
R CURRENCY SYMBOL RIEL*/ | |
| 62 { 0x20A0, 0x0000}, /*20A0; L; [14 48, 03, 03] # [0834.0020.0002] # EURO
-CURRENCY SIGN*/ | |
| 63 { 0x20A1, 0x0000}, /*20A1; L; [14 4A, 03, 03] # [0835.0020.0002] # COLO
N SIGN*/ | |
| 64 { 0x20A2, 0x0000}, /*20A2; L; [14 4C, 03, 03] # [0836.0020.0002] # CRUZ
EIRO SIGN*/ | |
| 65 { 0x20A3, 0x0000}, /*20A3; L; [14 4E, 03, 03] # [0837.0020.0002] # FREN
CH FRANC SIGN*/ | |
| 66 { 0x20A4, 0x0000}, /*20A4; L; [14 50, 03, 03] # [0838.0020.0002] # LIRA
SIGN*/ | |
| 67 { 0x20A5, 0x0000}, /*20A5; L; [14 52, 03, 03] # [0839.0020.0002] # MILL
SIGN*/ | |
| 68 { 0x20A6, 0x0000}, /*20A6; L; [14 54, 03, 03] # [083A.0020.0002] # NAIR
A SIGN*/ | |
| 69 { 0x20A7, 0x0000}, /*20A7; L; [14 56, 03, 03] # [083B.0020.0002] # PESE
TA SIGN*/ | |
| 70 { 0x20A9, 0x0000}, /*20A9; L; [14 58, 03, 03] # [083C.0020.0002] # WON
SIGN*/ | |
| 71 { 0xFFE6, 0x0000}, /*FFE6; L; [14 58, 03, 05] # [083C.0020.0003] # FULL
WIDTH WON SIGN*/ | |
| 72 { 0x20AA, 0x0000}, /*20AA; L; [14 5A, 03, 03] # [083D.0020.0002] # NEW
SHEQEL SIGN*/ | |
| 73 { 0x20AB, 0x0000}, /*20AB; L; [14 5C, 03, 03] # [083E.0020.0002] # DONG
SIGN*/ | |
| 74 { 0x20AC, 0x0000}, /*20AC; L; [14 5E, 03, 03] # [083F.0020.0002] # EURO
SIGN*/ | |
| 75 { 0x20AD, 0x0000}, /*20AD; L; [14 60, 03, 03] # [0840.0020.0002] # KIP
SIGN*/ | |
| 76 { 0x20AE, 0x0000}, /*20AE; L; [14 62, 03, 03] # [0841.0020.0002] # TUGR
IK SIGN*/ | |
| 77 { 0x20AF, 0x0000}, /*20AF; L; [14 64, 03, 03] # [0842.0020.0002] # DRAC
HMA SIGN*/ | |
| 78 }; | |
| 79 | |
| 80 | |
| 81 uint32_t i, j; | |
| 82 UErrorCode status = U_ZERO_ERROR; | |
| 83 Collator::EComparisonResult expectedResult = Collator::EQUAL; | |
| 84 RuleBasedCollator *c = (RuleBasedCollator *)Collator::createInstance("en_US"
, status); | |
| 85 | |
| 86 if (U_FAILURE(status)) | |
| 87 { | |
| 88 errcheckln (status, "Collator::createInstance() failed! - %s", u_errorNa
me(status)); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 // Compare each currency symbol against all the | |
| 93 // currency symbols, including itself | |
| 94 for (i = 0; i < ARRAY_LENGTH(currency); i += 1) | |
| 95 { | |
| 96 for (j = 0; j < ARRAY_LENGTH(currency); j += 1) | |
| 97 { | |
| 98 UnicodeString source(currency[i], 1); | |
| 99 UnicodeString target(currency[j], 1); | |
| 100 | |
| 101 if (i < j) | |
| 102 { | |
| 103 expectedResult = Collator::LESS; | |
| 104 } | |
| 105 else if ( i == j) | |
| 106 { | |
| 107 expectedResult = Collator::EQUAL; | |
| 108 } | |
| 109 else | |
| 110 { | |
| 111 expectedResult = Collator::GREATER; | |
| 112 } | |
| 113 | |
| 114 Collator::EComparisonResult compareResult = c->compare(source, targe
t); | |
| 115 | |
| 116 CollationKey sourceKey, targetKey; | |
| 117 UErrorCode status = U_ZERO_ERROR; | |
| 118 | |
| 119 c->getCollationKey(source, sourceKey, status); | |
| 120 | |
| 121 if (U_FAILURE(status)) | |
| 122 { | |
| 123 errln("Couldn't get collationKey for source"); | |
| 124 continue; | |
| 125 } | |
| 126 | |
| 127 c->getCollationKey(target, targetKey, status); | |
| 128 | |
| 129 if (U_FAILURE(status)) | |
| 130 { | |
| 131 errln("Couldn't get collationKey for target"); | |
| 132 continue; | |
| 133 } | |
| 134 | |
| 135 Collator::EComparisonResult keyResult = sourceKey.compareTo(targetKe
y); | |
| 136 | |
| 137 reportCResult( source, target, sourceKey, targetKey, compareResult,
keyResult, compareResult, expectedResult ); | |
| 138 | |
| 139 } | |
| 140 } | |
| 141 delete c; | |
| 142 } | |
| 143 | |
| 144 void CollationCurrencyTest::runIndexedTest(int32_t index, UBool exec, const char
* &name, char* /*par*/) | |
| 145 { | |
| 146 if (exec) | |
| 147 { | |
| 148 logln("Collation Currency Tests: "); | |
| 149 } | |
| 150 | |
| 151 switch (index) | |
| 152 { | |
| 153 case 0: name = "currencyTest"; if (exec) currencyTest(/*par*/); break; | |
| 154 default: name = ""; break; | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 #endif /* #if !UCONFIG_NO_COLLATION */ | |
| OLD | NEW |