/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1998-2010, International Business Machines Corporation and
+ * Copyright (c) 1998-2013, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
#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>
-#ifdef U_WINDOWS
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-
/* includes for TestSwapData() */
#include "udataswp.h"
#include "ucol_swp.h"
#include "ucnv_bld.h"
#include "sprpimpl.h"
-#include "propname.h"
#include "rbbidata.h"
/* swapping implementation in i18n */
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void TestUDataOpen(void);
static void TestUDataOpenChoiceDemo1(void);
static void TestUDataOpenChoiceDemo2(void);
static void TestUDataGetInfo(void);
static void TestUDataGetMemory(void);
-static void TestUDataSetAppData(void);
static void TestErrorConditions(void);
static void TestAppData(void);
-static void TestICUDataName(void);
static void TestSwapData(void);
+#endif
+static void TestUDataSetAppData(void);
+static void TestICUDataName(void);
static void PointerTableOfContents(void);
static void SetBadCommonData(void);
static void TestUDataFileAccess(void);
}
#endif
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void TestUDataOpen(){
UDataMemory *result;
UErrorCode status=U_ZERO_ERROR;
const char* memMap[][2]={
{"root", "res"},
- {"pnames", "icu"},
{"cnvalias", "icu"},
{"unames", "icu"},
{"ibm-37_P100-1995", "cnv"}
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 *)uprv_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);
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);
+ }
+ uprv_free(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);
free(path);
}
+#endif
typedef struct {
uint16_t headerSize;
}
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void TestUDataOpenChoiceDemo1() {
UDataMemory *result;
UErrorCode status=U_ZERO_ERROR;
}
}
-
static void TestUDataGetInfo() {
UDataMemory *result;
ures_close(icu);
ures_close(app);
}
+#endif
static void TestICUDataName()
{
switch(U_CHARSET_FAMILY)
{
case U_ASCII_FAMILY:
- switch(U_IS_BIG_ENDIAN)
+ switch((int)U_IS_BIG_ENDIAN)
{
case 1:
typeChar = 'b';
break;
}
- sprintf(expectDataName, "%s%d%d%c",
+ /* Only major number is needed. */
+ sprintf(expectDataName, "%s%d%c",
"icudt",
(int)icuVersion[0],
- (int)icuVersion[1],
typeChar);
log_verbose("Expected: %s\n", expectDataName);
/* test data swapping ------------------------------------------------------- */
-#ifdef OS400
+#if U_PLATFORM == U_PF_OS400
/* See comments in genccode.c on when this special implementation can be removed. */
static const struct {
double bogus;
}
};
-/* Unfortunately, trie dictionaries are in a C++ header */
-int32_t
-triedict_swap(const UDataSwapper *ds,
- const void *inData, int32_t length, void *outData,
- UErrorCode *pErrorCode);
+/* Unfortunately, dictionaries are in a C++ header */
+U_CAPI int32_t U_EXPORT2
+udict_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, UErrorCode *pErrorCode);
/* test cases for maximum data swapping code coverage */
static const struct {
#if !UCONFIG_NO_BREAK_ITERATION
{"char", "brk", ubrk_swap},
- {"thaidict", "ctd", triedict_swap},
+ {"thaidict", "dict",udict_swap},
#endif
- /* the last item should not be #if'ed so that it can reliably omit the last comma */
-
+#if 0
+ /*
+ * Starting with ICU 4.8, the Unicode property (value) aliases data
+ * is hardcoded in the ICU4C common library.
+ * The swapper was moved to the toolutil library for swapping for ICU4J.
+ */
/* Unicode properties */
{"pnames", "icu", upname_swap},
+#endif
+
#if 0
/*
* Starting with ICU4C 3.4, the core Unicode properties files
{"ucase", "icu", ucase_swap},
{"ubidi", "icu", ubidi_swap},
#endif
-#if !UCONFIG_NO_NORMALIZATION
+#if !UCONFIG_NO_NORMALIZATION && !UCONFIG_ONLY_COLLATION
{"nfc", "nrm", unorm2_swap},
{"confusables", "cfu", uspoof_swap},
#endif
{"unames", "icu", uchar_swapNames}
+ /* the last item should not be #if'ed so that it can reliably omit the last comma */
};
/* Large enough for the largest swappable data item. */
vsprintf((char *)context, fmt, args);
}
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void
TestSwapData() {
char name[100];
nm=swapCases[i].name+1;
uprv_strcpy(name, "testdata");
} else if (uprv_strcmp(swapCases[i].type, "brk")==0
- || uprv_strcmp(swapCases[i].type, "ctd")==0) {
+ || uprv_strcmp(swapCases[i].type, "dict")==0) {
pkg=U_ICUDATA_BRKITR;
nm=swapCases[i].name;
uprv_strcpy(name, U_ICUDATA_BRKITR);
uprv_strcat(name, swapCases[i].type);
pData=udata_open(pkg, swapCases[i].type, nm, &errorCode);
+
if(U_SUCCESS(errorCode)) {
TestSwapCase(pData, name, swapCases[i].swapFn, buffer, buffer+SWAP_BUFFER_SIZE);
udata_close(pData);
free(buffer);
}
-
+#endif
static void PointerTableOfContents() {
UDataMemory *dataItem;