[MSVCRT_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / msvcrt / locale.c
index 9afda11..65bb74b 100644 (file)
@@ -25,6 +25,8 @@
 
 static BOOL (__cdecl *p__crtGetStringTypeW)(DWORD, DWORD, const wchar_t*, int, WORD*);
 static int (__cdecl *pmemcpy_s)(void *, size_t, void*, size_t);
+static int (__cdecl *p___mb_cur_max_func)(void);
+static int *(__cdecl *p__p___mb_cur_max)(void);
 void* __cdecl _Gettnames(void);
 
 static void init(void)
@@ -33,6 +35,8 @@ static void init(void)
 
     p__crtGetStringTypeW = (void*)GetProcAddress(hmod, "__crtGetStringTypeW");
     pmemcpy_s = (void*)GetProcAddress(hmod, "memcpy_s");
+    p___mb_cur_max_func = (void*)GetProcAddress(hmod, "___mb_cur_max_func");
+    p__p___mb_cur_max = (void*)GetProcAddress(hmod, "__p___mb_cur_max");
 }
 
 static void test_setlocale(void)
@@ -45,9 +49,6 @@ static void test_setlocale(void)
     ret = setlocale(20, "C");
     ok(ret == NULL, "ret = %s\n", ret);
 
-    ret = setlocale(LC_ALL, "");
-    ok(ret != NULL, "ret == NULL\n");
-
     ret = setlocale(LC_ALL, "C");
     ok(!strcmp(ret, "C"), "ret = %s\n", ret);
 
@@ -112,12 +113,14 @@ static void test_setlocale(void)
     ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
     if(ret)
         ok(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")
+        || !strcmp(ret, "Chinese (Simplified)_China.936")
         || broken(!strcmp(ret, "Chinese_Taiwan.950")), "ret = %s\n", ret);
 
     ret = setlocale(LC_ALL, "chinese-simplified");
     ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
     if(ret)
         ok(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")
+        || !strcmp(ret, "Chinese (Simplified)_China.936")
         || broken(!strcmp(ret, "Chinese_People's Republic of China.936"))
         || broken(!strcmp(ret, "Chinese_Taiwan.950")), "ret = %s\n", ret);
 
@@ -131,6 +134,7 @@ static void test_setlocale(void)
     ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
     if(ret)
         ok(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")
+        || !strcmp(ret, "Chinese (Simplified)_China.936")
         || broken(!strcmp(ret, "Chinese_People's Republic of China.936")), "ret = %s\n", ret);
 
     ret = setlocale(LC_ALL, "cht");
@@ -139,6 +143,18 @@ static void test_setlocale(void)
         ok(!strcmp(ret, "Chinese (Traditional)_Taiwan.950")
         || broken(!strcmp(ret, "Chinese_Taiwan.950")), "ret = %s\n", ret);
 
+    ret = setlocale(LC_ALL, "Chinese_China.936");
+todo_wine
+    ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
+    if(ret)
+    {
+todo_wine
+        ok(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")
+        || !strcmp(ret, "Chinese (Simplified)_China.936")
+        || broken(!strcmp(ret, "Chinese_People's Republic of China.936")), "ret = %s\n", ret);
+        trace("ret is %s\n", ret);
+    }
+
     ret = setlocale(LC_ALL, "csy");
     ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
     if(ret)
@@ -571,6 +587,27 @@ static void test_setlocale(void)
     ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
     if(ret)
         ok(!strcmp(ret, "English_United States.1252"), "ret = %s\n", ret);
+
+    ret = setlocale(LC_ALL, "English_United States.ACP");
+    ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
+    if(ret) {
+        strcpy(buf, "English_United States.");
+        GetLocaleInfoA(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT),
+                LOCALE_IDEFAULTANSICODEPAGE, buf+strlen(buf), 80);
+        ok(!strcmp(ret, buf), "ret = %s, expected %s\n", ret, buf);
+    }
+
+    ret = setlocale(LC_ALL, "English_United States.OCP");
+    ok(ret != NULL || broken (ret == NULL), "ret == NULL\n");
+    if(ret) {
+        strcpy(buf, "English_United States.");
+        GetLocaleInfoA(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT),
+                LOCALE_IDEFAULTCODEPAGE, buf+strlen(buf), 80);
+        ok(!strcmp(ret, buf), "ret = %s, expected %s\n", ret, buf);
+    }
+
+    ret = setlocale(LC_ALL, "English_United States.UTF8");
+    ok(ret == NULL, "ret != NULL\n");
 }
 
 static void test_crtGetStringTypeW(void)
