mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 17:01:16 +00:00
ICU-1923 upgrade to Unicode 3.2: verify all DerivedCoreProperties.txt against u_hasBinaryProperty() which computes most of them
X-SVN-Rev: 8751
This commit is contained in:
parent
802f0c5735
commit
338fed0add
2 changed files with 191 additions and 2 deletions
|
@ -4,12 +4,15 @@
|
|||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
#include "ucdtest.h"
|
||||
#include "unicode/unicode.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/uchar.h"
|
||||
#include "unicode/uniset.h"
|
||||
#include "cstring.h"
|
||||
#include "uparse.h"
|
||||
#include "ucdtest.h"
|
||||
|
||||
#define LENGTHOF(array) (sizeof(array)/sizeof(array[0]))
|
||||
|
||||
UnicodeTest::UnicodeTest()
|
||||
{
|
||||
|
@ -32,6 +35,7 @@ void UnicodeTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
case 6: name = "TestCharLength"; if(exec) TestCharLength(); break;
|
||||
case 7: name = "TestIdentifier"; if(exec) TestIdentifier(); break;
|
||||
case 8: name = "TestScript"; if(exec) TestScript(); break;
|
||||
case 9: name = "TestAdditionalProperties"; if(exec) TestAdditionalProperties(); break;
|
||||
default: name = ""; break; //needed to end loop
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +174,7 @@ void UnicodeTest::TestMisc()
|
|||
const UChar sampleNonSpaces[] = {0x61, 0x62, 0x63, 0x64, 0x74};
|
||||
const UChar sampleWhiteSpaces[] = {0x2008, 0x2009, 0x200a, 0x001c, 0x000c};
|
||||
const UChar sampleNonWhiteSpaces[] = {0x61, 0x62, 0x3c, 0x28, 0x3f};
|
||||
const UChar sampleUndefined[] = {0xfff1, 0xfff7, 0xfa30};
|
||||
const UChar sampleUndefined[] = {0xfff1, 0xfff7, 0xfa6b};
|
||||
const UChar sampleDefined[] = {0x523E, 0x4f88, 0xfffd};
|
||||
const UChar sampleBase[] = {0x0061, 0x0031, 0x03d2};
|
||||
const UChar sampleNonBase[] = {0x002B, 0x0020, 0x203B};
|
||||
|
@ -724,3 +728,178 @@ void UnicodeTest::TestScript()
|
|||
errln("ERROR: Diffe rent Thai values in EUnicodeScript and UCharScript");
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
derivedCorePropsNames[]={
|
||||
"Math",
|
||||
"Alphabetic",
|
||||
"Lowercase",
|
||||
"Uppercase",
|
||||
"ID_Start",
|
||||
"ID_Continue",
|
||||
"XID_Start",
|
||||
"XID_Continue",
|
||||
"Default_Ignorable_Code_Point",
|
||||
"Grapheme_Extend",
|
||||
"Grapheme_Base"
|
||||
};
|
||||
|
||||
static const UProperty
|
||||
derivedCorePropsIndex[]={
|
||||
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,
|
||||
UCHAR_GRAPHEME_EXTEND,
|
||||
UCHAR_GRAPHEME_BASE
|
||||
};
|
||||
|
||||
void U_CALLCONV
|
||||
UnicodeTest::derivedCorePropsLineFn(void *context,
|
||||
char *fields[][2], int32_t fieldCount,
|
||||
UErrorCode *pErrorCode) {
|
||||
UnicodeTest *me=(UnicodeTest *)context;
|
||||
uint32_t start, end;
|
||||
int32_t i;
|
||||
|
||||
u_parseCodePointRange(fields[0][0], &start, &end, pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
me->errln("UnicodeTest: syntax error in DerivedCoreProperties.txt field 0 at %s\n", fields[0][0]);
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse derived binary property name, ignore unknown names */
|
||||
i=getTokenIndex(derivedCorePropsNames, LENGTHOF(derivedCorePropsNames), fields[1][0]);
|
||||
if(i<0) {
|
||||
me->errln("UnicodeTest warning: unknown property name '%s' in \n", fields[1][0]);
|
||||
return;
|
||||
}
|
||||
|
||||
me->derivedCoreProps[i].add(start, end);
|
||||
}
|
||||
|
||||
void UnicodeTest::TestAdditionalProperties() {
|
||||
// test DerivedCoreProperties.txt
|
||||
if(LENGTHOF(derivedCoreProps)<LENGTHOF(derivedCorePropsNames)) {
|
||||
errln("error: UnicodeTest::derivedCoreProps[] too short, need at least %d UnicodeSets\n",
|
||||
LENGTHOF(derivedCorePropsNames));
|
||||
return;
|
||||
}
|
||||
if(LENGTHOF(derivedCorePropsIndex)!=LENGTHOF(derivedCorePropsNames)) {
|
||||
errln("error in ucdtest.cpp: LENGTHOF(derivedCorePropsIndex)!=LENGTHOF(derivedCorePropsNames)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char newPath[256];
|
||||
char backupPath[256];
|
||||
char *fields[2][2];
|
||||
int32_t length;
|
||||
UErrorCode errorCode=U_ZERO_ERROR;
|
||||
|
||||
/* Look inside ICU_DATA first */
|
||||
strcpy(newPath, u_getDataDirectory());
|
||||
|
||||
// remove trailing "out/"
|
||||
length=uprv_strlen(newPath);
|
||||
if(length>=4 && uprv_strcmp(newPath+length-4, "out" U_FILE_SEP_STRING)==0) {
|
||||
newPath[length-4]=0;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
u_parseDelimitedFile(newPath, ';', fields, 2, derivedCorePropsLineFn, this, &errorCode);
|
||||
|
||||
if(errorCode==U_FILE_ACCESS_ERROR) {
|
||||
errorCode=U_ZERO_ERROR;
|
||||
u_parseDelimitedFile(backupPath, ';', fields, 2, derivedCorePropsLineFn, this, &errorCode);
|
||||
}
|
||||
if(U_FAILURE(errorCode)) {
|
||||
errln("error parsing DerivedCoreProperties.txt: %s\n", u_errorName(errorCode));
|
||||
return;
|
||||
}
|
||||
|
||||
// now we have all derived core properties in the UnicodeSets
|
||||
// run them all through the API
|
||||
int32_t i, rangeCount, range;
|
||||
UChar32 start, end;
|
||||
|
||||
// test all TRUE properties
|
||||
for(i=0; i<LENGTHOF(derivedCorePropsNames); ++i) {
|
||||
rangeCount=derivedCoreProps[i].getRangeCount();
|
||||
for(range=0; range<rangeCount; ++range) {
|
||||
start=derivedCoreProps[i].getRangeStart(range);
|
||||
end=derivedCoreProps[i].getRangeEnd(range);
|
||||
for(; start<=end; ++start) {
|
||||
if(!u_hasBinaryProperty(start, derivedCorePropsIndex[i])) {
|
||||
errln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==FALSE is wrong\n", start, derivedCorePropsNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// invert all properties
|
||||
for(i=0; i<LENGTHOF(derivedCorePropsNames); ++i) {
|
||||
derivedCoreProps[i].complement();
|
||||
}
|
||||
|
||||
// test all FALSE properties
|
||||
for(i=0; i<LENGTHOF(derivedCorePropsNames); ++i) {
|
||||
rangeCount=derivedCoreProps[i].getRangeCount();
|
||||
for(range=0; range<rangeCount; ++range) {
|
||||
start=derivedCoreProps[i].getRangeStart(range);
|
||||
end=derivedCoreProps[i].getRangeEnd(range);
|
||||
for(; start<=end; ++start) {
|
||||
if(u_hasBinaryProperty(start, derivedCorePropsIndex[i])) {
|
||||
errln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==TRUE is wrong\n", start, derivedCorePropsNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
#include "unicode/uniset.h"
|
||||
#include "intltest.h"
|
||||
|
||||
/** Helper function for TestUnicodeData */
|
||||
|
@ -65,6 +66,8 @@ public:
|
|||
**/
|
||||
void TestScript();
|
||||
|
||||
void TestAdditionalProperties();
|
||||
|
||||
private:
|
||||
/**
|
||||
* internal utility used by TestUnicodeData
|
||||
|
@ -78,5 +81,12 @@ private:
|
|||
friend void U_CALLCONV unicodeDataLineFn(void *context,
|
||||
char *fields[][2], int32_t fieldCount,
|
||||
UErrorCode *pErrorCode);
|
||||
|
||||
static void U_CALLCONV
|
||||
derivedCorePropsLineFn(void *context,
|
||||
char *fields[][2], int32_t fieldCount,
|
||||
UErrorCode *pErrorCode);
|
||||
|
||||
UnicodeSet derivedCoreProps[30];
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue