+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1998-2006, International Business Machines Corporation and
+ * Copyright (c) 1998-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
-* File test.c
+* File udatatst.c
*
* Modification History:
*
* Date Name Description
* 02/22/2000 Madhu Creation
-*******************************************************************************
+******************************************************************************
*/
#include "unicode/utypes.h"
#include "unicode/putil.h"
#include "unicode/udata.h"
+#include "unicode/ucal.h"
#include "unicode/uchar.h"
#include "unicode/ucnv.h"
#include "unicode/ures.h"
#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 "ucnv_io.h"
#include "uprops.h"
#include "ucase.h"
+#include "ucol_imp.h"
#include "ucol_swp.h"
#include "ucnv_bld.h"
-#include "unormimp.h"
#include "sprpimpl.h"
-#include "propname.h"
#include "rbbidata.h"
-/* other definitions and prototypes */
+/* swapping implementation in i18n */
+#include "uspoof_impl.h"
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+U_CAPI int32_t U_EXPORT2
+unorm2_swap(const UDataSwapper *ds,
+ const void *inData, int32_t length, void *outData,
+ UErrorCode *pErrorCode);
+/* other definitions and prototypes */
+
+#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);
-
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
+static void TestTZDataDir(void);
+#endif
void addUDataTest(TestNode** root);
void
addUDataTest(TestNode** root)
{
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
addTest(root, &TestUDataOpen, "udatatst/TestUDataOpen" );
addTest(root, &TestUDataOpenChoiceDemo1, "udatatst/TestUDataOpenChoiceDemo1");
addTest(root, &TestUDataOpenChoiceDemo2, "udatatst/TestUDataOpenChoiceDemo2");
addTest(root, &TestUDataGetInfo, "udatatst/TestUDataGetInfo" );
addTest(root, &TestUDataGetMemory, "udatatst/TestUDataGetMemory" );
- addTest(root, &TestUDataSetAppData, "udatatst/TestUDataSetAppData" );
addTest(root, &TestErrorConditions, "udatatst/TestErrorConditions");
addTest(root, &TestAppData, "udatatst/TestAppData" );
- addTest(root, &TestICUDataName, "udatatst/TestICUDataName" );
addTest(root, &TestSwapData, "udatatst/TestSwapData" );
+#endif
+ addTest(root, &TestUDataSetAppData, "udatatst/TestUDataSetAppData" );
+ addTest(root, &TestICUDataName, "udatatst/TestICUDataName" );
addTest(root, &PointerTableOfContents, "udatatst/PointerTableOfContents" );
addTest(root, &SetBadCommonData, "udatatst/SetBadCommonData" );
addTest(root, &TestUDataFileAccess, "udatatst/TestUDataFileAccess" );
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
+ addTest(root, &TestTZDataDir, "udatatst/TestTZDataDir" );
+#endif
}
#if 0
}
#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)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ free(path);
+ return;
+ }
/* 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_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", testPath, name, type, myErrorName(status));
+ log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", testPath, name, type, myErrorName(status));
} else {
log_verbose("PASS: udata_open worked\n");
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<UPRV_LENGTHOF(memMap); 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<UPRV_LENGTHOF(memMap); 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, "unorm.icu");
+ 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);
strcat(icuDataFilePath, dirSepString);
strcat(icuDataFilePath, U_ICUDATA_NAME);
log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
- for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
+ for(i=0; i<UPRV_LENGTHOF(memMap); i++){
status=U_ZERO_ERROR;
result=udata_open(icuDataFilePath, memMap[i][1], memMap[i][0], &status);
if(U_FAILURE(status)) {
}
}
}
-/* else
+ else
{
log_verbose("Skipping tests of udata_open() on %s. File not present in this configuration.\n",
icuDataFilePath);
- }*/
+ }
free(icuDataFilePath);
icuDataFilePath = NULL;
status = U_ZERO_ERROR;
result = udata_open( testPath, "typ", "nam", &status);
if (status != U_ZERO_ERROR) {
- log_err("FAIL: udata_open( \"%s\", \"typ\", \"nam\") returned status %s\n", testPath, u_errorName(status));
+ log_data_err("FAIL: udata_open( \"%s\", \"typ\", \"nam\") returned status %s\n", testPath, u_errorName(status));
}
udata_close(result);
free(icuDataFilePath);
strcat(longTestPath, testPath);
result=udata_open(longTestPath, type, name, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
+ log_data_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
longTestPath, name, type, myErrorName(status));
} else {
log_verbose("PASS: udata_open worked\n");
result=udata_open(longTestPath, type, longName, &status);
if (status != U_FILE_ACCESS_ERROR) {
- log_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
+ log_data_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
longTestPath, longName, type, myErrorName(status));
}
udata_close(result);
free(path);
}
+#endif
+typedef struct {
+ uint16_t headerSize;
+ uint8_t magic1, magic2;
+ UDataInfo info;
+ char padding[8];
+ uint32_t count, reserved;
+ /*
+ const struct {
+ const char *const name;
+ const void *const data;
+ } toc[1];
+ */
+ int32_t fakeNameAndData[4];
+} ICU_COMMON_Data_Header;
+static const ICU_COMMON_Data_Header gEmptyHeader = {
+ 32, /* headerSize */
+ 0xda, /* magic1, (see struct MappedData in udata.c) */
+ 0x27, /* magic2 */
+ { /*UDataInfo */
+ sizeof(UDataInfo), /* size */
+ 0, /* reserved */
-static void TestUDataSetAppData(){
-/* UDataMemory *dataItem;*/
-
- UErrorCode status=U_ZERO_ERROR;
- int fileHandle = 0; /* We are going to read the testdata.dat file */
- struct stat statBuf;
- size_t fileSize = 0;
- char *fileBuf = 0;
-
- size_t i;
-
- /* Open the testdata.dat file, using normal */
- const char* tdrelativepath = loadTestData(&status);
- char* filePath=(char*)malloc(sizeof(char) * (strlen(tdrelativepath) + strlen(".dat") +1 +strlen(tdrelativepath)) );
-
- strcpy(filePath, tdrelativepath);
- strcat(filePath, ".dat");
-
- log_verbose("Testing udata_setAppData() with %s\n", filePath);
-
-#if defined(U_WINDOWS) || defined(U_CYGWIN)
- fileHandle = open( filePath, O_RDONLY | O_BINARY );
+#if U_IS_BIG_ENDIAN
+ 1,
#else
- fileHandle = open( filePath, O_RDONLY);
+ 0,
#endif
- if( fileHandle == -1 ) {
- log_err("FAIL: TestUDataSetAppData() can not open(\"%s\", O_RDONLY)\n", filePath);
- goto cleanupAndReturn;
- }
- /*
- *Find the size of testdata.dat, and read the whole thing into memory
- */
- if (fstat(fileHandle, &statBuf) == 0) {
- fileSize = statBuf.st_size;
- }
- if (fileSize == 0) {
- log_err("FAIL: TestUDataSetAppData() can not find size of file \"%s\".\n", filePath);
- goto cleanupAndReturn;
+ U_CHARSET_FAMILY,
+ sizeof(UChar),
+ 0, /* reserved */
+ { /* data format identifier */
+ 0x43, 0x6d, 0x6e, 0x44}, /* "CmnD" */
+ {1, 0, 0, 0}, /* format version major, minor, milli, micro */
+ {0, 0, 0, 0} /* dataVersion */
+ },
+ {0,0,0,0,0,0,0,0}, /* Padding[8] */
+ 0, /* count */
+ 0, /* Reserved */
+ { /* TOC structure */
+/* { */
+ 0 , 0 , 0, 0 /* name and data entries. Count says there are none, */
+ /* but put one in just in case. */
+/* } */
}
+};
- fileBuf = (char *)ctst_malloc(fileSize);
- if (fileBuf == 0) {
- log_err("FAIL: TestUDataSetAppData() can not malloc(%d) for file \"%s\".\n", fileSize, filePath);
- goto cleanupAndReturn;
- }
- i = read(fileHandle, fileBuf, fileSize);
- if (i != fileSize) {
- log_err("FAIL: TestUDataSetAppData() error reading file \"%s\" size=%d read=%d.\n", filePath, fileSize, i);
- goto cleanupAndReturn;
- }
+static void TestUDataSetAppData(){
+/* UDataMemory *dataItem;*/
+
+ UErrorCode status=U_ZERO_ERROR;
/*
* First we try some monkey business and try to do bad things.
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData1\", NULL, status) should have failed."
" It returned status of %s\n", u_errorName(status));
- goto cleanupAndReturn;
+ return;
}
/* The following call should fail.
If the following works with a bad UErrorCode, then later calls to appData1 should fail. */
- udata_setAppData("appData1", fileBuf, &status);
+ udata_setAppData("appData1", &gEmptyHeader, &status);
/*
* Got testdata.dat into memory, now we try setAppData using the memory image.
*/
status=U_ZERO_ERROR;
- udata_setAppData("appData1", fileBuf, &status);
+ udata_setAppData("appData1", &gEmptyHeader, &status);
if (status != U_ZERO_ERROR) {
log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData1\", fileBuf, status) "
" returned status of %s\n", u_errorName(status));
- goto cleanupAndReturn;
+ return;
}
- udata_setAppData("appData2", fileBuf, &status);
+ udata_setAppData("appData2", &gEmptyHeader, &status);
if (status != U_ZERO_ERROR) {
log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData2\", fileBuf, status) "
" returned status of %s\n", u_errorName(status));
- goto cleanupAndReturn;
+ return;
}
/* If we try to setAppData with the same name a second time, we should get a
* a using default warning.
*/
- udata_setAppData("appData2", fileBuf, &status);
+ udata_setAppData("appData2", &gEmptyHeader, &status);
if (status != U_USING_DEFAULT_WARNING) {
log_err("FAIL: TestUDataSetAppData(): udata_setAppData(\"appData2\", fileBuf, status) "
" returned status of %s, expected U_USING_DEFAULT_WARNING.\n", u_errorName(status));
package of a contained item.
dataItem = udata_open("appData1", "res", "te_IN", &status); **/
-
-cleanupAndReturn:
- /* Note: fileBuf is not deleted because ICU retains a pointer to it
- * forever (until ICU is shut down).
- */
- if (fileHandle > 0) {
- close(fileHandle);
- }
- free(filePath);
- return;
}
static char *safeGetICUDataDirectory() {
u_setDataDirectory(icuDataDir);
u_init(&status);
if(U_FAILURE(status)){
- log_err("%s\n", u_errorName(status));
+ log_err_status(status, "%s\n", u_errorName(status));
}
free(icuDataDir);
+ ctest_resetICU();
}
}
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void TestUDataOpenChoiceDemo1() {
UDataMemory *result;
UErrorCode status=U_ZERO_ERROR;
const char* type="icu";
const char* testPath="testdata";
const char* fullTestDataPath = loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
result=udata_openChoice(NULL, "icu", name[0], isAcceptable1, NULL, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name[0], type, myErrorName(status));
+ log_data_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name[0], type, myErrorName(status));
} else {
log_verbose("PASS: udata_openChoice worked\n");
udata_close(result);
status=U_ZERO_ERROR;
result=udata_openChoice(NULL, type, name[1], isAcceptable2, NULL, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name[1], type, myErrorName(status));
+ log_data_err("FAIL: udata_openChoice() failed name=%s, type=%s, \n errorcode=%s\n", name[1], type, myErrorName(status));
}
}
else {
status=U_ZERO_ERROR;
result=udata_openChoice(testPath, type, name[2], isAcceptable3, NULL, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_openChoice() failed path=%s name=%s, type=%s, \n errorcode=%s\n", testPath, name[2], type, myErrorName(status));
+ log_data_err("FAIL: udata_openChoice() failed path=%s name=%s, type=%s, \n errorcode=%s\n", testPath, name[2], type, myErrorName(status));
}
}
else {
const char* name="test";
const char* type="icu";
const char* path = loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
result=udata_openChoice(path, type, name, isAcceptable, &p, &status);
if(U_FAILURE(status)){
- log_err("failed to load data at p=%s t=%s n=%s, isAcceptable", path, type, name);
+ log_data_err("failed to load data at p=%s t=%s n=%s, isAcceptable", path, type, name);
}
if(U_SUCCESS(status) ) {
udata_close(result);
p++;
}
else {
- log_err("FAIL: failed to either load the data or to reject the loaded data. ERROR=%s\n", myErrorName(status) );
+ log_data_err("FAIL: failed to either load the data or to reject the loaded data. ERROR=%s\n", myErrorName(status) );
}
}
else if(p == 2) {
if(U_FAILURE(status)) {
- log_err("FAIL: failed to load the data and accept it. ERROR=%s\n", myErrorName(status) );
+ log_data_err("FAIL: failed to load the data and accept it. ERROR=%s\n", myErrorName(status) );
}
else {
log_verbose("Loads the data and accepts it for p==2 as expected\n");
}
}
-
static void TestUDataGetInfo() {
UDataMemory *result;
const char* type="icu";
const char* testPath=loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
log_verbose("Testing udata_getInfo() for cnvalias.icu\n");
result=udata_open(NULL, "icu", name, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_open() failed for path = NULL, name=%s, type=%s, \n errorcode=%s\n", name, type, myErrorName(status));
+ log_data_err("FAIL: udata_open() failed for path = NULL, name=%s, type=%s, \n errorcode=%s\n", name, type, myErrorName(status));
return;
}
udata_getInfo(result, &dataInfo);
log_verbose("Testing udata_getInfo() for test.icu\n");
result=udata_open(testPath, type, name2, &status);
if(U_FAILURE(status)) {
- log_err("FAIL: udata_open() failed for path=%s name2=%s, type=%s, \n errorcode=%s\n", testPath, name2, type, myErrorName(status));
+ log_data_err("FAIL: udata_open() failed for path=%s name2=%s, type=%s, \n errorcode=%s\n", testPath, name2, type, myErrorName(status));
return;
}
udata_getInfo(result, &dataInfo);
const char* name2="test";
const char* testPath = loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
type="icu";
log_verbose("Testing udata_getMemory() for \"cnvalias.icu\"\n");
result=udata_openChoice(NULL, type, name, isAcceptable1, NULL, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_openChoice() failed for name=%s, type=%s, \n errorcode=%s\n", name, type, myErrorName(status));
+ log_data_err("FAIL: udata_openChoice() failed for name=%s, type=%s, \n errorcode=%s\n", name, type, myErrorName(status));
return;
}
table=(const int32_t *)udata_getMemory(result);
log_verbose("Testing udata_getMemory for \"test.icu\"()\n");
result=udata_openChoice(testPath, type, name2, isAcceptable3, NULL, &status);
if(U_FAILURE(status)){
- log_err("FAIL: udata_openChoice() failed for path=%s name=%s, type=%s, \n errorcode=%s\n", testPath, name2, type, myErrorName(status));
+ log_data_err("FAIL: udata_openChoice() failed for path=%s name=%s, type=%s, \n errorcode=%s\n", testPath, name2, type, myErrorName(status));
return;
}
intValue=(uint16_t *)udata_getMemory(result);
const char* type="icu";
const char *testPath = loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
status = U_ILLEGAL_ARGUMENT_ERROR;
/*Try udata_open with status != U_ZERO_ERROR*/
log_verbose("Testing udata_open() with status != U_ZERO_ERROR\n");
result=udata_open(testPath, type, name, &status);
if(result != NULL){
- log_err("FAIL: udata_open() is supposed to fail for path = %s, name=%s, type=%s, \n errorcode !=U_ZERO_ERROR\n", testPath, name, type);
+ log_data_err("FAIL: udata_open() is supposed to fail for path = %s, name=%s, type=%s, \n errorcode !=U_ZERO_ERROR\n", testPath, name, type);
udata_close(result);
} else {
/* Test whether apps and ICU can each have their own root.res */
static void TestAppData()
{
- UResourceBundle *icu, *app;
- UResourceBundle *tmp = NULL;
- UResourceBundle *tmp2 = NULL;
-
- const UChar *appString;
- const UChar *icuString;
-
- int32_t len;
-
- UErrorCode status = U_ZERO_ERROR;
- char testMsgBuf[256];
-
- const char* testPath=loadTestData(&status);
-
- icu = ures_open(NULL, "root", &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't open root ICU bundle- %s", __FILE__, __LINE__, u_errorName(status));
- return;
- }
- /* log_info("Open icu root: %s size_%d\n", u_errorName(status), ures_getSize(icu)); */
- status = U_ZERO_ERROR;
-
- app = ures_open(testPath, "root", &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't open app ICU bundle [%s]- %s", __FILE__, __LINE__, testPath, u_errorName(status));
- return;
- }
- /* log_info("Open app: %s, size %d\n", u_errorName(status), ures_getSize(app)); */
-
- tmp = ures_getByKey(icu, "Version", tmp, &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't get Version string from ICU root bundle- %s", __FILE__, __LINE__, u_errorName(status));
- return;
- }
-
- icuString = ures_getString(tmp, &len, &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't get string from Version string from ICU root bundle- %s", __FILE__, __LINE__, u_errorName(status));
- return;
- }
- /* log_info("icuString=%p - %s\n", icuString, austrdup(icuString)); */
-
-
- tmp2 = ures_getByKey(app, "Version", tmp2, &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't get Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status));
- return;
- }
-
- appString = ures_getString(tmp2, &len, &status);
- if(U_FAILURE(status))
- {
- log_err("%s:%d: Couldn't get string from Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status));
- return;
- }
-
- /* log_info("appString=%p - %s\n", appString, austrdup(appString)); */
-
-
- if(!u_strcmp(icuString, appString))
- {
- log_err("%s:%d: Error! Expected ICU and App root version strings to be DIFFERENT but they are both %s and %s\n", __FILE__, __LINE__, austrdup(icuString),
- austrdup(appString));
- }
- else
- {
- log_verbose("%s:%d: appstr=%s, icustr=%s\n", __FILE__,
- __LINE__, u_austrcpy(testMsgBuf, appString), u_austrcpy(testMsgBuf, icuString));
- }
-
- ures_close(tmp);
- ures_close(tmp2);
- ures_close(icu);
- ures_close(app);
+ UResourceBundle *icu, *app;
+ UResourceBundle *tmp = NULL;
+ UResourceBundle *tmp2 = NULL;
+
+ const UChar *appString;
+ const UChar *icuString;
+
+ int32_t len;
+
+ UErrorCode status = U_ZERO_ERROR;
+ char testMsgBuf[256];
+
+ const char* testPath=loadTestData(&status);
+ if(U_FAILURE(status)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
+ return;
+ }
+
+ icu = ures_open(NULL, "root", &status);
+ if(U_FAILURE(status))
+ {
+ log_data_err("%s:%d: Couldn't open root ICU bundle- %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+ /* log_info("Open icu root: %s size_%d\n", u_errorName(status), ures_getSize(icu)); */
+ status = U_ZERO_ERROR;
+
+ app = ures_open(testPath, "root", &status);
+ if(U_FAILURE(status))
+ {
+ log_data_err("%s:%d: Couldn't open app ICU bundle [%s]- %s", __FILE__, __LINE__, testPath, u_errorName(status));
+ return;
+ }
+ /* log_info("Open app: %s, size %d\n", u_errorName(status), ures_getSize(app)); */
+
+ tmp = ures_getByKey(icu, "Version", tmp, &status);
+ if(U_FAILURE(status))
+ {
+ log_err("%s:%d: Couldn't get Version string from ICU root bundle- %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ icuString = ures_getString(tmp, &len, &status);
+ if(U_FAILURE(status))
+ {
+ log_err("%s:%d: Couldn't get string from Version string from ICU root bundle- %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+ /* log_info("icuString=%p - %s\n", icuString, austrdup(icuString)); */
+
+
+ tmp2 = ures_getByKey(app, "Version", tmp2, &status);
+ if(U_FAILURE(status))
+ {
+ log_err("%s:%d: Couldn't get Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ appString = ures_getString(tmp2, &len, &status);
+ if(U_FAILURE(status))
+ {
+ log_err("%s:%d: Couldn't get string from Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status));
+ return;
+ }
+
+ /* log_info("appString=%p - %s\n", appString, austrdup(appString)); */
+
+
+ if(!u_strcmp(icuString, appString))
+ {
+ log_err("%s:%d: Error! Expected ICU and App root version strings to be DIFFERENT but they are both %s and %s\n", __FILE__, __LINE__, austrdup(icuString),
+ austrdup(appString));
+ }
+ else
+ {
+ log_verbose("%s:%d: appstr=%s, icustr=%s\n", __FILE__,
+ __LINE__, u_austrcpy(testMsgBuf, appString), u_austrcpy(testMsgBuf, icuString));
+ }
+
+ ures_close(tmp);
+ ures_close(tmp2);
+ 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 {
/* Test a 32-bit key table. This is large. */
{"*testtable32", "res", ures_swap},
- /* ICU 2.6 resource bundle - data format 1.0, without indexes[] (little-endian ASCII) */
- {"*icu26_testtypes", "res", ures_swap},
+ /* ICU 4.2 resource bundle - data format 1.2 (little-endian ASCII) */
+ {"*old_l_testtypes", "res", ures_swap},
/* same for big-endian EBCDIC */
- {"*icu26e_testtypes", "res", ures_swap},
+ {"*old_e_testtypes", "res", ures_swap},
#if !UCONFIG_NO_COLLATION
/* standalone collation data files */
{"ucadata", "icu", ucol_swap},
+#if 0
+ /* Starting with ICU 53, the "inverse UCA" data is integrated into ucadata.icu. */
{"invuca", "icu", ucol_swapInverseUCA},
#endif
+#endif
#if !UCONFIG_NO_LEGACY_CONVERSION
/* conversion table files */
/* SBCS conversion table file without extension */
- {"ibm-913_P100-2000", "cnv", ucnv_swap},
+ {"ibm-913_P100-2000", "cnv", ucnv_swap},
/* EBCDIC_STATEFUL conversion table file with extension */
{"ibm-1390_P110-2003", "cnv", ucnv_swap},
/* DBCS extension-only conversion table file */
{"gb18030", "cnv", ucnv_swap},
/* MBCS conversion table file with extension */
{"*test4x", "cnv", ucnv_swap},
+ /*
+ * MBCS conversion table file without extension,
+ * to test swapping and preflighting of UTF-8-friendly mbcsIndex[].
+ */
+ {"jisx-212", "cnv", ucnv_swap},
#endif
#if !UCONFIG_NO_CONVERSION
#endif
#if !UCONFIG_NO_IDNA
- {"uidna", "spp", usprep_swap},
+ {"rfc3491", "spp", usprep_swap},
#endif
#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
* we need not jump through hoops (like adding snapshots of these files
* to testdata) for code coverage in tests.
* See Jitterbug 4497.
+ *
+ * ICU4C 4.4 adds normalization data files again, e.g., nfkc.nrm.
*/
-#if !UCONFIG_NO_NORMALIZATION
- {"unorm", "icu", unorm_swap},
-#endif
{"uprops", "icu", uprops_swap},
{"ucase", "icu", ucase_swap},
{"ubidi", "icu", ubidi_swap},
+#endif
+#if !UCONFIG_NO_NORMALIZATION && !UCONFIG_ONLY_COLLATION
+ {"nfkc", "nrm", unorm2_swap},
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+ {"confusables", "cfu", uspoof_swap}, /* spoof data missing without regex */
+#endif
+
#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];
UDataSwapper *ds;
UDataMemory *pData;
uint8_t *buffer;
- const char *pkg, *nm;
- UErrorCode errorCode;
+ const char *pkg, *nm, *testPath;
+ UErrorCode errorCode = U_ZERO_ERROR;
int32_t i;
- buffer=(uint8_t *)uprv_malloc(2*SWAP_BUFFER_SIZE);
+ buffer=(uint8_t *)malloc(2*SWAP_BUFFER_SIZE);
if(buffer==NULL) {
log_err("unable to allocate %d bytes\n", 2*SWAP_BUFFER_SIZE);
return;
}
+ testPath=loadTestData(&errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(errorCode));
+ }
+
/* Test that printError works as expected. */
errorCode=U_USELESS_COLLATOR_ERROR;
ds=udata_openSwapper(U_IS_BIG_ENDIAN, U_ASCII_FAMILY,
}
errorCode=U_ZERO_ERROR;
- /* Test argument checking. ucol_swapBinary is normally tested via ures_swap, and isn't normally called directly. */
+ /* Test argument checking. ucol_swap is normally tested via ures_swap, and isn't normally called directly. */
#if !UCONFIG_NO_COLLATION
- ucol_swapBinary(NULL, NULL, -1, NULL, NULL);
- ucol_swapBinary(NULL, NULL, -1, NULL, &errorCode);
+ ucol_swap(NULL, NULL, -1, NULL, &errorCode);
if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
- log_err("ucol_swapBinary did not fail as expected\n", name);
+ log_err("ucol_swap did not fail as expected\n", name);
}
errorCode=U_ZERO_ERROR;
#endif
- for(i=0; i<LENGTHOF(swapCases); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(swapCases); ++i) {
/* build the name for logging */
errorCode=U_ZERO_ERROR;
if(swapCases[i].name[0]=='*') {
- pkg=loadTestData(&errorCode);
+ pkg=testPath;
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);
+#if !UCONFIG_NO_COLLATION
+ } else if (uprv_strcmp(swapCases[i].name, "ucadata")==0
+ || uprv_strcmp(swapCases[i].name, "invuca")==0) {
+ pkg=U_ICUDATA_COLL;
+ nm=swapCases[i].name;
+ uprv_strcpy(name, U_ICUDATA_COLL);
+#endif /* !UCONFIG_NO_COLLATION */
} else {
pkg=NULL;
nm=swapCases[i].name;
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);
}
}
- uprv_free(buffer);
+ free(buffer);
}
-
+#endif
static void PointerTableOfContents() {
UDataMemory *dataItem;
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
log_err("FAIL: udata_setCommonData did not fail with bad arguments.\n");
}
- if (u_getDataDirectory() == NULL || u_getDataDirectory()[0] == 0) {
- /* Check that we don't change the common data. Many ICU tests will fail after this test, if this works. */
- /* We could do a better test, if we called u_cleanup and udata_setCommonData returned the last value. */
- status = U_ZERO_ERROR;
- udata_setCommonData(&gOffsetTOCAppData_dat, &status);
- if (status != U_USING_DEFAULT_WARNING) {
- log_err("FAIL: udata_setCommonData allowed the data to be changed after initialization!\n");
- }
- }
- else {
- log_verbose("Can't test setting common data because files mode may have been used.\n");
- }
/* Check that we verify that the data isn't bad */
status = U_ZERO_ERROR;
}
}
+// Check the override loading of time zone .res files from a specified path
+//
+// Hand testing notes:
+// 1. Run this test with the environment variable set. The following should induce faiures:
+// ICU_TIMEZONE_FILES_DIR=../testdata/out/build LD_LIBRARY_PATH=../../lib:../../stubdata:../../tools/ctestfw:$LD_LIBRARY_PATH ./cintltst /udatatst/TestTZDataDir
+// 2. Build ICU with with U_TIMEZONE_FILES_DIR defined. This should also induce failures.
+// CPPFLAGS=-DU_TIMEZONE_FILES_DIR\=`pwd`/test/testdata/out/testdata ./runConfigureICU Linux
+// make check
+
+static void TestTZDataDir(void) {
+#if !UCONFIG_NO_FORMATTING
+ UErrorCode status = U_ZERO_ERROR;
+ const char *tzDataVersion;
+ const char *testDataPath;
+
+ // Verify that default ICU time zone data version is something newer than 2014a.
+ tzDataVersion = ucal_getTZDataVersion(&status);
+ // printf("tz data version is %s\n", tzDataVersion);
+ if (U_FAILURE(status)) {
+ log_data_err("Failed call to ucal_getTZDataVersion - %s\n", u_errorName(status));
+ return;
+ } else if (strcmp("2014a", tzDataVersion) == 0) {
+ log_err("File %s:%d - expected something newer than time zone data 2014a.\n", __FILE__, __LINE__, tzDataVersion);
+ }
+
+ testDataPath = loadTestData(&status);
+ // The path produced by loadTestData() will look something like
+ // whatever/.../testdata/out/testdata
+ // The test data puts an old (2014a) version of the time zone data there.
+
+ // Switch ICU to the testdata version of zoneinfo64.res, which is verison 2014a.
+ ctest_resetICU();
+ u_setTimeZoneFilesDirectory(testDataPath, &status);
+ tzDataVersion = ucal_getTZDataVersion(&status);
+ if (strcmp("2014a", tzDataVersion) != 0) {
+ log_err("File %s:%d - expected \"2014a\"; actual \"%s\"\n", __FILE__, __LINE__, tzDataVersion);
+ }
+
+ ctest_resetICU(); // Return ICU to using its standard tz data.
+ tzDataVersion = ucal_getTZDataVersion(&status);
+ // printf("tz data version is %s\n", tzDataVersion);
+ if (strcmp("2014a", tzDataVersion) == 0) {
+ log_err("File %s:%d - expected something newer than time zone data 2014a.\n", __FILE__, __LINE__, tzDataVersion);
+ }
+#endif
+}