ICU-4043 Use a real path to source data.

X-SVN-Rev: 16109
This commit is contained in:
George Rhoten 2004-08-04 23:40:31 +00:00
parent c34f70c3b8
commit 8900cd8fab
9 changed files with 44 additions and 54 deletions

View file

@ -537,6 +537,9 @@ static void TestConvert()
char* index = NULL;
err = U_ZERO_ERROR;
#ifdef U_TOPSRCDIR
strcpy(ucs_file_name, U_TOPSRCDIR U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING);
#else
strcpy(ucs_file_name, loadTestData(&err));
if(U_FAILURE(err)){
@ -551,6 +554,7 @@ static void TestConvert()
}
strcat(ucs_file_name,".."U_FILE_SEP_STRING);
#endif
strcat(ucs_file_name, CodePagesTestFiles[codepage_index]);
ucs_file_in = fopen(ucs_file_name,"rb");

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2003, International Business Machines
* Copyright (C) 2003-2004, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -271,11 +271,21 @@ void
doStringPrepTest(const char* binFileName, const char* txtFileName, int32_t options, UErrorCode* errorCode){
const char *testdatapath = loadTestData(errorCode);
const char *srcdatapath =ctest_dataOutDir();
const char *srcdatapath = NULL;
const char *relativepath = NULL;
char *filename = NULL;
UStringPrepProfile* profile = NULL;
const char *relativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
char *filename = (char*) malloc(strlen(srcdatapath)+strlen(relativepath)+strlen(txtFileName)+10 );
UStringPrepProfile* profile = usprep_open(testdatapath, binFileName, errorCode);
#ifdef U_TOPSRCDIR
srcdatapath = U_TOPSRCDIR;
relativepath = U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
#else
srcdatapath = ctest_dataOutDir();
relativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
#endif
filename = (char*) malloc(strlen(srcdatapath)+strlen(relativepath)+strlen(txtFileName)+10 );
profile = usprep_open(testdatapath, binFileName, errorCode);
if(U_FAILURE(*errorCode)){
log_err("Failed to load %s data file. Error: %s \n", binFileName, u_errorName(*errorCode));

View file

@ -1230,6 +1230,17 @@ const char* IntlTest::getTestDataPath(UErrorCode& err) {
return loadTestData(err);
}
/* Returns the path to icu/source/test/testdata/ */
const char *IntlTest::getSourceTestData(UErrorCode& err) {
const char *srcDataDir = NULL;
#ifdef U_TOPSRCDIR
srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
#else
srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
#endif
return srcDataDir;
}
const char* IntlTest::fgDataDir = NULL;
/* returns the path to icu/source/data */

View file

@ -208,6 +208,7 @@ public:
UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks
static const char* loadTestData(UErrorCode& err);
virtual const char* getTestDataPath(UErrorCode& err);
static const char* getSourceTestData(UErrorCode& err);
// static members
public:

View file

@ -1384,22 +1384,14 @@ void RBBITest::TestExtended() {
//
// Open and read the test data file.
//
const char *testDataDirectory = loadTestData(status);
const char *testDataDirectory = IntlTest::getSourceTestData(status);
char testFileName[1000];
if (strlen(testDataDirectory) >= sizeof(testFileName)) {
if (testDataDirectory == NULL || strlen(testDataDirectory) >= sizeof(testFileName)) {
errln("Can't open test data. Path too long.");
return;
}
strcpy(testFileName, testDataDirectory);
char *p = strstr(testFileName, "/out/testdata");
if (p == NULL) {
p = strstr(testFileName, "\\out\\testdata");
if (p == NULL) {
errln("Can't open test data. Bad test data directory path..");
return;
}
}
strcpy(p+1, "rbbitst.txt");
strcat(testFileName, "rbbitst.txt");
int len;
UChar *testFile = ReadAndConvertFile(testFileName, len, status);

View file

@ -1336,27 +1336,15 @@ void RegexTest::API_Pattern() {
const char *
RegexTest::getPath(char buffer[2048], const char *filename) {
UErrorCode status=U_ZERO_ERROR;
const char *testDataDirectory = loadTestData(status);
const char *testDataDirectory = IntlTest::getSourceTestData(status);
if (U_FAILURE(status)) {
errln("ERROR: loadTestData() failed - %s", u_errorName(status));
return NULL;
}
const char *folder=U_FILE_SEP_STRING "out" U_FILE_SEP_STRING "testdata";
const char *outTestdata=strstr(testDataDirectory, folder);
if(outTestdata!=NULL) {
/* skip the initial '/' */
outTestdata+=strlen(U_FILE_SEP_STRING);
int32_t length=outTestdata-testDataDirectory;
/* replace the trailing folder with the filename */
memcpy(buffer, testDataDirectory, length);
strcpy(buffer+length, filename);
return buffer;
} else {
errln("Could not find test data file %s because test data directory does not contain %s", filename, folder);
return NULL;
}
strcpy(buffer, testDataDirectory);
strcat(buffer, filename);
return buffer;
}
void RegexTest::Extended() {

View file

@ -46,18 +46,15 @@ TextFile::TextFile(const char* _name, const char* _encoding, UErrorCode& ec) :
encoding = (char*) _encoding;
#endif
const char* testDir = IntlTest::loadTestData(ec);
const char* testDir = IntlTest::getSourceTestData(ec);
if (U_FAILURE(ec)) {
return;
}
if (!ensureCapacity(uprv_strlen(testDir) + uprv_strlen(name) + 8)) {
if (!ensureCapacity(uprv_strlen(testDir) + uprv_strlen(name) + 1)) {
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_strcpy(buffer, testDir);
char* index = uprv_strrchr(buffer, (char)U_FILE_SEP_CHAR);
if (index) index[1] = 0;
uprv_strcat(buffer, ".." U_FILE_SEP_STRING);
uprv_strcat(buffer, name);
file = T_FileStream_open(buffer, "rb");

View file

@ -1212,18 +1212,12 @@ void MultithreadTest::TestCollators()
UErrorCode status = U_ZERO_ERROR;
FILE *testFile = NULL;
char testDataPath[1024];
strcpy(testDataPath, IntlTest::loadTestData(status));
strcpy(testDataPath, IntlTest::getSourceTestData(status));
char* index = 0;
if (U_FAILURE(status)) {
errln("ERROR: could not open test data %s", u_errorName(status));
return;
}
index=strrchr(testDataPath,(char)U_FILE_SEP_CHAR);
if((unsigned int)(index-testDataPath) != (strlen(testDataPath)-1)){
*(index+1)=0;
}
strcat(testDataPath,".."U_FILE_SEP_STRING);
strcat(testDataPath, "CollationTest_");
const char* type = "NON_IGNORABLE";

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2003, International Business Machines Corporation and
* Copyright (c) 2002-2004, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -29,19 +29,12 @@ status(U_ZERO_ERROR)
errln("ERROR - UCAConformanceTest: Unable to open UCA collator!");
}
uprv_strcpy(testDataPath, IntlTest::loadTestData(status));
const char *srcDir = IntlTest::getSourceTestData(status);
if (U_FAILURE(status)) {
errln("ERROR: could not open test data %s", u_errorName(status));
return;
}
char* index = 0;
index=strrchr(testDataPath,(char)U_FILE_SEP_CHAR);
if((unsigned int)(index-testDataPath) != (strlen(testDataPath)-1)){
*(index+1)=0;
}
uprv_strcat(testDataPath,".."U_FILE_SEP_STRING);
uprv_strcpy(testDataPath, srcDir);
uprv_strcat(testDataPath, "CollationTest_");
}