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
30 #include "wine/test.h"
34 typedef void (*vtable_ptr
)(void);
37 const vtable_ptr
*vtable
;
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)
65 module
= LoadLibraryA("msvcr110.dll");
68 win_skip("msvcr110.dll not installed\n");
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");
87 SET(p_Context_CurrentContext
, "?CurrentContext@Context@Concurrency@@SAPAV12@XZ");
90 SET(p_strcmp
, "strcmp");
91 SET(p_strncmp
, "strncmp");
96 static void test_CurrentScheduler(void)
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
);
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)
129 static const char *names
[] =
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
);
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");
157 || broken(ret
== NULL
)), /* Vista */
158 "expected success, but got NULL\n");
160 ok(!strcmp(ret
, "zh-Hans"), "setlocale zh-Hans failed\n");
162 ret
= p_setlocale(LC_ALL
, "zh-Hant");
164 || broken(ret
== NULL
)), /* Vista */
165 "expected success, but got NULL\n");
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");
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");
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");
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");
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");
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");
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");
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");
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)
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)
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
);
313 test_CurrentScheduler(); /* MUST be first (at least among Concurrency tests) */
316 test_CurrentContext();