Reimplement EnumTimeFormats, make it work for all available locales

Dmitry Timoshkov dmitry at baikal.ru
Thu Jul 28 00:01:04 CDT 2005


Hello,

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    - Reimplement EnumTimeFormats, make it work for all available locales.
    - Add a test for EnumTimeFormats

diff -up cvs/hq/wine/dlls/kernel/lcformat.c wine/dlls/kernel/lcformat.c
--- cvs/hq/wine/dlls/kernel/lcformat.c	2005-07-28 13:41:23.000000000 +0900
+++ wine/dlls/kernel/lcformat.c	2005-07-28 13:49:51.000000000 +0900
@@ -1685,82 +1685,61 @@ BOOL WINAPI EnumDateFormatsW(DATEFMT_ENU
 
 /**************************************************************************
  *              EnumTimeFormatsA	(KERNEL32.@)
+ *
+ * FIXME: MSDN mentions only LOCALE_USE_CP_ACP, should we handle
+ * LOCALE_NOUSEROVERRIDE here as well?
  */
-BOOL WINAPI EnumTimeFormatsA( TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags )
+BOOL WINAPI EnumTimeFormatsA(TIMEFMT_ENUMPROCA proc, LCID lcid, DWORD flags)
 {
-  LCID Loc = GetUserDefaultLCID();
-  if(!lpTimeFmtEnumProc)
+    char buf[256];
+
+    if (!proc)
     {
-      SetLastError(ERROR_INVALID_PARAMETER);
-      return FALSE;
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
     }
-  if(dwFlags)
+
+    switch (flags & ~LOCALE_USE_CP_ACP)
     {
-      FIXME("Unknown time format (%ld)\n", dwFlags);
+    case 0:
+        if (GetLocaleInfoA(lcid, LOCALE_STIMEFORMAT | (flags & LOCALE_USE_CP_ACP), buf, 256))
+            proc(buf);
+        break;
+
+    default:
+        FIXME("Unknown time format (%ld)\n", flags);
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
     }
-
-  switch( Loc )
- {
-   case 0x00000407:  /* (Loc,"de_DE") */
-   {
-    if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
-    return TRUE;
-   }
-
-   case 0x0000040c:  /* (Loc,"fr_FR") */
-   case 0x00000c0c:  /* (Loc,"fr_CA") */
-   {
-    if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
-    return TRUE;
-   }
-
-   case 0x00000809:  /* (Loc,"en_UK") */
-   case 0x00000c09:  /* (Loc,"en_AU") */
-   case 0x00001409:  /* (Loc,"en_NZ") */
-   case 0x00001809:  /* (Loc,"en_IE") */
-   {
-    if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
-    return TRUE;
-   }
-
-   case 0x00001c09:  /* (Loc,"en_ZA") */
-   case 0x00002809:  /* (Loc,"en_BZ") */
-   case 0x00002c09:  /* (Loc,"en_TT") */
-   {
-    if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
     return TRUE;
-   }
-
-   default:  /* default to US style "en_US" */
-   {
-    if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
-    if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
-    return TRUE;
-   }
- }
 }
 
 /**************************************************************************
  *              EnumTimeFormatsW	(KERNEL32.@)
  */
-BOOL WINAPI EnumTimeFormatsW( TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags )
+BOOL WINAPI EnumTimeFormatsW(TIMEFMT_ENUMPROCW proc, LCID lcid, DWORD flags)
 {
-  FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return FALSE;
+    WCHAR buf[256];
+
+    if (!proc)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    switch (flags & ~LOCALE_USE_CP_ACP)
+    {
+    case 0:
+        if (GetLocaleInfoW(lcid, LOCALE_STIMEFORMAT | (flags & LOCALE_USE_CP_ACP), buf, 256))
+            proc(buf);
+        break;
+
+    default:
+        FIXME("Unknown time format (%ld)\n", flags);
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+    return TRUE;
 }
 
 /******************************************************************************
diff -up cvs/hq/wine/dlls/kernel/tests/locale.c wine/dlls/kernel/tests/locale.c
--- cvs/hq/wine/dlls/kernel/tests/locale.c	2005-07-28 13:41:23.000000000 +0900
+++ wine/dlls/kernel/tests/locale.c	2005-07-28 13:54:14.000000000 +0900
@@ -51,7 +51,7 @@ static inline int strncmpW( const WCHAR 
 
 static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
 {
-    for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
+    do { if (*str == ch) return (WCHAR *)str; } while (*str++);
     return NULL;
 }
 
@@ -104,7 +104,6 @@ static void InitFunctionPointers(void)
            (label), (received), (expected))
 
 #define BUFFER_SIZE    128
-static char GlobalBuffer[BUFFER_SIZE]; /* Buffer used by callback function */
 #define COUNTOF(x) (sizeof(x)/sizeof(x)[0])
 
 #define EXPECT_LEN(len) ok(ret == (len), "Expected Len %d, got %d\n", (len), ret)
@@ -748,27 +747,6 @@ static void test_GetNumberFormatA(void)
 }
 
 
-/* Callback function used by TestEnumTimeFormats */
-static BOOL CALLBACK EnumTimeFormatsProc(char * lpTimeFormatString)
-{
-  trace("%s\n", lpTimeFormatString);
-  strcpy(GlobalBuffer, lpTimeFormatString);
-#if 0
-  return TRUE;
-#endif
-  return FALSE;
-}
-
-static void test_EnumTimeFormats(void)
-{
-  int ret;
-  LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
-
-  GlobalBuffer[0] = '\0';
-  ret = EnumTimeFormatsA(EnumTimeFormatsProc, lcid, 0);
-  ok (ret == 1 && !strcmp(GlobalBuffer,"h:mm:ss tt"), "Expected %d '%s'\n", ret, GlobalBuffer);
-}
-
 static void test_CompareStringA(void)
 {
   int ret;
@@ -2096,7 +2074,7 @@ static void test_EnumUILanguageA(void)
 
 static char date_fmt_buf[1024];
 
-static BOOL CALLBACK enum_datefmt_procA(LPSTR fmt)
+static BOOL CALLBACK enum_datetime_procA(LPSTR fmt)
 {
     lstrcatA(date_fmt_buf, fmt);
     lstrcatA(date_fmt_buf, "\n");
@@ -2111,7 +2089,7 @@ static void test_EnumDateFormatsA(void)
 
     trace("EnumDateFormatsA 0\n");
     date_fmt_buf[0] = 0;
-    ret = EnumDateFormatsA(enum_datefmt_procA, lcid, 0);
+    ret = EnumDateFormatsA(enum_datetime_procA, lcid, 0);
     ok(ret, "EnumDateFormatsA(0) error %ld\n", GetLastError());
     trace("%s\n", date_fmt_buf);
     /* test the 1st enumerated format */
@@ -2122,7 +2100,7 @@ static void test_EnumDateFormatsA(void)
 
     trace("EnumDateFormatsA LOCALE_USE_CP_ACP\n");
     date_fmt_buf[0] = 0;
-    ret = EnumDateFormatsA(enum_datefmt_procA, lcid, LOCALE_USE_CP_ACP);
+    ret = EnumDateFormatsA(enum_datetime_procA, lcid, LOCALE_USE_CP_ACP);
     ok(ret, "EnumDateFormatsA(LOCALE_USE_CP_ACP) error %ld\n", GetLastError());
     trace("%s\n", date_fmt_buf);
     /* test the 1st enumerated format */
@@ -2133,7 +2111,7 @@ static void test_EnumDateFormatsA(void)
 
     trace("EnumDateFormatsA DATE_SHORTDATE\n");
     date_fmt_buf[0] = 0;
-    ret = EnumDateFormatsA(enum_datefmt_procA, lcid, DATE_SHORTDATE);
+    ret = EnumDateFormatsA(enum_datetime_procA, lcid, DATE_SHORTDATE);
     ok(ret, "EnumDateFormatsA(DATE_SHORTDATE) error %ld\n", GetLastError());
     trace("%s\n", date_fmt_buf);
     /* test the 1st enumerated format */
@@ -2144,7 +2122,7 @@ static void test_EnumDateFormatsA(void)
 
     trace("EnumDateFormatsA DATE_LONGDATE\n");
     date_fmt_buf[0] = 0;
-    ret = EnumDateFormatsA(enum_datefmt_procA, lcid, DATE_LONGDATE);
+    ret = EnumDateFormatsA(enum_datetime_procA, lcid, DATE_LONGDATE);
     ok(ret, "EnumDateFormatsA(DATE_LONGDATE) error %ld\n", GetLastError());
     trace("%s\n", date_fmt_buf);
     /* test the 1st enumerated format */
@@ -2155,7 +2133,7 @@ static void test_EnumDateFormatsA(void)
 
     trace("EnumDateFormatsA DATE_YEARMONTH\n");
     date_fmt_buf[0] = 0;
-    ret = EnumDateFormatsA(enum_datefmt_procA, lcid, DATE_YEARMONTH);
+    ret = EnumDateFormatsA(enum_datetime_procA, lcid, DATE_YEARMONTH);
     ok(ret, "EnumDateFormatsA(DATE_YEARMONTH) error %ld\n", GetLastError());
     trace("%s\n", date_fmt_buf);
     /* test the 1st enumerated format */
@@ -2165,11 +2143,40 @@ static void test_EnumDateFormatsA(void)
     ok(!lstrcmpA(date_fmt_buf, buf), "expected \"%s\" got \"%s\"\n", date_fmt_buf, buf);
 }
 
+static void test_EnumTimeFormatsA(void)
+{
+    char *p, buf[256];
+    BOOL ret;
+    LCID lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
+
+    trace("EnumTimeFormatsA 0\n");
+    date_fmt_buf[0] = 0;
+    ret = EnumTimeFormatsA(enum_datetime_procA, lcid, 0);
+    ok(ret, "EnumTimeFormatsA(0) error %ld\n", GetLastError());
+    trace("%s\n", date_fmt_buf);
+    /* test the 1st enumerated format */
+    if ((p = strchr(date_fmt_buf, '\n'))) *p = 0;
+    ret = GetLocaleInfoA(lcid, LOCALE_STIMEFORMAT, buf, sizeof(buf));
+    ok(ret, "GetLocaleInfoA(LOCALE_STIMEFORMAT) error %ld\n", GetLastError());
+    ok(!lstrcmpA(date_fmt_buf, buf), "expected \"%s\" got \"%s\"\n", date_fmt_buf, buf);
+
+    trace("EnumTimeFormatsA LOCALE_USE_CP_ACP\n");
+    date_fmt_buf[0] = 0;
+    ret = EnumTimeFormatsA(enum_datetime_procA, lcid, LOCALE_USE_CP_ACP);
+    ok(ret, "EnumTimeFormatsA(LOCALE_USE_CP_ACP) error %ld\n", GetLastError());
+    trace("%s\n", date_fmt_buf);
+    /* test the 1st enumerated format */
+    if ((p = strchr(date_fmt_buf, '\n'))) *p = 0;
+    ret = GetLocaleInfoA(lcid, LOCALE_STIMEFORMAT, buf, sizeof(buf));
+    ok(ret, "GetLocaleInfoA(LOCALE_STIMEFORMAT) error %ld\n", GetLastError());
+    ok(!lstrcmpA(date_fmt_buf, buf), "expected \"%s\" got \"%s\"\n", date_fmt_buf, buf);
+}
+
 START_TEST(locale)
 {
   InitFunctionPointers();
 
-  if (0) test_EnumTimeFormats();
+  test_EnumTimeFormatsA();
   test_EnumDateFormatsA();
 
   test_GetLocaleInfoA();






More information about the wine-patches mailing list