]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/udatatst.c
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / cintltst / udatatst.c
index bdcf8340fe180e9bb2183fece3a3c6c59715473f..5c57d5aa4375c547dd647107589c892270e36644 100644 (file)
@@ -1,6 +1,8 @@
+// © 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.
  ********************************************************************/
 /*
@@ -16,6 +18,7 @@
 #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"
@@ -55,8 +58,6 @@ unorm2_swap(const UDataSwapper *ds,
 
 /* 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);
@@ -72,7 +73,9 @@ 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);
 
@@ -94,6 +97,9 @@ 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
@@ -164,7 +170,7 @@ static void TestUDataOpen(){
       {
           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);
@@ -204,7 +210,7 @@ static void TestUDataOpen(){
        {
          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);
@@ -255,7 +261,7 @@ static void TestUDataOpen(){
         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)) {
@@ -552,6 +558,7 @@ static UBool U_CALLCONV
 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 &&
@@ -584,6 +591,7 @@ static UBool U_CALLCONV
 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);
@@ -612,6 +620,7 @@ static UBool U_CALLCONV
 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 &&
@@ -1227,7 +1236,8 @@ static const struct {
 
     {0x31, 0x31, 0x31, 0x31},     /* dataFormat="1111" */
     {0, 0, 0, 0},                 /* formatVersion */
-    {0, 0, 0, 0}}                 /* dataVersion */
+    {0, 0, 0, 0}},                /* dataVersion */
+    0
 };
 #endif
 
@@ -1367,15 +1377,18 @@ static const struct {
      * 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 */
@@ -1386,6 +1399,7 @@ static const struct {
 
 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 */
 }
@@ -1688,7 +1702,7 @@ TestSwapData() {
     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]=='*') {
@@ -1813,3 +1827,49 @@ static void SetBadCommonData(void) {
     }
 }
 
+// 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
+}