diff --git a/icu4c/source/test/cintltst/ccapitst.c b/icu4c/source/test/cintltst/ccapitst.c index 3b54dc832ac..6a7eb3ef4ce 100644 --- a/icu4c/source/test/cintltst/ccapitst.c +++ b/icu4c/source/test/cintltst/ccapitst.c @@ -452,8 +452,21 @@ static void TestConvert() for (codepage_index=0; codepage_index < NUM_CODEPAGE; ++codepage_index) { int32_t i = 0; - - strcpy(ucs_file_name, ctest_getTestDirectory()); + char* index = NULL; + strcpy(ucs_file_name, loadTestData(&err)); + + index=strrchr(ucs_file_name,(char)U_FILE_SEP_CHAR); + + if((unsigned int)(index-ucs_file_name) != (strlen(ucs_file_name)-1)){ + *(index+1)=0; + } + + strcat(ucs_file_name,".."U_FILE_SEP_STRING); + + if(U_FAILURE(err)){ + log_err("Couldn't get the test data directory... Exiting...Error:%s\n", u_errorName(err)); + return; + } strcat(ucs_file_name, CodePagesTestFiles[codepage_index]); ucs_file_in = fopen(ucs_file_name,"rb"); @@ -1419,3 +1432,5 @@ static void bug3() log_err("error j932 bug 3b: expected 0x%04x, got 0x%04x\n", sizeof(char_in) * 2, size); } } + + diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index 50a1883aa99..56f09788245 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -40,7 +40,7 @@ U_CFUNC void ctst_freeAll(void); U_CFUNC void ctst_init(void); #endif -static char* _testDirectory=NULL; +static char* _testDataPath=NULL; /* * Forward Declarations @@ -181,29 +181,6 @@ ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath ) } } -const char* -ctest_getTestDirectory() -{ - if (_testDirectory == NULL) - { - /* always relative to icu/source/data/.. */ - ctest_setTestDirectory("test|testdata|"); - } - return _testDirectory; -} - -void -ctest_setTestDirectory(const char* newDir) -{ - char newTestDir[256]; - ctest_pathnameInContext(newTestDir, (int32_t)sizeof(newTestDir), newDir); - if(_testDirectory != NULL) - free(_testDirectory); - _testDirectory = (char*) ctst_malloc(sizeof(char*) * (strlen(newTestDir) + 1)); - strcpy(_testDirectory, newTestDir); -} - - /* ctest_setICU_DATA - if the ICU_DATA environment variable is not already * set, try to deduce the directory in which ICU was built, @@ -312,57 +289,56 @@ char *aescstrdup(const UChar* unichars){ return newString; } -void loadTestData(char* testdatapath,int32_t len, UErrorCode* err ){ +const char* loadTestData(UErrorCode* err){ const char* directory=NULL; UResourceBundle* test =NULL; - char tdpath[256]; + 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; - char tdpathFallback[256]; + if( _testDataPath == NULL){ + directory= u_getDataDirectory(); + + tdpath = (char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10)); - 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"); + /* 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 + */ + strcpy(tdpath, directory); + strcat(tdpath, tdrelativepath); + strcat(tdpath,"testdata"); + - strcat(tdpathFallback,".."U_FILE_SEP_STRING); - strcat(tdpathFallback, tdrelativepath); - strcat(tdpathFallback,"testdata"); + test=ures_open(tdpath, "testtypes", err); - 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; + /* we could not find the data in tdpath + * try tdpathFallback + */ + if(U_FAILURE(*err)) + { + strcpy(tdpath,directory); + strcat(tdpath,".."U_FILE_SEP_STRING); + 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 */ + 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); - strcpy(testdatapath,tdpathFallback); - return; + _testDataPath = tdpath; + return _testDataPath; } - ures_close(test); - strcpy(testdatapath,tdpath); + return _testDataPath; } #define CTST_MAX_ALLOC 10000 @@ -401,6 +377,6 @@ void ctst_freeAll() { free(ctst_allocated_stuff[i]); } } - _testDirectory=NULL; + _testDataPath=NULL; } #endif diff --git a/icu4c/source/test/cintltst/cintltst.h b/icu4c/source/test/cintltst/cintltst.h index ef55abc1dac..12e4091c9d9 100644 --- a/icu4c/source/test/cintltst/cintltst.h +++ b/icu4c/source/test/cintltst/cintltst.h @@ -36,18 +36,7 @@ U_CFUNC void addAllTests(TestNode** root); * @relPath the relative path name */ U_CFUNC void ctest_pathnameInContext(char* fullname, int32_t maxsize, const char* relPath ) ; -/** - *Fetches the current path name of the test directory - *returns the path of the test directory - */ -U_CFUNC const char* ctest_getTestDirectory(void); -/** - * - * sets the path of the test directory - * @param newDir the test directory to be set - */ -U_CFUNC void ctest_setTestDirectory(const char* newDir); /** * Convert a const UChar* into a char* * Caller owns storage, but in practice this function @@ -61,7 +50,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 ); +U_CFUNC const char* loadTestData(UErrorCode* err); /** * function used to specify the error diff --git a/icu4c/source/test/cintltst/crestst.c b/icu4c/source/test/cintltst/crestst.c index 2522a893c0d..7080eff4c4f 100644 --- a/icu4c/source/test/cintltst/crestst.c +++ b/icu4c/source/test/cintltst/crestst.c @@ -138,13 +138,13 @@ void TestConstruction1() int32_t resultLen; UErrorCode err = U_ZERO_ERROR; - char testdatapath[256] ; + const char* testdatapath ; const char* locale="te_IN"; log_verbose("Testing ures_open()......\n"); - loadTestData(testdatapath,256,&err); + testdatapath=loadTestData(&err); if(U_FAILURE(err)) { log_err("Could not load testdata.dat %s \n",myErrorName(err)); diff --git a/icu4c/source/test/cintltst/creststn.c b/icu4c/source/test/cintltst/creststn.c index be80253f1e3..5d436af20e0 100644 --- a/icu4c/source/test/cintltst/creststn.c +++ b/icu4c/source/test/cintltst/creststn.c @@ -282,8 +282,7 @@ static void TestDecodedBundle(){ static void TestNewTypes() { UResourceBundle* theBundle = NULL; char action[256]; - char testdatapath[256]; - const char *directory= u_getDataDirectory(); + const char* testdatapath; UErrorCode status = U_ZERO_ERROR; UResourceBundle* res = NULL; uint8_t *binResult = NULL; @@ -297,7 +296,7 @@ static void TestNewTypes() { const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''"; UChar uExpect[200]; - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); @@ -436,7 +435,7 @@ static void TestNewTypes() { static void TestEmptyTypes() { UResourceBundle* theBundle = NULL; char action[256]; - char testdatapath[256]; + const char* testdatapath; const char *directory= u_getDataDirectory(); UErrorCode status = U_ZERO_ERROR; UResourceBundle* res = NULL; @@ -449,7 +448,7 @@ static void TestEmptyTypes() { strcpy(action, "Construction of testtypes bundle"); - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); @@ -580,11 +579,10 @@ static void TestEmptyTypes() { static void TestEmptyBundle(){ UErrorCode status = U_ZERO_ERROR; - char testdatapath[256]; - const char *directory= u_getDataDirectory(); + const char* testdatapath=NULL; UResourceBundle *resb=0, *dResB=0; - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); @@ -606,7 +604,7 @@ static void TestEmptyBundle(){ static void TestBinaryCollationData(){ UErrorCode status=U_ZERO_ERROR; const char* locale="te"; - char testdatapath[256]; + const char* testdatapath; UResourceBundle *teRes = NULL; UResourceBundle *coll=NULL; UResourceBundle *binColl = NULL; @@ -616,7 +614,7 @@ static void TestBinaryCollationData(){ log_verbose("Testing binary collation data resource......\n"); - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); @@ -664,8 +662,8 @@ static void TestAPI() { int32_t len=0; const char* key=NULL; const UChar* value=NULL; - char testdatapath[256]; - UChar utestdatapath[256]; + const char* testdatapath; + UChar* utestdatapath=NULL; char convOutput[256]; UResourceBundle *teRes = NULL; UResourceBundle *teFillin=NULL; @@ -673,13 +671,15 @@ static void TestAPI() { log_verbose("Testing ures_openU()......\n"); - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } - + len =strlen(testdatapath); + utestdatapath = (UChar*) malloc((len+10)*sizeof(UChar)); + u_charsToUChars(testdatapath, utestdatapath, strlen(testdatapath)+1); /*u_uastrcpy(utestdatapath, testdatapath);*/ @@ -779,6 +779,7 @@ static void TestAPI() { } ures_close(teRes); } + free(utestdatapath); } static void TestErrorConditions(){ @@ -786,8 +787,8 @@ static void TestErrorConditions(){ const char* directory=NULL; const char *key=NULL; const UChar *value=NULL; - char testdatapath[256]; - UChar utestdatapath[256]; + const char* testdatapath; + UChar* utestdatapath; int32_t len=0; UResourceBundle *teRes = NULL; UResourceBundle *coll=NULL; @@ -798,13 +799,14 @@ static void TestErrorConditions(){ int32_t resultLen; - loadTestData(testdatapath,256,&status); + testdatapath = loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } - + len = strlen(testdatapath); + utestdatapath = (UChar*) malloc(sizeof(UChar) *(len+10)); u_uastrcpy(utestdatapath, testdatapath); /*Test ures_openU with status != U_ZERO_ERROR*/ @@ -1002,6 +1004,7 @@ static void TestErrorConditions(){ ures_close(coll); ures_close(binColl); ures_close(teRes); + free(utestdatapath); } @@ -1058,7 +1061,7 @@ static void TestConstruction1() UErrorCode err = U_ZERO_ERROR; const char* directory=NULL; const char* locale="te_IN"; - char testdatapath[256]; + const char* testdatapath; int32_t len1=0; int32_t len2=0; @@ -1072,7 +1075,7 @@ static void TestConstruction1() U_STRING_INIT(rootVal, "ROOT", 4); U_STRING_INIT(te_inVal, "TE_IN", 5); - loadTestData(testdatapath,256,&status); + testdatapath=loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); @@ -1218,14 +1221,14 @@ static UBool testTag(const char* frag, int32_t column_count=0; int32_t index = 0; int32_t tag_count= 0; - char testdatapath[256]; + const char* testdatapath; char verboseOutput[256]; UResourceBundle* array=NULL; UResourceBundle* array2d=NULL; UResourceBundle* tags=NULL; UResourceBundle* arrayItem1=NULL; - loadTestData(testdatapath,256,&status); + testdatapath = loadTestData(&status); if(U_FAILURE(status)) { log_err("Could not load testdata.dat %s \n",myErrorName(status)); diff --git a/icu4c/source/test/intltest/cppcnvt.cpp b/icu4c/source/test/intltest/cppcnvt.cpp index e1fd0c31a30..868ac15fe87 100644 --- a/icu4c/source/test/intltest/cppcnvt.cpp +++ b/icu4c/source/test/intltest/cppcnvt.cpp @@ -264,7 +264,20 @@ void ConvertTest::TestConvert() { err = U_ZERO_ERROR; i = 0; - strcpy(ucs_file_name, IntlTest::getTestDirectory()); + char* index = 0; + strcpy(ucs_file_name, IntlTest::loadTestData(err)); + + index=strrchr(ucs_file_name,(char)U_FILE_SEP_CHAR); + + if((unsigned int)(index-ucs_file_name) != (strlen(ucs_file_name)-1)){ + *(index+1)=0; + } + + strcat(ucs_file_name,".."U_FILE_SEP_STRING); + if(U_FAILURE(err)){ + char errmsg[UCS_FILE_NAME_SIZE + 128]; + sprintf(errmsg, "Couldn't open the testdata... Exiting...Error:%s \n", u_errorName(err)); + } strcat(ucs_file_name, CodePagesTestFiles[codepage_index]); ucs_file_in = fopen(ucs_file_name, "rb"); diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index 18707a760bd..8997da2bdb6 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -33,7 +33,7 @@ #endif -static char* _testDirectory=NULL; +static char* _testDataPath=NULL; // Static list of errors found static UnicodeString errorList; @@ -352,33 +352,6 @@ IntlTest::pathnameInContext( char* fullname, int32_t maxsize, const char* relPat } } -/** - * Functions to get and set the directory containing the Test files. - */ - -const char* -IntlTest::getTestDirectory() -{ - if (_testDirectory == NULL) - { - setTestDirectory("test|testdata|"); - } - return _testDirectory; -} - -void -IntlTest::setTestDirectory(const char* newDir) -{ - char newTestDir[256]; - IntlTest::pathnameInContext(newTestDir, sizeof(newTestDir), newDir); - if(_testDirectory != NULL) - delete _testDirectory; - _testDirectory = new char[strlen(newTestDir) + 1]; - strcpy(_testDirectory, newTestDir); -} - - - /* IntlTest::setICU_DATA - if the ICU_DATA environment variable is not already * set, try to deduce the directory in which ICU was built, * and set ICU_DATA to "icu/source/data" in that location. @@ -905,250 +878,237 @@ main(int argc, char* argv[]) argc = ccommand( &argv ); #endif - UBool repeatTestsInit = FALSE; /* Was REPEAT_TESTS initialized? */ - int32_t repeatTests = 1; /* Number of times to run the test */ - int32_t errorCount = 0; + UBool syntax = FALSE; + UBool all = TRUE; + UBool verbose = FALSE; + UBool no_err_msg = FALSE; + UBool quick = TRUE; + UBool name = FALSE; + UBool leaks = FALSE; - while (repeatTests > 0) { - UBool syntax = FALSE; - UBool all = TRUE; - UBool verbose = FALSE; - UBool no_err_msg = FALSE; - UBool quick = TRUE; - UBool name = FALSE; - UBool leaks = FALSE; + // If user didn't set ICU_DATA, attempt to generate one. + IntlTest::setICU_DATA(); - // If user didn't set ICU_DATA, attempt to generate one. - IntlTest::setICU_DATA(); - - for (int i = 1; i < argc; ++i) { - if (argv[i][0] == '-') { - const char* str = argv[i] + 1; - if (strcmp("verbose", str) == 0 || strcmp("v", str) == 0) { - verbose = TRUE; - } - else if (strcmp("noerrormsg", str) == 0 || strcmp("n", str) == 0) { - no_err_msg = TRUE; - } - else if (strcmp("exhaustive", str) == 0 || strcmp("e", str) == 0) { - quick = FALSE; - } - else if (strcmp("all", str) == 0 || strcmp("a", str) == 0) { - all = TRUE; - } - else if (strcmp("leaks", str) == 0 || strcmp("l", str) == 0) { - leaks = TRUE; - } - else if (strcmp("repeat", str) == 0 || strcmp("r", str) == 0) { - if (!repeatTestsInit) { - repeatTests++; - repeatTestsInit = TRUE; - } - } - else { - syntax = TRUE; - } - } - else{ - name = TRUE; - all = FALSE; - } - } - - if (all && name || !all && !name) - syntax = TRUE; - - if (syntax) { - fprintf(stdout, - "### Syntax:\n" - "### IntlTest [-option1 -option2 ...] [testname1 testname2 ...] \n" - "### where options are: verbose (v), all (a), noerrormsg (n), \n" - "### exhaustive (e), repeat (r) and leaks (l). \n" - "### (Specify either -all (shortcut -a) or a test name). \n" - "### -all will run all of the tests.\n" - "### \n" - "### To get a list of the test names type: intltest LIST \n" - "### To run just the utility tests type: intltest utility \n" - "### \n" - "### Test names can be nested using slashes (\"testA/subtest1\") \n" - "### For example to list the utility tests type: intltest utility/LIST \n" - "### To run just the Locale test type: intltest utility/LocaleTest \n" - "### \n" - "### A parameter can be specified for a test by appending '@' and the value \n" - "### to the testname. \n\n"); - return 1; - } - - UBool all_tests_exist = TRUE; - MajorTestLevel major; - major.setVerbose( verbose ); - major.setNoErrMsg( no_err_msg ); - major.setQuick( quick ); - major.setLeaks( leaks ); - fprintf(stdout, "-----------------------------------------------\n"); - fprintf(stdout, " IntlTest (C++) Test Suite for \n"); - fprintf(stdout, " International Components for Unicode %s\n", U_ICU_VERSION); - fprintf(stdout, "-----------------------------------------------\n"); - fprintf(stdout, " Options: \n"); - fprintf(stdout, " all (a) : %s\n", (all? "On" : "Off")); - fprintf(stdout, " Verbose (v) : %s\n", (verbose? "On" : "Off")); - fprintf(stdout, " No error messages (n) : %s\n", (no_err_msg? "On" : "Off")); - fprintf(stdout, " Exhaustive (e) : %s\n", (!quick? "On" : "Off")); - fprintf(stdout, " Leaks (l) : %s\n", (leaks? "On" : "Off")); - fprintf(stdout, " Repeat (r) : %s\n", (repeatTests>1? "On" : "Off")); - fprintf(stdout, "-----------------------------------------------\n"); - - // initial check for the default converter - UErrorCode errorCode = U_ZERO_ERROR; - UConverter *cnv = ucnv_open(0, &errorCode); - if(cnv != 0) { - // ok - ucnv_close(cnv); - } else { - fprintf(stdout, - "*** Failure! The default converter [%s] cannot be opened.\n" - "*** Check the ICU_DATA environment variable and\n" - "*** check that the data files are present.\n", - ucnv_getDefaultName()); - return 1; - } - - // try more data - cnv = ucnv_open("iso-8859-7", &errorCode); - if(cnv != 0) { - // ok - ucnv_close(cnv); - } else { - fprintf(stdout, - "*** Failure! The converter for iso-8859-7 cannot be opened.\n" - "*** Check the ICU_DATA environment variable and \n" - "*** check that the data files are present.\n"); - return 1; - } - - UResourceBundle *rb = ures_open(0, "en", &errorCode); - if(U_SUCCESS(errorCode)) { - // ok - ures_close(rb); - } else { - fprintf(stdout, - "*** Failure! The \"en\" locale resource bundle cannot be opened.\n" - "*** Check the ICU_DATA environment variable and \n" - "*** check that the data files are present.\n"); - return 1; - } - - if (all) { - major.runTest(); - if (leaks) { - major.run_phase2( NULL, NULL ); + for (int i = 1; i < argc; ++i) { + if (argv[i][0] == '-') { + const char* str = argv[i] + 1; + if (strcmp("verbose", str) == 0) + verbose = TRUE; + else if (strcmp("v", str) == 0) + verbose = TRUE; + else if (strcmp("noerrormsg", str) == 0) + no_err_msg = TRUE; + else if (strcmp("n", str) == 0) + no_err_msg = TRUE; + else if (strcmp("exhaustive", str) == 0) + quick = FALSE; + else if (strcmp("e", str) == 0) + quick = FALSE; + else if (strcmp("all", str) == 0) + all = TRUE; + else if (strcmp("a", str) == 0) + all = TRUE; + else if (strcmp("leaks", str) == 0) + leaks = TRUE; + else if (strcmp("l", str) == 0) + leaks = TRUE; + else { + syntax = TRUE; } }else{ - for (int i = 1; i < argc; ++i) { - if (argv[i][0] != '-') { - char* name = argv[i]; - fprintf(stdout, "\n=== Handling test: %s: ===\n", name); - char* parameter = strchr( name, '@' ); - if (parameter) { - *parameter = 0; - parameter += 1; - } - execCount = 0; - UBool res = major.runTest( name, parameter ); - if (leaks && res) { - major.run_phase2( name, parameter ); - } - if (!res || (execCount <= 0)) { - fprintf(stdout, "\n---ERROR: Test doesn't exist: %s!\n", name); - all_tests_exist = FALSE; - } - } - } + name = TRUE; + all = FALSE; } - - CalendarTimeZoneTest::cleanup(); - delete _testDirectory; - _testDirectory = 0; - - fprintf(stdout, "\n--------------------------------------\n"); - if (major.getErrors() == 0) { - /* Call it twice to make sure that the defaults were reset. */ - /* Call it before the OK message to verify proper cleanup. */ - u_cleanup(); - u_cleanup(); - - fprintf(stdout, "OK: All tests passed without error.\n"); - }else{ - fprintf(stdout, "Errors in total: %ld.\n", (long)major.getErrors()); - major.printErrors(); - - /* Call afterwards to display errors. */ - u_cleanup(); - } - - fprintf(stdout, "--------------------------------------\n"); - - if (execCount <= 0) { - fprintf(stdout, "***** Not all called tests actually exist! *****\n"); - } - errorCount = major.getErrors(); - errorList.remove(); - repeatTests--; } - return errorCount; -} -void IntlTest::loadTestData(char* testdatapath,int32_t len, UErrorCode& err ){ + if (all && name) syntax = TRUE; + if (!all && !name) syntax = TRUE; + + if (syntax) { + fprintf(stdout, + "### Syntax:\n" + "### IntlTest [-option1 -option2 ...] [testname1 testname2 ...] \n" + "### where options are: verbose (v), all (a), noerrormsg (n), \n" + "### exhaustive (e) and leaks (l). \n" + "### (Specify either -all (shortcut -a) or a test name). \n" + "### -all will run all of the tests.\n" + "### \n" + "### To get a list of the test names type: intltest LIST \n" + "### To run just the utility tests type: intltest utility \n" + "### \n" + "### Test names can be nested using slashes (\"testA/subtest1\") \n" + "### For example to list the utility tests type: intltest utility/LIST \n" + "### To run just the Locale test type: intltest utility/LocaleTest \n" + "### \n" + "### A parameter can be specified for a test by appending '@' and the value \n" + "### to the testname. \n\n"); + return 1; + } + + UBool all_tests_exist = TRUE; + MajorTestLevel major; + major.setVerbose( verbose ); + major.setNoErrMsg( no_err_msg ); + major.setQuick( quick ); + major.setLeaks( leaks ); + fprintf(stdout, "-----------------------------------------------\n"); + fprintf(stdout, " IntlTest (C++) Test Suite for \n"); + fprintf(stdout, " International Components for Unicode %s\n", U_ICU_VERSION); + fprintf(stdout, "-----------------------------------------------\n"); + fprintf(stdout, " Options: \n"); + fprintf(stdout, " all (a) : %s\n", (all? "On" : "Off")); + fprintf(stdout, " Verbose (v) : %s\n", (verbose? "On" : "Off")); + fprintf(stdout, " No error messages (n) : %s\n", (no_err_msg? "On" : "Off")); + fprintf(stdout, " Exhaustive (e) : %s\n", (!quick? "On" : "Off")); + fprintf(stdout, " Leaks (l) : %s\n", (leaks? "On" : "Off")); + fprintf(stdout, "-----------------------------------------------\n"); + + // initial check for the default converter + UErrorCode errorCode = U_ZERO_ERROR; + UConverter *cnv = ucnv_open(0, &errorCode); + if(cnv != 0) { + // ok + ucnv_close(cnv); + } else { + fprintf(stdout, + "*** Failure! The default converter [%s] cannot be opened.\n" + "*** Check the ICU_DATA environment variable and\n" + "*** check that the data files are present.\n", + ucnv_getDefaultName()); + return 1; + } + + // try more data + cnv = ucnv_open("iso-8859-7", &errorCode); + if(cnv != 0) { + // ok + ucnv_close(cnv); + } else { + fprintf(stdout, + "*** Failure! The converter for iso-8859-7 cannot be opened.\n" + "*** Check the ICU_DATA environment variable and \n" + "*** check that the data files are present.\n"); + return 1; + } + + UResourceBundle *rb = ures_open(0, "en", &errorCode); + if(U_SUCCESS(errorCode)) { + // ok + ures_close(rb); + } else { + fprintf(stdout, + "*** Failure! The \"en\" locale resource bundle cannot be opened.\n" + "*** Check the ICU_DATA environment variable and \n" + "*** check that the data files are present.\n"); + return 1; + } + + /* TODO: Add option to call u_cleanup and rerun tests. */ + if (all) { + major.runTest(); + if (leaks) { + major.run_phase2( NULL, NULL ); + } + }else{ + for (int i = 1; i < argc; ++i) { + if (argv[i][0] != '-') { + char* name = argv[i]; + fprintf(stdout, "\n=== Handling test: %s: ===\n", name); + char* parameter = strchr( name, '@' ); + if (parameter) { + *parameter = 0; + parameter += 1; + } + execCount = 0; + UBool res = major.runTest( name, parameter ); + if (leaks && res) { + major.run_phase2( name, parameter ); + } + if (!res || (execCount <= 0)) { + fprintf(stdout, "\n---ERROR: Test doesn't exist: %s!\n", name); + all_tests_exist = FALSE; + } + } + } + } + + CalendarTimeZoneTest::cleanup(); + delete _testDataPath; + _testDataPath = 0; + + fprintf(stdout, "\n--------------------------------------\n"); + if (major.getErrors() == 0) { + /* Call it twice to make sure that the defaults were reset. */ + /* Call it before the OK message to verify proper cleanup. */ + u_cleanup(); + u_cleanup(); + + fprintf(stdout, "OK: All tests passed without error.\n"); + }else{ + fprintf(stdout, "Errors in total: %ld.\n", (long)major.getErrors()); + major.printErrors(); + + /* Call afterwards to display errors. */ + u_cleanup(); + } + + fprintf(stdout, "--------------------------------------\n"); + + if (execCount <= 0) { + fprintf(stdout, "***** Not all called tests actually exist! *****\n"); + } + return major.getErrors(); +} +const char* IntlTest::loadTestData(UErrorCode& err){ const char* directory=NULL; UResourceBundle* test =NULL; - char tdpath[256]; + 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; - char tdpathFallback[256]; + if( _testDataPath == NULL){ + directory= u_getDataDirectory(); + + tdpath = new char[(( strlen(directory) * strlen(tdrelativepath)) + 10)];//(char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10)); - 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"); + /* 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 + */ + strcpy(tdpath, directory); + strcat(tdpath, tdrelativepath); + strcat(tdpath,"testdata"); + - strcat(tdpathFallback,".."U_FILE_SEP_STRING); - strcat(tdpathFallback, tdrelativepath); - strcat(tdpathFallback,"testdata"); + test=ures_open(tdpath, "testtypes", &err); - 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; + /* we could not find the data in tdpath + * try tdpathFallback + */ + if(U_FAILURE(err)) + { + strcpy(tdpath,directory); + strcat(tdpath,".."U_FILE_SEP_STRING); + 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 */ + if(U_FAILURE(err)){ + err = U_FILE_ACCESS_ERROR; + errln("construction of NULL did not succeed : %s \n", u_errorName(err)); + return ""; + } + ures_close(test); + _testDataPath = tdpath; + return _testDataPath; } ures_close(test); - strcpy(testdatapath,tdpathFallback); - return; + _testDataPath = tdpath; + return _testDataPath; } - ures_close(test); - strcpy(testdatapath,tdpath); + return _testDataPath; } /* * This is a variant of cintltst/ccolltst.c:CharsToUChars(). diff --git a/icu4c/source/test/intltest/intltest.h b/icu4c/source/test/intltest/intltest.h index df9dcaa9069..c60219fac68 100644 --- a/icu4c/source/test/intltest/intltest.h +++ b/icu4c/source/test/intltest/intltest.h @@ -144,16 +144,13 @@ protected: /* complete a relative path to a full pathname, and convert to platform-specific syntax. */ /* The character seperating directories for the relative path is '|'. */ static void pathnameInContext( char* fullname, int32_t maxsize, const char* relpath ); - /*The function to set the Test Directory*/ - static void setTestDirectory(const char* newDir); - /*The function to get the Test Directory*/ - static const char* getTestDirectory(void); + public: static void setICU_DATA(); // Set up ICU_DATA if necessary. public: UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks - void loadTestData(char* testdatapath,int32_t len,UErrorCode& err); + const char* loadTestData(UErrorCode& err); // static members public: diff --git a/icu4c/source/test/intltest/restest.cpp b/icu4c/source/test/intltest/restest.cpp index 673a0bba0c6..cac7ba7d624 100644 --- a/icu4c/source/test/intltest/restest.cpp +++ b/icu4c/source/test/intltest/restest.cpp @@ -255,10 +255,10 @@ ResourceBundleTest::TestConstruction() { { UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; + const char* testdatapath; Locale locale("te", "IN"); - loadTestData(testdatapath,256,err); + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -307,10 +307,10 @@ ResourceBundleTest::TestConstruction() } { UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; + const char* testdatapath; Locale locale("te", "IN"); - loadTestData(testdatapath,256,err); + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -365,8 +365,8 @@ ResourceBundleTest::testTag(const char* frag, // int32_t row,col; int32_t index; UErrorCode status = U_ZERO_ERROR; - char testdatapath[256]; - loadTestData(testdatapath,256,status); + const char* testdatapath; + testdatapath=loadTestData(status); if(U_FAILURE(status)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status))); diff --git a/icu4c/source/test/intltest/restsnew.cpp b/icu4c/source/test/intltest/restsnew.cpp index aa7d13ac7b3..981adcdbbb1 100644 --- a/icu4c/source/test/intltest/restsnew.cpp +++ b/icu4c/source/test/intltest/restsnew.cpp @@ -257,9 +257,9 @@ NewResourceBundleTest::TestConstruction() { { UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; + const char* testdatapath; Locale locale("te", "IN"); - loadTestData(testdatapath,256,err); + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -308,10 +308,10 @@ NewResourceBundleTest::TestConstruction() } { UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; + const char* testdatapath; Locale locale("te", "IN"); - loadTestData(testdatapath,256,err); + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -344,7 +344,7 @@ void NewResourceBundleTest::TestIteration() { UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; + const char* testdatapath; const char* data[]={ "string_in_Root_te_te_IN", "1", "array_in_Root_te_te_IN", "5", @@ -353,7 +353,7 @@ NewResourceBundleTest::TestIteration() Locale *locale=new Locale("te_IN"); - loadTestData(testdatapath,256,err); + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -456,8 +456,8 @@ NewResourceBundleTest::TestIteration() void NewResourceBundleTest::TestOtherAPI(){ UErrorCode err = U_ZERO_ERROR; - char testdatapath[256]; - loadTestData(testdatapath,256,err); + const char* testdatapath; + testdatapath=loadTestData(err); if(U_FAILURE(err)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); @@ -637,10 +637,10 @@ NewResourceBundleTest::testTag(const char* frag, int32_t i,j,row,col, actual_bundle; int32_t index; - char testdatapath[256]; + const char* testdatapath; UErrorCode status = U_ZERO_ERROR; - loadTestData(testdatapath,256,status); + testdatapath=loadTestData(status); if(U_FAILURE(status)) { errln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status))); diff --git a/icu4c/source/test/intltest/thcoll.cpp b/icu4c/source/test/intltest/thcoll.cpp index a0f36af84fc..545faed82eb 100644 --- a/icu4c/source/test/intltest/thcoll.cpp +++ b/icu4c/source/test/intltest/thcoll.cpp @@ -104,10 +104,19 @@ void CollationThaiTest::TestDictionary(void) { errln("Error: could not construct Thai collator"); return; } - + // Read in a dictionary of Thai words + UErrorCode status = U_ZERO_ERROR; char buffer[1024]; - uprv_strcpy(buffer, IntlTest::getTestDirectory()); + uprv_strcpy(buffer,IntlTest::loadTestData(status) ); + char* index = 0; + + index=strrchr(buffer,(char)U_FILE_SEP_CHAR); + + if((unsigned int)(index-buffer) != (strlen(buffer)-1)){ + *(index+1)=0; + } + uprv_strcat(buffer,".."U_FILE_SEP_STRING); uprv_strcat(buffer, TEST_FILE); FileStream *in = T_FileStream_open(buffer, "rb");