mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-1992 data packaging, improve robustness of intltest search for test data
X-SVN-Rev: 9478
This commit is contained in:
parent
53ac097505
commit
ffd9cf9a81
2 changed files with 44 additions and 6 deletions
|
@ -1157,14 +1157,49 @@ main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
const char* IntlTest::loadTestData(UErrorCode& err){
|
||||
const char* directory=NULL;
|
||||
UResourceBundle* test =NULL;
|
||||
char* tdpath=NULL;
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
const char* directory = ".";
|
||||
char p[1024];
|
||||
const char* tdrelativepath = U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
if( _testDataPath == NULL){
|
||||
directory= u_getDataDirectory();
|
||||
|
||||
/* get the data/out dir */
|
||||
|
||||
#if defined (U_TOPBUILDDIR)
|
||||
directory = U_TOPBUILDDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata";
|
||||
#else
|
||||
// Use #else so we don't get compiler warnings due to the return above.
|
||||
|
||||
/* On Windows, the file name obtained from __FILE__ includes a full path.
|
||||
* This file is "wherever\icu\source\test\cintltst\cintltst.c"
|
||||
* Change to "wherever\icu\source\data"
|
||||
*/
|
||||
{
|
||||
char *pBackSlash;
|
||||
int i;
|
||||
|
||||
strcpy(p, __FILE__);
|
||||
/* We want to back over three '\' chars. */
|
||||
/* Only Windows should end up here, so looking for '\' is safe. */
|
||||
for (i=1; i<=3; i++) {
|
||||
pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
|
||||
if (pBackSlash != NULL) {
|
||||
*pBackSlash = 0; /* Truncate the string at the '\' */
|
||||
}
|
||||
}
|
||||
|
||||
if (pBackSlash != NULL) {
|
||||
/* We found and truncated three names from the path.
|
||||
* Now append "source\data" and set the environment
|
||||
*/
|
||||
strcpy(pBackSlash, U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata");
|
||||
directory = p;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tdpath = new char[(( strlen(directory) * strlen(tdrelativepath)) + 10)];//(char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
|
||||
tdpath = new char[(( strlen(directory) * strlen(tdrelativepath)) + 10)];//(char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
|
||||
|
||||
|
||||
/* u_getDataDirectory shoul return \source\data ... set the
|
||||
|
@ -1176,7 +1211,6 @@ const char* IntlTest::loadTestData(UErrorCode& err){
|
|||
strcpy(tdpath, directory);
|
||||
strcat(tdpath, tdrelativepath);
|
||||
strcat(tdpath,"testdata");
|
||||
|
||||
|
||||
test=ures_open(tdpath, "testtypes", &err);
|
||||
|
||||
|
@ -1185,6 +1219,7 @@ const char* IntlTest::loadTestData(UErrorCode& err){
|
|||
*/
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
fprintf(stderr, "Path %s failed to load testdata\n", tdpath);
|
||||
strcpy(tdpath,directory);
|
||||
strcat(tdpath,".."U_FILE_SEP_STRING);
|
||||
strcat(tdpath, tdrelativepath);
|
||||
|
@ -1195,6 +1230,7 @@ const char* IntlTest::loadTestData(UErrorCode& err){
|
|||
* try one more tdpathFallback
|
||||
*/
|
||||
if(U_FAILURE(err)){
|
||||
fprintf(stderr, "Path %s failed to load testdata\n", tdpath);
|
||||
strcpy(tdpath,directory);
|
||||
strcat(tdpath,".."U_FILE_SEP_STRING);
|
||||
strcat(tdpath,".."U_FILE_SEP_STRING);
|
||||
|
@ -1207,6 +1243,8 @@ const char* IntlTest::loadTestData(UErrorCode& err){
|
|||
err = U_FILE_ACCESS_ERROR;
|
||||
it_errln((UnicodeString)"construction of NULL did not succeed: "
|
||||
+ (UnicodeString)u_errorName(err)
|
||||
+ ", path was based on "
|
||||
+ (UnicodeString)tdpath
|
||||
+ (UnicodeString)" \n");
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ ResourceBundleTest::TestConstruction()
|
|||
testdatapath=loadTestData(err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
|
||||
errln("Could not load testdata.dat " + UnicodeString(testdatapath) + ", " + UnicodeString(u_errorName(err)));
|
||||
return;
|
||||
}
|
||||
ResourceBundle test1((UnicodeString)testdatapath, err);
|
||||
|
|
Loading…
Add table
Reference in a new issue