ICU-1627 implement fallback for loading data
X-SVN-Rev: 7518
This commit is contained in:
parent
7ef6ef2d77
commit
7b4ed42d34
@ -312,7 +312,58 @@ char *aescstrdup(const UChar* unichars){
|
||||
return newString;
|
||||
}
|
||||
|
||||
void 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;
|
||||
log_err("construction of NULL did not succeed : %s \n", myErrorName(*err));
|
||||
return;
|
||||
}
|
||||
ures_close(test);
|
||||
strcpy(testdatapath,tdpathFallback);
|
||||
return;
|
||||
}
|
||||
ures_close(test);
|
||||
strcpy(testdatapath,tdpath);
|
||||
}
|
||||
|
||||
#define CTST_MAX_ALLOC 10000
|
||||
/* Array used as a queue */
|
||||
|
@ -61,7 +61,7 @@ U_CFUNC char *aescstrdup(const UChar* unichars);
|
||||
U_CFUNC void *ctst_malloc(size_t size);
|
||||
U_CFUNC void ctst_freeAll();
|
||||
|
||||
|
||||
U_CFUNC void loadTestData(char* testdatapath,int32_t len, UErrorCode* err );
|
||||
|
||||
/**
|
||||
* function used to specify the error
|
||||
|
@ -132,35 +132,34 @@ void TestResourceBundles()
|
||||
log_verbose("Passed:= %d Failed= %d \n", pass, fail);
|
||||
}
|
||||
|
||||
|
||||
void TestConstruction1()
|
||||
{
|
||||
UResourceBundle *test1 = 0, *test2 = 0;
|
||||
const UChar *result1, *result2;
|
||||
int32_t resultLen;
|
||||
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
const char* directory=NULL;
|
||||
char testdatapath[256] ;
|
||||
const char* locale="te_IN";
|
||||
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;
|
||||
directory= u_getDataDirectory();
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
|
||||
/* u_getDataDirectory shoul return \source\data ... set the
|
||||
* directory to ..\source\data\..\test\testdata\out\testdata
|
||||
*/
|
||||
uprv_strcat(testdatapath, tdrelativepath);
|
||||
uprv_strcat(testdatapath,"testdata");
|
||||
|
||||
log_verbose("Testing ures_open()......\n");
|
||||
|
||||
test1=ures_open(testdatapath, NULL, &err);
|
||||
|
||||
|
||||
loadTestData(testdatapath,256,&err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
log_err("construction of NULL did not succeed : %s \n", myErrorName(err));
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(err));
|
||||
return;
|
||||
}
|
||||
|
||||
test1=ures_open(testdatapath, NULL, &err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
log_err("construction of %s did not succeed : %s \n",NULL, myErrorName(err));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
test2=ures_open(testdatapath, locale, &err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
|
@ -291,14 +291,14 @@ static void TestNewTypes() {
|
||||
UChar expected[] = { 'a','b','c','\0','d','e','f' };
|
||||
const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
|
||||
UChar uExpect[200];
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1);
|
||||
strcpy(action, "Construction of testtypes bundle");
|
||||
|
||||
strcpy(testdatapath, directory);
|
||||
strcat(testdatapath,tdrelativepath);
|
||||
strcat(testdatapath, "testdata");
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
theBundle = ures_open(testdatapath, "testtypes", &status);
|
||||
|
||||
empty = ures_getStringByKey(theBundle, "emptystring", &len, &status);
|
||||
@ -407,8 +407,9 @@ static void TestNewTypes() {
|
||||
const UChar* str = ures_getStringByKey(theBundle,"testescape",&len,&status);
|
||||
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
|
||||
if(U_SUCCESS(status)){
|
||||
u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1);
|
||||
if(u_strcmp(uExpect,str)){
|
||||
log_err("Did not get the expected string for testescape");
|
||||
log_err("Did not get the expected string for testescape\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -419,7 +420,7 @@ static void TestNewTypes() {
|
||||
u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1);
|
||||
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
|
||||
if(u_strcmp(uExpect,str)){
|
||||
log_err("Did not get the expected string for test_underscores.");
|
||||
log_err("Did not get the expected string for test_underscores.\n");
|
||||
}
|
||||
}
|
||||
ures_close(res);
|
||||
@ -440,13 +441,16 @@ static void TestEmptyTypes() {
|
||||
int32_t intResult = 0;
|
||||
const UChar *zeroString;
|
||||
const int32_t *zeroIntVect;
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
strcpy(action, "Construction of testtypes bundle");
|
||||
|
||||
strcpy(testdatapath, directory);
|
||||
strcat(testdatapath,tdrelativepath);
|
||||
strcat(testdatapath, "testdata");
|
||||
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
theBundle = ures_open(testdatapath, "testtypes", &status);
|
||||
|
||||
CONFIRM_ErrorCode(status, U_ZERO_ERROR);
|
||||
@ -574,11 +578,13 @@ static void TestEmptyBundle(){
|
||||
char testdatapath[256];
|
||||
const char *directory= u_getDataDirectory();
|
||||
UResourceBundle *resb=0, *dResB=0;
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
strcpy(testdatapath, directory);
|
||||
strcat(testdatapath,tdrelativepath);
|
||||
strcat(testdatapath, "testdata");
|
||||
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
resb = ures_open(testdatapath, "testempty", &status);
|
||||
|
||||
if(U_SUCCESS(status)){
|
||||
@ -594,7 +600,6 @@ static void TestEmptyBundle(){
|
||||
|
||||
static void TestBinaryCollationData(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
const char* directory=NULL;
|
||||
const char* locale="te";
|
||||
char testdatapath[256];
|
||||
UResourceBundle *teRes = NULL;
|
||||
@ -603,15 +608,17 @@ static void TestBinaryCollationData(){
|
||||
uint8_t *binResult = NULL;
|
||||
int32_t len=0;
|
||||
const char* action="testing the binary collaton data";
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
directory= u_getDataDirectory();
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
uprv_strcat(testdatapath,tdrelativepath);
|
||||
uprv_strcat(testdatapath, "testdata");
|
||||
|
||||
|
||||
log_verbose("Testing binary collation data resource......\n");
|
||||
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
teRes=ures_open(testdatapath, locale, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status));
|
||||
@ -658,17 +665,21 @@ static void TestAPI() {
|
||||
UResourceBundle *teRes = NULL;
|
||||
UResourceBundle *teFillin=NULL;
|
||||
UResourceBundle *teFillin2=NULL;
|
||||
char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
directory= u_getDataDirectory();
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
uprv_strcat(testdatapath,tdrelativepath);
|
||||
uprv_strcat(testdatapath, "testdata");
|
||||
|
||||
log_verbose("Testing ures_openU()......\n");
|
||||
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
u_charsToUChars(testdatapath, utestdatapath, strlen(testdatapath)+1);
|
||||
/*u_uastrcpy(utestdatapath, testdatapath);*/
|
||||
|
||||
/*Test ures_openU */
|
||||
log_verbose("Testing ures_openU()......\n");
|
||||
|
||||
teRes=ures_openU(utestdatapath, "te", &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath), myErrorName(status));
|
||||
@ -780,13 +791,15 @@ static void TestErrorConditions(){
|
||||
UResourceBundle *teFillin2=NULL;
|
||||
uint8_t *binResult = NULL;
|
||||
int32_t resultLen;
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
directory= u_getDataDirectory();
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
uprv_strcat(testdatapath,tdrelativepath);
|
||||
uprv_strcat(testdatapath, "testdata");
|
||||
u_uastrcpy(utestdatapath, testdatapath);
|
||||
|
||||
/*Test ures_openU with status != U_ZERO_ERROR*/
|
||||
@ -1042,8 +1055,6 @@ static void TestConstruction1()
|
||||
const char* locale="te_IN";
|
||||
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;
|
||||
|
||||
int32_t len1=0;
|
||||
int32_t len2=0;
|
||||
UVersionInfo versionInfo;
|
||||
@ -1056,10 +1067,13 @@ static void TestConstruction1()
|
||||
U_STRING_INIT(rootVal, "ROOT", 4);
|
||||
U_STRING_INIT(te_inVal, "TE_IN", 5);
|
||||
|
||||
directory= u_getDataDirectory();
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
uprv_strcat(testdatapath, tdrelativepath);
|
||||
uprv_strcat(testdatapath,"testdata");
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
log_verbose("Testing ures_open()......\n");
|
||||
|
||||
empty = ures_open(testdatapath, "testempty", &status);
|
||||
@ -1206,12 +1220,12 @@ static UBool testTag(const char* frag,
|
||||
UResourceBundle* tags=NULL;
|
||||
UResourceBundle* arrayItem1=NULL;
|
||||
|
||||
const char* directory = u_getDataDirectory();
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
uprv_strcpy(testdatapath, directory);
|
||||
uprv_strcat(testdatapath,tdrelativepath);
|
||||
uprv_strcat(testdatapath, "testdata");
|
||||
loadTestData(testdatapath,256,&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Could not load testdata.dat %s \n",myErrorName(status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
is_in[0] = in_Root;
|
||||
is_in[1] = in_te;
|
||||
|
@ -1031,17 +1031,39 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
|
||||
}
|
||||
|
||||
static void TestCoverageMBCS(){
|
||||
char testdatapath[256];
|
||||
char tdpath[256];
|
||||
char tdfallbackpath[256];
|
||||
char saveDirectory[256];
|
||||
const char *directory= u_getDataDirectory();
|
||||
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
|
||||
|
||||
UConverter* conv = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
/*save the data directory */
|
||||
strcpy(saveDirectory, directory);
|
||||
|
||||
strcpy(tdpath, directory);
|
||||
strcat(tdpath,tdrelativepath);
|
||||
|
||||
/* set the fallback path for Memory Mapped build */
|
||||
strcpy(tdfallbackpath,directory);
|
||||
strcat(tdfallbackpath,".."U_FILE_SEP_STRING);
|
||||
strcat(tdfallbackpath,tdrelativepath);
|
||||
|
||||
strcpy(testdatapath, directory);
|
||||
strcat(testdatapath,tdrelativepath);
|
||||
u_setDataDirectory(testdatapath);
|
||||
u_setDataDirectory(tdpath);
|
||||
/* test if we can open test1.cnv from testdatapath */
|
||||
conv = ucnv_open("test1",&status);
|
||||
if(U_FAILURE(status)){
|
||||
status=U_ZERO_ERROR;
|
||||
/* try the fallback path */
|
||||
u_setDataDirectory(tdfallbackpath);
|
||||
conv= ucnv_open("test1",&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Could not open converters from fallback path :%s . Error : %s \n",tdfallbackpath,u_errorName(status));
|
||||
}
|
||||
ucnv_close(conv);
|
||||
}
|
||||
ucnv_close(conv);
|
||||
|
||||
/*some more test to increase the code coverage in MBCS. Create an test converter from test1.ucm
|
||||
which is test file for MBCS conversion with single-byte codepage data.*/
|
||||
|
Loading…
Reference in New Issue
Block a user