ICU-1627 implement fallback for loading data

X-SVN-Rev: 7517
This commit is contained in:
Ram Viswanadha 2002-01-29 03:56:11 +00:00
parent cd99f1f68f
commit 7ef6ef2d77
4 changed files with 104 additions and 44 deletions

View file

@ -1086,7 +1086,58 @@ main(int argc, char* argv[])
}
return major.getErrors();
}
void IntlTest::loadTestData(char* testdatapath,int32_t len, UErrorCode& err ){
const char* directory=NULL;
UResourceBundle* test =NULL;
char tdpath[256];
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
char tdpathFallback[256];
directory= u_getDataDirectory();
strcpy(tdpath, directory);
strcpy(tdpathFallback,directory);
if(len < 256){
err = U_BUFFER_OVERFLOW_ERROR;
return ;
}
/* u_getDataDirectory shoul return \source\data ... set the
* directory to ..\source\data\..\test\testdata\out\testdata
*
* Fallback: When Memory mapped file is built
* ..\source\data\out\..\..\test\testdata\out\testdata
*/
strcat(tdpath, tdrelativepath);
strcat(tdpath,"testdata");
strcat(tdpathFallback,".."U_FILE_SEP_STRING);
strcat(tdpathFallback, tdrelativepath);
strcat(tdpathFallback,"testdata");
test=ures_open(tdpath, "testtypes", &err);
/* we could not find the data in tdpath
* try tdpathFallback
*/
if(U_FAILURE(err))
{
testdatapath=tdpathFallback;
err =U_ZERO_ERROR;
test=ures_open(testdatapath, "ja_data", &err);
/* Fall back did not succeed either so return */
if(U_FAILURE(err)){
err = U_FILE_ACCESS_ERROR;
errln("construction of NULL did not succeed : " + UnicodeString(u_errorName(err)));
return;
}
ures_close(test);
strcpy(testdatapath,tdpathFallback);
return;
}
ures_close(test);
strcpy(testdatapath,tdpath);
}
/*
* This is a variant of cintltst/ccolltst.c:CharsToUChars().
* It converts a character string into a UnicodeString, with

View file

@ -153,6 +153,7 @@ public:
public:
UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks
void loadTestData(char* testdatapath,int32_t len,UErrorCode& err);
// static members
public:

View file

@ -258,12 +258,12 @@ ResourceBundleTest::TestConstruction()
char testdatapath[256];
Locale locale("te", "IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
ResourceBundle test1((UnicodeString)testdatapath, err);
ResourceBundle test2(testdatapath, locale, err);
//ResourceBundle test1("c:\\icu\\icu\\source\\test\\testdata\\testdata", err);
@ -310,11 +310,12 @@ ResourceBundleTest::TestConstruction()
char testdatapath[256];
Locale locale("te", "IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
wchar_t* wideDirectory = new wchar_t[256];
@ -363,19 +364,21 @@ ResourceBundleTest::testTag(const char* frag,
int32_t i,j,actual_bundle;
// int32_t row,col;
int32_t index;
UErrorCode status = U_ZERO_ERROR;
char testdatapath[256];
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,status);
if(U_FAILURE(status))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
return FALSE;
}
for (i=0; i<bundles_count; ++i)
{
action = "Constructor for ";
action += param[i].name;
UErrorCode status = U_ZERO_ERROR;
status = U_ZERO_ERROR;
ResourceBundle theBundle( testdatapath, *param[i].locale, status);
//ResourceBundle theBundle( "c:\\icu\\icu\\source\\test\\testdata\\testdata", *param[i].locale, status);
CONFIRM_UErrorCode(status, param[i].expected_constructor_status, action);

View file

@ -259,12 +259,12 @@ NewResourceBundleTest::TestConstruction()
UErrorCode err = U_ZERO_ERROR;
char testdatapath[256];
Locale locale("te", "IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
ResourceBundle test1((UnicodeString)testdatapath, err);
ResourceBundle test2(testdatapath, locale, err);
@ -311,11 +311,12 @@ NewResourceBundleTest::TestConstruction()
char testdatapath[256];
Locale locale("te", "IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
wchar_t* wideDirectory = new wchar_t[256];
@ -352,11 +353,12 @@ NewResourceBundleTest::TestIteration()
Locale *locale=new Locale("te_IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
ResourceBundle test1(testdatapath, *locale, err);
if(U_FAILURE(err)){
@ -455,12 +457,13 @@ void
NewResourceBundleTest::TestOtherAPI(){
UErrorCode err = U_ZERO_ERROR;
char testdatapath[256];
loadTestData(testdatapath,256,err);
if(U_FAILURE(err))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
return;
}
Locale *locale=new Locale("te_IN");
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
ResourceBundle test1(testdatapath, *locale, err);
if(U_FAILURE(err)){
@ -636,18 +639,20 @@ NewResourceBundleTest::testTag(const char* frag,
int32_t index;
char testdatapath[256];
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
strcpy(testdatapath, u_getDataDirectory());
strcat(testdatapath,tdrelativepath);
strcat(testdatapath, "testdata");
UErrorCode status = U_ZERO_ERROR;
loadTestData(testdatapath,256,status);
if(U_FAILURE(status))
{
errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
return FALSE;
}
for (i=0; i<bundles_count; ++i)
{
action = "Constructor for ";
action += param[i].name;
UErrorCode status = U_ZERO_ERROR;
status = U_ZERO_ERROR;
ResourceBundle theBundle( testdatapath, *param[i].locale, status);
//ResourceBundle theBundle( "c:\\icu\\icu\\source\\test\\testdata\\testdata", *param[i].locale, status);
CONFIRM_UErrorCode(status,param[i].expected_constructor_status);