2 *******************************************************************************
\r
3 * Copyright (C) 2002-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
9 * Port From: ICU4C v2.1 : Collate/CollationCurrencyTest
\r
10 * Source File: $ICU4CRoot/source/test/intltest/currcoll.cpp
\r
13 package com.ibm.icu.dev.test.collator;
\r
15 import java.util.Locale;
\r
17 import com.ibm.icu.dev.test.TestFmwk;
\r
18 import com.ibm.icu.text.CollationKey;
\r
19 import com.ibm.icu.text.Collator;
\r
20 import com.ibm.icu.text.RuleBasedCollator;
\r
22 public class CollationCurrencyTest extends TestFmwk {
\r
23 public static void main(String[] args) throws Exception {
\r
24 new CollationCurrencyTest().run(args);
\r
27 public void TestCurrency() {
\r
28 // All the currency symbols, in collation order
\r
29 char[][] currency = {
\r
30 { 0x00A4 }, /*00A4; L; [14 36, 03, 03] # [082B.0020.0002] # CURRENCY SIGN*/
\r
31 { 0x00A2 }, /*00A2; L; [14 38, 03, 03] # [082C.0020.0002] # CENT SIGN*/
\r
32 { 0xFFE0 }, /*FFE0; L; [14 38, 03, 05] # [082C.0020.0003] # FULLWIDTH CENT SIGN*/
\r
33 { 0x0024 }, /*0024; L; [14 3A, 03, 03] # [082D.0020.0002] # DOLLAR SIGN*/
\r
34 { 0xFF04 }, /*FF04; L; [14 3A, 03, 05] # [082D.0020.0003] # FULLWIDTH DOLLAR SIGN*/
\r
35 { 0xFE69 }, /*FE69; L; [14 3A, 03, 1D] # [082D.0020.000F] # SMALL DOLLAR SIGN*/
\r
36 { 0x00A3 }, /*00A3; L; [14 3C, 03, 03] # [082E.0020.0002] # POUND SIGN*/
\r
37 { 0xFFE1 }, /*FFE1; L; [14 3C, 03, 05] # [082E.0020.0003] # FULLWIDTH POUND SIGN*/
\r
38 { 0x00A5 }, /*00A5; L; [14 3E, 03, 03] # [082F.0020.0002] # YEN SIGN*/
\r
39 { 0xFFE5 }, /*FFE5; L; [14 3E, 03, 05] # [082F.0020.0003] # FULLWIDTH YEN SIGN*/
\r
40 { 0x09F2 }, /*09F2; L; [14 40, 03, 03] # [0830.0020.0002] # BENGALI RUPEE MARK*/
\r
41 { 0x09F3 }, /*09F3; L; [14 42, 03, 03] # [0831.0020.0002] # BENGALI RUPEE SIGN*/
\r
42 { 0x0E3F }, /*0E3F; L; [14 44, 03, 03] # [0832.0020.0002] # THAI CURRENCY SYMBOL BAHT*/
\r
43 { 0x17DB }, /*17DB; L; [14 46, 03, 03] # [0833.0020.0002] # KHMER CURRENCY SYMBOL RIEL*/
\r
44 { 0x20A0 }, /*20A0; L; [14 48, 03, 03] # [0834.0020.0002] # EURO-CURRENCY SIGN*/
\r
45 { 0x20A1 }, /*20A1; L; [14 4A, 03, 03] # [0835.0020.0002] # COLON SIGN*/
\r
46 { 0x20A2 }, /*20A2; L; [14 4C, 03, 03] # [0836.0020.0002] # CRUZEIRO SIGN*/
\r
47 { 0x20A3 }, /*20A3; L; [14 4E, 03, 03] # [0837.0020.0002] # FRENCH FRANC SIGN*/
\r
48 { 0x20A4 }, /*20A4; L; [14 50, 03, 03] # [0838.0020.0002] # LIRA SIGN*/
\r
49 { 0x20A5 }, /*20A5; L; [14 52, 03, 03] # [0839.0020.0002] # MILL SIGN*/
\r
50 { 0x20A6 }, /*20A6; L; [14 54, 03, 03] # [083A.0020.0002] # NAIRA SIGN*/
\r
51 { 0x20A7 }, /*20A7; L; [14 56, 03, 03] # [083B.0020.0002] # PESETA SIGN*/
\r
52 { 0x20A9 }, /*20A9; L; [14 58, 03, 03] # [083C.0020.0002] # WON SIGN*/
\r
53 { 0xFFE6 }, /*FFE6; L; [14 58, 03, 05] # [083C.0020.0003] # FULLWIDTH WON SIGN*/
\r
54 { 0x20AA }, /*20AA; L; [14 5A, 03, 03] # [083D.0020.0002] # NEW SHEQEL SIGN*/
\r
55 { 0x20AB }, /*20AB; L; [14 5C, 03, 03] # [083E.0020.0002] # DONG SIGN*/
\r
56 { 0x20AC }, /*20AC; L; [14 5E, 03, 03] # [083F.0020.0002] # EURO SIGN*/
\r
57 { 0x20AD }, /*20AD; L; [14 60, 03, 03] # [0840.0020.0002] # KIP SIGN*/
\r
58 { 0x20AE }, /*20AE; L; [14 62, 03, 03] # [0841.0020.0002] # TUGRIK SIGN*/
\r
59 { 0x20AF } /*20AF; L; [14 64, 03, 03] # [0842.0020.0002] # DRACHMA SIGN*/
\r
63 int expectedResult = 0;
\r
64 RuleBasedCollator c = (RuleBasedCollator)Collator.getInstance(Locale.ENGLISH);
\r
66 // Compare each currency symbol against all the
\r
67 // currency symbols, including itself
\r
71 for (i = 0; i < currency.length; i += 1) {
\r
72 for (j = 0; j < currency.length; j += 1) {
\r
73 source = new String(currency[i]);
\r
74 target = new String(currency[j]);
\r
77 expectedResult = -1;
\r
78 } else if ( i == j) {
\r
84 int compareResult = c.compare(source, target);
\r
85 CollationKey sourceKey = null;
\r
87 sourceKey = c.getCollationKey(source);
\r
89 if (sourceKey == null) {
\r
90 errln("Couldn't get collationKey for source");
\r
94 CollationKey targetKey = null;
\r
95 targetKey = c.getCollationKey(target);
\r
96 if (targetKey == null) {
\r
97 errln("Couldn't get collationKey for source");
\r
101 int keyResult = sourceKey.compareTo(targetKey);
\r
103 reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult );
\r
108 private void reportCResult( String source, String target, CollationKey sourceKey, CollationKey targetKey,
\r
109 int compareResult, int keyResult, int incResult, int expectedResult ) {
\r
110 if (expectedResult < -1 || expectedResult > 1) {
\r
111 errln("***** invalid call to reportCResult ****");
\r
115 boolean ok1 = (compareResult == expectedResult);
\r
116 boolean ok2 = (keyResult == expectedResult);
\r
117 boolean ok3 = (incResult == expectedResult);
\r
119 if (ok1 && ok2 && ok3 && !isVerbose()) {
\r
122 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
\r
123 String msg2 = "\", \"";
\r
124 String msg3 = "\") returned ";
\r
125 String msg4 = "; expected ";
\r
127 String sExpect = new String("");
\r
128 String sResult = new String("");
\r
129 sResult = appendCompareResult(compareResult, sResult);
\r
130 sExpect = appendCompareResult(expectedResult, sExpect);
\r
132 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
134 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
137 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
\r
138 msg2 = "\").compareTo(key(\"";
\r
139 msg3 = "\")) returned ";
\r
140 sResult = appendCompareResult(keyResult, sResult);
\r
142 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
144 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
147 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
\r
150 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
\r
152 msg3 = "\") returned ";
\r
154 sResult = appendCompareResult(incResult, sResult);
\r
157 logln(msg1 + source + msg2 + target + msg3 + sResult);
\r
159 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
\r
164 private String appendCompareResult(int result, String target){
\r
165 if (result == -1) {
\r
167 } else if (result == 0) {
\r
169 } else if (result == 1) {
\r
170 target += "GREATER";
\r
173 target += huh + result;
\r
178 String prettify(CollationKey sourceKey) {
\r
180 byte[] bytes= sourceKey.toByteArray();
\r
181 String target = "[";
\r
183 for (i = 0; i < bytes.length; i++) {
\r
184 target += Integer.toHexString(bytes[i]);
\r