]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/iotest/iotest.cpp
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / test / iotest / iotest.cpp
index 320aca2a3cd11db83bf27d57d463da70a06a5300..204e59812639372070fd76fb4d8ec117c0723bcd 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 2002-2004, International Business Machines
+*   Copyright (C) 2002-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   file name:  iotest.cpp
 
 
 #include "unicode/ustdio.h"
-#include "unicode/ustream.h"
 #include "unicode/uclean.h"
 
 #include "unicode/ucnv.h"
 #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"
-
-#if U_IOSTREAM_SOURCE >= 199711
-#include <iostream>
-#ifdef U_LINUX
-#define USE_SSTREAM 1
-#include <sstream>
-#else
-// <strstream> is deprecated on some platforms, and the compiler complains very loudly if you use it.
-#include <strstream>
-#endif
-using namespace std;
-#elif U_IOSTREAM_SOURCE >= 198506
-#include <iostream.h>
-#include <strstream.h>
-#endif
+#include "putilimp.h"
 
 #include <string.h>
 #include <stdlib.h>
 
-U_CDECL_BEGIN
-#ifdef WIN32
-const UChar NEW_LINE[] = {0x0d,0x0a,0};
-const char C_NEW_LINE[] = {0x0d,0x0a,0};
-#define UTF8_NEW_LINE "\x0d\x0a"
-#else
-const UChar NEW_LINE[] = {0x0a,0};
-const char C_NEW_LINE[] = {'\n',0};
-#define UTF8_NEW_LINE "\x0a"
-#endif
-U_CDECL_END
-
 class DataDrivenLogger : public TestLog {
     static const char* fgDataDir;
     static char *fgTestDataPath;
@@ -73,6 +47,20 @@ public:
         log_err(buffer);
     }
 
+    virtual void logln( const UnicodeString &message ) {
+        char buffer[4000];
+        message.extract(0, message.length(), buffer, sizeof(buffer));
+        buffer[3999] = 0; /* NULL terminate */
+        log_info(buffer);
+    }
+
+    virtual void dataerrln( const UnicodeString &message ) {
+        char buffer[4000];
+        message.extract(0, message.length(), buffer, sizeof(buffer));
+        buffer[3999] = 0; /* NULL terminate */
+        log_data_err(buffer);
+    }
+
     static const char * pathToDataDirectory(void)
     {
 
@@ -122,13 +110,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 "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;
                 }
             }
         }
@@ -146,10 +134,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
 
@@ -167,7 +155,7 @@ public:
 
             if(U_FAILURE(err)){
                 err = U_FILE_ACCESS_ERROR;
-                log_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(err));
+                log_data_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(err));
                 return "";
             }
             ures_close(test);
@@ -184,6 +172,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)
 {
@@ -200,12 +189,12 @@ uto64(const UChar     *buffer)
     }
     return result;
 }
-
+#endif
 
 U_CDECL_BEGIN
 static void U_CALLCONV DataDrivenPrintf(void)
 {
-#if !UCONFIG_NO_FORMATTING
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO
     UErrorCode errorCode;
     TestDataModule *dataModule;
     TestData *testData;
@@ -229,7 +218,7 @@ static void U_CALLCONV DataDrivenPrintf(void)
 
     const char *fileLocale = "en_US_POSIX";
     int32_t uFileBufferLenReturned;
-    UFILE *testFile;
+    LocalUFILEPointer testFile;
 
     errorCode=U_ZERO_ERROR;
     dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
@@ -243,20 +232,20 @@ static void U_CALLCONV DataDrivenPrintf(void)
                     errorCode=U_ZERO_ERROR;
                     continue;
                 }
-                testFile = u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8");
-                if (!testFile) {
+                testFile.adoptInstead(u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8"));
+                if (testFile.isNull()) {
                     log_err("Can't open test file - %s\n",
                             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",
@@ -269,36 +258,36 @@ static void U_CALLCONV DataDrivenPrintf(void)
                 case 0x64:  // 'd' double
                     dbl = atof(u_austrcpy(cBuffer, argument));
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, dbl);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, dbl);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, dbl);
                     break;
                 case 0x31:  // '1' int8_t
                     i8 = (int8_t)uto64(argument);
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, i8);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, i8);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, i8);
                     break;
                 case 0x32:  // '2' int16_t
                     i16 = (int16_t)uto64(argument);
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, i16);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, i16);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, i16);
                     break;
                 case 0x34:  // '4' int32_t
                     i32 = (int32_t)uto64(argument);
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, i32);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, i32);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, i32);
                     break;
                 case 0x38:  // '8' int64_t
                     i64 = uto64(argument);
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, i64);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, i64);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, i64);
                     break;
                 case 0x73:  // 's' char *
