// TODO: Move to a common place (IntlTest?) to avoid duplication with UnicodeTest (ucdtest.cpp). char *BiDiConformanceTest::getUnidataPath(char path[]) { IcuTestErrorCode errorCode(*this, "getUnidataPath"); const int kUnicodeDataTxtLength=15; // strlen("UnicodeData.txt") // Look inside ICU_DATA first. strcpy(path, pathToDataDirectory()); strcat(path, "unidata" U_FILE_SEP_STRING "UnicodeData.txt"); FILE *f=fopen(path, "r"); if(f!=NULL) { fclose(f); *(strchr(path, 0)-kUnicodeDataTxtLength)=0; // Remove the basename. return path; } // 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(path, U_TOPSRCDIR U_FILE_SEP_STRING "data"); # else strcpy(path, loadTestData(errorCode)); strcat(path, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data"); # endif strcat(path, U_FILE_SEP_STRING); strcat(path, "unidata" U_FILE_SEP_STRING "UnicodeData.txt"); f=fopen(path, "r"); if(f!=NULL) { fclose(f); *(strchr(path, 0)-kUnicodeDataTxtLength)=0; // Remove the basename. return path; } return NULL; }
static const char* loadTestData(UErrorCode& err){ if( fgTestDataPath == NULL){ const char* directory=NULL; UResourceBundle* test =NULL; char* tdpath=NULL; const char* tdrelativepath; #if defined (U_TOPBUILDDIR) tdrelativepath = "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; directory = U_TOPBUILDDIR; #else tdrelativepath = ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; directory = pathToDataDirectory(); #endif tdpath = (char*) malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 100)); /* u_getDataDirectory shoul return \source\data ... set the * directory to ..\source\data\..\test\testdata\out\testdata */ strcpy(tdpath, directory); strcat(tdpath, tdrelativepath); strcat(tdpath,"testdata"); test=ures_open(tdpath, "testtypes", &err); if(U_FAILURE(err)){ err = U_FILE_ACCESS_ERROR; log_data_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(err)); return ""; } ures_close(test); fgTestDataPath = tdpath; } return fgTestDataPath; }
FileStream * NormalizerConformanceTest::openNormalizationTestFile(const char *filename) { char unidataPath[2000]; const char *folder; FileStream *input; UErrorCode errorCode; // look inside ICU_DATA first folder=pathToDataDirectory(); if(folder!=NULL) { strcpy(unidataPath, folder); strcat(unidataPath, "unidata" U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } } // find icu/source/data/unidata relative to the test data errorCode=U_ZERO_ERROR; folder=loadTestData(errorCode); if(U_SUCCESS(errorCode)) { strcpy(unidataPath, folder); strcat(unidataPath, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } } // look in icu/source/test/testdata/out/build errorCode=U_ZERO_ERROR; folder=loadTestData(errorCode); if(U_SUCCESS(errorCode)) { strcpy(unidataPath, folder); strcat(unidataPath, U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } } // look in icu/source/test/testdata errorCode=U_ZERO_ERROR; folder=loadTestData(errorCode); if(U_SUCCESS(errorCode)) { strcpy(unidataPath, folder); strcat(unidataPath, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } } // find icu/source/data/unidata relative to U_TOPSRCDIR #if defined(U_TOPSRCDIR) strcpy(unidataPath, U_TOPSRCDIR U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } strcpy(unidataPath, U_TOPSRCDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING); strcat(unidataPath, filename); input=T_FileStream_open(unidataPath, "rb"); if(input!=NULL) { return input; } #endif dataerrln("Failed to open %s", filename); return NULL; }
void UnicodeTest::TestAdditionalProperties() { #if !UCONFIG_NO_NORMALIZATION // 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)); return; } if(LENGTHOF(derivedPropsIndex)!=LENGTHOF(derivedPropsNames)) { errln("error in ucdtest.cpp: LENGTHOF(derivedPropsIndex)!=LENGTHOF(derivedPropsNames)\n"); return; } char newPath[256]; char backupPath[256]; char *fields[2][2]; UErrorCode errorCode=U_ZERO_ERROR; /* Look inside ICU_DATA first */ strcpy(newPath, pathToDataDirectory()); 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"); char *path=newPath; u_parseDelimitedFile(newPath, ';', fields, 2, derivedPropsLineFn, this, &errorCode); if(errorCode==U_FILE_ACCESS_ERROR) { errorCode=U_ZERO_ERROR; path=backupPath; u_parseDelimitedFile(backupPath, ';', fields, 2, derivedPropsLineFn, this, &errorCode); } if(U_FAILURE(errorCode)) { errln("error parsing DerivedCoreProperties.txt: %s\n", u_errorName(errorCode)); return; } 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; } // 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 for(i=0; i<LENGTHOF(derivedPropsNames); ++i) { rangeCount=derivedProps[i].getRangeCount(); for(range=0; range<rangeCount && numErrors[i]<MAX_ERRORS; ++range) { start=derivedProps[i].getRangeStart(range); end=derivedProps[i].getRangeEnd(range); for(; start<=end; ++start) { if(!u_hasBinaryProperty(start, derivedPropsIndex[i])) { dataerrln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==FALSE is wrong", start, derivedPropsNames[i]); if(++numErrors[i]>=MAX_ERRORS) { dataerrln("Too many errors, moving to the next test"); break; } } } } } // invert all properties for(i=0; i<LENGTHOF(derivedPropsNames); ++i) { derivedProps[i].complement(); } // test all FALSE properties for(i=0; i<LENGTHOF(derivedPropsNames); ++i) { rangeCount=derivedProps[i].getRangeCount(); for(range=0; range<rangeCount && numErrors[i]<MAX_ERRORS; ++range) { start=derivedProps[i].getRangeStart(range); end=derivedProps[i].getRangeEnd(range); for(; start<=end; ++start) { if(u_hasBinaryProperty(start, derivedPropsIndex[i])) { errln("UnicodeTest error: u_hasBinaryProperty(U+%04lx, %s)==TRUE is wrong\n", start, derivedPropsNames[i]); if(++numErrors[i]>=MAX_ERRORS) { errln("Too many errors, moving to the next test"); break; } } } } } #endif /* !UCONFIG_NO_NORMALIZATION */ }