2003-02-26 23:22:03 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2010-01-06 23:50:03 +00:00
|
|
|
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
2003-02-26 23:22:03 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/uchar.h"
|
|
|
|
#include "unicode/uniset.h"
|
2004-09-23 00:24:36 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-02-26 23:22:03 +00:00
|
|
|
#include "cstring.h"
|
2009-11-13 19:25:21 +00:00
|
|
|
#include "hash.h"
|
2003-02-26 23:22:03 +00:00
|
|
|
#include "uparse.h"
|
|
|
|
#include "ucdtest.h"
|
|
|
|
|
2008-04-04 22:47:43 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0]))
|
2003-02-26 23:22:03 +00:00
|
|
|
|
2010-01-06 23:50:03 +00:00
|
|
|
static const char *ignorePropNames[]={
|
|
|
|
"FC_NFKC",
|
|
|
|
"NFD_QC",
|
|
|
|
"NFC_QC",
|
|
|
|
"NFKD_QC",
|
|
|
|
"NFKC_QC",
|
|
|
|
"Expands_On_NFD",
|
|
|
|
"Expands_On_NFC",
|
|
|
|
"Expands_On_NFKD",
|
|
|
|
"Expands_On_NFKC",
|
|
|
|
"NFKC_CF"
|
|
|
|
};
|
|
|
|
|
2003-02-26 23:22:03 +00:00
|
|
|
UnicodeTest::UnicodeTest()
|
|
|
|
{
|
2009-11-13 19:25:21 +00:00
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
unknownPropertyNames=new U_NAMESPACE_QUALIFIER Hashtable(errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
delete unknownPropertyNames;
|
|
|
|
unknownPropertyNames=NULL;
|
|
|
|
}
|
2010-01-06 23:50:03 +00:00
|
|
|
// Ignore some property names altogether.
|
|
|
|
for(int32_t i=0; i<LENGTHOF(ignorePropNames); ++i) {
|
|
|
|
unknownPropertyNames->puti(UnicodeString(ignorePropNames[i], -1, US_INV), 1, errorCode);
|
|
|
|
}
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeTest::~UnicodeTest()
|
|
|
|
{
|
2009-11-13 19:25:21 +00:00
|
|
|
delete unknownPropertyNames;
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite UnicodeTest: ");
|
|
|
|
switch (index) {
|
2008-04-04 22:47:43 +00:00
|
|
|
case 0: name = "TestAdditionalProperties"; if(exec) TestAdditionalProperties(); break;
|
|
|
|
case 1: name = "TestBinaryValues"; if(exec) TestBinaryValues(); break;
|
2003-02-26 23:22:03 +00:00
|
|
|
default: name = ""; break; //needed to end loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================
|
|
|
|
// private data used by the tests
|
|
|
|
//====================================================
|
|
|
|
|
|
|
|
// test DerivedCoreProperties.txt -------------------------------------------
|
|
|
|
|
|
|
|
// copied from genprops.c
|
|
|
|
static int32_t
|
|
|
|
getTokenIndex(const char *const tokens[], int32_t countTokens, const char *s) {
|
|
|
|
const char *t, *z;
|
|
|
|
int32_t i, j;
|
|
|
|
|
|
|
|
s=u_skipWhitespace(s);
|
|
|
|
for(i=0; i<countTokens; ++i) {
|
|
|
|
t=tokens[i];
|
|
|
|
if(t!=NULL) {
|
|
|
|
for(j=0;; ++j) {
|
|
|
|
if(t[j]!=0) {
|
|
|
|
if(s[j]!=t[j]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
z=u_skipWhitespace(s+j);
|
|
|
|
if(*z==';' || *z==0) {
|
|
|
|
return i;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const
|
2010-01-06 23:50:03 +00:00
|
|
|
derivedPropsNames[]={
|
2003-02-26 23:22:03 +00:00
|
|
|
"Math",
|
|
|
|
"Alphabetic",
|
|
|
|
"Lowercase",
|
|
|
|
"Uppercase",
|
|
|
|
"ID_Start",
|
|
|
|
"ID_Continue",
|
|
|
|
"XID_Start",
|
|
|
|
"XID_Continue",
|
|
|
|
"Default_Ignorable_Code_Point",
|
2010-01-06 23:50:03 +00:00
|
|
|
"Full_Composition_Exclusion",
|
2003-02-26 23:22:03 +00:00
|
|
|
"Grapheme_Extend",
|
2006-03-17 22:07:05 +00:00
|
|
|
"Grapheme_Link", /* Unicode 5 moves this property here from PropList.txt */
|
2009-11-13 19:25:21 +00:00
|
|
|
"Grapheme_Base",
|
|
|
|
"Cased",
|
|
|
|
"Case_Ignorable",
|
|
|
|
"Changes_When_Lowercased",
|
|
|
|
"Changes_When_Uppercased",
|
|
|
|
"Changes_When_Titlecased",
|
|
|
|
"Changes_When_Casefolded",
|
2010-01-06 23:50:03 +00:00
|
|
|
"Changes_When_Casemapped",
|
|
|
|
"Changes_When_NFKC_Casefolded"
|
2003-02-26 23:22:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const UProperty
|
2010-01-06 23:50:03 +00:00
|
|
|
derivedPropsIndex[]={
|
2003-02-26 23:22:03 +00:00
|
|
|
UCHAR_MATH,
|
|
|
|
UCHAR_ALPHABETIC,
|
|
|
|
UCHAR_LOWERCASE,
|
|
|
|
UCHAR_UPPERCASE,
|
|
|
|
UCHAR_ID_START,
|
|
|
|
UCHAR_ID_CONTINUE,
|
|
|
|
UCHAR_XID_START,
|
|
|
|
UCHAR_XID_CONTINUE,
|
|
|
|
UCHAR_DEFAULT_IGNORABLE_CODE_POINT,
|
2010-01-06 23:50:03 +00:00
|
|
|
UCHAR_FULL_COMPOSITION_EXCLUSION,
|
2003-02-26 23:22:03 +00:00
|
|
|
UCHAR_GRAPHEME_EXTEND,
|
2006-03-17 22:07:05 +00:00
|
|
|
UCHAR_GRAPHEME_LINK,
|
2009-11-13 19:25:21 +00:00
|
|
|
UCHAR_GRAPHEME_BASE,
|
|
|
|
UCHAR_CASED,
|
|
|
|
UCHAR_CASE_IGNORABLE,
|
|
|
|
UCHAR_CHANGES_WHEN_LOWERCASED,
|
|
|
|
UCHAR_CHANGES_WHEN_UPPERCASED,
|
|
|
|
UCHAR_CHANGES_WHEN_TITLECASED,
|
|
|
|
UCHAR_CHANGES_WHEN_CASEFOLDED,
|
2010-01-06 23:50:03 +00:00
|
|
|
UCHAR_CHANGES_WHEN_CASEMAPPED,
|
|
|
|
UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED
|
2003-02-26 23:22:03 +00:00
|
|
|
};
|
|
|
|
|
2010-01-06 23:50:03 +00:00
|
|
|
static int32_t numErrors[LENGTHOF(derivedPropsIndex)]={ 0 };
|
2009-11-13 19:25:21 +00:00
|
|
|
|
|
|
|
enum { MAX_ERRORS=50 };
|
|
|
|
|
2004-03-29 21:58:57 +00:00
|
|
|
U_CFUNC void U_CALLCONV
|
2010-01-06 23:50:03 +00:00
|
|
|
derivedPropsLineFn(void *context,
|
|
|
|
char *fields[][2], int32_t /* fieldCount */,
|
|
|
|
UErrorCode *pErrorCode)
|
2003-02-26 23:22:03 +00:00
|
|
|
{
|
|
|
|
UnicodeTest *me=(UnicodeTest *)context;
|
|
|
|
uint32_t start, end;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
u_parseCodePointRange(fields[0][0], &start, &end, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2010-01-06 23:50:03 +00:00
|
|
|
me->errln("UnicodeTest: syntax error in DerivedCoreProperties.txt or DerivedNormalizationProps.txt field 0 at %s\n", fields[0][0]);
|
2003-02-26 23:22:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse derived binary property name, ignore unknown names */
|
2010-01-06 23:50:03 +00:00
|
|
|
i=getTokenIndex(derivedPropsNames, LENGTHOF(derivedPropsNames), fields[1][0]);
|
2003-02-26 23:22:03 +00:00
|
|
|
if(i<0) {
|
2009-11-13 19:25:21 +00:00
|
|
|
UnicodeString propName(fields[1][0], (int32_t)(fields[1][1]-fields[1][0]));
|
|
|
|
propName.trim();
|
|
|
|
if(me->unknownPropertyNames->find(propName)==NULL) {
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
me->unknownPropertyNames->puti(propName, 1, errorCode);
|
2010-01-06 23:50:03 +00:00
|
|
|
me->errln("UnicodeTest warning: unknown property name '%s' in DerivedCoreProperties.txt or DerivedNormalizationProps.txt\n", fields[1][0]);
|
2009-11-13 19:25:21 +00:00
|
|
|
}
|
2003-02-26 23:22:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-06 23:50:03 +00:00
|
|
|
me->derivedProps[i].add(start, end);
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeTest::TestAdditionalProperties() {
|
2010-01-26 00:55:35 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2010-01-06 23:50:03 +00:00
|
|
|
// test DerivedCoreProperties.txt and DerivedNormalizationProps.txt
|
|
|
|
if(LENGTHOF(derivedProps)<LENGTHOF(derivedPropsNames)) {
|
|
|
|
errln("error: UnicodeTest::derivedProps[] too short, need at least %d UnicodeSets\n",
|
|
|
|
LENGTHOF(derivedPropsNames));
|
2003-02-26 23:22:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-06 23:50:03 +00:00
|
|
|
if(LENGTHOF(derivedPropsIndex)!=LENGTHOF(derivedPropsNames)) {
|
|
|
|
errln("error in ucdtest.cpp: LENGTHOF(derivedPropsIndex)!=LENGTHOF(derivedPropsNames)\n");
|
2003-02-26 23:22:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char newPath[256];
|
|
|
|
char backupPath[256];
|
|
|
|
char *fields[2][2];
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
|
|
|
|
/* Look inside ICU_DATA first */
|
2004-09-23 00:24:36 +00:00
|
|
|
strcpy(newPath, pathToDataDirectory());
|
2003-02-26 23:22:03 +00:00
|
|
|
strcat(newPath, "unidata" U_FILE_SEP_STRING "DerivedCoreProperties.txt");
|
|
|
|
|
|
|
|
// As a fallback, try to guess where the source data was located
|
|
|
|
// at the time ICU was built, and look there.
|
|
|
|
# ifdef U_TOPSRCDIR
|
|
|
|
strcpy(backupPath, U_TOPSRCDIR U_FILE_SEP_STRING "data");
|
|
|
|
# else
|
|
|
|
strcpy(backupPath, loadTestData(errorCode));
|
|
|
|
strcat(backupPath, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data");
|
|
|
|
# endif
|
|
|
|
strcat(backupPath, U_FILE_SEP_STRING);
|
|
|
|
strcat(backupPath, "unidata" U_FILE_SEP_STRING "DerivedCoreProperties.txt");
|
|
|
|
|
2010-01-06 23:50:03 +00:00
|
|
|
char *path=newPath;
|
|
|
|
u_parseDelimitedFile(newPath, ';', fields, 2, derivedPropsLineFn, this, &errorCode);
|
2003-02-26 23:22:03 +00:00
|
|
|
|
|
|
|
if(errorCode==U_FILE_ACCESS_ERROR) {
|
|
|
|
errorCode=U_ZERO_ERROR;
|
2010-01-06 23:50:03 +00:00
|
|
|
path=backupPath;
|
|
|
|
u_parseDelimitedFile(backupPath, ';', fields, 2, derivedPropsLineFn, this, &errorCode);
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
errln("error parsing DerivedCoreProperties.txt: %s\n", u_errorName(errorCode));
|
|
|
|
return;
|
|
|
|
}
|
2010-01-06 23:50:03 +00:00
|
|
|
char *basename=path+strlen(path)-strlen("DerivedCoreProperties.txt");
|
|
|
|
strcpy(basename, "DerivedNormalizationProps.txt");
|
|
|
|
u_parseDelimitedFile(path, ';', fields, 2, derivedPropsLineFn, this, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
errln("error parsing DerivedNormalizationProps.txt: %s\n", u_errorName(errorCode));
|
|
|
|
return;
|
|
|
|
}
|
2003-02-26 23:22:03 +00:00
|
|
|
|
|
|
|
// now we have all derived core properties in the UnicodeSets
|
|
|
|
// run them all through the API
|
|
|
|
int32_t rangeCount, range;
|
|
|
|
uint32_t i;
|
|
|
|
UChar32 start, end;
|
|
|
|
|
|
|
|
// test all TRUE properties
|
2010-01-06 23:50:03 +00:00
|
|
|
for(i=0; i<LENGTHOF(derivedPropsNames); ++i) {
|
|
|
|
rangeCount=derivedProps[i].getRangeCount();
|
2009-11-13 19:25:21 +00:00
|
|
|
for(range=0; range<rangeCount && numErrors[i]<MAX_ERRORS; ++range) {
|
2010-01-06 23:50:03 +00:00
|
|
|
start=derivedProps[i].getRangeStart(range);
|
|
|
|
end=derivedProps[i].getRangeEnd(range);
|
2003-02-26 23:22:03 +00:00
|
|
|
for(; start<=end; ++start) {
|
2010-01-06 23:50:03 +00:00
|
|
|
if(!u_hasBinaryProperty(start, derivedPropsIndex[i])) {
|
|
|
|
errln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==FALSE is wrong\n", start, derivedPropsNames[i]);
|
2009-11-13 19:25:21 +00:00
|
|
|
if(++numErrors[i]>=MAX_ERRORS) {
|
2003-06-04 23:56:49 +00:00
|
|
|
errln("Too many errors, moving to the next test");
|
|
|
|
break;
|
|
|
|
}
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// invert all properties
|
2010-01-06 23:50:03 +00:00
|
|
|
for(i=0; i<LENGTHOF(derivedPropsNames); ++i) {
|
|
|
|
derivedProps[i].complement();
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test all FALSE properties
|
2010-01-06 23:50:03 +00:00
|
|
|
for(i=0; i<LENGTHOF(derivedPropsNames); ++i) {
|
|
|
|
rangeCount=derivedProps[i].getRangeCount();
|
2009-11-13 19:25:21 +00:00
|
|
|
for(range=0; range<rangeCount && numErrors[i]<MAX_ERRORS; ++range) {
|
2010-01-06 23:50:03 +00:00
|
|
|
start=derivedProps[i].getRangeStart(range);
|
|
|
|
end=derivedProps[i].getRangeEnd(range);
|
2003-02-26 23:22:03 +00:00
|
|
|
for(; start<=end; ++start) {
|
2010-01-06 23:50:03 +00:00
|
|
|
if(u_hasBinaryProperty(start, derivedPropsIndex[i])) {
|
|
|
|
errln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==TRUE is wrong\n", start, derivedPropsNames[i]);
|
2009-11-13 19:25:21 +00:00
|
|
|
if(++numErrors[i]>=MAX_ERRORS) {
|
2003-06-04 23:56:49 +00:00
|
|
|
errln("Too many errors, moving to the next test");
|
|
|
|
break;
|
|
|
|
}
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-26 00:55:35 +00:00
|
|
|
#endif /* !UCONFIG_NO_NORMALIZATION */
|
2003-02-26 23:22:03 +00:00
|
|
|
}
|
2008-04-04 22:47:43 +00:00
|
|
|
|
|
|
|
void UnicodeTest::TestBinaryValues() {
|
|
|
|
/*
|
|
|
|
* Unicode 5.1 explicitly defines binary property value aliases.
|
|
|
|
* Verify that they are all recognized.
|
|
|
|
*/
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
UnicodeSet alpha(UNICODE_STRING_SIMPLE("[:Alphabetic:]"), errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("UnicodeSet([:Alphabetic:]) failed - %s", u_errorName(errorCode));
|
2008-04-04 22:47:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
UnicodeString pattern=UNICODE_STRING_SIMPLE("[:Alphabetic=:]");
|
|
|
|
pattern.insert(pattern.length()-2, UnicodeString(falseValues[i], -1, US_INV));
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
UnicodeSet set(pattern, errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
errln("UnicodeSet([:Alphabetic=%s:]) failed - %s\n", falseValues[i], u_errorName(errorCode));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
set.complement();
|
|
|
|
if(set!=alpha) {
|
|
|
|
errln("UnicodeSet([:Alphabetic=%s:]).complement()!=UnicodeSet([:Alphabetic:])\n", falseValues[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0; i<LENGTHOF(trueValues); ++i) {
|
|
|
|
UnicodeString pattern=UNICODE_STRING_SIMPLE("[:Alphabetic=:]");
|
|
|
|
pattern.insert(pattern.length()-2, UnicodeString(trueValues[i], -1, US_INV));
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
UnicodeSet set(pattern, errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
errln("UnicodeSet([:Alphabetic=%s:]) failed - %s\n", trueValues[i], u_errorName(errorCode));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(set!=alpha) {
|
|
|
|
errln("UnicodeSet([:Alphabetic=%s:])!=UnicodeSet([:Alphabetic:])\n", trueValues[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|