X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..a0b4f637ba1a6c3c5651b61a69303b029bacf7d3:/icuSources/test/cintltst/udatatst.c diff --git a/icuSources/test/cintltst/udatatst.c b/icuSources/test/cintltst/udatatst.c index b68ec82a..b0740dae 100644 --- a/icuSources/test/cintltst/udatatst.c +++ b/icuSources/test/cintltst/udatatst.c @@ -1,21 +1,22 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1998-2006, International Business Machines Corporation and + * Copyright (c) 1998-2014, 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" @@ -27,19 +28,10 @@ #include "udatamem.h" #include "cintltst.h" #include "ubrkimpl.h" - -#include -#include -#include +#include "toolutil.h" /* for uprv_fileExists() */ #include #include -#ifdef U_WINDOWS -#include -#else -#include -#endif - /* includes for TestSwapData() */ #include "udataswp.h" @@ -48,50 +40,64 @@ #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 @@ -107,12 +113,12 @@ static void lots_of_mallocs() } #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"} @@ -125,40 +131,44 @@ 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)) { + 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 0) { - close(fileHandle); - } - free(filePath); - return; } static char *safeGetICUDataDirectory() { @@ -503,9 +545,10 @@ static void TestUDataFileAccess(){ 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(); } @@ -594,6 +637,7 @@ isAcceptable3(void *context, } +#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION static void TestUDataOpenChoiceDemo1() { UDataMemory *result; UErrorCode status=U_ZERO_ERROR; @@ -607,10 +651,14 @@ static void TestUDataOpenChoiceDemo1() { 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); @@ -622,7 +670,7 @@ static void TestUDataOpenChoiceDemo1() { 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 { @@ -639,7 +687,7 @@ static void TestUDataOpenChoiceDemo1() { 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 { @@ -699,10 +747,14 @@ static void TestUDataOpenChoiceDemo2() { 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); @@ -718,12 +770,12 @@ static void TestUDataOpenChoiceDemo2() { 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"); @@ -733,7 +785,6 @@ static void TestUDataOpenChoiceDemo2() { } } - static void TestUDataGetInfo() { UDataMemory *result; @@ -757,11 +808,15 @@ static void TestUDataGetInfo() { 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); @@ -785,7 +840,7 @@ static void TestUDataGetInfo() { 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); @@ -819,12 +874,16 @@ static void TestUDataGetMemory() { 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); @@ -839,7 +898,7 @@ static void TestUDataGetMemory() { 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); @@ -874,13 +933,17 @@ static void TestErrorConditions(){ 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 { @@ -966,86 +1029,91 @@ static void TestErrorConditions(){ /* 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() { @@ -1064,7 +1132,7 @@ 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'; @@ -1082,10 +1150,10 @@ static void TestICUDataName() 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); @@ -1124,7 +1192,7 @@ static void TestICUDataName() /* 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; @@ -1209,11 +1277,9 @@ static const struct { } }; -/* 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 { @@ -1234,22 +1300,25 @@ 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 */ @@ -1260,6 +1329,11 @@ static const struct { {"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 @@ -1268,18 +1342,24 @@ static const struct { #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 @@ -1290,15 +1370,22 @@ static const struct { * 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. */ @@ -1534,22 +1621,28 @@ printErrorToString(void *context, const char *fmt, va_list args) { 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, @@ -1593,28 +1686,34 @@ TestSwapData() { } 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