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 *
10 * File CCURRTST.C
11 *
12 * Modification History:
13 * Name Description
14 * Madhu Katragadda Ported for C API
15 *********************************************************************************
16 */
17
18 #include <stdlib.h>
19
20 #include "unicode/utypes.h"
21
22 #if (!UCONFIG_NO_COLLATION) /* This is not a formatting test. This is a collation test. */
23
24 #include "unicode/ucol.h"
25 #include "unicode/uloc.h"
26 #include "cintltst.h"
27 #include "ccurrtst.h"
28 #include "ccolltst.h"
29 #include "unicode/ustring.h"
30 #include "cmemory.h"
31
addCurrencyCollTest(TestNode ** root)32 void addCurrencyCollTest(TestNode** root)
33 {
34
35 addTest(root, &currTest, "tscoll/ccurrtst/currTest");
36
37 }
38
39
currTest(void)40 void currTest(void)
41 {
42 /* All the currency symbols, in UCA order*/
43 static const UChar currency[][2] =
44 {
45 { 0x00A4, 0x0000}, /*00A4; L; [14 36, 03, 03] # [082B.0020.0002] # CURRENCY SIGN*/
46 { 0x00A2, 0x0000}, /*00A2; L; [14 38, 03, 03] # [082C.0020.0002] # CENT SIGN*/
47 { 0xFFE0, 0x0000}, /*FFE0; L; [14 38, 03, 05] # [082C.0020.0003] # FULLWIDTH CENT SIGN*/
48 { 0x0024, 0x0000}, /*0024; L; [14 3A, 03, 03] # [082D.0020.0002] # DOLLAR SIGN*/
49 { 0xFF04, 0x0000}, /*FF04; L; [14 3A, 03, 05] # [082D.0020.0003] # FULLWIDTH DOLLAR SIGN*/
50 { 0xFE69, 0x0000}, /*FE69; L; [14 3A, 03, 1D] # [082D.0020.000F] # SMALL DOLLAR SIGN*/
51 { 0x00A3, 0x0000}, /*00A3; L; [14 3C, 03, 03] # [082E.0020.0002] # POUND SIGN*/
52 { 0xFFE1, 0x0000}, /*FFE1; L; [14 3C, 03, 05] # [082E.0020.0003] # FULLWIDTH POUND SIGN*/
53 { 0x00A5, 0x0000}, /*00A5; L; [14 3E, 03, 03] # [082F.0020.0002] # YEN SIGN*/
54 { 0xFFE5, 0x0000}, /*FFE5; L; [14 3E, 03, 05] # [082F.0020.0003] # FULLWIDTH YEN SIGN*/
55 { 0x09F2, 0x0000}, /*09F2; L; [14 40, 03, 03] # [0830.0020.0002] # BENGALI RUPEE MARK*/
56 { 0x09F3, 0x0000}, /*09F3; L; [14 42, 03, 03] # [0831.0020.0002] # BENGALI RUPEE SIGN*/
57 { 0x0E3F, 0x0000}, /*0E3F; L; [14 44, 03, 03] # [0832.0020.0002] # THAI CURRENCY SYMBOL BAHT*/
58 { 0x17DB, 0x0000}, /*17DB; L; [14 46, 03, 03] # [0833.0020.0002] # KHMER CURRENCY SYMBOL RIEL*/
59 { 0x20A0, 0x0000}, /*20A0; L; [14 48, 03, 03] # [0834.0020.0002] # EURO-CURRENCY SIGN*/
60 { 0x20A1, 0x0000}, /*20A1; L; [14 4A, 03, 03] # [0835.0020.0002] # COLON SIGN*/
61 { 0x20A2, 0x0000}, /*20A2; L; [14 4C, 03, 03] # [0836.0020.0002] # CRUZEIRO SIGN*/
62 { 0x20A3, 0x0000}, /*20A3; L; [14 4E, 03, 03] # [0837.0020.0002] # FRENCH FRANC SIGN*/
63 { 0x20A4, 0x0000}, /*20A4; L; [14 50, 03, 03] # [0838.0020.0002] # LIRA SIGN*/
64 { 0x20A5, 0x0000}, /*20A5; L; [14 52, 03, 03] # [0839.0020.0002] # MILL SIGN*/
65 { 0x20A6, 0x0000}, /*20A6; L; [14 54, 03, 03] # [083A.0020.0002] # NAIRA SIGN*/
66 // Unicode 15.1: ₧ now sorts like "Pts", no longer as a stand-alone symbol.
67 // { 0x20A7, 0x0000}, /*20A7; L; [14 56, 03, 03] # [083B.0020.0002] # PESETA SIGN*/
68 { 0x20A9, 0x0000}, /*20A9; L; [14 58, 03, 03] # [083C.0020.0002] # WON SIGN*/
69 { 0xFFE6, 0x0000}, /*FFE6; L; [14 58, 03, 05] # [083C.0020.0003] # FULLWIDTH WON SIGN*/
70 { 0x20AA, 0x0000}, /*20AA; L; [14 5A, 03, 03] # [083D.0020.0002] # NEW SHEQEL SIGN*/
71 { 0x20AB, 0x0000}, /*20AB; L; [14 5C, 03, 03] # [083E.0020.0002] # DONG SIGN*/
72 { 0x20AC, 0x0000}, /*20AC; L; [14 5E, 03, 03] # [083F.0020.0002] # EURO SIGN*/
73 { 0x20AD, 0x0000}, /*20AD; L; [14 60, 03, 03] # [0840.0020.0002] # KIP SIGN*/
74 { 0x20AE, 0x0000}, /*20AE; L; [14 62, 03, 03] # [0841.0020.0002] # TUGRIK SIGN*/
75 { 0x20AF, 0x0000}, /*20AF; L; [14 64, 03, 03] # [0842.0020.0002] # DRACHMA SIGN*/
76 };
77
78 #if 0
79 /* All the currency symbols, in collation order*/
80 static const UChar currency[][2] =
81 {
82 { 0x00a4, 0x0000}, /* generic currency*/
83 { 0x0e3f, 0x0000}, /* baht*/
84 { 0x00a2, 0x0000}, /* cent*/
85 { 0x20a1, 0x0000}, /* colon*/
86 { 0x20a2, 0x0000}, /* cruzeiro*/
87 { 0x0024, 0x0000}, /* dollar */
88 { 0x20ab, 0x0000}, /* dong */
89 { 0x20ac, 0x0000}, /* euro */
90 { 0x20a3, 0x0000}, /* franc */
91 { 0x20a4, 0x0000}, /* lira */
92 { 0x20a5, 0x0000}, /* mill */
93 { 0x20a6, 0x0000}, /* naira */
94 { 0x20a7, 0x0000}, /* peseta */
95 { 0x00a3, 0x0000}, /* pound */
96 { 0x20a8, 0x0000}, /* rupee */
97 { 0x20aa, 0x0000}, /* shekel*/
98 { 0x20a9, 0x0000}, /* won*/
99 { 0x00a5, 0x0000} /* yen*/
100 };
101 #endif
102
103 UChar source[2], target[2];
104 int32_t i, j, sortklen;
105 int res;
106 UCollator *c;
107 uint8_t *sortKey1, *sortKey2;
108 UErrorCode status = U_ZERO_ERROR;
109 UCollationResult compareResult, keyResult;
110 UCollationResult expectedResult = UCOL_EQUAL;
111 log_verbose("Testing currency of all locales\n");
112 c = ucol_open("en_US", &status);
113 if (U_FAILURE(status))
114 {
115 log_err_status(status, "collator open failed! :%s\n", myErrorName(status));
116 return;
117 }
118
119 /*Compare each currency symbol against all the
120 currency symbols, including itself*/
121 for (i = 0; i < UPRV_LENGTHOF(currency); i += 1)
122 {
123 for (j = 0; j < UPRV_LENGTHOF(currency); j += 1)
124 {
125 u_strcpy(source, currency[i]);
126 u_strcpy(target, currency[j]);
127
128 if (i < j)
129 {
130 expectedResult = UCOL_LESS;
131 }
132 else if ( i == j)
133 {
134 expectedResult = UCOL_EQUAL;
135 }
136 else
137 {
138 expectedResult = UCOL_GREATER;
139 }
140
141 compareResult = ucol_strcoll(c, source, u_strlen(source), target, u_strlen(target));
142
143 status = U_ZERO_ERROR;
144
145 sortklen=ucol_getSortKey(c, source, u_strlen(source), NULL, 0);
146 sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
147 ucol_getSortKey(c, source, u_strlen(source), sortKey1, sortklen+1);
148
149 sortklen=ucol_getSortKey(c, target, u_strlen(target), NULL, 0);
150 sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
151 ucol_getSortKey(c, target, u_strlen(target), sortKey2, sortklen+1);
152
153 res = uprv_memcmp(sortKey1, sortKey2, sortklen);
154 if (res < 0) keyResult = (UCollationResult)-1;
155 else if (res > 0) keyResult = (UCollationResult)1;
156 else keyResult = (UCollationResult)0;
157
158 reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, expectedResult );
159
160 free(sortKey1);
161 free(sortKey2);
162
163 }
164 }
165 ucol_close(c);
166 }
167
168 #endif /* #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_COLLATION */
169