]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/iotest/iotest.cpp
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / test / iotest / iotest.cpp
index 407e2014c560ff38713abdc7a20eff256dd45e15..6bc549ad4dae2f87ed6babd634a85f9cfcdced1a 100644 (file)
@@ -1,10 +1,12 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
-*   Copyright (C) 2002-2010, International Business Machines
+*   Copyright (C) 2002-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   file name:  iotest.cpp
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -20,6 +22,7 @@
 #include "unicode/uchar.h"
 #include "unicode/unistr.h"
 #include "unicode/ustring.h"
+#include "cmemory.h"
 #include "ustr_cnv.h"
 #include "iotest.h"
 #include "unicode/tstdtmod.h"
@@ -109,13 +112,13 @@ public:
             }
             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;
                 }
             }
         }
@@ -133,10 +136,10 @@ public:
             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
 
@@ -171,6 +174,7 @@ public:
 const char* DataDrivenLogger::fgDataDir = NULL;
 char* DataDrivenLogger::fgTestDataPath = NULL;
 
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO
 static int64_t
 uto64(const UChar     *buffer)
 {
@@ -187,7 +191,7 @@ uto64(const UChar     *buffer)
     }
     return result;
 }
-
+#endif
 
 U_CDECL_BEGIN
 static void U_CALLCONV DataDrivenPrintf(void)
@@ -236,14 +240,14 @@ static void U_CALLCONV DataDrivenPrintf(void)
                             STANDARD_TEST_FILE);
                     continue;
                 }
-                u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
-                uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
+                u_memset(uBuffer, 0x2A, UPRV_LENGTHOF(uBuffer));
+                uBuffer[UPRV_LENGTHOF(uBuffer)-1] = 0;
                 tempStr=testCase->getString("format", errorCode);
-                tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
+                tempStr.extract(format, UPRV_LENGTHOF(format), errorCode);
                 tempStr=testCase->getString("result", errorCode);
-                tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
+                tempStr.extract(expectedResult, UPRV_LENGTHOF(expectedResult), errorCode);
                 tempStr=testCase->getString("argument", errorCode);
-                tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
+                tempStr.extract(argument, UPRV_LENGTHOF(argument), errorCode);
                 u_austrncpy(cBuffer, format, sizeof(cBuffer));
                 if(U_FAILURE(errorCode)) {
                     log_err("error retrieving icuio/printf test case %d - %s\n",
@@ -320,7 +324,7 @@ static void U_CALLCONV DataDrivenPrintf(void)
                             STANDARD_TEST_FILE);
                 }
                 uBuffer[0]=0;
-                u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile.getAlias());
+                u_fgets(uBuffer, UPRV_LENGTHOF(uBuffer), testFile.getAlias());
                 if (u_strcmp(uBuffer, expectedResult) != 0) {
                     u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
                     u_austrncpy(cFormat, format, sizeof(cFormat));
@@ -401,14 +405,14 @@ static void U_CALLCONV DataDrivenScanf(void)
                     log_err("Can't open test file - %s\n",
                             STANDARD_TEST_FILE);
                 }*/
-                u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
-                uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
+                u_memset(uBuffer, 0x2A, UPRV_LENGTHOF(uBuffer));
+                uBuffer[UPRV_LENGTHOF(uBuffer)-1] = 0;
                 tempStr=testCase->getString("format", errorCode);
-                tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
+                tempStr.extract(format, UPRV_LENGTHOF(format), errorCode);
                 tempStr=testCase->getString("result", errorCode);
-                tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
+                tempStr.extract(expectedResult, UPRV_LENGTHOF(expectedResult), errorCode);
                 tempStr=testCase->getString("argument", errorCode);
-                tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
+                tempStr.extract(argument, UPRV_LENGTHOF(argument), errorCode);
                 u_austrncpy(cBuffer, format, sizeof(cBuffer));
                 if(U_FAILURE(errorCode)) {
                     log_err("error retrieving icuio/printf test case %d - %s\n",
@@ -521,7 +525,7 @@ static void U_CALLCONV DataDrivenScanf(void)
                             STANDARD_TEST_FILE);
                 }
                 uBuffer[0];
-                u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile);
+                u_fgets(uBuffer, UPRV_LENGTHOF(uBuffer), testFile);
                 if (u_strcmp(uBuffer, expectedResult) != 0) {
                     u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
                     u_austrncpy(cFormat, format, sizeof(cFormat));
@@ -595,14 +599,14 @@ static void U_CALLCONV DataDrivenPrintfPrecision(void)
                     errorCode=U_ZERO_ERROR;
                     continue;
                 }
-                u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
-                uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
+                u_memset(uBuffer, 0x2A, UPRV_LENGTHOF(uBuffer));
+                uBuffer[UPRV_LENGTHOF(uBuffer)-1] = 0;
                 tempStr=testCase->getString("format", errorCode);
-                tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
+                tempStr.extract(format, UPRV_LENGTHOF(format), errorCode);
                 tempStr=testCase->getString("result", errorCode);
-                tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
+                tempStr.extract(expectedResult, UPRV_LENGTHOF(expectedResult), errorCode);
                 tempStr=testCase->getString("argument", errorCode);
-                tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
+                tempStr.extract(argument, UPRV_LENGTHOF(argument), errorCode);
                 precision=testCase->getInt28("precision", errorCode);
                 u_austrncpy(cBuffer, format, sizeof(cBuffer));
                 if(U_FAILURE(errorCode)) {
@@ -694,9 +698,7 @@ static void addAllTests(TestNode** root) {
     addTest(root, &DataDrivenPrintfPrecision, "datadriv/DataDrivenPrintfPrecision");
     addTest(root, &DataDrivenScanf, "datadriv/DataDrivenScanf");
 #endif
-#if U_IOSTREAM_SOURCE
     addStreamTests(root);
-#endif
 }
 
 /* returns the path to icu/source/data/out */
@@ -718,7 +720,7 @@ static const char *ctest_dataOutDir()
     */
 #if defined (U_TOPBUILDDIR)
     {
-        dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
+        dataOutDir = U_TOPBUILDDIR "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
     }
 #else
 
@@ -750,13 +752,13 @@ static const char *ctest_dataOutDir()
         }
         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);
-                dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
+                dataOutDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
             }
             else {
-                dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
+                dataOutDir = ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
             }
         }
     }