From: Steven R. Loomis Date: Wed, 4 Sep 2013 22:36:52 +0000 (+0000) Subject: ICU-10331 move platform dependency out of udatatst.c , other fixes for msys/mingw X-Git-Tag: milestone-59-0-1~2617 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a537be4363f82d102b838923a6d7e998562ef40;p=icu ICU-10331 move platform dependency out of udatatst.c , other fixes for msys/mingw X-SVN-Rev: 34192 --- diff --git a/icu4c/source/test/cintltst/cnumtst.c b/icu4c/source/test/cintltst/cnumtst.c index 37b5bf601e5..1398dc97632 100644 --- a/icu4c/source/test/cintltst/cnumtst.c +++ b/icu4c/source/test/cintltst/cnumtst.c @@ -2228,10 +2228,10 @@ static void TestUFormattable(void) { u_uastrcpy(buffer, pattern); unum_parseToUFormattable(unum, ufmt, buffer, -1, NULL, &status); if(assertSuccess("unum_parseToUFormattable[3.14159]", &status)) { - assertTrue("ufmt_getDouble()=3.14159", ufmt_getDouble(ufmt, &status) == 3.14159); + assertTrue("ufmt_getDouble()==3.14159", withinErr(ufmt_getDouble(ufmt, &status), 3.14159, 1e-15)); + assertSuccess("ufmt_getDouble()", &status); assertTrue("ufmt_getType()=UFMT_DOUBLE", ufmt_getType(ufmt, &status) == UFMT_DOUBLE); log_verbose("double = %g\n", ufmt_getDouble(ufmt, &status)); - assertSuccess("ufmt_getDouble()", &status); } unum_formatUFormattable(unum, ufmt, out2k, 2048, NULL, &status); if(assertSuccess("unum_formatUFormattable(3.14159)", &status)) { diff --git a/icu4c/source/test/cintltst/udatatst.c b/icu4c/source/test/cintltst/udatatst.c index cf41dd9f086..09aef10030a 100644 --- a/icu4c/source/test/cintltst/udatatst.c +++ b/icu4c/source/test/cintltst/udatatst.c @@ -27,19 +27,10 @@ #include "udatamem.h" #include "cintltst.h" #include "ubrkimpl.h" - -#include -#include -#include +#include "toolutil.h" /* for uprv_fileExists() */ #include #include -#if U_PLATFORM_USES_ONLY_WIN32_API -#include -#else -#include -#endif - /* includes for TestSwapData() */ #include "udataswp.h" @@ -136,10 +127,9 @@ static void TestUDataOpen(){ char* path=(char*)malloc(sizeof(char) * (strlen(ctest_dataOutDir()) + strlen(U_ICUDATA_NAME) - + strlen("/build")+1 ) ); + + strlen("/build/tmp/..")+1 ) ); char *icuDataFilePath = 0; - struct stat stat_buf; const char* testPath=loadTestData(&status); if(U_FAILURE(status)) { @@ -149,10 +139,7 @@ static void TestUDataOpen(){ } /* lots_of_mallocs(); */ - - strcat(strcpy(path, ctest_dataOutDir()), U_ICUDATA_NAME); - - log_verbose("Testing udata_open()\n"); + log_verbose("Testing udata_open(%s)\n", testPath); result=udata_open(testPath, type, name, &status); if(U_FAILURE(status)){ log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", testPath, name, type, myErrorName(status)); @@ -161,37 +148,81 @@ static void TestUDataOpen(){ udata_close(result); } - /* If the ICU system common data file is present in this confiugration, - * verify that udata_open can explicitly fetch items from it. - * If packaging mode == dll, the file may not exist. So, if the file is - * missing, skip this test without error. - */ - icuDataFilePath = (char *)malloc(strlen(path) + 10); - strcpy(icuDataFilePath, path); - strcat(icuDataFilePath, ".dat"); - /* lots_of_mallocs(); */ - if (stat(icuDataFilePath, &stat_buf) == 0) { - int i; - log_verbose("Testing udata_open() on %s\n", icuDataFilePath); - for(i=0; i #include "putilimp.h" -UDate startTime = -1.0; +UDate startTime; static int elapsedTime() { return (int)uprv_floor((uprv_getRawUTCtime()-startTime)/1000.0); } #if U_PLATFORM_IMPLEMENTS_POSIX && !U_PLATFORM_HAS_WIN32_API + #include #include @@ -64,9 +65,6 @@ static void install_watchdog(const char *toolName, const char *outFileName) { wToolname=toolName; wOutname=outFileName; - if(startTime<0) { // uninitialized - startTime = uprv_getRawUTCtime(); - } signal(SIGALRM, &alarm_fn); alarm(firstSeconds); // set the alarm @@ -301,6 +299,7 @@ int main(int argc, char **argv) { const char *outFileName = argv[2]; const char *wordFileName = argv[1]; + startTime = uprv_getRawUTCtime(); // initialize start timer // set up the watchdog install_watchdog(progName, outFileName); diff --git a/icu4c/source/tools/toolutil/toolutil.cpp b/icu4c/source/tools/toolutil/toolutil.cpp index 48f34a0eaea..038f21b52ae 100644 --- a/icu4c/source/tools/toolutil/toolutil.cpp +++ b/icu4c/source/tools/toolutil/toolutil.cpp @@ -201,6 +201,18 @@ uprv_mkdir(const char *pathname, UErrorCode *status) { } } +#if !UCONFIG_NO_FILE_IO +U_CAPI UBool U_EXPORT2 +uprv_fileExists(const char *file) { + struct stat stat_buf; + if (stat(file, &stat_buf) == 0) { + return TRUE; + } else { + return FALSE; + } +} +#endif + /*U_CAPI UDate U_EXPORT2 uprv_getModificationDate(const char *pathname, UErrorCode *status) { diff --git a/icu4c/source/tools/toolutil/toolutil.h b/icu4c/source/tools/toolutil/toolutil.h index 7b93211c2b9..297c83b3f43 100644 --- a/icu4c/source/tools/toolutil/toolutil.h +++ b/icu4c/source/tools/toolutil/toolutil.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2011, International Business Machines +* Copyright (C) 1999-2013, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -108,6 +108,16 @@ getCurrentYear(void); U_CAPI void U_EXPORT2 uprv_mkdir(const char *pathname, UErrorCode *status); +#if !UCONFIG_NO_FILE_IO +/** + * Return TRUE if the named item exists + * @param file filename + * @return TRUE if named item (file, dir, etc) exists, FALSE otherwise + */ +U_CAPI UBool U_EXPORT2 +uprv_fileExists(const char *file); +#endif + /** * Return the modification date for the specified file or directory. * Return value is undefined if there was an error.