diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index e2e30361ff2..ce11c64498d 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -343,12 +343,27 @@ const char* loadTestData(UErrorCode* err){ strcat(tdpath, tdrelativepath); strcat(tdpath,"testdata"); *err =U_ZERO_ERROR; - test=ures_open(tdpath, "ja_data", err); - /* Fall back did not succeed either so return */ + test=ures_open(tdpath, "testtypes", err); + /* we could not find the data in tdpath + * try one more tdpathFallback + */ if(U_FAILURE(*err)){ - *err = U_FILE_ACCESS_ERROR; - log_err("construction of NULL did not succeed : %s \n", u_errorName(*err)); - return ""; + strcpy(tdpath,directory); + strcat(tdpath,".."U_FILE_SEP_STRING); + strcat(tdpath,".."U_FILE_SEP_STRING); + strcat(tdpath, tdrelativepath); + strcat(tdpath,"testdata"); + *err =U_ZERO_ERROR; + test=ures_open(tdpath, "testtypes", 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", u_errorName(*err)); + return ""; + } + ures_close(test); + _testDataPath = tdpath; + return _testDataPath; } ures_close(test); _testDataPath = tdpath; diff --git a/icu4c/source/test/cintltst/citertst.c b/icu4c/source/test/cintltst/citertst.c index 586fb3d3f05..1d163378960 100644 --- a/icu4c/source/test/cintltst/citertst.c +++ b/icu4c/source/test/cintltst/citertst.c @@ -1307,12 +1307,15 @@ static FileStream * getFractionalUCA(void) /* As a fallback, try to guess where the source data was located * at the time ICU was built, and look there. */ - #if defined (U_TOPSRCDIR) - strcpy(backupPath, U_TOPSRCDIR U_FILE_SEP_STRING "data"); - #else - strcpy(backupPath, u_getDataDirectory()); - strcat(backupPath, ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data"); - #endif +#if defined (U_TOPSRCDIR) + strcpy(backupPath, U_TOPSRCDIR U_FILE_SEP_STRING "data"); +#else + { + UErrorCode errorCode = U_ZERO_ERROR; + 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 "unidata" U_FILE_SEP_STRING "FractionalUCA.txt"); result = T_FileStream_open(newPath, "rb"); diff --git a/icu4c/source/test/cintltst/crestst.c b/icu4c/source/test/cintltst/crestst.c index 7080eff4c4f..ac1818fbbc5 100644 --- a/icu4c/source/test/cintltst/crestst.c +++ b/icu4c/source/test/cintltst/crestst.c @@ -275,11 +275,7 @@ UBool testTag(const char* frag, int32_t i,j; int32_t actual_bundle; int32_t resultLen; - char testdatapath[256]; - const char *directory= u_getDataDirectory(); - - uprv_strcpy(testdatapath, directory); - uprv_strcat(testdatapath, "testdata"); + const char *testdatapath = loadTestData(&status); is_in[0] = in_Root; is_in[1] = in_te; @@ -534,7 +530,7 @@ TestOpenDirect(void) { /* falling back to default or root is ok */ errorCode=U_ZERO_ERROR; } else { - log_err("ures_open(\"translit_index\") succeeded, should fail!\n"); + log_err("ures_open(\"translit_index\") succeeded, should fail! Got: %s\n", u_errorName(errorCode)); } ures_close(translit_index); diff --git a/icu4c/source/test/cintltst/udatatst.c b/icu4c/source/test/cintltst/udatatst.c index a6a057a1199..22b569ef1b7 100644 --- a/icu4c/source/test/cintltst/udatatst.c +++ b/icu4c/source/test/cintltst/udatatst.c @@ -82,12 +82,7 @@ static void TestUDataOpen(){ char *icuDataFilePath = 0; struct stat stat_buf; - const char* tdrelativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; - char* testPath=(char*)malloc(sizeof(char) * (strlen(u_getDataDirectory()) + strlen("testdata") +1 +strlen(tdrelativepath)) ); - - strcpy(testPath, u_getDataDirectory()); - strcat(testPath,tdrelativepath); - strcat(testPath, "testdata"); + const char* testPath=loadTestData(&status); strcat(strcpy(path, u_getDataDirectory()), U_ICUDATA_NAME); @@ -184,8 +179,8 @@ static void TestUDataOpen(){ */ log_verbose("Testing udata_open, with base_name.type style fallback to individual file.\n"); icuDataFilePath = (char *)malloc(sizeof(char) * (strlen(u_getDataDirectory()) + 50)); - strcpy(icuDataFilePath, u_getDataDirectory()); - strcat(icuDataFilePath,tdrelativepath); + strcpy(icuDataFilePath, testPath); + strrchr(icuDataFilePath, U_FILE_SEP_CHAR)[1] = 0; /* Trncate after the '\' */ strcat(icuDataFilePath, "testudata"); status = U_ZERO_ERROR; result = udata_open( icuDataFilePath, "typ", "nam", &status); @@ -202,8 +197,7 @@ static void TestUDataOpen(){ */ log_verbose("Testing udata_open, with path containing a trailing directory separator.\n"); icuDataFilePath = (char *)malloc(strlen(u_getDataDirectory()) + 50); - strcpy(icuDataFilePath, u_getDataDirectory()); - strcat(icuDataFilePath,tdrelativepath); + strcpy(icuDataFilePath, testPath); status = U_ZERO_ERROR; result = udata_open( icuDataFilePath, "cnv", "test1", &status); if (status != U_ZERO_ERROR) { @@ -233,7 +227,6 @@ static void TestUDataOpen(){ } free(path); - free(testPath); } @@ -250,12 +243,11 @@ static void TestUDataSetAppData(){ size_t i; /* Open the testdata.dat file, using normal */ - const char* tdrelativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; + const char* tdrelativepath = loadTestData(&status); char* filePath=(char*)malloc(sizeof(char) * (strlen(u_getDataDirectory()) + strlen("testdata.dat") +1 +strlen(tdrelativepath)) ); - strcpy(filePath, u_getDataDirectory()); - strcat(filePath,tdrelativepath); - strcat(filePath, "testdata.dat"); + strcpy(filePath, tdrelativepath); + strcat(filePath, ".dat"); log_verbose("Testing udata_setAppData()\n");