/********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
+ * Copyright (c) 1997-2008, International Business Machines
+ * Corporation and others. All Rights Reserved.
********************************************************************/
#include <string.h>
#include "unicode/uscript.h"
#include "unicode/uchar.h"
#include "cintltst.h"
+#include "cucdapi.h"
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0]))
void TestUScriptCodeAPI(){
int i =0;
{
UErrorCode err = U_ZERO_ERROR;
int32_t capacity=0;
- UScriptCode jaCode[]={ USCRIPT_KATAKANA,USCRIPT_HIRAGANA,USCRIPT_HAN};
+ int32_t j;
+ UScriptCode jaCode[]={USCRIPT_KATAKANA, USCRIPT_HIRAGANA, USCRIPT_HAN };
UScriptCode script[10]={USCRIPT_INVALID_CODE};
int32_t num = uscript_getCode("ja",script,capacity, &err);
/* preflight */
err = U_ZERO_ERROR;
capacity = 10;
num = uscript_getCode("ja",script,capacity, &err);
- if(num!=(sizeof(jaCode)/sizeof(UScriptCode)) || script[0]!=jaCode[0] || script[1]!=jaCode[1]){
- log_err("Errors uscript_getScriptCode() for Japaneese locale \n");
+ if(num!=(sizeof(jaCode)/sizeof(UScriptCode))){
+ log_err("Errors uscript_getScriptCode() for Japanese locale: num=%d, expected %d \n",
+ num, (sizeof(jaCode)/sizeof(UScriptCode)));
+ }
+ for(j=0;j<sizeof(jaCode)/sizeof(UScriptCode);j++) {
+ if(script[j]!=jaCode[j]) {
+ log_err("Japanese locale: code #%d was %d (%s) but expected %d (%s)\n", j,
+ script[j], uscript_getName(script[j]),
+ jaCode[j], uscript_getName(jaCode[j]));
+
+ }
}
}else{
log_data_err("Errors in uscript_getScriptCode() expected error : %s got: %s \n",
}
/* now test uscript_getScript() API */
{
-#define MAX_ARRAY_SIZE 23
uint32_t codepoints[] = {
0x0000FF9D, /* USCRIPT_KATAKANA*/
0x0000FFBE, /* USCRIPT_HANGUL*/
0x0001D1AA, /* USCRIPT_INHERITED*/
0x00020000, /* USCRIPT_HAN*/
0x00000D02, /* USCRIPT_MALAYALAM*/
- 0x00000D00, /* USCRIPT_COMMON */
+ 0x00000D00, /* USCRIPT_UNKNOWN (new Zzzz value in Unicode 5.0) */
0x00000000, /* USCRIPT_COMMON*/
0x0001D169, /* USCRIPT_INHERITED*/
0x0001D182, /* USCRIPT_INHERITED*/
0x0001D18B, /* USCRIPT_INHERITED*/
0x0001D1AD, /* USCRIPT_INHERITED*/
- 0x00110000, /* USCRIPT_INVALID_CODE */
};
UScriptCode expected[] = {
USCRIPT_INHERITED,
USCRIPT_HAN ,
USCRIPT_MALAYALAM,
- USCRIPT_COMMON,
+ USCRIPT_UNKNOWN,
USCRIPT_COMMON,
USCRIPT_INHERITED ,
USCRIPT_INHERITED ,
USCRIPT_INHERITED ,
USCRIPT_INHERITED ,
- USCRIPT_INVALID_CODE,
};
UScriptCode code = USCRIPT_INVALID_CODE;
UErrorCode status = U_ZERO_ERROR;
UBool passed = TRUE;
- i =0;
- while(i< MAX_ARRAY_SIZE){
+ for(i=0; i<LENGTHOF(codepoints); ++i){
code = uscript_getScript(codepoints[i],&status);
if(U_SUCCESS(status)){
if( code != expected[i] ||
codepoints[i],u_errorName(status));
break;
}
- i++;
}
if(passed==FALSE){
for(i=0; (UScriptCode)i< USCRIPT_CODE_LIMIT; i++){
const char* name = uscript_getName((UScriptCode)i);
if(name==NULL || strcmp(name,"")==0){
- log_err("uscript_getName failed for code : %i\n",i);
+ log_err("uscript_getName failed for code %i: name is NULL or \"\"\n",i);
}
}
}
+ {
+ /*
+ * These script codes were originally added to ICU pre-3.6, so that ICU would
+ * have all ISO 15924 script codes. ICU was then based on Unicode 4.1.
+ * These script codes were added with only short names because we don't
+ * want to invent long names ourselves.
+ * Unicode 5 and later encode some of these scripts and give them long names.
+ * Whenever this happens, the long script names here need to be updated.
+ */
+ static const char* expectedLong[] = {
+ "Balinese", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyp",
+ "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Java", "Kayah_Li", "Latf", "Latg",
+ "Lepcha", "Lina", "Mand", "Maya", "Mero", "Nko", "Orkh", "Perm", "Phags_Pa", "Phoenician",
+ "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vai", "Visp", "Cuneiform",
+ "Zxxx", "Unknown",
+ "Carian", "Jpan", "Lana", "Lycian", "Lydian", "Ol_Chiki", "Rejang", "Saurashtra", "Sgnw", "Sundanese",
+ "Moon", "Mtei",
+ /* new in ICU 4.0 */
+ "Armi", "Avst", "Cakm", "Kore",
+ "Kthi", "Mani", "Phli", "Phlp", "Phlv", "Prti", "Samr", "Tavt",
+ "Zmth", "Zsym",
+ };
+ static const char* expectedShort[] = {
+ "Bali", "Batk", "Blis", "Brah", "Cham", "Cirt", "Cyrs", "Egyd", "Egyh", "Egyp",
+ "Geok", "Hans", "Hant", "Hmng", "Hung", "Inds", "Java", "Kali", "Latf", "Latg",
+ "Lepc", "Lina", "Mand", "Maya", "Mero", "Nkoo", "Orkh", "Perm", "Phag", "Phnx",
+ "Plrd", "Roro", "Sara", "Syre", "Syrj", "Syrn", "Teng", "Vaii", "Visp", "Xsux",
+ "Zxxx", "Zzzz",
+ "Cari", "Jpan", "Lana", "Lyci", "Lydi", "Olck", "Rjng", "Saur", "Sgnw", "Sund",
+ "Moon", "Mtei",
+ /* new in ICU 4.0 */
+ "Armi", "Avst", "Cakm", "Kore",
+ "Kthi", "Mani", "Phli", "Phlp", "Phlv", "Prti", "Samr", "Tavt",
+ "Zmth", "Zsym",
+ };
+ int32_t j = 0;
+ for(i=USCRIPT_BALINESE; (UScriptCode)i<USCRIPT_CODE_LIMIT; i++, j++){
+ const char* name = uscript_getName((UScriptCode)i);
+ if(name==NULL || strcmp(name,expectedLong[j])!=0){
+ log_err("uscript_getName failed for code %i: %s!=%s\n", i, name, expectedLong[j]);
+ }
+ name = uscript_getShortName((UScriptCode)i);
+ if(name==NULL || strcmp(name,expectedShort[j])!=0){
+ log_err("uscript_getShortName failed for code %i: %s!=%s\n", i, name, expectedShort[j]);
+ }
+ }
+ for(i=0; i<LENGTHOF(expectedLong); i++){
+ UScriptCode fillIn[5] = {USCRIPT_INVALID_CODE};
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t len = 0;
+ len = uscript_getCode(expectedShort[i], fillIn, LENGTHOF(fillIn), &status);
+ if(U_FAILURE(status)){
+ log_err("uscript_getCode failed for script name %s. Error: %s\n",expectedShort[i], u_errorName(status));
+ }
+ if(len>1){
+ log_err("uscript_getCode did not return expected number of codes for script %s. EXPECTED: 1 GOT: %i\n", expectedShort[i], len);
+ }
+ if(fillIn[0]!= (UScriptCode)(USCRIPT_BALINESE+i)){
+ log_err("uscript_getCode did not return expected code for script %s. EXPECTED: %i GOT: %i\n", expectedShort[i], (USCRIPT_BALINESE+i), fillIn[0] );
+ }
+ }
+ }
+}
- }
+void TestBinaryValues() {
+ /*
+ * Unicode 5.1 explicitly defines binary property value aliases.
+ * Verify that they are all recognized.
+ */
+ static const char *const falseValues[]={ "N", "No", "F", "False" };
+ static const char *const trueValues[]={ "Y", "Yes", "T", "True" };
+ int32_t i;
+ for(i=0; i<LENGTHOF(falseValues); ++i) {
+ if(FALSE!=u_getPropertyValueEnum(UCHAR_ALPHABETIC, falseValues[i])) {
+ log_err("u_getPropertyValueEnum(UCHAR_ALPHABETIC, \"%s\")!=FALSE\n", falseValues[i]);
+ }
+ }
+ for(i=0; i<LENGTHOF(trueValues); ++i) {
+ if(TRUE!=u_getPropertyValueEnum(UCHAR_ALPHABETIC, trueValues[i])) {
+ log_err("u_getPropertyValueEnum(UCHAR_ALPHABETIC, \"%s\")!=TRUE\n", trueValues[i]);
+ }
+ }
+}