msvcrt/tests: Added __crtGetStringTypeW tests.
[wine.git] / dlls / msvcrt / tests / locale.c
blob45ab9b750f0cbd3a5c1997bcee42f5f163e0a8b6
1 /*
2 * Unit test suite for locale functions.
4 * Copyright 2010 Piotr Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <locale.h>
23 #include "wine/test.h"
24 #include "winnls.h"
26 static BOOL (__cdecl *p__crtGetStringTypeW)(DWORD, DWORD, const wchar_t*, int, WORD*);
27 static int (__cdecl *pmemcpy_s)(void *, size_t, void*, size_t);
29 static void init(void)
31 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
33 p__crtGetStringTypeW = (void*)GetProcAddress(hmod, "__crtGetStringTypeW");
34 pmemcpy_s = (void*)GetProcAddress(hmod, "memcpy_s");
37 static void test_setlocale(void)
39 static const char lc_all[] = "LC_COLLATE=C;LC_CTYPE=C;"
40 "LC_MONETARY=Greek_Greece.1253;LC_NUMERIC=Polish_Poland.1250;LC_TIME=C";
42 char *ret, buf[100];
44 ret = setlocale(20, "C");
45 ok(ret == NULL, "ret = %s\n", ret);
47 ret = setlocale(LC_ALL, "");
48 ok(ret != NULL, "ret == NULL\n");
50 ret = setlocale(LC_ALL, "C");
51 ok(!strcmp(ret, "C"), "ret = %s\n", ret);
53 ret = setlocale(LC_ALL, NULL);
54 todo_wine ok(!strcmp(ret, "C"), "ret = %s\n", ret);
56 if(!setlocale(LC_NUMERIC, "Polish")
57 || !setlocale(LC_NUMERIC, "Greek")
58 || !setlocale(LC_NUMERIC, "German")
59 || !setlocale(LC_NUMERIC, "English")) {
60 win_skip("System with limited locales\n");
61 return;
64 ret = setlocale(LC_NUMERIC, "Polish");
65 ok(!strcmp(ret, "Polish_Poland.1250"), "ret = %s\n", ret);
67 ret = setlocale(LC_MONETARY, "Greek");
68 ok(!strcmp(ret, "Greek_Greece.1253"), "ret = %s\n", ret);
70 ret = setlocale(LC_ALL, NULL);
71 ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
73 strcpy(buf, ret);
74 ret = setlocale(LC_ALL, buf);
75 todo_wine ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
77 ret = setlocale(LC_ALL, "German");
78 todo_wine ok(!strcmp(ret, "German_Germany.1252"), "ret = %s\n", ret);
80 /* This test shows that _country_synonims table is incorrect */
81 /* It translates "America" to "US" */
82 ret = setlocale(LC_ALL, "America");
83 ok(ret == NULL, "ret = %s\n", ret);
85 ret = setlocale(LC_ALL, "US");
86 todo_wine ok(ret != NULL, "ret == NULL\n");
87 if(ret)
88 ok(!strcmp(ret, "English_United States.1252"), "ret = %s\n", ret);
91 static void test_crtGetStringTypeW(void)
93 static const wchar_t str0[] = { '0', '\0' };
94 static const wchar_t strA[] = { 'A', '\0' };
95 static const wchar_t str_space[] = { ' ', '\0' };
96 static const wchar_t str_null[] = { '\0', '\0' };
97 static const wchar_t str_rand[] = { 1234, '\0' };
99 const wchar_t *str[] = { str0, strA, str_space, str_null, str_rand };
101 WORD out_crt, out;
102 BOOL ret_crt, ret;
103 int i;
105 if(!p__crtGetStringTypeW) {
106 win_skip("Skipping __crtGetStringTypeW tests\n");
107 return;
110 if(!pmemcpy_s) {
111 win_skip("To old version of msvcrt.dll\n");
112 return;
115 for(i=0; i<sizeof(str)/sizeof(*str); i++) {
116 ret_crt = p__crtGetStringTypeW(0, CT_CTYPE1, str[i], 1, &out_crt);
117 ret = GetStringTypeW(CT_CTYPE1, str[i], 1, &out);
118 ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
119 ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);
121 ret_crt = p__crtGetStringTypeW(0, CT_CTYPE2, str[i], 1, &out_crt);
122 ret = GetStringTypeW(CT_CTYPE2, str[i], 1, &out);
123 ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
124 ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);
126 ret_crt = p__crtGetStringTypeW(0, CT_CTYPE3, str[i], 1, &out_crt);
127 ret = GetStringTypeW(CT_CTYPE3, str[i], 1, &out);
128 ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
129 ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);
132 ret = p__crtGetStringTypeW(0, 3, str[0], 1, &out);
133 ok(!ret, "ret == TRUE\n");
136 START_TEST(locale)
138 init();
140 test_crtGetStringTypeW();
141 test_setlocale();