ucrtbase/tests: Use more functions directly.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
feature/deterministic
Jacek Caban 2020-03-16 21:12:57 +01:00 committed by Alexandre Julliard
parent f202beb745
commit c2ee20c95b
1 changed files with 44 additions and 78 deletions

View File

@ -140,18 +140,14 @@ static int (CDECL *p_o__initialize_onexit_table)(MSVCRT__onexit_table_t *table);
static int (CDECL *p_o__register_onexit_function)(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func);
static int (CDECL *p_o__execute_onexit_table)(MSVCRT__onexit_table_t *table);
static int (CDECL *p___fpe_flt_rounds)(void);
static unsigned int (CDECL *p__controlfp)(unsigned int, unsigned int);
static _invalid_parameter_handler (CDECL *p__set_invalid_parameter_handler)(_invalid_parameter_handler);
static _invalid_parameter_handler (CDECL *p__get_invalid_parameter_handler)(void);
static _invalid_parameter_handler (CDECL *p__set_thread_local_invalid_parameter_handler)(_invalid_parameter_handler);
static _invalid_parameter_handler (CDECL *p__get_thread_local_invalid_parameter_handler)(void);
static int (CDECL *p__ltoa_s)(LONG, char*, size_t, int);
static char* (CDECL *p__get_narrow_winmain_command_line)(void);
static int (CDECL *p_sopen_dispatch)(const char *, int, int, int, int *, int);
static int (CDECL *p_sopen_s)(int *, const char *, int, int, int);
static int (WINAPIV *p__open)(const char*, int, ...);
static MSVCRT_lldiv_t* (CDECL *p_lldiv)(MSVCRT_lldiv_t*,LONGLONG,LONGLONG);
static int (CDECL *p__isctype)(int,int);
static int (CDECL *p_isblank)(int);
static int (CDECL *p__isblank_l)(int,_locale_t);
static int (CDECL *p__iswctype_l)(int,int,_locale_t);
@ -159,22 +155,12 @@ static int (CDECL *p_iswblank)(int);
static int (CDECL *p__iswblank_l)(wint_t,_locale_t);
static int (CDECL *p_fesetround)(int);
static void (CDECL *p___setusermatherr)(MSVCRT_matherr_func);
static int* (CDECL *p_errno)(void);
static char* (CDECL *p_asctime)(const struct tm *);
static size_t (__cdecl *p_strftime)(char *, size_t, const char *, const struct tm *);
static size_t (__cdecl *p__Strftime)(char*, size_t, const char*, const struct tm*, void*);
static char* (__cdecl *p_setlocale)(int, const char*);
static struct tm* (__cdecl *p__gmtime32)(const __time32_t*);
static void (CDECL *p_exit)(int);
static int (CDECL *p__crt_atexit)(void (CDECL*)(void));
static int (__cdecl *p_crt_at_quick_exit)(void (__cdecl *func)(void));
static void (__cdecl *p_quick_exit)(int exitcode);
static int (__cdecl *p__stat32)(const char*, struct _stat32 *buf);
static int (__cdecl *p__close)(int);
static void* (__cdecl *p__o_malloc)(size_t);
static size_t (__cdecl *p__msize)(void*);
static void (__cdecl *p_free)(void*);
static clock_t (__cdecl *p_clock)(void);
static void test__initialize_onexit_table(void)
{
@ -376,7 +362,7 @@ static void test__execute_onexit_table(void)
static void test___fpe_flt_rounds(void)
{
unsigned int cfp = p__controlfp(0, 0);
unsigned int cfp = _controlfp(0, 0);
int ret;
if(!cfp) {
@ -384,19 +370,19 @@ static void test___fpe_flt_rounds(void)
return;
}
ok((p__controlfp(_RC_NEAR, _RC_CHOP) & _RC_CHOP) == _RC_NEAR, "_controlfp(_RC_NEAR, _RC_CHOP) failed\n");
ok((_controlfp(_RC_NEAR, _RC_CHOP) & _RC_CHOP) == _RC_NEAR, "_controlfp(_RC_NEAR, _RC_CHOP) failed\n");
ret = p___fpe_flt_rounds();
ok(ret == 1, "__fpe_flt_rounds returned %d\n", ret);
ok((p__controlfp(_RC_UP, _RC_CHOP) & _RC_CHOP) == _RC_UP, "_controlfp(_RC_UP, _RC_CHOP) failed\n");
ok((_controlfp(_RC_UP, _RC_CHOP) & _RC_CHOP) == _RC_UP, "_controlfp(_RC_UP, _RC_CHOP) failed\n");
ret = p___fpe_flt_rounds();
ok(ret == 2 || broken(ret == 3) /* w1064v1507 */, "__fpe_flt_rounds returned %d\n", ret);
ok((p__controlfp(_RC_DOWN, _RC_CHOP) & _RC_CHOP) == _RC_DOWN, "_controlfp(_RC_DOWN, _RC_CHOP) failed\n");
ok((_controlfp(_RC_DOWN, _RC_CHOP) & _RC_CHOP) == _RC_DOWN, "_controlfp(_RC_DOWN, _RC_CHOP) failed\n");
ret = p___fpe_flt_rounds();
ok(ret == 3 || broken(ret == 2) /* w1064v1507 */, "__fpe_flt_rounds returned %d\n", ret);
ok((p__controlfp(_RC_CHOP, _RC_CHOP) & _RC_CHOP) == _RC_CHOP, "_controlfp(_RC_CHOP, _RC_CHOP) failed\n");
ok((_controlfp(_RC_CHOP, _RC_CHOP) & _RC_CHOP) == _RC_CHOP, "_controlfp(_RC_CHOP, _RC_CHOP) failed\n");
ret = p___fpe_flt_rounds();
ok(ret == 0, "__fpe_flt_rounds returned %d\n", ret);
}
@ -444,14 +430,14 @@ static void test_invalid_parameter_handler(void)
ok(ret == thread_invalid_parameter_handler, "ret = %p\n", ret);
SET_EXPECT(thread_invalid_parameter_handler);
p__ltoa_s(0, NULL, 0, 0);
_ltoa_s(0, NULL, 0, 0);
CHECK_CALLED(thread_invalid_parameter_handler);
ret = p__set_thread_local_invalid_parameter_handler(NULL);
ok(ret == thread_invalid_parameter_handler, "ret = %p\n", ret);
SET_EXPECT(global_invalid_parameter_handler);
p__ltoa_s(0, NULL, 0, 0);
_ltoa_s(0, NULL, 0, 0);
CHECK_CALLED(global_invalid_parameter_handler);
ret = p__set_invalid_parameter_handler(NULL);
@ -517,18 +503,14 @@ static BOOL init(void)
p_o__register_onexit_function = (void*)GetProcAddress(module, "_o__register_onexit_function");
p_o__execute_onexit_table = (void*)GetProcAddress(module, "_o__execute_onexit_table");
p___fpe_flt_rounds = (void*)GetProcAddress(module, "__fpe_flt_rounds");
p__controlfp = (void*)GetProcAddress(module, "_controlfp");
p__set_invalid_parameter_handler = (void*)GetProcAddress(module, "_set_invalid_parameter_handler");
p__get_invalid_parameter_handler = (void*)GetProcAddress(module, "_get_invalid_parameter_handler");
p__set_thread_local_invalid_parameter_handler = (void*)GetProcAddress(module, "_set_thread_local_invalid_parameter_handler");
p__get_thread_local_invalid_parameter_handler = (void*)GetProcAddress(module, "_get_thread_local_invalid_parameter_handler");
p__ltoa_s = (void*)GetProcAddress(module, "_ltoa_s");
p__get_narrow_winmain_command_line = (void*)GetProcAddress(GetModuleHandleA("ucrtbase.dll"), "_get_narrow_winmain_command_line");
p_sopen_dispatch = (void*)GetProcAddress(module, "_sopen_dispatch");
p_sopen_s = (void*)GetProcAddress(module, "_sopen_s");
p__open = (void*)GetProcAddress(module, "_open");
p_lldiv = (void*)GetProcAddress(module, "lldiv");
p__isctype = (void*)GetProcAddress(module, "_isctype");
p_isblank = (void*)GetProcAddress(module, "isblank");
p__isblank_l = (void*)GetProcAddress(module, "_isblank_l");
p__iswctype_l = (void*)GetProcAddress(module, "_iswctype_l");
@ -536,22 +518,12 @@ static BOOL init(void)
p__iswblank_l = (void*)GetProcAddress(module, "_iswblank_l");
p_fesetround = (void*)GetProcAddress(module, "fesetround");
p___setusermatherr = (void*)GetProcAddress(module, "__setusermatherr");
p_errno = (void*)GetProcAddress(module, "_errno");
p_asctime = (void*)GetProcAddress(module, "asctime");
p_strftime = (void*)GetProcAddress(module, "strftime");
p__Strftime = (void*)GetProcAddress(module, "_Strftime");
p_setlocale = (void*)GetProcAddress(module, "setlocale");
p__gmtime32 = (void*)GetProcAddress(module, "_gmtime32");
p__crt_atexit = (void*)GetProcAddress(module, "_crt_atexit");
p_exit = (void*)GetProcAddress(module, "exit");
p_crt_at_quick_exit = (void*)GetProcAddress(module, "_crt_at_quick_exit");
p_quick_exit = (void*)GetProcAddress(module, "quick_exit");
p__stat32 = (void*)GetProcAddress(module, "_stat32");
p__close = (void*)GetProcAddress(module, "_close");
p__o_malloc = (void*)GetProcAddress(module, "_o_malloc");
p__msize = (void*)GetProcAddress(module, "_msize");
p_free = (void*)GetProcAddress(module, "free");
p_clock = (void*)GetProcAddress(module, "clock");
return TRUE;
}
@ -567,7 +539,7 @@ static void test__sopen_dispatch(void)
ret = p_sopen_dispatch(tempf, _O_CREAT, _SH_DENYWR, 0xff, &fd, 0);
ok(!ret, "got %d\n", ret);
ok(fd > 0, "got fd %d\n", fd);
p__close(fd);
_close(fd);
unlink(tempf);
SET_EXPECT(global_invalid_parameter_handler);
@ -578,7 +550,7 @@ static void test__sopen_dispatch(void)
CHECK_CALLED(global_invalid_parameter_handler);
if (fd > 0)
{
p__close(fd);
_close(fd);
unlink(tempf);
}
@ -596,13 +568,13 @@ static void test__sopen_s(void)
ret = p_sopen_s(&fd, tempf, _O_CREAT, _SH_DENYWR, 0);
ok(!ret, "got %d\n", ret);
ok(fd > 0, "got fd %d\n", fd);
p__close(fd);
_close(fd);
unlink(tempf);
/* _open() does not validate pmode */
fd = p__open(tempf, _O_CREAT, 0xff);
fd = _open(tempf, _O_CREAT, 0xff);
ok(fd > 0, "got fd %d\n", fd);
p__close(fd);
_close(fd);
unlink(tempf);
/* _sopen_s() invokes invalid parameter handler on invalid pmode */
@ -632,13 +604,13 @@ static void test_isblank(void)
for(c = 0; c <= 0xff; c++) {
if(c == '\t' || c == ' ') {
if(c == '\t')
ok(!p__isctype(c, _BLANK), "tab shouldn't be blank\n");
ok(!_isctype(c, _BLANK), "tab shouldn't be blank\n");
else
ok(p__isctype(c, _BLANK), "space should be blank\n");
ok(_isctype(c, _BLANK), "space should be blank\n");
ok(p_isblank(c), "%d should be blank\n", c);
ok(p__isblank_l(c, NULL), "%d should be blank\n", c);
} else {
ok(!p__isctype(c, _BLANK), "%d shouldn't be blank\n", c);
ok(!_isctype(c, _BLANK), "%d shouldn't be blank\n", c);
ok(!p_isblank(c), "%d shouldn't be blank\n", c);
ok(!p__isblank_l(c, NULL), "%d shouldn't be blank\n", c);
}
@ -848,11 +820,11 @@ static void test_math_errors(void)
for(i = 0; i < ARRAY_SIZE(testsd); i++) {
p_funcd = (void*)GetProcAddress(module, testsd[i].func);
*p_errno() = -1;
errno = -1;
exception.type = -1;
p_funcd(testsd[i].x);
ok(*p_errno() == testsd[i].error,
"%s(%f) got errno %d\n", testsd[i].func, testsd[i].x, *p_errno());
ok(errno == testsd[i].error,
"%s(%f) got errno %d\n", testsd[i].func, testsd[i].x, errno);
ok(exception.type == testsd[i].exception,
"%s(%f) got exception type %d\n", testsd[i].func, testsd[i].x, exception.type);
if(exception.type == -1) continue;
@ -862,11 +834,11 @@ static void test_math_errors(void)
for(i = 0; i < ARRAY_SIZE(tests2d); i++) {
p_func2d = (void*)GetProcAddress(module, tests2d[i].func);
*p_errno() = -1;
errno = -1;
exception.type = -1;
p_func2d(tests2d[i].a, tests2d[i].b);
ok(*p_errno() == tests2d[i].error,
"%s(%f, %f) got errno %d\n", tests2d[i].func, tests2d[i].a, tests2d[i].b, *p_errno());
ok(errno == tests2d[i].error,
"%s(%f, %f) got errno %d\n", tests2d[i].func, tests2d[i].a, tests2d[i].b, errno);
ok(exception.type == tests2d[i].exception,
"%s(%f, %f) got exception type %d\n", tests2d[i].func, tests2d[i].a, tests2d[i].b, exception.type);
if(exception.type == -1) continue;
@ -878,11 +850,11 @@ static void test_math_errors(void)
for(i = 0; i < ARRAY_SIZE(tests3d); i++) {
p_func3d = (void*)GetProcAddress(module, tests3d[i].func);
*p_errno() = -1;
errno = -1;
exception.type = -1;
p_func3d(tests3d[i].a, tests3d[i].b, tests3d[i].c);
ok(*p_errno() == tests3d[i].error,
"%s(%f, %f, %f) got errno %d\n", tests3d[i].func, tests3d[i].a, tests3d[i].b, tests3d[i].c, *p_errno());
ok(errno == tests3d[i].error,
"%s(%f, %f, %f) got errno %d\n", tests3d[i].func, tests3d[i].a, tests3d[i].b, tests3d[i].c, errno);
ok(exception.type == tests3d[i].exception,
"%s(%f, %f, %f) got exception type %d\n", tests3d[i].func, tests3d[i].a, tests3d[i].b, tests3d[i].c, exception.type);
if(exception.type == -1) continue;
@ -894,11 +866,11 @@ static void test_math_errors(void)
for(i = 0; i < ARRAY_SIZE(testsdl); i++) {
p_funcdl = (void*)GetProcAddress(module, testsdl[i].func);
*p_errno() = -1;
errno = -1;
exception.type = -1;
p_funcdl(testsdl[i].a, testsdl[i].b);
ok(*p_errno() == testsdl[i].error,
"%s(%f, %ld) got errno %d\n", testsdl[i].func, testsdl[i].a, testsdl[i].b, *p_errno());
ok(errno == testsdl[i].error,
"%s(%f, %ld) got errno %d\n", testsdl[i].func, testsdl[i].a, testsdl[i].b, errno);
ok(exception.type == testsdl[i].exception,
"%s(%f, %ld) got exception type %d\n", testsdl[i].func, testsdl[i].a, testsdl[i].b, exception.type);
if(exception.type == -1) continue;
@ -914,13 +886,7 @@ static void test_asctime(void)
const struct tm epoch = { 0, 0, 0, 1, 0, 70, 4, 0, 0 };
char *ret;
if(!p_asctime)
{
win_skip("asctime is not available\n");
return;
}
ret = p_asctime(&epoch);
ret = asctime(&epoch);
ok(!strcmp(ret, "Thu Jan 1 00:00:00 1970\n"), "asctime returned %s\n", ret);
}
@ -1144,7 +1110,7 @@ static void test_strftime(void)
todo_wine_if(tests[i].todo_handler) {
if (!tests[i].ret[0])
SET_EXPECT(global_invalid_parameter_handler);
ret = p_strftime(buf, sizeof(buf), tests[i].format, &tests[i].tm);
ret = strftime(buf, sizeof(buf), tests[i].format, &tests[i].tm);
if (!tests[i].ret[0])
CHECK_CALLED(global_invalid_parameter_handler);
}
@ -1156,7 +1122,7 @@ static void test_strftime(void)
}
}
ret = p_strftime(buf, sizeof(buf), "%z", &epoch);
ret = strftime(buf, sizeof(buf), "%z", &epoch);
ok(ret == 5, "expected 5, got %d\n", ret);
ok((buf[0] == '+' || buf[0] == '-') &&
isdigit(buf[1]) && isdigit(buf[2]) &&
@ -1183,23 +1149,23 @@ static void test_strftime(void)
for (j=0; j<7; j++)
{
tm_yweek.tm_wday = j;
p_strftime(buf, sizeof(buf), "%g %V", &tm_yweek);
strftime(buf, sizeof(buf), "%g %V", &tm_yweek);
ok(!strcmp(buf, tests_yweek[i].ret[j]), "%d,%d) buf = \"%s\", expected \"%s\"\n",
i, j, buf, tests_yweek[i].ret[j]);
}
}
if(!p_setlocale(LC_ALL, "fr-FR")) {
if(!setlocale(LC_ALL, "fr-FR")) {
win_skip("fr-FR locale not available\n");
return;
}
ret = p_strftime(buf, sizeof(buf), "%c", &epoch);
ret = strftime(buf, sizeof(buf), "%c", &epoch);
ok(ret == 19, "ret = %d\n", ret);
ok(!strcmp(buf, "01/01/1970 00:00:00"), "buf = \"%s\", expected \"%s\"\n", buf, "01/01/1970 00:00:00");
ret = p_strftime(buf, sizeof(buf), "%r", &epoch);
ret = strftime(buf, sizeof(buf), "%r", &epoch);
ok(ret == 8, "ret = %d\n", ret);
ok(!strcmp(buf, "00:00:00"), "buf = \"%s\", expected \"%s\"\n", buf, "00:00:00");
p_setlocale(LC_ALL, "C");
setlocale(LC_ALL, "C");
}
static LONG* get_failures_counter(HANDLE *map)
@ -1311,7 +1277,7 @@ static void test_call_exit(void)
ok(!p_crt_at_quick_exit(at_quick_exit_func2), "_crt_at_quick_exit failed\n");
set_failures_counter(winetest_get_failures());
p_exit(1);
exit(1);
}
static void test_call_quick_exit(void)
@ -1373,18 +1339,18 @@ static void test__stat32(void)
len = GetTempPathA(MAX_PATH, path);
ok(len, "GetTempPathA failed\n");
ret = p__stat32("c:", &buf);
ret = _stat32("c:", &buf);
ok(ret == -1, "_stat32('c:') returned %d\n", ret);
ret = p__stat32("c:\\", &buf);
ret = _stat32("c:\\", &buf);
ok(!ret, "_stat32('c:\\') returned %d\n", ret);
memcpy(path+len, test_file, sizeof(test_file));
if((fd = open(path, O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE)) >= 0)
{
ret = p__stat32(path, &buf);
ret = _stat32(path, &buf);
ok(!ret, "_stat32('%s') returned %d\n", path, ret);
strcat(path, "\\");
ret = p__stat32(path, &buf);
ret = _stat32(path, &buf);
todo_wine ok(ret, "_stat32('%s') returned %d\n", path, ret);
close(fd);
remove(path);
@ -1393,10 +1359,10 @@ static void test__stat32(void)
memcpy(path+len, test_dir, sizeof(test_dir));
if(!mkdir(path))
{
ret = p__stat32(path, &buf);
ret = _stat32(path, &buf);
ok(!ret, "_stat32('%s') returned %d\n", path, ret);
strcat(path, "\\");
ret = p__stat32(path, &buf);
ret = _stat32(path, &buf);
ok(!ret, "_stat32('%s') returned %d\n", path, ret);
rmdir(path);
}
@ -1413,7 +1379,7 @@ static void test__o_malloc(void)
s = p__msize(m);
ok(s == 1, "_msize returned %d\n", (int)s);
p_free(m);
free(m);
}
static void test_clock(void)
@ -1423,7 +1389,7 @@ static void test_clock(void)
FILETIME cur;
GetSystemTimeAsFileTime(&cur);
c = p_clock();
c = clock();
expect_min = (((LONGLONG)cur.dwHighDateTime << 32) + cur.dwLowDateTime - crt_init_end) / 10000;
expect_max = (((LONGLONG)cur.dwHighDateTime << 32) + cur.dwLowDateTime - crt_init_start) / 10000;