ICU-10331 move platform dependency out of udatatst.c , other fixes for msys/mingw

X-SVN-Rev: 34192
This commit is contained in:
Steven R. Loomis 2013-09-04 22:36:52 +00:00
parent eccd3b0f42
commit 9a537be436
5 changed files with 99 additions and 47 deletions

View 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)) {

View file

@ -27,19 +27,10 @@
#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
{
/* lots_of_mallocs(); */
log_verbose("Skipping tests of udata_open() on %s. File not present in this configuration.\n",
icuDataFilePath);
}
}
else
/* 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);

View 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.
**********************************************************************
*
@ -37,13 +37,14 @@
#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);

View 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)
{

View 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.