#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"
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)) {
}
/* 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));
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(); */
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);