-                    u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
+                    u_austrncpy(cBuffer, argument, sizeof(cBuffer));
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, cBuffer);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, cBuffer);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, cBuffer);
                     break;
                 case 0x53:  // 'S' UChar *
                     uBufferLenReturned = u_sprintf_u(uBuffer, format, argument);
-                    uFileBufferLenReturned = u_fprintf_u(testFile, format, argument);
+                    uFileBufferLenReturned = u_fprintf_u(testFile.getAlias(), format, argument);
                     break;
                 default:
                     uBufferLenReturned = 0;
@@ -313,7 +302,11 @@ static void U_CALLCONV DataDrivenPrintf(void)
                     log_err("FAILURE string test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
                             i, cFormat, cBuffer, cExpected);
                 }
-                if (uBuffer[uBufferLenReturned-1] == 0
+                if (uBufferLenReturned <= 0) {
+                    log_err("FAILURE test case %d - \"%s\" is an empty string.\n",
+                            i, cBuffer);
+                }
+                else if (uBuffer[uBufferLenReturned-1] == 0
                     || uBuffer[uBufferLenReturned] != 0
                     || uBuffer[uBufferLenReturned+1] != 0x2A
                     || uBuffer[uBufferLenReturned+2] != 0x2A)
@@ -323,14 +316,13 @@ static void U_CALLCONV DataDrivenPrintf(void)
                     log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n",
                             i, cBuffer, uBufferLenReturned);
                 }
-                u_fclose(testFile);
-                testFile = u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8");
-                if (!testFile) {
+                testFile.adoptInstead(u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8"));
+                if (testFile.isNull()) {
                     log_err("Can't open test file - %s\n",
                             STANDARD_TEST_FILE);
                 }
                 uBuffer[0]=0;
-                u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile);
+                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));
@@ -353,14 +345,13 @@ static void U_CALLCONV DataDrivenPrintf(void)
                     errorCode=U_ZERO_ERROR;
                     continue;
                 }
-                u_fclose(testFile);
             }
             delete testData;
         }
         delete dataModule;
     }
     else {
-        log_err("Failed: could not load test icuio data\n");
+        log_data_err("Failed: could not load test icuio data\n");
     }
 #endif
 }
@@ -369,7 +360,7 @@ U_CDECL_END
 U_CDECL_BEGIN
 static void U_CALLCONV DataDrivenScanf(void)
 {
-#if !UCONFIG_NO_FORMATTING
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO
     UErrorCode errorCode;
     TestDataModule *dataModule;
     TestData *testData;
@@ -388,6 +379,7 @@ static void U_CALLCONV DataDrivenScanf(void)
     int32_t i32, expected32;
     int64_t i64, expected64;
     double dbl, expectedDbl;
+    volatile float flt, expectedFlt; // Use volatile in order to get around an Intel compiler issue.
     int32_t uBufferLenReturned;
 
     //const char *fileLocale = "en_US_POSIX";
@@ -411,14 +403,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",
@@ -437,6 +429,15 @@ static void U_CALLCONV DataDrivenScanf(void)
                                 i, dbl, expectedDbl);
                     }
                     break;
+                case 0x66:  // 'f' float
+                    expectedFlt = (float)atof(u_austrcpy(cBuffer, expectedResult));
+                    uBufferLenReturned = u_sscanf_u(argument, format, &flt);
+                    //uFileBufferLenReturned = u_fscanf_u(testFile, format, flt);
+                    if (flt != expectedFlt) {
+                        log_err("error in scanf test case[%d] Got: %f Exp: %f\n",
+                                i, flt, expectedFlt);
+                    }
+                    break;
                 case 0x31:  // '1' int8_t
                     expected8 = (int8_t)uto64(expectedResult);
                     uBufferLenReturned = u_sscanf_u(argument, format, &i8);
@@ -522,7 +523,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));
@@ -552,7 +553,7 @@ static void U_CALLCONV DataDrivenScanf(void)
         delete dataModule;
     }
     else {
-        log_err("Failed: could not load test icuio data\n");
+        log_data_err("Failed: could not load test icuio data\n");
     }
 #endif
 }
@@ -561,7 +562,7 @@ U_CDECL_END
 U_CDECL_BEGIN
 static void U_CALLCONV DataDrivenPrintfPrecision(void)
 {
-#if !UCONFIG_NO_FORMATTING
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO
     UErrorCode errorCode;
     TestDataModule *dataModule;
     TestData *testData;
@@ -596,14 +597,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)) {
@@ -653,7 +654,11 @@ static void U_CALLCONV DataDrivenPrintfPrecision(void)
                     log_err("FAILURE test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
                             i, cFormat, cBuffer, cExpected);
                 }
