]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/windttst.cpp
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / windttst.cpp
index 3869f34acfcda8b1272ac4cb0e5f93311baaa26d..92d6f6721e765e4a634b299a8d21de51ea9f7a66 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 ********************************************************************************
-*   Copyright (C) 2005-2006, International Business Machines
+*   Copyright (C) 2005-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
@@ -11,7 +13,7 @@
 
 #include "unicode/utypes.h"
 
-#ifdef U_WINDOWS
+#if U_PLATFORM_USES_ONLY_WIN32_API
 
 #if !UCONFIG_NO_FORMATTING
 
 #include "winutil.h"
 #include "windttst.h"
 
+#include "dtfmttst.h"
+
 #include "cmemory.h"
 #include "cstring.h"
 #include "locmap.h"
-#include "wintz.h"
+#include "wintzimpl.h"
 
 #   define WIN32_LEAN_AND_MEAN
 #   define VC_EXTRALEAN
@@ -39,7 +43,7 @@
 #   define NOMCX
 #   include <windows.h>
 
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
+#include <algorithm>
 
 static const char *getCalendarType(int32_t type)
 {
@@ -66,7 +70,7 @@ static const char *getCalendarType(int32_t type)
     }
 }
 
-void Win32DateTimeTest::testLocales(TestLog *log)
+void Win32DateTimeTest::testLocales(DateFormatTest *log)
 {
     SYSTEMTIME winNow;
     UDate icuNow = 0;
@@ -76,7 +80,6 @@ void Win32DateTimeTest::testLocales(TestLog *log)
     const TimeZone *tz = TimeZone::createDefault();
     TIME_ZONE_INFORMATION tzi;
 
-    uprv_memset(&tzi, 0, sizeof(tzi));
     tz->getID(zoneID);
     if (! uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length())) {
         UBool found = FALSE;
@@ -85,7 +88,8 @@ void Win32DateTimeTest::testLocales(TestLog *log)
         for (int z = 0; z < ec; z += 1) {
             UnicodeString equiv = TimeZone::getEquivalentID(zoneID, z);
 
-            if (found = uprv_getWindowsTimeZoneInfo(&tzi, equiv.getBuffer(), equiv.length())) {
+            found = uprv_getWindowsTimeZoneInfo(&tzi, equiv.getBuffer(), equiv.length());
+            if (found) {
                 break;
             }
         }
@@ -112,17 +116,34 @@ void Win32DateTimeTest::testLocales(TestLog *log)
     for(int i = 0; i < lcidCount; i += 1) {
         UErrorCode status = U_ZERO_ERROR;
         WCHAR longDateFormat[81], longTimeFormat[81], wdBuffer[256], wtBuffer[256];
+        DWORD value = 0;
         int32_t calType = 0;
 
-               // NULL localeID means ICU didn't recognize this locale
-               if (lcidRecords[i].localeID == NULL) {
-                       continue;
-               }
+        // NULL localeID means ICU didn't recognize this locale
+        if (lcidRecords[i].localeID == NULL) {
+            continue;
+        }
+
+        // Some locales have had their names change over various OS releases; skip them in the test for now.
+        int32_t failingLocaleLCIDs[] = {
+            0x040a, /* es-ES_tradnl;es-ES-u-co-trad; */
+            0x048c, /* fa-AF;prs-AF;prs-Arab-AF; */
+            0x046b, /* qu-BO;quz-BO;quz-Latn-BO; */
+            0x086b, /* qu-EC;quz-EC;quz-Latn-EC; */
+            0x0c6b, /* qu-PE;quz-PE;quz-Latn-PE; */
+            0x0492  /* ckb-IQ;ku-Arab-IQ; */
+        };
+        bool skip = (std::find(std::begin(failingLocaleLCIDs), std::end(failingLocaleLCIDs), lcidRecords[i].lcid) != std::end(failingLocaleLCIDs));
+        if (skip && log->logKnownIssue("13119", "Windows '@compat=host' fails on down-level versions of the OS")) {
+            log->logln("ticket:13119 - Skipping LCID = 0x%04x", lcidRecords[i].lcid);
+            continue;
+        }
 
         GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_SLONGDATE,   longDateFormat, 81);
         GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_STIMEFORMAT, longTimeFormat, 81);
-        GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_RETURN_NUMBER|LOCALE_ICALENDARTYPE, (LPWSTR) calType, sizeof(int32_t));
+        GetLocaleInfoW(lcidRecords[i].lcid, LOCALE_RETURN_NUMBER|LOCALE_ICALENDARTYPE, (LPWSTR)&value, sizeof(value)/sizeof(WCHAR));
 
