]> granicus.if.org Git - icu/commitdiff
ICU-10331 move platform dependency out of udatatst.c , other fixes for msys/mingw
authorSteven R. Loomis <srl@icu-project.org>
Wed, 4 Sep 2013 22:36:52 +0000 (22:36 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 4 Sep 2013 22:36:52 +0000 (22:36 +0000)
X-SVN-Rev: 34192

icu4c/source/test/cintltst/cnumtst.c
icu4c/source/test/cintltst/udatatst.c
icu4c/source/tools/gendict/gendict.cpp
icu4c/source/tools/toolutil/toolutil.cpp
icu4c/source/tools/toolutil/toolutil.h

index 37b5bf601e5efa504a048dc5bb969d2147422677..1398dc976328de3d2fcb6436d832be24aba3d077 100644 (file)
@@ -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)) {
index cf41dd9f08623cad802faeba2e686deb49d73409..09aef10030a5aadcb09cd4a38981528c5d732696 100644 (file)
 #include "udatamem.h"
 #include "cintltst.h"
 #include "ubrkimpl.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include "toolutil.h" /* for uprv_fileExists() */
 #include <stdlib.h>
 #include <stdio.h>
 
-#if U_PLATFORM_USES_ONLY_WIN32_API
-#include <io.h>
-#else
-#include <unistd.h>
-#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<sizeof(memMap)/sizeof(memMap[0]); i++){
+      strcat(strcpy(path, ctest_dataOutDir()), U_ICUDATA_NAME);
+
+      /* 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 (uprv_fileExists(icuDataFilePath))
+       {
+         int i;
+         log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
+         for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
             /* lots_of_mallocs(); */
             status=U_ZERO_ERROR;
             result=udata_open(path, memMap[i][1], memMap[i][0], &status);
             if(U_FAILURE(status)) {
-                log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
+             log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
             } else {
-                log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
-                udata_close(result);
+             log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
+             udata_close(result);
             }
-        }
-    }
-    else
+         }
+       }
+      else
+       {
+         /* lots_of_mallocs(); */
+         log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
+                     icuDataFilePath);
+       }
+    }
+    /* try again, adding /tmp */
     {
-    /* lots_of_mallocs(); */
-         log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
-             icuDataFilePath);
+      strcpy(path, ctest_dataOutDir());
+      strcat(path, "tmp");
+      strcat(path, dirSepString);
+      strcat(path, U_ICUDATA_NAME);
+
+      /* 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 (uprv_fileExists(icuDataFilePath))
+       {
+         int i;
+         log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
+         for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
+            /* lots_of_mallocs(); */
+            status=U_ZERO_ERROR;
+            result=udata_open(path, memMap[i][1], memMap[i][0], &status);
+            if(U_FAILURE(status)) {
+             log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
+            } else {
+             log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
+             udata_close(result);
+            }
+         }
+       }
+      else
+       {
+         /* lots_of_mallocs(); */
+         log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
+                     icuDataFilePath);
+       }
     }
+
     free(icuDataFilePath);
     icuDataFilePath = NULL;
     /* lots_of_mallocs(); */
@@ -210,11 +241,11 @@ static void TestUDataOpen(){
     strcat(icuDataFilePath, "build");
     strcat(icuDataFilePath, dirSepString);
     strcat(icuDataFilePath, U_ICUDATA_NAME);
-    strcat(icuDataFilePath, "_");
+    strcat(icuDataFilePath, dirSepString);
     strcat(icuDataFilePath, "cnvalias.icu");
 
     /* lots_of_mallocs(); */
-    if (stat(icuDataFilePath, &stat_buf) == 0)
+    if (uprv_fileExists(icuDataFilePath))
     {
         int i;
         log_verbose("%s exists, so..\n", icuDataFilePath);
index 81affcd9c0f1f8ce4983830d4d2f47d320ce68e3..c3566255db1a6ef4f3c3fecd0990bf07774bdaa7 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 2002-2012, International Business Machines
+*   Copyright (C) 2002-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *
 #include <string.h>
 
 #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 <signal.h>
 #include <unistd.h>
 
@@ -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);
 
index 48f34a0eaea2447bfb41923329253543ad982cbd..038f21b52ae9b84c5ecfed6ae1762b761453ba62 100644 (file)
@@ -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)
 {
index 7b93211c2b9d9f0327e579104e8e576e890b952f..297c83b3f43a004e8ceec1a14cf55cad674e064b 100644 (file)
@@ -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.