-                if (uBuffer[uBufferLenReturned-1] == 0
+                if (uBufferLenReturned <= 0) {
+                    log_err("FAILURE test case %d - \"%s\" is an empty string.\n",
+                            i, cBuffer);
+                }
+                else if (uBuffer[uBufferLenReturned-1] == 0
                     || uBuffer[uBufferLenReturned] != 0
                     || uBuffer[uBufferLenReturned+1] != 0x2A
                     || uBuffer[uBufferLenReturned+2] != 0x2A)
@@ -675,89 +680,8 @@ static void U_CALLCONV DataDrivenPrintfPrecision(void)
         delete dataModule;
     }
     else {
-        log_err("Failed: could not load test icuio data\n");
-    }
-#endif
-}
-U_CDECL_END
-
-U_CDECL_BEGIN
-static void U_CALLCONV TestStream(void)
-{
-#if U_IOSTREAM_SOURCE >= 198506
-    const UChar thisMu[] = { 0x74, 0x48, 0x69, 0x73, 0x3BC, 0};
-    const UChar mu[] = { 0x6D, 0x75, 0};
-    UnicodeString str1 = UNICODE_STRING_SIMPLE("str1");
-    UnicodeString str2 = UNICODE_STRING_SIMPLE(" <<");
-    UnicodeString str3 = UNICODE_STRING_SIMPLE("2");
-    UnicodeString str4 = UNICODE_STRING_SIMPLE(" UTF-8 ");
-    UnicodeString inStr = UNICODE_STRING_SIMPLE(" UTF-8 ");
-    UnicodeString inStr2;
-    char defConvName[UCNV_MAX_CONVERTER_NAME_LENGTH*2];
-    char inStrC[128];
-    UErrorCode status = U_ZERO_ERROR;
-    UConverter *defConv;
-    static const char testStr[] = "\x42\x65\x67\x69\x6E\x6E\x69\x6E\x67\x20\x6F\x66\x20\x74\x65\x73\x74\x20\x73\x74\x72\x31\x20\x20\x20\x3C\x3C\x32\x31\x20" UTF8_NEW_LINE "\x20\x55\x54\x46\x2D\x38\x20\xCE\xBC\xF0\x90\x80\x81\xF0\x90\x80\x82";
-
-    str4.append((UChar32)0x03BC);   /* mu */
-    str4.append((UChar32)0x10001);
-    str4.append((UChar32)0x10002);
-
-    /* release the default converter and use utf-8 for a bit */
-    defConv = u_getDefaultConverter(&status);
-    if (U_FAILURE(status)) {
-        log_err("Can't get default converter\n");
-        return;
-    }
-    ucnv_close(defConv);
-    strncpy(defConvName, ucnv_getDefaultName(), sizeof(defConvName)/sizeof(defConvName[0]));
-    ucnv_setDefaultName("UTF-8");
-
-#ifdef USE_SSTREAM
-    ostringstream outTestStream;
-    istringstream inTestStream("\x20\x74\x48\x69\x73\xCE\xBC\xE2\x80\x82\x20\x6D\x75\x20\x77\x6F\x72\x6C\x64");
-#else
-    char testStreamBuf[512];
-    ostrstream outTestStream(testStreamBuf, sizeof(testStreamBuf));
-    istrstream inTestStream("\x20\x74\x48\x69\x73\xCE\xBC\xE2\x80\x82\x20\x6D\x75\x20\x77\x6F\x72\x6C\x64", 0);
-
-    /* initialize testStreamBuf */
-    memset(testStreamBuf, '*', sizeof(testStreamBuf));
-    testStreamBuf[sizeof(testStreamBuf)-1] = 0;
-#endif
-
-    outTestStream << "\x42\x65\x67\x69\x6E\x6E\x69\x6E\x67\x20\x6F\x66\x20\x74\x65\x73\x74\x20";
-    outTestStream << str1 << "\x20\x20" << str2 << str3 << "\x31\x20" << UTF8_NEW_LINE << str4 << ends;
-#ifdef USE_SSTREAM
-    string tempStr = outTestStream.str();
-    const char *testStreamBuf = tempStr.c_str();
-#endif
-    if (strcmp(testStreamBuf, testStr) != 0) {
-        log_err("Got: \"%s\", Expected: \"%s\"\n", testStreamBuf, testStr);
-    }
-
-    inTestStream >> inStr >> inStr2;
-    if (inStr.compare(thisMu) != 0) {
-        u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
-        inStrC[inStr.length()] = 0;
-        log_err("Got: \"%s\", Expected: \"tHis\\u03BC\"\n", inStrC);
+        log_data_err("Failed: could not load test icuio data\n");
     }
-    if (inStr2.compare(mu) != 0) {
-        u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
-        inStrC[inStr.length()] = 0;
-        log_err("Got: \"%s\", Expected: \"mu\"\n", inStrC);
-    }
-
-    /* return the default converter to the original state. */
-    ucnv_setDefaultName(defConvName);
-    defConv = u_getDefaultConverter(&status);
-    if (U_FAILURE(status)) {
-        log_err("Can't get default converter");
-        return;
-    }
-    ucnv_close(defConv);
-#else
-    log_info("U_IOSTREAM_SOURCE is disabled\n");
 #endif
 }
 U_CDECL_END
