]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cucdapi.c
1 /********************************************************************
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
8 #include "unicode/utypes.h"
9 #include "unicode/uscript.h"
10 #include "unicode/uchar.h"
14 void TestUScriptCodeAPI(){
18 const char* testNames
[]={
20 "en", "en_US", "sr", "ta" , "te_IN",
23 "Hani", "Hang","Hebr","Hira",
24 "Knda","Kana","Khmr","Lao",
25 "Latn",/*"Latf","Latg",*/
29 "CYRILLIC","DESERET","DEVANAGARI","ETHIOPIC","GEORGIAN",
30 "GOTHIC", "GREEK", "GUJARATI", "COMMON", "INHERITED",
31 /* test lower case names */
32 "malayalam", "mongolian", "myanmar", "ogham", "old-italic",
33 "oriya", "runic", "sinhala", "syriac","tamil",
34 "telugu", "thaana", "thai", "tibetan",
38 "asfdasd", "5464", "12235",
39 /* test the last index */
43 UScriptCode expected
[] ={
44 /* locales should return */
45 USCRIPT_LATIN
, USCRIPT_LATIN
, USCRIPT_CYRILLIC
, USCRIPT_TAMIL
, USCRIPT_TELUGU
,
46 USCRIPT_DEVANAGARI
, USCRIPT_HEBREW
, USCRIPT_ARABIC
,
47 /* abbr should return */
48 USCRIPT_HAN
, USCRIPT_HANGUL
, USCRIPT_HEBREW
, USCRIPT_HIRAGANA
,
49 USCRIPT_KANNADA
, USCRIPT_KATAKANA
, USCRIPT_KHMER
, USCRIPT_LAO
,
50 USCRIPT_LATIN
,/* USCRIPT_LATIN, USCRIPT_LATIN,*/
51 USCRIPT_MALAYALAM
, USCRIPT_MONGOLIAN
,
52 /* names should return */
53 USCRIPT_CYRILLIC
, USCRIPT_DESERET
, USCRIPT_DEVANAGARI
, USCRIPT_ETHIOPIC
, USCRIPT_GEORGIAN
,
54 USCRIPT_GOTHIC
, USCRIPT_GREEK
, USCRIPT_GUJARATI
, USCRIPT_COMMON
, USCRIPT_INHERITED
,
55 /* lower case names should return */
56 USCRIPT_MALAYALAM
, USCRIPT_MONGOLIAN
, USCRIPT_MYANMAR
, USCRIPT_OGHAM
, USCRIPT_OLD_ITALIC
,
57 USCRIPT_ORIYA
, USCRIPT_RUNIC
, USCRIPT_SINHALA
, USCRIPT_SYRIAC
, USCRIPT_TAMIL
,
58 USCRIPT_TELUGU
, USCRIPT_THAANA
, USCRIPT_THAI
, USCRIPT_TIBETAN
,
60 USCRIPT_TAGBANWA
, USCRIPT_ARABIC
,
61 /* bogus names should return invalid code */
62 USCRIPT_INVALID_CODE
, USCRIPT_INVALID_CODE
, USCRIPT_INVALID_CODE
,
63 USCRIPT_COMMON
, USCRIPT_YI
,
66 UErrorCode err
= U_ZERO_ERROR
;
68 const int32_t capacity
= 10;
70 for( ; testNames
[i
]!='\0'; i
++){
71 UScriptCode script
[10]={USCRIPT_INVALID_CODE
};
72 uscript_getCode(testNames
[i
],script
,capacity
, &err
);
73 if( script
[0] != expected
[i
]){
74 log_err("Error getting script code Got: %i Expected: %i for name %s\n",
75 script
[0],expected
[i
],testNames
[i
]);
80 log_data_err("Errors uchar_getScriptCode() : %i \n",numErrors
);
85 UErrorCode err
= U_ZERO_ERROR
;
87 UScriptCode jaCode
[]={ USCRIPT_KATAKANA
,USCRIPT_HIRAGANA
,USCRIPT_HAN
};
88 UScriptCode script
[10]={USCRIPT_INVALID_CODE
};
89 int32_t num
= uscript_getCode("ja",script
,capacity
, &err
);
91 if(err
==U_BUFFER_OVERFLOW_ERROR
){
94 num
= uscript_getCode("ja",script
,capacity
, &err
);
95 if(num
!=(sizeof(jaCode
)/sizeof(UScriptCode
)) || script
[0]!=jaCode
[0] || script
[1]!=jaCode
[1]){
96 log_err("Errors uscript_getScriptCode() for Japaneese locale \n");
99 log_data_err("Errors in uscript_getScriptCode() expected error : %s got: %s \n",
100 "U_BUFFER_OVERFLOW_ERROR",
107 UScriptCode testAbbr
[]={
108 /* names should return */
109 USCRIPT_CYRILLIC
, USCRIPT_DESERET
, USCRIPT_DEVANAGARI
, USCRIPT_ETHIOPIC
, USCRIPT_GEORGIAN
,
110 USCRIPT_GOTHIC
, USCRIPT_GREEK
, USCRIPT_GUJARATI
,
113 const char* expectedNames
[]={
116 "Cyrillic","Deseret","Devanagari","Ethiopic","Georgian",
117 "Gothic", "Greek", "Gujarati",
121 while(i
<sizeof(testAbbr
)/sizeof(UScriptCode
)){
122 const char* name
= uscript_getName(testAbbr
[i
]);
124 log_data_err("Couldn't get script name\n");
128 if(strcmp(expectedNames
[i
],name
)!=0){
129 log_err("Error getting abbreviations Got: %s Expected: %s\n",name
,expectedNames
[i
]);
134 log_err("Errors uchar_getScriptAbbr() : %i \n",numErrors
);
143 UScriptCode testAbbr
[]={
144 /* abbr should return */
145 USCRIPT_HAN
, USCRIPT_HANGUL
, USCRIPT_HEBREW
, USCRIPT_HIRAGANA
,
146 USCRIPT_KANNADA
, USCRIPT_KATAKANA
, USCRIPT_KHMER
, USCRIPT_LAO
,
148 USCRIPT_MALAYALAM
, USCRIPT_MONGOLIAN
,
151 const char* expectedAbbr
[]={
153 "Hani", "Hang","Hebr","Hira",
154 "Knda","Kana","Khmr","Laoo",
160 while(i
<sizeof(testAbbr
)/sizeof(UScriptCode
)){
161 const char* name
= uscript_getShortName(testAbbr
[i
]);
163 if(strcmp(expectedAbbr
[i
],name
)!=0){
164 log_err("Error getting abbreviations Got: %s Expected: %s\n",name
,expectedAbbr
[i
]);
169 log_err("Errors uchar_getScriptAbbr() : %i \n",numErrors
);
176 /* now test uscript_getScript() API */
178 #define MAX_ARRAY_SIZE 23
179 uint32_t codepoints
[] = {
180 0x0000FF9D, /* USCRIPT_KATAKANA*/
181 0x0000FFBE, /* USCRIPT_HANGUL*/
182 0x0000FFC7, /* USCRIPT_HANGUL*/
183 0x0000FFCF, /* USCRIPT_HANGUL*/
184 0x0000FFD7, /* USCRIPT_HANGUL*/
185 0x0000FFDC, /* USCRIPT_HANGUL*/
186 0x00010300, /* USCRIPT_OLD_ITALIC*/
187 0x00010330, /* USCRIPT_GOTHIC*/
188 0x0001034A, /* USCRIPT_GOTHIC*/
189 0x00010400, /* USCRIPT_DESERET*/
190 0x00010428, /* USCRIPT_DESERET*/
191 0x0001D167, /* USCRIPT_INHERITED*/
192 0x0001D17B, /* USCRIPT_INHERITED*/
193 0x0001D185, /* USCRIPT_INHERITED*/
194 0x0001D1AA, /* USCRIPT_INHERITED*/
195 0x00020000, /* USCRIPT_HAN*/
196 0x00000D02, /* USCRIPT_MALAYALAM*/
197 0x00000D00, /* USCRIPT_COMMON */
198 0x00000000, /* USCRIPT_COMMON*/
199 0x0001D169, /* USCRIPT_INHERITED*/
200 0x0001D182, /* USCRIPT_INHERITED*/
201 0x0001D18B, /* USCRIPT_INHERITED*/
202 0x0001D1AD, /* USCRIPT_INHERITED*/
203 0x00110000, /* USCRIPT_INVALID_CODE */
206 UScriptCode expected
[] = {
230 USCRIPT_INVALID_CODE
,
232 UScriptCode code
= USCRIPT_INVALID_CODE
;
233 UErrorCode status
= U_ZERO_ERROR
;
237 while(i
< MAX_ARRAY_SIZE
){
238 code
= uscript_getScript(codepoints
[i
],&status
);
239 if(U_SUCCESS(status
)){
240 if( code
!= expected
[i
] ||
241 code
!= (UScriptCode
)u_getIntPropertyValue(codepoints
[i
], UCHAR_SCRIPT
)
243 log_err("uscript_getScript for codepoint \\U%08X failed\n",codepoints
[i
]);
247 log_err("uscript_getScript for codepoint \\U%08X failed. Error: %s\n",
248 codepoints
[i
],u_errorName(status
));
255 log_err("uscript_getScript failed.\n");
259 UScriptCode code
= USCRIPT_INVALID_CODE
;
260 UErrorCode status
= U_ZERO_ERROR
;
261 code
= uscript_getScript(0x001D169,&status
);
262 if(code
!= USCRIPT_INHERITED
){
263 log_err("\\U001D169 is not contained in USCRIPT_INHERITED");
267 UScriptCode code
= USCRIPT_INVALID_CODE
;
268 UErrorCode status
= U_ZERO_ERROR
;
271 for(i
= 0; i
<=0x10ffff; i
++){
272 code
= uscript_getScript(i
,&status
);
273 if(code
== USCRIPT_INVALID_CODE
){
275 log_err("uscript_getScript for codepoint \\U%08X failed.\n", i
);
279 log_err("uscript_getScript failed for %d codepoints\n", err
);
283 for(i
=0; (UScriptCode
)i
< USCRIPT_CODE_LIMIT
; i
++){
284 const char* name
= uscript_getName((UScriptCode
)i
);
285 if(name
==NULL
|| strcmp(name
,"")==0){
286 log_err("uscript_getName failed for code : %i\n",i
);