]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/eurocreg.c
ICU-6.2.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / eurocreg.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1999-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 #include "unicode/utypes.h"
7 #include "unicode/ustring.h"
8 #include "unicode/ctest.h"
9 #include "unicode/ucnv.h"
10
11 void TestEuroRegression(void);
12 void addTestEuroRegression(TestNode** root);
13
14 void addTestEuroRegression(TestNode** root)
15 {
16 addTest(root, &TestEuroRegression, "tsconv/eurocreg/TestEuroRegression");
17 }
18
19 /*
20 * The table below lists codepages that are supposed to have roundtrip mappings for
21 * the U+20AC Euro sign.
22 *
23 * Changes made 2000nov28 and marked as such are due to the following:
24 *
25 * After updating all ibm-*.ucm files with precise fallback indicators (|0, |1, |3),
26 * some of these codepages failed the Euro regression test.
27 * This means that the actuall mappings changed when only the preciseness of fallback
28 * mappings should have changed.
29 * My (Markus) suspicion is that some files got Euro sign mappings added manually,
30 * changing their contents compared to the NLTC (IBM Toronto codepage database) definition.
31 * Such changes are highly undesirable because they effectively define new codepages.
32 * Codepage mapping files with "ibm-*.ucm" should always exactly match the files
33 * from the IBM codepage database.
34 * (If there are several mappings with the same number, then we choose the
35 * default mappings with Private-Use Area assignments.)
36 *
37 * Also, in the past, some aliases were set such that e.g. cp850 became an alias for ibm-858.
38 * This followed the practice of OS/2 that uses the old codepage number 850 for the new
39 * codepage 858, with the main difference being the additional Euro sign.
40 * However, we have documented that the "cp" prefix should be used for Microsoft-compatible
41 * codepages, and Microsoft Windows 2000's codepage 850 does not contain a Euro sign mapping.
42 * Therefore, cp850 must not support the Euro sign.
43 * In these cases, I have changed the codepage name here to point to a newer codepage with the
44 * Euro sign, using its new name.
45 * I could not find such "updates" for codepages 1362 and 1363 - we might want to supply them later.
46 */
47
48 char convertersToCheck[][15] = {
49 "cp1250",
50 "cp1251",
51 "cp1252",
52 "cp1254",
53 "cp1255",
54 "cp1256",
55 "cp1257",
56 "cp1258",
57 "ibm1140",
58 "ibm1142",
59 "ibm1143",
60 "ibm1144",
61 "ibm1145",
62 "ibm1146",
63 "ibm1147",
64 "ibm1148",
65 "ibm1149",
66 "ibm1153",
67 "ibm1154",
68 "ibm1155",
69 "ibm1156",
70 "ibm1157",
71 "ibm1158",
72 /*"ibm-1159",*/ /* removed 2003Apr17 */
73 "ibm12712",
74 "ibm16804",
75 "ibm-1160",
76 "ibm-1162",
77 "ibm-1164",
78
79 "ibm-858", /* was "cp850" changed 2000nov28 */
80 /* duplicate "cp850" removed 2000nov28 */
81 /*"ibm-9049",*/ /* was "cp857" changed 2002nov25 */
82 "ibm-12712", /* was "cp424" changed 2000nov28 */
83 "ibm-4899", /* was "cp803" changed 2000nov28 */
84 "ibm-867", /* was "cp862" changed 2002nov25 */
85 "cp1258",
86 "windows-950",
87 "cp1253",
88 /* "cp819",
89 "cp13488",*/
90 "cpibm4971",
91 /*"ibm-9061",*/ /* was "cp869" changed 2002nov25 */
92 /* "cp813",*/
93 /*"ibm-9044",*/ /* was "cp852" changed 2002nov25 */
94 /*"ibm-872",*/ /* was "cp855" changed 2002nov25 */
95 /*"ibm-808",*/ /* was "cp866" changed 2002nov25 */
96 /* "cp1131",
97 "cp1125",*/
98 "ibm-902", /* was "cp922" changed 2003jan08 */
99 "ibm-901", /* was "cp921" changed 2003jan09 */
100 /*"ibm-17248",*/ /* was "cp864" changed 2002nov25 */
101 /*"cp1008",
102 "cp1046",*/
103 /* "cp9066",
104 "cp1129",*/
105 "ibm-5123", /* was "cp1027" changed 2003jan08 */
106 /* "cp300",*/
107 /* "cp4930",*/
108 "cp1364",
109 /* "cp1362" removed 2000nov28 */
110 "cp1363",
111 /* "cp1114", removed 2002jul3
112 "cp947", removed 2002jul3 */
113 "gb18030",
114 ""};
115
116 UBool isEuroAware(UConverter*);
117
118 void TestEuroRegression()
119 {
120 int32_t i=0;
121
122 do
123 {
124 UErrorCode err = U_ZERO_ERROR;
125 UConverter* myConv = ucnv_open(convertersToCheck[i], &err);
126 if (U_FAILURE(err)&&convertersToCheck[i][0])
127 log_data_err("%s \tMISSING [%s]\n", convertersToCheck[i], u_errorName(err));
128 else
129 {
130 if (isEuroAware(myConv))
131 log_verbose("%s \tsupports euro\n", convertersToCheck[i]);
132 else
133 log_err("%s \tDOES NOT support euro\n", convertersToCheck[i]);
134 ucnv_close(myConv);
135 }
136 } while (convertersToCheck[++i][0]);
137 }
138
139 UBool isEuroAware(UConverter* myConv)
140 {
141 static const UChar euroString[2] = { 0x20AC, 0x0000 };
142 char target[20];
143 UChar euroBack[2];
144 int32_t targetSize, euroBackSize;
145 UErrorCode err = U_ZERO_ERROR;
146 /*const char* myName = ucnv_getName(myConv, &err);*/
147
148 targetSize = ucnv_fromUChars(myConv,
149 target,
150 sizeof(target),
151 euroString,
152 -1,
153 &err);
154 if (U_FAILURE(err))
155 {
156 log_err("Failure Occured in ucnv_fromUChars euro roundtrip test\n");
157 return FALSE;
158 }
159 euroBackSize = ucnv_toUChars(myConv,
160 euroBack,
161 2,
162 target,
163 targetSize,
164 &err);
165 if (U_FAILURE(err))
166 {
167 log_err("Failure Occured in ucnv_toUChars euro roundtrip test\n");
168 return FALSE;
169 }
170 if (u_strcmp(euroString, euroBack))
171 {
172 /* log_err("%s FAILED Euro rountrip\n", myName);*/
173 return FALSE;
174 }
175 else
176 {
177 /* log_verbose("%s PASSED Euro rountrip\n", myName);*/
178 return TRUE;
179 }
180
181 }