+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1998-2014, International Business Machines Corporation and
+ * Copyright (c) 1998-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
#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"
/* other definitions and prototypes */
-#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 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);
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
{
int i;
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++){
/* lots_of_mallocs(); */
status=U_ZERO_ERROR;
result=udata_open(path, memMap[i][1], memMap[i][0], &status);
{
int i;
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++){
/* lots_of_mallocs(); */
status=U_ZERO_ERROR;
result=udata_open(path, memMap[i][1], memMap[i][0], &status);
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)) {
isAcceptable1(void *context,
const char *type, const char *name,
const UDataInfo *pInfo) {
+ (void)context; // suppress compiler warnings about unused variable
if( pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
isAcceptable2(void *context,
const char *type, const char *name,
const UDataInfo *pInfo){
+ (void)context; // suppress compiler warnings about unused variable
UVersionInfo unicodeVersion;
u_getUnicodeVersion(unicodeVersion);
isAcceptable3(void *context,
const char *type, const char *name,
const UDataInfo *pInfo){
+ (void)context; // suppress compiler warnings about unused variable
if( pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
{0x31, 0x31, 0x31, 0x31}, /* dataFormat="1111" */
{0, 0, 0, 0}, /* formatVersion */
- {0, 0, 0, 0}} /* dataVersion */
+ {0, 0, 0, 0}}, /* dataVersion */
+ 0
};
#endif
* to testdata) for code coverage in tests.
* See Jitterbug 4497.
*
- * ICU4C 4.4 adds normalization data files again, e.g., nfc.nrm.
+ * ICU4C 4.4 adds normalization data files again, e.g., nfkc.nrm.
*/
{"uprops", "icu", uprops_swap},
{"ucase", "icu", ucase_swap},
{"ubidi", "icu", ubidi_swap},
#endif
#if !UCONFIG_NO_NORMALIZATION && !UCONFIG_ONLY_COLLATION
- {"nfc", "nrm", unorm2_swap},
- {"confusables", "cfu", uspoof_swap},
+ {"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 */
static void U_CALLCONV
printError(void *context, const char *fmt, va_list args) {
+ (void)context; // suppress compiler warnings about unused variable
vlog_info("[swap] ", fmt, args);
log_err("\n"); /* Register error */
}
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]=='*') {
}
}
+// 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
+}