@@ -765,13 +689,16 @@ U_CDECL_END
 static void addAllTests(TestNode** root) {
     addFileTest(root);
     addStringTest(root);
+    addTranslitTest(root);
 
-#if !UCONFIG_NO_FORMATTING
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_LEGACY_CONVERSION
     addTest(root, &DataDrivenPrintf, "datadriv/DataDrivenPrintf");
     addTest(root, &DataDrivenPrintfPrecision, "datadriv/DataDrivenPrintfPrecision");
     addTest(root, &DataDrivenScanf, "datadriv/DataDrivenScanf");
 #endif
-    addTest(root, &TestStream, "stream/TestStream");
+#if U_IOSTREAM_SOURCE >= 199711
+    addStreamTests(root);
+#endif
 }
 
 /* returns the path to icu/source/data/out */
@@ -793,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
 
@@ -825,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;
             }
         }
     }
@@ -860,11 +787,34 @@ static void ctest_setICU_DATA() {
     }
 }
 
+U_CDECL_BEGIN
+/*
+ * Note: this assumes that context is a pointer to STANDARD_TEST_FILE. It would be
+ * cleaner to define an acutal context with a string pointer in it and set STANDARD_TEST_FILE
+ * after the call to initArgs()...
+ */
+static int U_CALLCONV argHandler(int arg, int /*argc*/, const char * const argv[], void *context)
+{
+    const char **str = (const char **) context;
+
+    if (argv[arg][0] != '/' && argv[arg][0] != '-') {
+        *str = argv[arg];
+        return 1;
+    }
+
+    return 0;
+}
+U_CDECL_END
+
 int main(int argc, char* argv[])
 {
     int32_t nerrors = 0;
     TestNode *root = NULL;
     UErrorCode errorCode = U_ZERO_ERROR;
+    UDate startTime, endTime;
+    int32_t diffTime;
+
+    startTime = uprv_getRawUTCtime();
 
     /* Check whether ICU will initialize without forcing the build data directory into
     *  the ICU_DATA path.  Success here means either the data dll contains data, or that
@@ -881,13 +831,17 @@ int main(int argc, char* argv[])
     }
     u_cleanup();
     errorCode = U_ZERO_ERROR;
+    if (!initArgs(argc, argv, argHandler, (void *) &STANDARD_TEST_FILE)) {
+        /* Error already displayed. */
+        return -1;
+    }
 
     /* Initialize ICU */
     ctest_setICU_DATA();    /* u_setDataDirectory() must happen Before u_init() */
     u_init(&errorCode);
     if (U_FAILURE(errorCode)) {
         fprintf(stderr,
-            "#### ERROR! %s: u_init() failed with status = \"%s\".\n" 
+            "#### ERROR! %s: u_init() failed with status = \"%s\".\n"
             "*** Check the ICU_DATA environment variable and \n"
             "*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
         return 1;
@@ -896,7 +850,7 @@ int main(int argc, char* argv[])
     fprintf(stdout, "Default charset for this run is %s\n", ucnv_getDefaultName());
 
     addAllTests(&root);
-    nerrors = processArgs(root, argc, argv);
+    nerrors = runTestRequest(root, argc, argv);
 
 #if 1
     {
@@ -904,6 +858,7 @@ int main(int argc, char* argv[])
         /* This should delete any temporary files. */
         if (fileToRemove) {
             fclose(fileToRemove);
+            log_verbose("Deleting: %s\n", STANDARD_TEST_FILE);
             if (remove(STANDARD_TEST_FILE) != 0) {
                 /* Maybe someone didn't close the file correctly. */
                 fprintf(stderr, "FAIL: Could not delete %s\n", STANDARD_TEST_FILE);
@@ -916,5 +871,14 @@ int main(int argc, char* argv[])
     cleanUpTestTree(root);
     DataDrivenLogger::cleanUp();
     u_cleanup();
+
+    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));
+
     return nerrors;
 }