+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (C) 2002-2008, 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
*
#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"
buffer[3999] = 0; /* NULL terminate */
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));
}
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;
}
}
}
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
const char* DataDrivenLogger::fgDataDir = NULL;
char* DataDrivenLogger::fgTestDataPath = NULL;
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO
static int64_t
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;
const char *fileLocale = "en_US_POSIX";
int32_t uFileBufferLenReturned;
- UFILE *testFile;
+ LocalUFILEPointer testFile;
errorCode=U_ZERO_ERROR;
dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
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",
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, 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;
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));
errorCode=U_ZERO_ERROR;
continue;
}
- u_fclose(testFile);
}
delete testData;
}
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;
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",
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));
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;
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)) {
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");
*/
#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
}
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;
}
}
}
UDate startTime, endTime;
int32_t diffTime;
- startTime = uprv_getUTCtime();
+ 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
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;
/* 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);
DataDrivenLogger::cleanUp();
u_cleanup();
- endTime = uprv_getUTCtime();
+ 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),