2 * Copyright 2010 Detlef Riekenberg
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"
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT2(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT(func) \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 DEFINE_EXPECT(invalid_parameter_handler);
58 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
59 typedef int (__cdecl *_INITTERM_E_FN)(void);
60 static int (__cdecl *p_initterm_e)(_INITTERM_E_FN *table, _INITTERM_E_FN *end);
61 static void* (__cdecl *p_encode_pointer)(void *);
62 static void* (__cdecl *p_decode_pointer)(void *);
63 static void* (__cdecl *p_encoded_null)(void);
64 static int *p_sys_nerr;
65 static int* (__cdecl *p__sys_nerr)(void);
66 static char **p_sys_errlist;
67 static char** (__cdecl *p__sys_errlist)(void);
68 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
69 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
70 static errno_t (__cdecl *p_itoa_s)(int,char*,size_t,int);
71 static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
72 static void (__cdecl *p_qsort_s)(void *, size_t, size_t, int (__cdecl *)(void *, const void *, const void *), void *);
73 static int (__cdecl *p_controlfp_s)(unsigned int *, unsigned int, unsigned int);
74 static int (__cdecl *p_atoflt)(_CRT_FLOAT *, char *);
75 static unsigned int (__cdecl *p_set_abort_behavior)(unsigned int, unsigned int);
76 static int (__cdecl *p_sopen_s)(int*, const char*, int, int, int);
77 static int (__cdecl *p_wsopen_s)(int*, const wchar_t*, int, int, int);
78 static void* (__cdecl *p_realloc_crt)(void*, size_t);
79 static void* (__cdecl *p_malloc)(size_t);
80 static void (__cdecl *p_free)(void*);
82 static void* (WINAPI *pEncodePointer)(void *);
84 static int cb_called[4];
85 static int g_qsort_s_context_counter;
87 static inline int almost_equal_f(float f1, float f2)
89 return f1-f2 > -1e-30 && f1-f2 < 1e-30;
94 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
95 const wchar_t *function, const wchar_t *file,
96 unsigned line, uintptr_t arg)
98 CHECK_EXPECT(invalid_parameter_handler);
99 ok(expression == NULL, "expression is not NULL\n");
100 ok(function == NULL, "function is not NULL\n");
101 ok(file == NULL, "file is not NULL\n");
102 ok(line == 0, "line = %u\n", line);
103 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
106 static int __cdecl initterm_cb0(void)
112 static int __cdecl initterm_cb1(void)
118 static int __cdecl initterm_cb2(void)
125 static void test__initterm_e(void)
127 _INITTERM_E_FN table[4];
131 skip("_initterm_e not found\n");
135 memset(table, 0, sizeof(table));
137 memset(cb_called, 0, sizeof(cb_called));
139 res = p_initterm_e(table, table);
140 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
141 "got %d with 0x%x {%d, %d, %d}\n",
142 res, errno, cb_called[0], cb_called[1], cb_called[2]);
144 memset(cb_called, 0, sizeof(cb_called));
146 res = p_initterm_e(table, NULL);
147 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
148 "got %d with 0x%x {%d, %d, %d}\n",
149 res, errno, cb_called[0], cb_called[1], cb_called[2]);
152 /* this crash on Windows */
154 res = p_initterm_e(NULL, table);
155 trace("got %d with 0x%x\n", res, errno);
158 table[0] = initterm_cb0;
159 memset(cb_called, 0, sizeof(cb_called));
161 res = p_initterm_e(table, &table[1]);
162 ok( !res && (cb_called[0] == 1) && !cb_called[1] && !cb_called[2],
163 "got %d with 0x%x {%d, %d, %d}\n",
164 res, errno, cb_called[0], cb_called[1], cb_called[2]);
167 /* init-function returning failure */
168 table[1] = initterm_cb1;
169 memset(cb_called, 0, sizeof(cb_called));
171 res = p_initterm_e(table, &table[3]);
172 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
173 "got %d with 0x%x {%d, %d, %d}\n",
174 res, errno, cb_called[0], cb_called[1], cb_called[2]);
176 /* init-function not called, when end < start */
177 memset(cb_called, 0, sizeof(cb_called));
179 res = p_initterm_e(&table[3], table);
180 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
181 "got %d with 0x%x {%d, %d, %d}\n",
182 res, errno, cb_called[0], cb_called[1], cb_called[2]);
184 /* initialization stop after first non-zero result */
185 table[2] = initterm_cb0;
186 memset(cb_called, 0, sizeof(cb_called));
188 res = p_initterm_e(table, &table[3]);
189 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
190 "got %d with 0x%x {%d, %d, %d}\n",
191 res, errno, cb_called[0], cb_called[1], cb_called[2]);
193 /* NULL pointer in the array are skipped */
195 table[2] = initterm_cb2;
196 memset(cb_called, 0, sizeof(cb_called));
198 res = p_initterm_e(table, &table[3]);
199 ok( (res == 2) && (cb_called[0] == 1) && !cb_called[1] && (cb_called[2] == 1),
200 "got %d with 0x%x {%d, %d, %d}\n",
201 res, errno, cb_called[0], cb_called[1], cb_called[2]);
205 /* Beware that _encode_pointer is a NOP before XP
206 (the parameter is returned unchanged) */
207 static void test__encode_pointer(void)
211 if(!p_encode_pointer || !p_decode_pointer || !p_encoded_null) {
212 win_skip("_encode_pointer, _decode_pointer or _encoded_null not found\n");
216 ptr = (void*)0xdeadbeef;
217 res = p_encode_pointer(ptr);
218 res = p_decode_pointer(res);
219 ok(res == ptr, "Pointers are different after encoding and decoding\n");
221 ok(p_encoded_null() == p_encode_pointer(NULL), "Error encoding null\n");
223 ptr = p_encode_pointer(p_encode_pointer);
224 ok(p_decode_pointer(ptr) == p_encode_pointer, "Error decoding pointer\n");
226 /* Not present before XP */
227 if (!pEncodePointer) {
228 win_skip("EncodePointer not found\n");
232 res = pEncodePointer(p_encode_pointer);
233 ok(ptr == res, "_encode_pointer produced different result than EncodePointer\n");
237 static void test_error_messages(void)
239 int *size, size_copy;
241 if(!p_sys_nerr || !p__sys_nerr || !p_sys_errlist || !p__sys_errlist) {
242 win_skip("Skipping test_error_messages tests\n");
246 size = p__sys_nerr();
248 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
251 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
255 ok(*p_sys_errlist == *(p__sys_errlist()), "p_sys_errlist != p__sys_errlist()\n");
258 static void test__strtoi64(void)
261 unsigned __int64 ures;
263 if(!p_strtoi64 || !p_strtoui64) {
264 win_skip("_strtoi64 or _strtoui64 not found\n");
268 if(!p_set_invalid_parameter_handler) {
269 win_skip("_set_invalid_parameter_handler not found\n");
274 SET_EXPECT(invalid_parameter_handler);
275 res = p_strtoi64(NULL, NULL, 10);
276 ok(res == 0, "res != 0\n");
277 CHECK_CALLED(invalid_parameter_handler);
279 SET_EXPECT(invalid_parameter_handler);
280 res = p_strtoi64("123", NULL, 1);
281 ok(res == 0, "res != 0\n");
282 CHECK_CALLED(invalid_parameter_handler);
284 SET_EXPECT(invalid_parameter_handler);
285 res = p_strtoi64("123", NULL, 37);
286 ok(res == 0, "res != 0\n");
287 CHECK_CALLED(invalid_parameter_handler);
289 SET_EXPECT(invalid_parameter_handler);
290 ures = p_strtoui64(NULL, NULL, 10);
291 ok(ures == 0, "res = %d\n", (int)ures);
292 CHECK_CALLED(invalid_parameter_handler);
294 SET_EXPECT(invalid_parameter_handler);
295 ures = p_strtoui64("123", NULL, 1);
296 ok(ures == 0, "res = %d\n", (int)ures);
297 CHECK_CALLED(invalid_parameter_handler);
299 SET_EXPECT(invalid_parameter_handler);
300 ures = p_strtoui64("123", NULL, 37);
301 ok(ures == 0, "res = %d\n", (int)ures);
302 CHECK_CALLED(invalid_parameter_handler);
303 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
306 static void test__itoa_s(void)
313 win_skip("Skipping _itoa_s tests\n");
317 if(!p_set_invalid_parameter_handler) {
318 win_skip("_set_invalid_parameter_handler not found\n");
322 /* _itoa_s (on msvcr90) doesn't set errno (in case of errors) while msvcrt does
323 * as we always set errno in our msvcrt implementation, don't test here that errno
326 SET_EXPECT(invalid_parameter_handler);
327 ret = p_itoa_s(0, NULL, 0, 0);
328 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
329 CHECK_CALLED(invalid_parameter_handler);
331 memset(buffer, 'X', sizeof(buffer));
332 SET_EXPECT(invalid_parameter_handler);
333 ret = p_itoa_s(0, buffer, 0, 0);
334 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
335 ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n");
336 CHECK_CALLED(invalid_parameter_handler);
338 memset(buffer, 'X', sizeof(buffer));
339 SET_EXPECT(invalid_parameter_handler);
340 ret = p_itoa_s(0, buffer, sizeof(buffer), 0);
341 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
342 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
343 CHECK_CALLED(invalid_parameter_handler);
345 memset(buffer, 'X', sizeof(buffer));
346 SET_EXPECT(invalid_parameter_handler);
347 ret = p_itoa_s(0, buffer, sizeof(buffer), 64);
348 ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret);
349 ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n");
350 CHECK_CALLED(invalid_parameter_handler);
352 memset(buffer, 'X', sizeof(buffer));
353 SET_EXPECT(invalid_parameter_handler);
354 ret = p_itoa_s(12345678, buffer, 4, 10);
355 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
356 ok(!memcmp(buffer, "\000765", 4),
357 "Expected the output buffer to be null terminated with truncated output\n");
358 CHECK_CALLED(invalid_parameter_handler);
360 memset(buffer, 'X', sizeof(buffer));
361 SET_EXPECT(invalid_parameter_handler);
362 ret = p_itoa_s(12345678, buffer, 8, 10);
363 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
364 ok(!memcmp(buffer, "\0007654321", 8),
365 "Expected the output buffer to be null terminated with truncated output\n");
366 CHECK_CALLED(invalid_parameter_handler);
368 memset(buffer, 'X', sizeof(buffer));
369 SET_EXPECT(invalid_parameter_handler);
370 ret = p_itoa_s(-12345678, buffer, 9, 10);
371 ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret);
372 ok(!memcmp(buffer, "\00087654321", 9),
373 "Expected the output buffer to be null terminated with truncated output\n");
374 CHECK_CALLED(invalid_parameter_handler);
376 ret = p_itoa_s(12345678, buffer, 9, 10);
377 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
378 ok(!strcmp(buffer, "12345678"),
379 "Expected output buffer string to be \"12345678\", got \"%s\"\n",
382 ret = p_itoa_s(43690, buffer, sizeof(buffer), 2);
383 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
384 ok(!strcmp(buffer, "1010101010101010"),
385 "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n",
388 ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36);
389 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
390 ok(!strcmp(buffer, "nell"),
391 "Expected output buffer string to be \"nell\", got \"%s\"\n",
394 ret = p_itoa_s(5704, buffer, sizeof(buffer), 18);
395 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
396 ok(!strcmp(buffer, "hag"),
397 "Expected output buffer string to be \"hag\", got \"%s\"\n",
400 ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10);
401 ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret);
402 ok(!strcmp(buffer, "-12345678"),
403 "Expected output buffer string to be \"-12345678\", got \"%s\"\n",
407 static void test_wcsncat_s(void)
409 static wchar_t abcW[] = {'a','b','c',0};
416 win_skip("skipping wcsncat_s tests\n");
420 if(!p_set_invalid_parameter_handler) {
421 win_skip("_set_invalid_parameter_handler not found\n");
425 memcpy(src, abcW, sizeof(abcW));
427 SET_EXPECT(invalid_parameter_handler);
428 ret = p_wcsncat_s(NULL, 4, src, 4);
429 ok(ret == EINVAL, "err = %d\n", ret);
430 CHECK_CALLED(invalid_parameter_handler);
432 SET_EXPECT(invalid_parameter_handler);
433 ret = p_wcsncat_s(dst, 0, src, 4);
434 ok(ret == EINVAL, "err = %d\n", ret);
435 CHECK_CALLED(invalid_parameter_handler);
437 SET_EXPECT(invalid_parameter_handler);
438 ret = p_wcsncat_s(dst, 0, src, _TRUNCATE);
439 ok(ret == EINVAL, "err = %d\n", ret);
440 CHECK_CALLED(invalid_parameter_handler);
442 ret = p_wcsncat_s(dst, 4, NULL, 0);
443 ok(ret == 0, "err = %d\n", ret);
446 SET_EXPECT(invalid_parameter_handler);
447 ret = p_wcsncat_s(dst, 2, src, 4);
448 ok(ret == ERANGE, "err = %d\n", ret);
449 CHECK_CALLED(invalid_parameter_handler);
452 ret = p_wcsncat_s(dst, 2, src, _TRUNCATE);
453 ok(ret == STRUNCATE, "err = %d\n", ret);
454 ok(dst[0] == 'a' && dst[1] == 0, "dst is %s\n", wine_dbgstr_w(dst));
456 memcpy(dst, abcW, sizeof(abcW));
458 SET_EXPECT(invalid_parameter_handler);
459 ret = p_wcsncat_s(dst, 4, src, 4);
460 ok(ret == EINVAL, "err = %d\n", ret);
461 CHECK_CALLED(invalid_parameter_handler);
464 /* Based on dlls/ntdll/tests/string.c */
465 static __cdecl int intcomparefunc(void *context, const void *a, const void*b)
467 ok (a != b, "must never get the same pointer\n");
469 return (*(int*)a) - (*(int*)b);
472 static __cdecl int charcomparefunc(void *context, const void *a, const void*b)
474 ok (a != b, "must never get the same pointer\n");
476 return (*(char*)a) - (*(char*)b);
479 static __cdecl int strcomparefunc(void *context, const void *a, const void*b)
481 ok (a != b, "must never get the same pointer\n");
483 return lstrcmpA(*(char**)a,*(char**)b);
486 static void test_qsort_s(void)
488 int arr[5] = { 23, 42, 8, 4, 16 };
489 int arr2[5] = { 23, 42, 8, 4, 16 };
490 char carr[5] = { 42, 23, 4, 8, 16 };
491 const char *strarr[7] = {
502 win_skip("qsort_s not found\n");
506 SET_EXPECT(invalid_parameter_handler);
507 p_qsort_s(NULL, 0, 0, NULL, NULL);
508 CHECK_CALLED(invalid_parameter_handler);
510 SET_EXPECT(invalid_parameter_handler);
511 p_qsort_s(NULL, 0, 0, intcomparefunc, NULL);
512 CHECK_CALLED(invalid_parameter_handler);
514 SET_EXPECT(invalid_parameter_handler);
515 p_qsort_s(NULL, 0, sizeof(int), NULL, NULL);
516 CHECK_CALLED(invalid_parameter_handler);
518 SET_EXPECT(invalid_parameter_handler);
519 p_qsort_s(NULL, 1, sizeof(int), intcomparefunc, NULL);
520 CHECK_CALLED(invalid_parameter_handler);
522 g_qsort_s_context_counter = 0;
523 p_qsort_s(NULL, 0, sizeof(int), intcomparefunc, NULL);
524 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
526 /* overflow without side effects, other overflow values crash */
527 g_qsort_s_context_counter = 0;
528 p_qsort_s((void*)arr2, (((size_t)1) << (8*sizeof(size_t) - 1)) + 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
529 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
530 ok(arr2[0] == 23, "should remain unsorted, arr2[0] is %d\n", arr2[0]);
531 ok(arr2[1] == 42, "should remain unsorted, arr2[1] is %d\n", arr2[1]);
532 ok(arr2[2] == 8, "should remain unsorted, arr2[2] is %d\n", arr2[2]);
533 ok(arr2[3] == 4, "should remain unsorted, arr2[3] is %d\n", arr2[3]);
535 g_qsort_s_context_counter = 0;
536 p_qsort_s((void*)arr, 0, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
537 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
538 ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]);
539 ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]);
540 ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]);
541 ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]);
542 ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]);
544 g_qsort_s_context_counter = 0;
545 p_qsort_s((void*)arr, 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
546 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
547 ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]);
548 ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]);
549 ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]);
550 ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]);
551 ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]);
553 SET_EXPECT(invalid_parameter_handler);
554 g_qsort_s_context_counter = 0;
555 p_qsort_s((void*)arr, 5, 0, intcomparefunc, &g_qsort_s_context_counter);
556 ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n");
557 ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]);
558 ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]);
559 ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]);
560 ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]);
561 ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]);
562 CHECK_CALLED(invalid_parameter_handler);
564 g_qsort_s_context_counter = 0;
565 p_qsort_s((void*)arr, 5, sizeof(int), intcomparefunc, &g_qsort_s_context_counter);
566 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
567 ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]);
568 ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]);
569 ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]);
570 ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]);
571 ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]);
573 g_qsort_s_context_counter = 0;
574 p_qsort_s((void*)carr, 5, sizeof(char), charcomparefunc, &g_qsort_s_context_counter);
575 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
576 ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]);
577 ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]);
578 ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]);
579 ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]);
580 ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]);
582 g_qsort_s_context_counter = 0;
583 p_qsort_s((void*)strarr, 7, sizeof(char*), strcomparefunc, &g_qsort_s_context_counter);
584 ok(g_qsort_s_context_counter > 0, "callback wasn't called\n");
585 ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]);
586 ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]);
587 ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]);
588 ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]);
589 ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]);
590 ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]);
591 ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]);
594 static void test_controlfp_s(void)
601 win_skip("_controlfp_s not found\n");
605 SET_EXPECT(invalid_parameter_handler);
606 ret = p_controlfp_s( NULL, ~0, ~0 );
607 ok( ret == EINVAL, "wrong result %d\n", ret );
608 CHECK_CALLED(invalid_parameter_handler);
611 SET_EXPECT(invalid_parameter_handler);
612 ret = p_controlfp_s( &cur, ~0, ~0 );
613 ok( ret == EINVAL, "wrong result %d\n", ret );
614 ok( cur != 0xdeadbeef, "value not set\n" );
615 CHECK_CALLED(invalid_parameter_handler);
618 ret = p_controlfp_s( &cur, 0, 0 );
619 ok( !ret, "wrong result %d\n", ret );
620 ok( cur != 0xdeadbeef, "value not set\n" );
622 SET_EXPECT(invalid_parameter_handler);
624 ret = p_controlfp_s( &cur, 0x80000000, 0x80000000 );
625 ok( ret == EINVAL, "wrong result %d\n", ret );
626 ok( cur != 0xdeadbeef, "value not set\n" );
627 CHECK_CALLED(invalid_parameter_handler);
630 /* mask is only checked when setting invalid bits */
631 ret = p_controlfp_s( &cur, 0, 0x80000000 );
632 ok( !ret, "wrong result %d\n", ret );
633 ok( cur != 0xdeadbeef, "value not set\n" );
643 static const _atoflt_test _atoflt_testdata[] = {
645 { "-13.721", -13.721, 0 },
647 { ".21e12", 0.21e12, 0 },
648 { "214353e-3", 214.353, 0 },
649 { "1d9999999999999999999", 0.0, _OVERFLOW },
651 /* more significant digits */
652 { "1.23456789", 1.23456789, 0 },
653 { "1.23456789e1", 12.3456789, 0 },
654 { "1e39", 0.0, _OVERFLOW },
655 { "1e-39", 0.0, _UNDERFLOW },
659 static void test__atoflt(void)
666 win_skip("_atoflt not found\n");
672 /* crashes on native */
673 ret = p_atoflt(NULL, NULL);
674 ret = p_atoflt(NULL, (char*)_atoflt_testdata[0].str);
675 ret = p_atoflt(&flt, NULL);
678 while (_atoflt_testdata[i].str)
680 ret = p_atoflt(&flt, (char*)_atoflt_testdata[i].str);
681 ok(ret == _atoflt_testdata[i].ret, "got ret %d, expected ret %d, for %s\n", ret,
682 _atoflt_testdata[i].ret, _atoflt_testdata[i].str);
685 ok(almost_equal_f(flt.f, _atoflt_testdata[i].flt), "got %f, expected %f, for %s\n", flt.f,
686 _atoflt_testdata[i].flt, _atoflt_testdata[i].str);
692 static void test__set_abort_behavior(void)
696 if (!p_set_abort_behavior)
698 win_skip("_set_abort_behavior not found\n");
702 /* default is _WRITE_ABORT_MSG | _CALL_REPORTFAULT */
703 res = p_set_abort_behavior(0, 0);
704 ok (res == (_WRITE_ABORT_MSG | _CALL_REPORTFAULT),
705 "got 0x%x (expected 0x%x)\n", res, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
707 /* no internal mask */
708 p_set_abort_behavior(0xffffffff, 0xffffffff);
709 res = p_set_abort_behavior(0, 0);
710 ok (res == 0xffffffff, "got 0x%x (expected 0x%x)\n", res, 0xffffffff);
712 /* set to default value */
713 p_set_abort_behavior(_WRITE_ABORT_MSG | _CALL_REPORTFAULT, 0xffffffff);
716 static void test__sopen_s(void)
722 win_skip("_sopen_s not found\n");
726 SET_EXPECT(invalid_parameter_handler);
727 ret = p_sopen_s(NULL, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
728 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
729 CHECK_CALLED(invalid_parameter_handler);
732 ret = p_sopen_s(&fd, "test", _O_RDONLY, _SH_DENYNO, _S_IREAD);
733 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
734 ok(fd == -1, "got %d\n", fd);
737 static void test__wsopen_s(void)
739 wchar_t testW[] = {'t','e','s','t',0};
744 win_skip("_wsopen_s not found\n");
748 SET_EXPECT(invalid_parameter_handler);
749 ret = p_wsopen_s(NULL, testW, _O_RDONLY, _SH_DENYNO, _S_IREAD);
750 ok(ret == EINVAL, "got %d, expected EINVAL\n", ret);
751 CHECK_CALLED(invalid_parameter_handler);
754 ret = p_wsopen_s(&fd, testW, _O_RDONLY, _SH_DENYNO, _S_IREAD);
755 ok(ret == ENOENT, "got %d, expected ENOENT\n", ret);
756 ok(fd == -1, "got %d\n", fd);
759 static void test__realloc_crt(void)
765 win_skip("_realloc_crt not found\n");
771 /* crashes on some systems starting Vista */
772 mem = p_realloc_crt(NULL, 10);
776 ok(mem != NULL, "memory not allocated\n");
778 mem = p_realloc_crt(mem, 20);
779 ok(mem != NULL, "memory not reallocated\n");
781 mem = p_realloc_crt(mem, 0);
782 ok(mem == NULL, "memory not freed\n");
784 mem = p_realloc_crt(NULL, 0);
785 ok(mem != NULL, "memory not (re)allocated for size 0\n");
794 SetLastError(0xdeadbeef);
795 hcrt = LoadLibraryA("msvcr90.dll");
797 win_skip("msvcr90.dll not installed (got %d)\n", GetLastError());
801 p_set_invalid_parameter_handler = (void *) GetProcAddress(hcrt, "_set_invalid_parameter_handler");
802 if(p_set_invalid_parameter_handler)
803 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
804 "Invalid parameter handler was already set\n");
806 p_initterm_e = (void *) GetProcAddress(hcrt, "_initterm_e");
807 p_encode_pointer = (void *) GetProcAddress(hcrt, "_encode_pointer");
808 p_decode_pointer = (void *) GetProcAddress(hcrt, "_decode_pointer");
809 p_encoded_null = (void *) GetProcAddress(hcrt, "_encoded_null");
810 p_sys_nerr = (void *) GetProcAddress(hcrt, "_sys_nerr");
811 p__sys_nerr = (void *) GetProcAddress(hcrt, "__sys_nerr");
812 p_sys_errlist = (void *) GetProcAddress(hcrt, "_sys_errlist");
813 p__sys_errlist = (void *) GetProcAddress(hcrt, "__sys_errlist");
814 p_strtoi64 = (void *) GetProcAddress(hcrt, "_strtoi64");
815 p_strtoui64 = (void *) GetProcAddress(hcrt, "_strtoui64");
816 p_itoa_s = (void *)GetProcAddress(hcrt, "_itoa_s");
817 p_wcsncat_s = (void *)GetProcAddress( hcrt,"wcsncat_s" );
818 p_qsort_s = (void *) GetProcAddress(hcrt, "qsort_s");
819 p_controlfp_s = (void *) GetProcAddress(hcrt, "_controlfp_s");
820 p_atoflt = (void* )GetProcAddress(hcrt, "_atoflt");
821 p_set_abort_behavior = (void *) GetProcAddress(hcrt, "_set_abort_behavior");
822 p_sopen_s = (void*) GetProcAddress(hcrt, "_sopen_s");
823 p_wsopen_s = (void*) GetProcAddress(hcrt, "_wsopen_s");
824 p_realloc_crt = (void*) GetProcAddress(hcrt, "_realloc_crt");
825 p_malloc = (void*) GetProcAddress(hcrt, "malloc");
826 p_free = (void*)GetProcAddress(hcrt, "free");
828 hkernel32 = GetModuleHandleA("kernel32.dll");
829 pEncodePointer = (void *) GetProcAddress(hkernel32, "EncodePointer");
832 test__encode_pointer();
833 test_error_messages();
840 test__set_abort_behavior();