+        calType = value;
         char localeID[64];
 
         uprv_strcpy(localeID, lcidRecords[i].localeID);
@@ -132,8 +153,8 @@ void Win32DateTimeTest::testLocales(TestLog *log)
         Locale ulocale(localeID);
         int32_t wdLength, wtLength;
 
-        wdLength = GetDateFormatW(lcidRecords[i].lcid, DATE_LONGDATE, &winNow, NULL, wdBuffer, ARRAY_SIZE(wdBuffer));
-        wtLength = GetTimeFormatW(lcidRecords[i].lcid, 0, &winNow, NULL, wtBuffer, ARRAY_SIZE(wtBuffer));
+        wdLength = GetDateFormatW(lcidRecords[i].lcid, DATE_LONGDATE, &winNow, NULL, wdBuffer, UPRV_LENGTHOF(wdBuffer));
+        wtLength = GetTimeFormatW(lcidRecords[i].lcid, 0, &winNow, NULL, wtBuffer, UPRV_LENGTHOF(wtBuffer));
 
         if (uprv_strchr(localeID, '@') > 0) {
             uprv_strcat(localeID, ";");
@@ -152,33 +173,33 @@ void Win32DateTimeTest::testLocales(TestLog *log)
         wdf->format(icuNow, udBuffer);
         wtf->format(icuNow, utBuffer);
 
-        if (ubBuffer.indexOf(wdBuffer, wdLength - 1, 0) < 0) {
+        if (ubBuffer.indexOf((const UChar *)wdBuffer, wdLength - 1, 0) < 0) {
             UnicodeString baseName(wlocale.getBaseName());
-            UnicodeString expected(wdBuffer);
+            UnicodeString expected((const UChar *)wdBuffer);
 
             log->errln("DateTime format error for locale " + baseName + ": expected date \"" + expected +
                        "\" got \"" + ubBuffer + "\"");
         }
 
-        if (ubBuffer.indexOf(wtBuffer, wtLength - 1, 0) < 0) {
+        if (ubBuffer.indexOf((const UChar *)wtBuffer, wtLength - 1, 0) < 0) {
             UnicodeString baseName(wlocale.getBaseName());
-            UnicodeString expected(wtBuffer);
+            UnicodeString expected((const UChar *)wtBuffer);
 
             log->errln("DateTime format error for locale " + baseName + ": expected time \"" + expected +
                        "\" got \"" + ubBuffer + "\"");
         }
 
-        if (udBuffer.compare(wdBuffer) != 0) {
+        if (udBuffer.compare((const UChar *)wdBuffer) != 0) {
             UnicodeString baseName(wlocale.getBaseName());
-            UnicodeString expected(wdBuffer);
+            UnicodeString expected((const UChar *)wdBuffer);
 
             log->errln("Date format error for locale " + baseName + ": expected \"" + expected +
                        "\" got \"" + udBuffer + "\"");
         }
 
-        if (utBuffer.compare(wtBuffer) != 0) {
+        if (utBuffer.compare((const UChar *)wtBuffer) != 0) {
             UnicodeString baseName(wlocale.getBaseName());
-            UnicodeString expected(wtBuffer);
+            UnicodeString expected((const UChar *)wtBuffer);
 
             log->errln("Time format error for locale " + baseName + ": expected \"" + expected +
                        "\" got \"" + utBuffer + "\"");
@@ -194,4 +215,4 @@ void Win32DateTimeTest::testLocales(TestLog *log)
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
 
-#endif /* #ifdef U_WINDOWS */
+#endif /* U_PLATFORM_USES_ONLY_WIN32_API */