X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..e4f10fab0c078f399c9deef476d9c9b73b47dff8:/icuSources/test/intltest/intltest.cpp diff --git a/icuSources/test/intltest/intltest.cpp b/icuSources/test/intltest/intltest.cpp index 508368c7..6d08af15 100644 --- a/icuSources/test/intltest/intltest.cpp +++ b/icuSources/test/intltest/intltest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2010, International Business Machines Corporation and + * Copyright (c) 1997-2013, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -92,7 +92,7 @@ Int64ToUnicodeString(int64_t num) char buffer[64]; // nos changed from 10 to 64 char danger = 'p'; // guard against overrunning the buffer (rtg) -#ifdef U_WINDOWS +#if defined(_MSC_VER) sprintf(buffer, "%I64d", num); #else sprintf(buffer, "%lld", (long long)num); @@ -233,6 +233,14 @@ IntlTest::appendHex(uint32_t number, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0 }; /* "0123456789ABCDEF" */ + if (digits < 0) { // auto-digits + digits = 2; + uint32_t max = 0xff; + while (number > max) { + digits += 2; + max = (max << 8) | 0xff; + } + } switch (digits) { case 8: @@ -258,6 +266,13 @@ IntlTest::appendHex(uint32_t number, return target; } +UnicodeString +IntlTest::toHex(uint32_t number, int32_t digits) { + UnicodeString result; + appendHex(number, digits, result); + return result; +} + static inline UBool isPrintable(UChar32 c) { return c <= 0x7E && (c >= 0x20 || c == 9 || c == 0xA || c == 0xD); } @@ -508,6 +523,7 @@ IntlTest::IntlTest() errorCount = 0; dataErrorCount = 0; verbose = FALSE; + no_time = FALSE; no_err_msg = FALSE; warn_on_missing_data = FALSE; quick = FALSE; @@ -558,6 +574,13 @@ UBool IntlTest::setVerbose( UBool verboseVal ) return rval; } +UBool IntlTest::setNotime( UBool no_time ) +{ + UBool rval = this->no_time; + this->no_time = no_time; + return rval; +} + UBool IntlTest::setWarnOnMissingData( UBool warn_on_missing_dataVal ) { UBool rval = this->warn_on_missing_data; @@ -645,7 +668,7 @@ UBool IntlTest::runTest( char* name, char* par, char *baseName ) } // call individual tests, to be overriden to call implementations -void IntlTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) +void IntlTest::runIndexedTest( int32_t /*index*/, UBool /*exec*/, const char* & /*name*/, char* /*par*/ ) { // to be overriden by a method like: /* @@ -656,7 +679,6 @@ void IntlTest::runIndexedTest( int32_t index, UBool exec, const char* &name, cha } */ this->errln("*** runIndexedTest needs to be overriden! ***"); - name = ""; exec = exec; index = index; par = par; } @@ -710,7 +732,11 @@ UBool IntlTest::runTestLoop( char* testname, char* par, char *baseName ) UDate timeStop = uprv_getRawUTCtime(); rval = TRUE; // at least one test has been called char secs[256]; - sprintf(secs, "%f", (timeStop-timeStart)/1000.0); + if(!no_time) { + sprintf(secs, "%f", (timeStop-timeStart)/1000.0); + } else { + secs[0]=0; + } strcpy(saveBaseLoc,name); @@ -723,11 +749,11 @@ UBool IntlTest::runTestLoop( char* testname, char* par, char *baseName ) if (lastErrorCount == errorCount) { sprintf( msg, " } OK: %s ", name ); - str_timeDelta(msg+strlen(msg),timeStop-timeStart); + if(!no_time) str_timeDelta(msg+strlen(msg),timeStop-timeStart); lastTestFailed = FALSE; }else{ sprintf(msg, " } ERRORS (%li) in %s", (long)(errorCount-lastErrorCount), name); - str_timeDelta(msg+strlen(msg),timeStop-timeStart); + if(!no_time) str_timeDelta(msg+strlen(msg),timeStop-timeStart); for(int i=0;i=argc) { printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n"); @@ -1151,6 +1181,7 @@ main(int argc, char* argv[]) "### \n" "### Options are: verbose (v), all (a), noerrormsg (n), \n" "### exhaustive (e), leaks (l), -x xmlfile.xml, prop:=, \n" + "### notime (T), \n" "### threads: (Mulithreading must first be \n" "### enabled otherwise this will be ignored. \n" "### The default thread count is 1.),\n" @@ -1181,6 +1212,7 @@ main(int argc, char* argv[]) major.setLeaks( leaks ); major.setThreadCount( threadCount ); major.setWarnOnMissingData( warnOnMissingData ); + major.setNotime (no_time); for (int32_t i = 0; i < nProps; i++) { major.setProperty(props[i]); } @@ -1212,6 +1244,7 @@ main(int argc, char* argv[]) 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, " notime (T) : %s\n", (no_time? "On" : "Off")); fprintf(stdout, " Warn on missing data (w) : %s\n", (warnOnMissingData? "On" : "Off")); #if (ICU_USE_THREADS==0) fprintf(stdout, " Threads : Disabled\n"); @@ -1394,13 +1427,15 @@ main(int argc, char* argv[]) if (execCount <= 0) { fprintf(stdout, "***** Not all called tests actually exist! *****\n"); } - endTime = uprv_getRawUTCtime(); - diffTime = (int32_t)(endTime - startTime); - printf("Elapsed Time: %02d:%02d:%02d.%03d\n", - (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR), - (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), - (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND), - (int)(diffTime%U_MILLIS_PER_SECOND)); + if(!no_time) { + endTime = uprv_getRawUTCtime(); + diffTime = (int32_t)(endTime - startTime); + printf("Elapsed Time: %02d:%02d:%02d.%03d\n", + (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR), + (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), + (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND), + (int)(diffTime%U_MILLIS_PER_SECOND)); + } if(ctest_xml_fini()) return 1; @@ -1416,10 +1451,10 @@ const char* IntlTest::loadTestData(UErrorCode& err){ const char* tdrelativepath; #if defined (U_TOPBUILDDIR) - tdrelativepath = "test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; + tdrelativepath = "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; directory = U_TOPBUILDDIR; #else - tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING; + tdrelativepath = ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING; directory = pathToDataDirectory(); #endif @@ -1455,17 +1490,17 @@ const char* IntlTest::getTestDataPath(UErrorCode& err) { 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; + 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; - FILE *f = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"rbbitst.txt", "r"); + srcDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING; + FILE *f = fopen(".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING "rbbitst.txt", "r"); if (f) { /* We're in icu/source/test/intltest/ */ fclose(f); } else { /* We're in icu/source/test/intltest/Platform/(Debug|Release) */ - srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING; + srcDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata"U_FILE_SEP_STRING; } #endif return srcDataDir; @@ -1523,13 +1558,13 @@ const char * IntlTest::pathToDataDirectory() } else { /* __FILE__ on MSVC7 does not contain the directory */ - FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r"); + FILE *file = fopen(".." U_FILE_SEP_STRING ".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r"); if (file) { fclose(file); - fgDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; + fgDataDir = ".." U_FILE_SEP_STRING ".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; } else { - fgDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; + fgDataDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING; } } } @@ -1619,15 +1654,28 @@ static UnicodeString& escape(const UnicodeString& s, UnicodeString& result) { #define VERBOSE_ASSERTIONS -UBool IntlTest::assertTrue(const char* message, UBool condition, UBool quiet, UBool possibleDataError) { - if (!condition) { - if (possibleDataError) { - dataerrln("FAIL: assertTrue() failed: %s", message); - } else { - errln("FAIL: assertTrue() failed: %s", message); +UBool IntlTest::assertTrue(const char* message, UBool condition, UBool quiet, UBool possibleDataError, const char *file, int line) { + if (file != NULL) { + if (!condition) { + if (possibleDataError) { + dataerrln("%s:%d: FAIL: assertTrue() failed: %s", file, line, message); + } else { + errln("%s:%d: FAIL: assertTrue() failed: %s", file, line, message); + } + } else if (!quiet) { + logln("%s:%d: Ok: %s", file, line, message); } - } else if (!quiet) { - logln("Ok: %s", message); + } else { + if (!condition) { + if (possibleDataError) { + dataerrln("FAIL: assertTrue() failed: %s", message); + } else { + errln("FAIL: assertTrue() failed: %s", message); + } + } else if (!quiet) { + logln("Ok: %s", message); + } + } return condition; } @@ -1695,6 +1743,23 @@ UBool IntlTest::assertEquals(const char* message, return TRUE; } +UBool IntlTest::assertEquals(const char* message, + int32_t expected, + int32_t actual) { + if (expected != actual) { + errln((UnicodeString)"FAIL: " + message + "; got " + + actual + "=0x" + toHex(actual) + + "; expected " + expected + "=0x" + toHex(expected)); + return FALSE; + } +#ifdef VERBOSE_ASSERTIONS + else { + logln((UnicodeString)"Ok: " + message + "; got " + actual + "=0x" + toHex(actual)); + } +#endif + return TRUE; +} + #if !UCONFIG_NO_FORMATTING UBool IntlTest::assertEquals(const char* message, const Formattable& expected, @@ -1752,10 +1817,11 @@ UBool IntlTest::assertEquals(const UnicodeString& message, // release //-------------------------------------------------------------------- -UBool IntlTest::isICUVersionAtLeast(const UVersionInfo x) { - UVersionInfo v; - u_getVersion(v); - return (uprv_memcmp(v, x, U_MAX_VERSION_LENGTH) >= 0); +UBool IntlTest::isICUVersionBefore(int major, int minor, int milli) { + UVersionInfo iv; + UVersionInfo ov = { (uint8_t)major, (uint8_t)minor, (uint8_t)milli, 0 }; + u_getVersion(iv); + return uprv_memcmp(iv, ov, U_MAX_VERSION_LENGTH) < 0; } #if !UCONFIG_NO_FORMATTING