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