@@ -618,7 +655,6 @@ static void test_crtGetStringTypeW(void)
     ok(!ret, "ret == TRUE\n");
 }
 
-#if ROSTESTS_91_IS_FIXED
 static void test__Gettnames(void)
 {
     struct {
@@ -629,6 +665,7 @@ static void test__Gettnames(void)
         char data[1];
     } *ret;
     int size;
+    char buf[64];
 
     if(!setlocale(LC_ALL, "english"))
         return;
@@ -639,9 +676,9 @@ static void test__Gettnames(void)
      * Unicode strings are only initialized on Windows 7
      */
     if(sizeof(void*) == 8)
-        ok(size==0x2c0 || broken(size==0x170), "strucure size: %x\n", size);
+        ok(size==0x2c0 || broken(size==0x170), "structure size: %x\n", size);
     else
-        ok(size==0x164 || broken(size==0xb8), "strucure size: %x\n", size);
+        ok(size==0x164 || broken(size==0xb8), "structure size: %x\n", size);
 
     ok(!strcmp(ret->str[0], "Sun"), "ret->str[0] = %s\n", ret->str[0]);
     ok(!strcmp(ret->str[1], "Mon"), "ret->str[1] = %s\n", ret->str[1]);
@@ -685,7 +722,10 @@ static void test__Gettnames(void)
     ok(!strcmp(ret->str[39], "PM"), "ret->str[39] = %s\n", ret->str[39]);
     ok(!strcmp(ret->str[40], "M/d/yyyy") || broken(!strcmp(ret->str[40], "M/d/yy"))/*NT*/,
             "ret->str[40] = %s\n", ret->str[40]);
-    ok(!strcmp(ret->str[41], "dddd, MMMM dd, yyyy"), "ret->str[41] = %s\n", ret->str[41]);
+    size = GetLocaleInfoA(MAKELCID(LANG_ENGLISH, SORT_DEFAULT),
+           LOCALE_SLONGDATE|LOCALE_NOUSEROVERRIDE, buf, sizeof(buf));
+    ok(size, "GetLocaleInfo failed: %x\n", GetLastError());
+    ok(!strcmp(ret->str[41], buf), "ret->str[41] = %s, expected %s\n", ret->str[41], buf);
     free(ret);
 
     if(!setlocale(LC_TIME, "german"))
@@ -738,7 +778,47 @@ static void test__Gettnames(void)
 
     setlocale(LC_ALL, "C");
 }
-#endif /* ROSTESTS_91_IS_FIXED */
+
+static void test___mb_cur_max_func(void)
+{
+    int mb_cur_max;
+
+    setlocale(LC_ALL, "C");
+
+    /* for newer Windows */
+    if(!p___mb_cur_max_func)
+        win_skip("Skipping ___mb_cur_max_func tests\n");
+    else {
+        mb_cur_max = p___mb_cur_max_func();
+        ok(mb_cur_max == 1, "mb_cur_max = %d, expected 1\n", mb_cur_max);
+
+        /* some old Windows don't set chinese */
+        if (!setlocale(LC_ALL, "chinese"))
+            win_skip("Skipping test with chinese locale\n");
+        else {
+            mb_cur_max = p___mb_cur_max_func();
+            ok(mb_cur_max == 2, "mb_cur_max = %d, expected 2\n", mb_cur_max);
+            setlocale(LC_ALL, "C");
+        }
+    }
+
+    /* for older Windows */
+    if (!p__p___mb_cur_max)
+        win_skip("Skipping __p___mb_cur_max tests\n");
+    else {
+        mb_cur_max = *p__p___mb_cur_max();
+        ok(mb_cur_max == 1, "mb_cur_max = %d, expected 1\n", mb_cur_max);
+
+        /* some old Windows don't set chinese */
+        if (!setlocale(LC_ALL, "chinese"))
+            win_skip("Skipping test with chinese locale\n");
+        else {
+            mb_cur_max = *p__p___mb_cur_max();
+            ok(mb_cur_max == 2, "mb_cur_max = %d, expected 2\n", mb_cur_max);
+            setlocale(LC_ALL, "C");
+        }
+    }
+}
 
 START_TEST(locale)
 {
@@ -746,7 +826,6 @@ START_TEST(locale)
 
     test_crtGetStringTypeW();
     test_setlocale();
-#if ROSTESTS_91_IS_FIXED
     test__Gettnames();
-#endif
+    test___mb_cur_max_func();
 }