dmstyle: Rewrite style pref chunk parsing.
[wine.git] / dlls / msvcr110 / tests / msvcr110.c
blob35ba370bb499e5a0a3168486e8a5198bf8ce4f23
1 /*
2 * Copyright 2018 Daniel Lehman
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <wchar.h>
23 #include <stdio.h>
24 #include <float.h>
25 #include <limits.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winnls.h>
30 #include "wine/test.h"
32 #include <locale.h>
34 typedef void (*vtable_ptr)(void);
36 typedef struct {
37 const vtable_ptr *vtable;
38 } Context;
40 typedef struct {
41 Context *ctx;
42 } _Context;
44 static char* (CDECL *p_setlocale)(int category, const char* locale);
45 static size_t (CDECL *p___strncnt)(const char *str, size_t count);
47 static unsigned int (CDECL *p_CurrentScheduler_GetNumberOfVirtualProcessors)(void);
48 static unsigned int (CDECL *p__CurrentScheduler__GetNumberOfVirtualProcessors)(void);
49 static unsigned int (CDECL *p_CurrentScheduler_Id)(void);
50 static unsigned int (CDECL *p__CurrentScheduler__Id)(void);
52 static Context* (__cdecl *p_Context_CurrentContext)(void);
53 static _Context* (__cdecl *p__Context__CurrentContext)(_Context*);
55 static int (__cdecl *p_strcmp)(const char *, const char *);
56 static int (__cdecl *p_strncmp)(const char *, const char *, size_t);
58 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y)
59 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
61 static BOOL init(void)
63 HMODULE module;
65 module = LoadLibraryA("msvcr110.dll");
66 if (!module)
68 win_skip("msvcr110.dll not installed\n");
69 return FALSE;
72 SET(p_setlocale, "setlocale");
73 SET(p___strncnt, "__strncnt");
74 SET(p_CurrentScheduler_GetNumberOfVirtualProcessors, "?GetNumberOfVirtualProcessors@CurrentScheduler@Concurrency@@SAIXZ");
75 SET(p__CurrentScheduler__GetNumberOfVirtualProcessors, "?_GetNumberOfVirtualProcessors@_CurrentScheduler@details@Concurrency@@SAIXZ");
76 SET(p_CurrentScheduler_Id, "?Id@CurrentScheduler@Concurrency@@SAIXZ");
77 SET(p__CurrentScheduler__Id, "?_Id@_CurrentScheduler@details@Concurrency@@SAIXZ");
79 SET(p__Context__CurrentContext, "?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ");
81 if(sizeof(void*) == 8)
83 SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPEAV12@XZ");
85 else
87 SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPAV12@XZ");
90 SET(p_strcmp, "strcmp");
91 SET(p_strncmp, "strncmp");
93 return TRUE;
96 static void test_CurrentScheduler(void)
98 unsigned int id;
99 unsigned int ncpus;
100 unsigned int expect;
101 SYSTEM_INFO si;
103 expect = ~0;
104 ncpus = p_CurrentScheduler_GetNumberOfVirtualProcessors();
105 ok(ncpus == expect, "expected %x, got %x\n", expect, ncpus);
106 id = p_CurrentScheduler_Id();
107 ok(id == expect, "expected %u, got %u\n", expect, id);
109 GetSystemInfo(&si);
110 expect = si.dwNumberOfProcessors;
111 /* these _CurrentScheduler calls trigger scheduler creation
112 if either is commented out, the following CurrentScheduler (no _) tests will still work */
113 ncpus = p__CurrentScheduler__GetNumberOfVirtualProcessors();
114 id = p__CurrentScheduler__Id();
115 ok(ncpus == expect, "expected %u, got %u\n", expect, ncpus);
116 ok(id == 0, "expected 0, got %u\n", id);
118 /* these CurrentScheduler tests assume scheduler is created */
119 ncpus = p_CurrentScheduler_GetNumberOfVirtualProcessors();
120 ok(ncpus == expect, "expected %u, got %u\n", expect, ncpus);
121 id = p_CurrentScheduler_Id();
122 ok(id == 0, "expected 0, got %u\n", id);
125 static void test_setlocale(void)
127 int i;
128 char *ret;
129 static const char *names[] =
131 "en-us",
132 "en-US",
133 "EN-US",
134 "syr-SY",
135 "uz-Latn-uz",
138 for(i=0; i<ARRAY_SIZE(names); i++) {
139 ret = p_setlocale(LC_ALL, names[i]);
140 ok(ret != NULL, "expected success, but got NULL\n");
141 if(!strcmp(names[i], "syr-SY") && GetACP() == CP_UTF8)
143 ok(!strcmp(ret, "LC_COLLATE=syr-SY;LC_CTYPE=EN-US;LC_MONETARY=syr-SY;"
144 "LC_NUMERIC=syr-SY;LC_TIME=syr-SY"), "got %s\n", ret);
146 else
148 ok(!strcmp(ret, names[i]), "expected %s, got %s\n", names[i], ret);
152 ret = p_setlocale(LC_ALL, "en-us.1250");
153 ok(!ret, "setlocale(en-us.1250) succeeded (%s)\n", ret);
155 ret = p_setlocale(LC_ALL, "zh-Hans");
156 ok((ret != NULL
157 || broken(ret == NULL)), /* Vista */
158 "expected success, but got NULL\n");
159 if (ret)
160 ok(!strcmp(ret, "zh-Hans"), "setlocale zh-Hans failed\n");
162 ret = p_setlocale(LC_ALL, "zh-Hant");
163 ok((ret != NULL
164 || broken(ret == NULL)), /* Vista */
165 "expected success, but got NULL\n");
166 if (ret)
167 ok(!strcmp(ret, "zh-Hant"), "setlocale zh-Hant failed\n");
169 /* used to return Chinese (Simplified)_China.936 */
170 ret = p_setlocale(LC_ALL, "chinese");
171 ok(ret != NULL, "expected success, but got NULL\n");
172 if (ret)
173 ok((!strcmp(ret, "Chinese_China.936")
174 || broken(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")) /* Vista */
175 || broken(!strcmp(ret, "Chinese_People's Republic of China.936"))), /* 7 */
176 "setlocale chinese failed, got %s\n", ret);
178 /* used to return Chinese (Simplified)_China.936 */
179 ret = p_setlocale(LC_ALL, "Chinese_China.936");
180 ok(ret != NULL, "expected success, but got NULL\n");
181 if (ret)
182 ok((!strcmp(ret, "Chinese_China.936")
183 || broken(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936")) /* Vista */
184 || broken(!strcmp(ret, "Chinese_People's Republic of China.936"))), /* 7 */
185 "setlocale Chinese_China.936 failed, got %s\n", ret);
187 /* used to return Chinese (Simplified)_China.936 */
188 ret = p_setlocale(LC_ALL, "chinese-simplified");
189 ok(ret != NULL, "expected success, but got NULL\n");
190 if (ret)
191 ok((!strcmp(ret, "Chinese_China.936")
192 || broken(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936"))), /* Vista */
193 "setlocale chinese-simplified failed, got %s\n", ret);
195 /* used to return Chinese (Simplified)_China.936 */
196 ret = p_setlocale(LC_ALL, "chs");
197 ok(ret != NULL, "expected success, but got NULL\n");
198 if (ret)
199 ok((!strcmp(ret, "Chinese_China.936")
200 || broken(!strcmp(ret, "Chinese (Simplified)_People's Republic of China.936"))), /* Vista */
201 "setlocale chs failed, got %s\n", ret);
203 /* used to return Chinese (Traditional)_Taiwan.950 */
204 ret = p_setlocale(LC_ALL, "cht");
205 ok(ret != NULL, "expected success, but got NULL\n");
206 if (ret)
207 todo_wine ok((!strcmp(ret, "Chinese (Traditional)_Hong Kong SAR.950")
208 || broken(!strcmp(ret, "Chinese (Traditional)_Taiwan.950"))), /* Vista - 7 */
209 "setlocale cht failed, got %s\n", ret);
211 /* used to return Chinese (Traditional)_Taiwan.950 */
212 ret = p_setlocale(LC_ALL, "chinese-traditional");
213 ok(ret != NULL, "expected success, but got NULL\n");
214 if (ret)
215 todo_wine ok((!strcmp(ret, "Chinese (Traditional)_Hong Kong SAR.950")
216 || broken(!strcmp(ret, "Chinese (Traditional)_Taiwan.950"))), /* Vista - 7 */
217 "setlocale chinese-traditional failed, got %s\n", ret);
219 ret = p_setlocale(LC_ALL, "norwegian-nynorsk");
220 ok(ret != NULL, "expected success, but got NULL\n");
221 if (ret)
222 ok((!strcmp(ret, "Norwegian Nynorsk_Norway.1252")
223 || broken(!strcmp(ret, "Norwegian (Nynorsk)_Norway.1252"))), /* Vista - 7 */
224 "setlocale norwegian-nynorsk failed, got %s\n", ret);
226 ret = p_setlocale(LC_ALL, "non");
227 ok(ret != NULL, "expected success, but got NULL\n");
228 if (ret)
229 ok((!strcmp(ret, "Norwegian Nynorsk_Norway.1252")
230 || broken(!strcmp(ret, "Norwegian (Nynorsk)_Norway.1252"))), /* Vista - 7 */
231 "setlocale norwegian-nynorsk failed, got %s\n", ret);
233 p_setlocale(LC_ALL, "C");
236 static void test___strncnt(void)
238 static const struct
240 const char *str;
241 size_t size;
242 size_t ret;
244 strncnt_tests[] =
246 { NULL, 0, 0 },
247 { "a", 0, 0 },
248 { "a", 1, 1 },
249 { "a", 10, 1 },
250 { "abc", 1, 1 },
252 unsigned int i;
253 size_t ret;
255 if (0) /* crashes */
256 ret = p___strncnt(NULL, 1);
258 for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i)
260 ret = p___strncnt(strncnt_tests[i].str, strncnt_tests[i].size);
261 ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret);
265 static void test_CurrentContext(void)
267 _Context _ctx, *ret;
268 Context *ctx;
270 ctx = p_Context_CurrentContext();
271 ok(!!ctx, "got NULL\n");
273 memset(&_ctx, 0xcc, sizeof(_ctx));
274 ret = p__Context__CurrentContext(&_ctx);
275 ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx);
276 ok(ret == &_ctx, "expected %p, got %p\n", &_ctx, ret);
279 static void test_strcmp(void)
281 int ret = p_strcmp( "abc", "abcd" );
282 ok( ret == -1, "wrong ret %d\n", ret );
283 ret = p_strcmp( "", "abc" );
284 ok( ret == -1, "wrong ret %d\n", ret );
285 ret = p_strcmp( "abc", "ab\xa0" );
286 ok( ret == -1, "wrong ret %d\n", ret );
287 ret = p_strcmp( "ab\xb0", "ab\xa0" );
288 ok( ret == 1, "wrong ret %d\n", ret );
289 ret = p_strcmp( "ab\xc2", "ab\xc2" );
290 ok( ret == 0, "wrong ret %d\n", ret );
292 ret = p_strncmp( "abc", "abcd", 3 );
293 ok( ret == 0, "wrong ret %d\n", ret );
294 ret = p_strncmp( "", "abc", 3 );
295 ok( ret == -1, "wrong ret %d\n", ret );
296 ret = p_strncmp( "abc", "ab\xa0", 4 );
297 ok( ret == -1, "wrong ret %d\n", ret );
298 ret = p_strncmp( "ab\xb0", "ab\xa0", 3 );
299 ok( ret == 1, "wrong ret %d\n", ret );
300 ret = p_strncmp( "ab\xb0", "ab\xa0", 2 );
301 ok( ret == 0, "wrong ret %d\n", ret );
302 ret = p_strncmp( "ab\xc2", "ab\xc2", 3 );
303 ok( ret == 0, "wrong ret %d\n", ret );
304 ret = p_strncmp( "abc", "abd", 0 );
305 ok( ret == 0, "wrong ret %d\n", ret );
306 ret = p_strncmp( "abc", "abc", 12 );
307 ok( ret == 0, "wrong ret %d\n", ret );
310 START_TEST(msvcr110)
312 if (!init()) return;
313 test_CurrentScheduler(); /* MUST be first (at least among Concurrency tests) */
314 test_setlocale();
315 test___strncnt();
316 test_CurrentContext();
317 test_strcmp();