Skip to content

Commit ba592da

Browse files
committed
[CRT_APITEST] Fix tests for _vs(c/n)(w)printf
- Dynamically load function from the appropriate DLL - Fix tests for ntdll/crtdll
1 parent e1f843b commit ba592da

File tree

4 files changed

+134
-15
lines changed

4 files changed

+134
-15
lines changed

modules/rostests/apitests/crt/_vscprintf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
#include <tchar.h>
1111
#include <errno.h>
1212

13+
#ifndef TEST_STATIC_CRT
14+
15+
typedef int (__cdecl *PFN_vscprintf)(const char *format, va_list argptr);
16+
static PFN_vscprintf p_vscprintf;
17+
18+
static BOOL Init(void)
19+
{
20+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
21+
p_vscprintf = (PFN_vscprintf)GetProcAddress(hdll, "_vscprintf");
22+
ok(p_vscprintf != NULL, "Failed to load _vscprintf from %s\n", TEST_DLL_NAME);
23+
return (p_vscprintf != NULL);
24+
}
25+
#define _vscprintf p_vscprintf
26+
27+
#endif // !TEST_STATIC_CRT
28+
1329
static void call_varargs(int expected_ret, LPCSTR formatString, ...)
1430
{
1531
va_list args;
@@ -23,6 +39,14 @@ static void call_varargs(int expected_ret, LPCSTR formatString, ...)
2339

2440
START_TEST(_vscprintf)
2541
{
42+
#ifndef TEST_STATIC_CRT
43+
if (!Init())
44+
{
45+
skip("Skipping tests, because _vscprintf is not available\n");
46+
return;
47+
}
48+
#endif
49+
2650
/* Here you can mix wide and ANSI strings */
2751
call_varargs(12, "%S world!", L"hello");
2852
call_varargs(12, "%s world!", "hello");

modules/rostests/apitests/crt/_vscwprintf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
#include <tchar.h>
1111
#include <errno.h>
1212

13+
#ifndef TEST_STATIC_CRT
14+
15+
typedef int (__cdecl *PFN_vscwprintf)(const char *format, va_list argptr);
16+
static PFN_vscwprintf p_vscwprintf;
17+
18+
static BOOL Init(void)
19+
{
20+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
21+
p_vscwprintf = (PFN_vscwprintf)GetProcAddress(hdll, "_vscwprintf");
22+
ok(p_vscwprintf != NULL, "Failed to load _vscwprintf from %s\n", TEST_DLL_NAME);
23+
return (p_vscwprintf != NULL);
24+
}
25+
#define _vscprintf p_vscwprintf
26+
27+
#endif // !TEST_STATIC_CRT
28+
1329
static void call_varargs(int expected_ret, LPCWSTR formatString, ...)
1430
{
1531
va_list args;
@@ -23,6 +39,14 @@ static void call_varargs(int expected_ret, LPCWSTR formatString, ...)
2339

2440
START_TEST(_vscwprintf)
2541
{
42+
#ifndef TEST_STATIC_CRT
43+
if (!Init())
44+
{
45+
skip("Skipping tests, because _vscwprintf is not available\n");
46+
return;
47+
}
48+
#endif
49+
2650
/* Lesson of the day: don't mix wide and ansi char */
2751
/* Lesson of the week: don't ignore the lesson of the day */
2852
call_varargs(12, L"%hs world!", "hello");

modules/rostests/apitests/crt/_vsnprintf.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@
1313
#include <ndk/mmfuncs.h>
1414
#include <ndk/rtlfuncs.h>
1515

16+
#ifndef TEST_STATIC_CRT
17+
18+
typedef int (__cdecl *PFN_vsnprintf)(char *buf, size_t cnt, const char *fmt, va_list args);
19+
static PFN_vsnprintf p_vsnprintf;
20+
21+
static BOOL Init(void)
22+
{
23+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
24+
p_vsnprintf = (PFN_vsnprintf)GetProcAddress(hdll, "_vsnprintf");
25+
ok(p_vsnprintf != NULL, "Failed to load _vsnprintf from %s\n", TEST_DLL_NAME);
26+
return (p_vsnprintf != NULL);
27+
}
28+
#define _vsnprintf p_vsnprintf
29+
30+
#endif // !TEST_STATIC_CRT
31+
1632
static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
1733
{
1834
va_list args;
@@ -28,6 +44,14 @@ START_TEST(_vsnprintf)
2844
{
2945
char buffer[255];
3046

47+
#ifndef TEST_STATIC_CRT
48+
if (!Init())
49+
{
50+
skip("Skipping tests, because _vsnprintf is not available\n");
51+
return;
52+
}
53+
#endif
54+
3155
/* Here you can mix wide and ANSI strings */
3256
call_varargs(buffer, 255, 12, "%S world!", L"hello");
3357
call_varargs(buffer, 255, 12, "%s world!", "hello");
@@ -49,8 +73,10 @@ START_TEST(_vsnprintf)
4973
EndSeh(STATUS_SUCCESS);
5074
#endif
5175

52-
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
53-
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
76+
#if defined(TEST_USER32)
77+
ok_eq_uint(errno, EINVAL);
78+
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
79+
ok_eq_uint(errno, 0);
5480
#else
5581
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
5682
ok_eq_uint(errno, ERROR_BAD_COMMAND);
@@ -72,8 +98,10 @@ START_TEST(_vsnprintf)
7298
EndSeh(STATUS_SUCCESS);
7399
#endif
74100

75-
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
76-
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
101+
#if defined(TEST_USER32)
102+
ok_eq_uint(errno, EINVAL);
103+
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
104+
ok_eq_uint(errno, 0);
77105
#else
78106
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
79107
ok_eq_uint(errno, ERROR_BAD_COMMAND);
@@ -84,10 +112,16 @@ START_TEST(_vsnprintf)
84112
/* One more NULL checks */
85113
StartSeh()
86114
call_varargs(buffer, 255, -1, NULL);
115+
#if defined(TEST_CRTDLL)
116+
EndSeh(STATUS_ACCESS_VIOLATION);
117+
#else
87118
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
119+
#endif
88120

89-
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
90-
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
121+
#if defined(TEST_USER32)
122+
ok_eq_uint(errno, EINVAL);
123+
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
124+
ok_eq_uint(errno, 0);
91125
#else
92126
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
93127
ok_eq_uint(errno, ERROR_BAD_COMMAND);

modules/rostests/apitests/crt/_vsnwprintf.c

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@
1313
#include <ndk/mmfuncs.h>
1414
#include <ndk/rtlfuncs.h>
1515

16+
#ifndef TEST_STATIC_CRT
17+
18+
typedef int (__cdecl *PFN_vsnwprintf)(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args);
19+
static PFN_vsnwprintf p_vsnwprintf;
20+
21+
static BOOL Init(void)
22+
{
23+
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
24+
p_vsnwprintf = (PFN_vsnwprintf)GetProcAddress(hdll, "_vsnwprintf");
25+
ok(p_vsnwprintf != NULL, "Failed to load _vsnwprintf from %s\n", TEST_DLL_NAME);
26+
return (p_vsnwprintf != NULL);
27+
}
28+
#define _vsnwprintf p_vsnwprintf
29+
30+
#endif // !TEST_STATIC_CRT
31+
1632
static void call_varargs(wchar_t* buf, size_t buf_size, int expected_ret, LPCWSTR formatString, ...)
1733
{
1834
va_list args;
@@ -28,6 +44,14 @@ START_TEST(_vsnwprintf)
2844
{
2945
wchar_t buffer[255];
3046

47+
#ifndef TEST_STATIC_CRT
48+
if (!Init())
49+
{
50+
skip("Skipping tests, because _vsnwprintf is not available\n");
51+
return;
52+
}
53+
#endif
54+
3155
/* Test basic functionality */
3256
//call_varargs(buffer, 255, 10, L"%s world!", "hello"); // this test is broken
3357
call_varargs(buffer, 255, 12, L"%s world!", L"hello");
@@ -49,13 +73,15 @@ START_TEST(_vsnwprintf)
4973
EndSeh(STATUS_SUCCESS);
5074
#endif
5175

52-
#if defined(TEST_USER32)/* NTDLL doesn't use/set errno */
53-
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
76+
#if defined(TEST_USER32)
77+
ok_eq_uint(errno, EINVAL);
78+
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
79+
ok_eq_uint(errno, 0);
5480
#else
5581
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
56-
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
82+
ok_eq_uint(errno, ERROR_BAD_COMMAND);
5783
else
58-
ok(errno == 0, "Expected 0, got %u\n", errno);
84+
ok_eq_uint(errno, 0);
5985
#endif
6086

6187
/* This one is no better */
@@ -66,18 +92,29 @@ START_TEST(_vsnwprintf)
6692
call_varargs(NULL, 0, 20, L"%s it really work?", L"does");
6793
#endif
6894
EndSeh(STATUS_SUCCESS);
95+
#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
96+
ok_eq_uint(errno, 0);
97+
#else
6998
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
70-
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
99+
ok_eq_uint(errno, ERROR_BAD_COMMAND);
71100
else
72-
ok(errno == 0, "Expected 0, got %u\n", errno);
73-
101+
ok_eq_uint(errno, 0);
102+
#endif
74103

75104
/* One more NULL checks */
76105
StartSeh()
77106
call_varargs(buffer, 255, -1, NULL);
107+
#if defined(TEST_CRTDLL)
108+
EndSeh(STATUS_ACCESS_VIOLATION);
109+
#else
78110
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
111+
#endif
112+
#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
113+
ok_eq_uint(errno, 0);
114+
#else
79115
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
80-
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
116+
ok_eq_uint(errno, ERROR_BAD_COMMAND);
81117
else
82-
ok(errno == 0, "Expected 0, got %u\n", errno);
118+
ok_eq_uint(errno, 0);
119+
#endif
83120
}

0 commit comments

Comments
 (0)