msvcrt: Change strtod_l implementation.
[wine] / dlls / msvcrt / tests / locale.c
1 /*
2  * Unit test suite for locale functions.
3  *
4  * Copyright 2010 Piotr Caban for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <locale.h>
22
23 #include "wine/test.h"
24 #include "winnls.h"
25
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);
28
29 static void init(void)
30 {
31     HMODULE hmod = GetModuleHandleA("msvcrt.dll");
32
33     p__crtGetStringTypeW = (void*)GetProcAddress(hmod, "__crtGetStringTypeW");
34     pmemcpy_s = (void*)GetProcAddress(hmod, "memcpy_s");
35 }
36
37 static void test_setlocale(void)
38 {
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";
41
42     char *ret, buf[100];
43
44     ret = setlocale(20, "C");
45     ok(ret == NULL, "ret = %s\n", ret);
46
47     ret = setlocale(LC_ALL, "");
48     ok(ret != NULL, "ret == NULL\n");
49
50     ret = setlocale(LC_ALL, "C");
51     ok(!strcmp(ret, "C"), "ret = %s\n", ret);
52
53     ret = setlocale(LC_ALL, NULL);
54     ok(!strcmp(ret, "C"), "ret = %s\n", ret);
55
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;
62     }
63
64     ret = setlocale(LC_NUMERIC, "Polish");
65     ok(!strcmp(ret, "Polish_Poland.1250"), "ret = %s\n", ret);
66
67     ret = setlocale(LC_MONETARY, "Greek");
68     ok(!strcmp(ret, "Greek_Greece.1253"), "ret = %s\n", ret);
69
70     ret = setlocale(LC_ALL, NULL);
71     ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
72
73     strcpy(buf, ret);
74     ret = setlocale(LC_ALL, buf);
75     ok(!strcmp(ret, lc_all), "ret = %s\n", ret);
76
77     ret = setlocale(LC_ALL, "German");
78     todo_wine ok(!strcmp(ret, "German_Germany.1252"), "ret = %s\n", ret);
79
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);
84
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);
89 }
90
91 static void test_crtGetStringTypeW(void)
92 {
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' };
98
99     const wchar_t *str[] = { str0, strA, str_space, str_null, str_rand };
100
101     WORD out_crt, out;
102     BOOL ret_crt, ret;
103     int i;
104
105     if(!p__crtGetStringTypeW) {
106         win_skip("Skipping __crtGetStringTypeW tests\n");
107         return;
108     }
109
110     if(!pmemcpy_s) {
111         win_skip("To old version of msvcrt.dll\n");
112         return;
113     }
114
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);
120
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);
125
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);
130     }
131
132     ret = p__crtGetStringTypeW(0, 3, str[0], 1, &out);
133     ok(!ret, "ret == TRUE\n");
134 }
135
136 START_TEST(locale)
137 {
138     init();
139
140     test_crtGetStringTypeW();
141     test_setlocale();
142 }