mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / msvcr110 / tests / msvcr110.c
blobf88e3122ac9e0d97e2db69863dc53f402f7f4ab6
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 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y)
56 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
58 static BOOL init(void)
60 HMODULE module;
62 module = LoadLibraryA("msvcr110.dll");
63 if (!module)
65 win_skip("msvcr110.dll not installed\n");
66 return FALSE;
69 SET(p_setlocale, "setlocale");
70 SET(p___strncnt, "__strncnt");
71 SET(p_CurrentScheduler_GetNumberOfVirtualProcessors, "?GetNumberOfVirtualProcessors@CurrentScheduler@Concurrency@@SAIXZ");
72 SET(p__CurrentScheduler__GetNumberOfVirtualProcessors, "?_GetNumberOfVirtualProcessors@_CurrentScheduler@details@Concurrency@@SAIXZ");
73 SET(p_CurrentScheduler_Id, "?Id@CurrentScheduler@Concurrency@@SAIXZ");
74 SET(p__CurrentScheduler__Id, "?_Id@_CurrentScheduler@details@Concurrency@@SAIXZ");
76 SET(p__Context__CurrentContext, "?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ");
78 if(sizeof(void*) == 8)
80 SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPEAV12@XZ");
82 else
84 SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPAV12@XZ");
87 return TRUE;
90 static void test_CurrentScheduler(void)
92 unsigned int id;
93 unsigned int ncpus;
94 unsigned int expect;
95 SYSTEM_INFO si;
97 expect = ~0;
98 ncpus = p_CurrentScheduler_GetNumberOfVirtualProcessors();
99 ok(ncpus == expect, "expected %x, got %x\n", expect, ncpus);
100 id = p_CurrentScheduler_Id();
101 ok(id == expect, "expected %u, got %u\n", expect, id);
103 GetSystemInfo(&si);
104 expect = si.dwNumberOfProcessors;
105 /* these _CurrentScheduler calls trigger scheduler creation
106 if either is commented out, the following CurrentScheduler (no _) tests will still work */
107 ncpus = p__CurrentScheduler__GetNumberOfVirtualProcessors();
108 id = p__CurrentScheduler__Id();
109 ok(ncpus == expect, "expected %u, got %u\n", expect, ncpus);
110 ok(id == 0, "expected 0, got %u\n", id);
112 /* these CurrentScheduler tests assume scheduler is created */
113 ncpus = p_CurrentScheduler_GetNumberOfVirtualProcessors();
114 ok(ncpus == expect, "expected %u, got %u\n", expect, ncpus);
115 id = p_CurrentScheduler_Id();
116 ok(id == 0, "expected 0, got %u\n", id);
119 static void test_setlocale(void)
121 int i;
122 char *ret;
123 static const char *names[] =
125 "en-us",
126 "en-US",
127 "EN-US",
128 "syr-SY",
129 "uz-Latn-uz",
132 for(i=0; i<ARRAY_SIZE(names); i++) {
133 ret = p_setlocale(LC_ALL, names[i]);
134 ok(ret != NULL, "expected success, but got NULL\n");
135 ok(!strcmp(ret, names[i]), "expected %s, got %s\n", names[i], ret);
138 ret = p_setlocale(LC_ALL, "en-us.1250");
139 ok(!ret, "setlocale(en-us.1250) succeeded (%s)\n", ret);
141 p_setlocale(LC_ALL, "C");
144 static void test___strncnt(void)
146 static const struct
148 const char *str;
149 size_t size;
150 size_t ret;
152 strncnt_tests[] =
154 { NULL, 0, 0 },
155 { "a", 0, 0 },
156 { "a", 1, 1 },
157 { "a", 10, 1 },
158 { "abc", 1, 1 },
160 unsigned int i;
161 size_t ret;
163 if (0) /* crashes */
164 ret = p___strncnt(NULL, 1);
166 for (i = 0; i < ARRAY_SIZE(strncnt_tests); ++i)
168 ret = p___strncnt(strncnt_tests[i].str, strncnt_tests[i].size);
169 ok(ret == strncnt_tests[i].ret, "%u: unexpected return value %u.\n", i, (int)ret);
173 static void test_CurrentContext(void)
175 _Context _ctx, *ret;
176 Context *ctx;
178 ctx = p_Context_CurrentContext();
179 ok(!!ctx, "got NULL\n");
181 memset(&_ctx, 0xcc, sizeof(_ctx));
182 ret = p__Context__CurrentContext(&_ctx);
183 ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx);
184 ok(ret == &_ctx, "expected %p, got %p\n", &_ctx, ret);
187 START_TEST(msvcr110)
189 if (!init()) return;
190 test_CurrentScheduler(); /* MUST be first (at least among Concurrency tests) */
191 test_setlocale();
192 test___strncnt();
193 test_CurrentContext();