msvcrt: Added _fread_nolock_s implementation.
[wine/multimedia.git] / dlls / msvcr100 / tests / msvcr100.c
blob4c66ed57bb5589cbadb40a9821e4d2b77e30c075
1 /*
2 * Copyright 2012 Dan Kegel
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>
25 #include <windef.h>
26 #include <winbase.h>
27 #include "wine/test.h"
29 #define DEFINE_EXPECT(func) \
30 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
32 #define SET_EXPECT(func) \
33 expect_ ## func = TRUE
35 #define CHECK_EXPECT2(func) \
36 do { \
37 ok(expect_ ##func, "unexpected call " #func "\n"); \
38 called_ ## func = TRUE; \
39 }while(0)
41 #define CHECK_EXPECT(func) \
42 do { \
43 CHECK_EXPECT2(func); \
44 expect_ ## func = FALSE; \
45 }while(0)
47 #define CHECK_CALLED(func) \
48 do { \
49 ok(called_ ## func, "expected " #func "\n"); \
50 expect_ ## func = called_ ## func = FALSE; \
51 }while(0)
53 DEFINE_EXPECT(invalid_parameter_handler);
54 DEFINE_EXPECT(yield_func);
56 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
58 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
59 const wchar_t *function, const wchar_t *file,
60 unsigned line, uintptr_t arg)
62 CHECK_EXPECT(invalid_parameter_handler);
63 ok(expression == NULL, "expression is not NULL\n");
64 ok(function == NULL, "function is not NULL\n");
65 ok(file == NULL, "file is not NULL\n");
66 ok(line == 0, "line = %u\n", line);
67 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
70 #ifdef __i386__
72 #include "pshpack1.h"
73 struct thiscall_thunk
75 BYTE pop_eax; /* popl %eax (ret addr) */
76 BYTE pop_edx; /* popl %edx (func) */
77 BYTE pop_ecx; /* popl %ecx (this) */
78 BYTE push_eax; /* pushl %eax */
79 WORD jmp_edx; /* jmp *%edx */
81 #include "poppack.h"
83 static ULONG_PTR (WINAPI *call_thiscall_func1)( void *func, void *this );
84 static ULONG_PTR (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
86 static void init_thiscall_thunk(void)
88 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
89 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
90 thunk->pop_eax = 0x58; /* popl %eax */
91 thunk->pop_edx = 0x5a; /* popl %edx */
92 thunk->pop_ecx = 0x59; /* popl %ecx */
93 thunk->push_eax = 0x50; /* pushl %eax */
94 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
95 call_thiscall_func1 = (void *)thunk;
96 call_thiscall_func2 = (void *)thunk;
99 #define call_func1(func,_this) call_thiscall_func1(func,_this)
100 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
102 #else
104 #define init_thiscall_thunk()
105 #define call_func1(func,_this) func(_this)
106 #define call_func2(func,_this,a) func(_this,a)
108 #endif /* __i386__ */
110 #undef __thiscall
111 #ifdef __i386__
112 #define __thiscall __stdcall
113 #else
114 #define __thiscall __cdecl
115 #endif
117 typedef unsigned char MSVCRT_bool;
119 typedef enum
121 SPINWAIT_INIT,
122 SPINWAIT_SPIN,
123 SPINWAIT_YIELD,
124 SPINWAIT_DONE
125 } SpinWait_state;
127 typedef void (__cdecl *yield_func)(void);
129 typedef struct
131 ULONG spin;
132 ULONG unknown;
133 SpinWait_state state;
134 yield_func yield_func;
135 } SpinWait;
137 static int* (__cdecl *p_errno)(void);
138 static int (__cdecl *p_wmemcpy_s)(wchar_t *dest, size_t numberOfElements, const wchar_t *src, size_t count);
139 static int (__cdecl *p_wmemmove_s)(wchar_t *dest, size_t numberOfElements, const wchar_t *src, size_t count);
140 static FILE* (__cdecl *p_fopen)(const char*,const char*);
141 static int (__cdecl *p_fclose)(FILE*);
142 static size_t (__cdecl *p_fread_s)(void*,size_t,size_t,size_t,FILE*);
143 static void (__cdecl *p_lock_file)(FILE*);
144 static void (__cdecl *p_unlock_file)(FILE*);
145 static void* (__cdecl *p__aligned_offset_malloc)(size_t, size_t, size_t);
146 static void (__cdecl *p__aligned_free)(void*);
147 static size_t (__cdecl *p__aligned_msize)(void*, size_t, size_t);
148 static int (__cdecl *p_atoi)(const char*);
150 static SpinWait* (__thiscall *pSpinWait_ctor_yield)(SpinWait*, yield_func);
151 static void (__thiscall *pSpinWait_dtor)(SpinWait*);
152 static void (__thiscall *pSpinWait__DoYield)(SpinWait*);
153 static ULONG (__thiscall *pSpinWait__NumberOfSpins)(SpinWait*);
154 static void (__thiscall *pSpinWait__SetSpinCount)(SpinWait*, unsigned int);
155 static MSVCRT_bool (__thiscall *pSpinWait__ShouldSpinAgain)(SpinWait*);
156 static MSVCRT_bool (__thiscall *pSpinWait__SpinOnce)(SpinWait*);
158 /* make sure we use the correct errno */
159 #undef errno
160 #define errno (*p_errno())
162 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
163 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
165 static BOOL init(void)
167 HMODULE hcrt;
169 SetLastError(0xdeadbeef);
170 hcrt = LoadLibraryA("msvcr100.dll");
171 if (!hcrt) {
172 win_skip("msvcr100.dll not installed (got %d)\n", GetLastError());
173 return FALSE;
176 SET(p_errno, "_errno");
177 SET(p_set_invalid_parameter_handler, "_set_invalid_parameter_handler");
178 SET(p_wmemcpy_s, "wmemcpy_s");
179 SET(p_wmemmove_s, "wmemmove_s");
180 SET(p_fopen, "fopen");
181 SET(p_fclose, "fclose");
182 SET(p_fread_s, "fread_s");
183 SET(p_lock_file, "_lock_file");
184 SET(p_unlock_file, "_unlock_file");
185 SET(p__aligned_offset_malloc, "_aligned_offset_malloc");
186 SET(p__aligned_free, "_aligned_free");
187 SET(p__aligned_msize, "_aligned_msize");
188 SET(p_atoi, "atoi");
190 if(sizeof(void*) == 8) { /* 64-bit initialization */
191 SET(pSpinWait_ctor_yield, "??0?$_SpinWait@$00@details@Concurrency@@QEAA@P6AXXZ@Z");
192 SET(pSpinWait_dtor, "??_F?$_SpinWait@$00@details@Concurrency@@QEAAXXZ");
193 SET(pSpinWait__DoYield, "?_DoYield@?$_SpinWait@$00@details@Concurrency@@IEAAXXZ");
194 SET(pSpinWait__NumberOfSpins, "?_NumberOfSpins@?$_SpinWait@$00@details@Concurrency@@IEAAKXZ");
195 SET(pSpinWait__SetSpinCount, "?_SetSpinCount@?$_SpinWait@$00@details@Concurrency@@QEAAXI@Z");
196 SET(pSpinWait__ShouldSpinAgain, "?_ShouldSpinAgain@?$_SpinWait@$00@details@Concurrency@@IEAA_NXZ");
197 SET(pSpinWait__SpinOnce, "?_SpinOnce@?$_SpinWait@$00@details@Concurrency@@QEAA_NXZ");
198 } else {
199 SET(pSpinWait_ctor_yield, "??0?$_SpinWait@$00@details@Concurrency@@QAE@P6AXXZ@Z");
200 SET(pSpinWait_dtor, "??_F?$_SpinWait@$00@details@Concurrency@@QAEXXZ");
201 SET(pSpinWait__DoYield, "?_DoYield@?$_SpinWait@$00@details@Concurrency@@IAEXXZ");
202 SET(pSpinWait__NumberOfSpins, "?_NumberOfSpins@?$_SpinWait@$00@details@Concurrency@@IAEKXZ");
203 SET(pSpinWait__SetSpinCount, "?_SetSpinCount@?$_SpinWait@$00@details@Concurrency@@QAEXI@Z");
204 SET(pSpinWait__ShouldSpinAgain, "?_ShouldSpinAgain@?$_SpinWait@$00@details@Concurrency@@IAE_NXZ");
205 SET(pSpinWait__SpinOnce, "?_SpinOnce@?$_SpinWait@$00@details@Concurrency@@QAE_NXZ");
208 init_thiscall_thunk();
209 return TRUE;
212 #define NUMELMS(array) (sizeof(array)/sizeof((array)[0]))
214 #define okwchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \
215 ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \
216 dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \
217 "Bad result: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",\
218 dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7])
220 static void test_wmemcpy_s(void)
222 static wchar_t dest[8];
223 static const wchar_t tiny[] = {'T',0,'I','N','Y',0};
224 static const wchar_t big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
225 const wchar_t XX = 0x5858; /* two 'X' bytes */
226 int ret;
228 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
229 "Invalid parameter handler was already set\n");
231 /* Normal */
232 memset(dest, 'X', sizeof(dest));
233 ret = p_wmemcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
234 ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret);
235 okwchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], XX, XX);
237 /* Vary source size */
238 errno = 0xdeadbeef;
239 SET_EXPECT(invalid_parameter_handler);
240 memset(dest, 'X', sizeof(dest));
241 ret = p_wmemcpy_s(dest, NUMELMS(dest), big, NUMELMS(big));
242 ok(errno == ERANGE, "Copying a big buffer to a small destination errno %d, expected ERANGE\n", errno);
243 ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret);
244 okwchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
245 CHECK_CALLED(invalid_parameter_handler);
247 /* Replace source with NULL */
248 errno = 0xdeadbeef;
249 SET_EXPECT(invalid_parameter_handler);
250 memset(dest, 'X', sizeof(dest));
251 ret = p_wmemcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
252 ok(errno == EINVAL, "Copying a NULL source buffer errno %d, expected EINVAL\n", errno);
253 ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret);
254 okwchars(dest, 0, 0, 0, 0, 0, 0, 0, 0);
255 CHECK_CALLED(invalid_parameter_handler);
257 /* Vary dest size */
258 errno = 0xdeadbeef;
259 SET_EXPECT(invalid_parameter_handler);
260 memset(dest, 'X', sizeof(dest));
261 ret = p_wmemcpy_s(dest, 0, tiny, NUMELMS(tiny));
262 ok(errno == ERANGE, "Copying into a destination of size 0 errno %d, expected ERANGE\n", errno);
263 ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret);
264 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
265 CHECK_CALLED(invalid_parameter_handler);
267 /* Replace dest with NULL */
268 errno = 0xdeadbeef;
269 SET_EXPECT(invalid_parameter_handler);
270 ret = p_wmemcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
271 ok(errno == EINVAL, "Copying a tiny buffer to a big NULL destination errno %d, expected EINVAL\n", errno);
272 ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
273 CHECK_CALLED(invalid_parameter_handler);
275 /* Combinations */
276 errno = 0xdeadbeef;
277 SET_EXPECT(invalid_parameter_handler);
278 memset(dest, 'X', sizeof(dest));
279 ret = p_wmemcpy_s(dest, 0, NULL, NUMELMS(tiny));
280 ok(errno == EINVAL, "Copying a NULL buffer into a destination of size 0 errno %d, expected EINVAL\n", errno);
281 ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
282 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
283 CHECK_CALLED(invalid_parameter_handler);
285 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
286 "Cannot reset invalid parameter handler\n");
289 static void test_wmemmove_s(void)
291 static wchar_t dest[8];
292 static const wchar_t tiny[] = {'T',0,'I','N','Y',0};
293 static const wchar_t big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
294 const wchar_t XX = 0x5858; /* two 'X' bytes */
295 int ret;
297 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
298 "Invalid parameter handler was already set\n");
300 /* Normal */
301 memset(dest, 'X', sizeof(dest));
302 ret = p_wmemmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny));
303 ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret);
304 okwchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], XX, XX);
306 /* Overlapping */
307 memcpy(dest, big, sizeof(dest));
308 ret = p_wmemmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1);
309 ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret);
310 okwchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]);
312 /* Vary source size */
313 errno = 0xdeadbeef;
314 SET_EXPECT(invalid_parameter_handler);
315 memset(dest, 'X', sizeof(dest));
316 ret = p_wmemmove_s(dest, NUMELMS(dest), big, NUMELMS(big));
317 ok(errno == ERANGE, "Moving a big buffer to a small destination errno %d, expected ERANGE\n", errno);
318 ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret);
319 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
320 CHECK_CALLED(invalid_parameter_handler);
322 /* Replace source with NULL */
323 errno = 0xdeadbeef;
324 SET_EXPECT(invalid_parameter_handler);
325 memset(dest, 'X', sizeof(dest));
326 ret = p_wmemmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny));
327 ok(errno == EINVAL, "Moving a NULL source buffer errno %d, expected EINVAL\n", errno);
328 ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret);
329 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
330 CHECK_CALLED(invalid_parameter_handler);
332 /* Vary dest size */
333 errno = 0xdeadbeef;
334 SET_EXPECT(invalid_parameter_handler);
335 memset(dest, 'X', sizeof(dest));
336 ret = p_wmemmove_s(dest, 0, tiny, NUMELMS(tiny));
337 ok(errno == ERANGE, "Moving into a destination of size 0 errno %d, expected ERANGE\n", errno);
338 ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret);
339 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
340 CHECK_CALLED(invalid_parameter_handler);
342 /* Replace dest with NULL */
343 errno = 0xdeadbeef;
344 SET_EXPECT(invalid_parameter_handler);
345 ret = p_wmemmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny));
346 ok(errno == EINVAL, "Moving a tiny buffer to a big NULL destination errno %d, expected EINVAL\n", errno);
347 ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret);
348 CHECK_CALLED(invalid_parameter_handler);
350 /* Combinations */
351 errno = 0xdeadbeef;
352 SET_EXPECT(invalid_parameter_handler);
353 memset(dest, 'X', sizeof(dest));
354 ret = p_wmemmove_s(dest, 0, NULL, NUMELMS(tiny));
355 ok(errno == EINVAL, "Moving a NULL buffer into a destination of size 0 errno %d, expected EINVAL\n", errno);
356 ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
357 okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
358 CHECK_CALLED(invalid_parameter_handler);
360 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
361 "Cannot reset invalid parameter handler\n");
364 struct block_file_arg
366 FILE *test_file;
367 HANDLE init;
368 HANDLE finish;
371 static DWORD WINAPI block_file(void *arg)
373 struct block_file_arg *files = arg;
374 p_lock_file(files->test_file);
375 SetEvent(files->init);
376 WaitForSingleObject(files->finish, INFINITE);
377 p_unlock_file(files->test_file);
378 return 0;
381 static void test_fread_s(void)
383 static const char test_file[] = "fread_s.tst";
384 int ret;
385 char buf[10];
386 HANDLE thread;
387 struct block_file_arg arg;
389 FILE *f = fopen(test_file, "w");
390 if(!f) {
391 skip("Error creating test file\n");
392 return;
394 fwrite("test", 1, 4, f);
395 fclose(f);
397 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
398 "Invalid parameter handler was already set\n");
400 SET_EXPECT(invalid_parameter_handler);
401 errno = 0xdeadbeef;
402 ret = p_fread_s(buf, sizeof(buf), 1, 1, NULL);
403 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
404 ok(errno == EINVAL, "errno = %d, expected EINVAL\n", errno);
405 CHECK_CALLED(invalid_parameter_handler);
407 f = p_fopen(test_file, "r");
408 arg.test_file = f;
409 arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
410 arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
411 thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
412 WaitForSingleObject(arg.init, INFINITE);
414 errno = 0xdeadbeef;
415 ret = p_fread_s(NULL, sizeof(buf), 0, 1, f);
416 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
417 ok(errno == 0xdeadbeef, "errno = %d, expected 0xdeadbeef\n", errno);
418 ret = p_fread_s(NULL, sizeof(buf), 1, 0, f);
419 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
420 ok(errno == 0xdeadbeef, "errno = %d, expected 0xdeadbeef\n", errno);
422 SetEvent(arg.finish);
423 WaitForSingleObject(thread, INFINITE);
425 SET_EXPECT(invalid_parameter_handler);
426 errno = 0xdeadbeef;
427 ret = p_fread_s(NULL, sizeof(buf), 1, 1, f);
428 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
429 ok(errno == EINVAL, "errno = %d, expected EINVAL\n", errno);
430 CHECK_CALLED(invalid_parameter_handler);
432 SET_EXPECT(invalid_parameter_handler);
433 errno = 0xdeadbeef;
434 buf[1] = 'a';
435 ret = p_fread_s(buf, 3, 1, 10, f);
436 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
437 ok(buf[0] == 0, "buf[0] = '%c', expected 0\n", buf[0]);
438 ok(buf[1] == 0, "buf[1] = '%c', expected 0\n", buf[1]);
439 ok(errno == ERANGE, "errno = %d, expected ERANGE\n", errno);
440 CHECK_CALLED(invalid_parameter_handler);
442 SET_EXPECT(invalid_parameter_handler);
443 errno = 0xdeadbeef;
444 ret = p_fread_s(buf, 2, 1, 10, f);
445 ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
446 ok(buf[0] == 0, "buf[0] = '%c', expected 0\n", buf[0]);
447 ok(errno == ERANGE, "errno = %d, expected ERANGE\n", errno);
448 CHECK_CALLED(invalid_parameter_handler);
450 memset(buf, 'a', sizeof(buf));
451 ret = p_fread_s(buf, sizeof(buf), 3, 10, f);
452 ok(ret==1, "fread_s returned %d, expected 1\n", ret);
453 ok(buf[0] == 'e', "buf[0] = '%c', expected 'e'\n", buf[0]);
454 ok(buf[1] == 's', "buf[1] = '%c', expected 's'\n", buf[1]);
455 ok(buf[2] == 't', "buf[2] = '%c', expected 't'\n", buf[2]);
456 ok(buf[3] == 'a', "buf[3] = '%c', expected 'a'\n", buf[3]);
457 p_fclose(f);
459 ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
460 "Cannot reset invalid parameter handler\n");
461 CloseHandle(arg.init);
462 CloseHandle(arg.finish);
463 CloseHandle(thread);
464 unlink(test_file);
467 static void test__aligned_msize(void)
469 void *mem;
470 int ret;
472 mem = p__aligned_offset_malloc(23, 16, 7);
473 ret = p__aligned_msize(mem, 16, 7);
474 ok(ret == 23, "_aligned_msize returned %d\n", ret);
475 ret = p__aligned_msize(mem, 15, 7);
476 ok(ret == 24, "_aligned_msize returned %d\n", ret);
477 ret = p__aligned_msize(mem, 11, 7);
478 ok(ret == 28, "_aligned_msize returned %d\n", ret);
479 ret = p__aligned_msize(mem, 1, 7);
480 ok(ret == 39-sizeof(void*), "_aligned_msize returned %d\n", ret);
481 ret = p__aligned_msize(mem, 8, 0);
482 todo_wine ok(ret == 32, "_aligned_msize returned %d\n", ret);
483 p__aligned_free(mem);
485 mem = p__aligned_offset_malloc(3, 16, 0);
486 ret = p__aligned_msize(mem, 16, 0);
487 ok(ret == 3, "_aligned_msize returned %d\n", ret);
488 ret = p__aligned_msize(mem, 11, 0);
489 ok(ret == 8, "_aligned_msize returned %d\n", ret);
490 p__aligned_free(mem);
493 static void test_atoi(void)
495 int r;
497 r = p_atoi("0");
498 ok(r == 0, "atoi(0) = %d\n", r);
500 r = p_atoi("-1");
501 ok(r == -1, "atoi(-1) = %d\n", r);
503 r = p_atoi("1");
504 ok(r == 1, "atoi(1) = %d\n", r);
506 r = p_atoi("4294967296");
507 ok(r == 2147483647, "atoi(4294967296) = %d\n", r);
510 static void __cdecl test_yield_func(void)
512 CHECK_EXPECT(yield_func);
515 static void test__SpinWait(void)
517 SpinWait sp;
518 ULONG ul;
519 MSVCRT_bool b;
521 call_func2(pSpinWait_ctor_yield, &sp, test_yield_func);
523 SET_EXPECT(yield_func);
524 call_func1(pSpinWait__DoYield, &sp);
525 CHECK_CALLED(yield_func);
527 ul = call_func1(pSpinWait__NumberOfSpins, &sp);
528 ok(ul == 1, "_SpinWait::_NumberOfSpins returned %u\n", ul);
530 sp.spin = 2;
531 b = call_func1(pSpinWait__ShouldSpinAgain, &sp);
532 ok(b, "_SpinWait::_ShouldSpinAgain returned %x\n", b);
533 ok(sp.spin == 1, "sp.spin = %u\n", sp.spin);
534 b = call_func1(pSpinWait__ShouldSpinAgain, &sp);
535 ok(!b, "_SpinWait::_ShouldSpinAgain returned %x\n", b);
536 ok(sp.spin == 0, "sp.spin = %u\n", sp.spin);
537 b = call_func1(pSpinWait__ShouldSpinAgain, &sp);
538 ok(b, "_SpinWait::_ShouldSpinAgain returned %x\n", b);
539 ok(sp.spin == -1, "sp.spin = %u\n", sp.spin);
541 call_func2(pSpinWait__SetSpinCount, &sp, 2);
542 b = call_func1(pSpinWait__SpinOnce, &sp);
543 ok(b, "_SpinWait::_SpinOnce returned %x\n", b);
544 ok(sp.spin == 1, "sp.spin = %u\n", sp.spin);
545 b = call_func1(pSpinWait__SpinOnce, &sp);
546 ok(b, "_SpinWait::_SpinOnce returned %x\n", b);
547 ok(sp.spin == 0, "sp.spin = %u\n", sp.spin);
548 SET_EXPECT(yield_func);
549 b = call_func1(pSpinWait__SpinOnce, &sp);
550 ok(b, "_SpinWait::_SpinOnce returned %x\n", b);
551 ok(sp.spin == 0, "sp.spin = %u\n", sp.spin);
552 CHECK_CALLED(yield_func);
553 b = call_func1(pSpinWait__SpinOnce, &sp);
554 ok(!b, "_SpinWait::_SpinOnce returned %x\n", b);
555 ok(sp.spin==0 || sp.spin==4000, "sp.spin = %u\n", sp.spin);
557 call_func1(pSpinWait_dtor, &sp);
560 START_TEST(msvcr100)
562 if (!init())
563 return;
565 test_wmemcpy_s();
566 test_wmemmove_s();
567 test_fread_s();
568 test__aligned_msize();
569 test_atoi();
570 test__SpinWait();