mirror of
https://github.com/reactos/reactos.git
synced 2026-06-02 01:11:03 +08:00
[CRT_APITEST] Fix tests for _vs(c/n)(w)printf
- Dynamically load function from the appropriate DLL - Fix tests for ntdll/crtdll
This commit is contained in:
@@ -10,6 +10,22 @@
|
||||
#include <tchar.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
|
||||
typedef int (__cdecl *PFN_vscprintf)(const char *format, va_list argptr);
|
||||
static PFN_vscprintf p_vscprintf;
|
||||
|
||||
static BOOL Init(void)
|
||||
{
|
||||
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
|
||||
p_vscprintf = (PFN_vscprintf)GetProcAddress(hdll, "_vscprintf");
|
||||
ok(p_vscprintf != NULL, "Failed to load _vscprintf from %s\n", TEST_DLL_NAME);
|
||||
return (p_vscprintf != NULL);
|
||||
}
|
||||
#define _vscprintf p_vscprintf
|
||||
|
||||
#endif // !TEST_STATIC_CRT
|
||||
|
||||
static void call_varargs(int expected_ret, LPCSTR formatString, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -23,6 +39,14 @@ static void call_varargs(int expected_ret, LPCSTR formatString, ...)
|
||||
|
||||
START_TEST(_vscprintf)
|
||||
{
|
||||
#ifndef TEST_STATIC_CRT
|
||||
if (!Init())
|
||||
{
|
||||
skip("Skipping tests, because _vscprintf is not available\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Here you can mix wide and ANSI strings */
|
||||
call_varargs(12, "%S world!", L"hello");
|
||||
call_varargs(12, "%s world!", "hello");
|
||||
|
||||
@@ -10,6 +10,22 @@
|
||||
#include <tchar.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
|
||||
typedef int (__cdecl *PFN_vscwprintf)(const char *format, va_list argptr);
|
||||
static PFN_vscwprintf p_vscwprintf;
|
||||
|
||||
static BOOL Init(void)
|
||||
{
|
||||
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
|
||||
p_vscwprintf = (PFN_vscwprintf)GetProcAddress(hdll, "_vscwprintf");
|
||||
ok(p_vscwprintf != NULL, "Failed to load _vscwprintf from %s\n", TEST_DLL_NAME);
|
||||
return (p_vscwprintf != NULL);
|
||||
}
|
||||
#define _vscprintf p_vscwprintf
|
||||
|
||||
#endif // !TEST_STATIC_CRT
|
||||
|
||||
static void call_varargs(int expected_ret, LPCWSTR formatString, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -23,6 +39,14 @@ static void call_varargs(int expected_ret, LPCWSTR formatString, ...)
|
||||
|
||||
START_TEST(_vscwprintf)
|
||||
{
|
||||
#ifndef TEST_STATIC_CRT
|
||||
if (!Init())
|
||||
{
|
||||
skip("Skipping tests, because _vscwprintf is not available\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Lesson of the day: don't mix wide and ansi char */
|
||||
/* Lesson of the week: don't ignore the lesson of the day */
|
||||
call_varargs(12, L"%hs world!", "hello");
|
||||
|
||||
@@ -13,6 +13,22 @@
|
||||
#include <ndk/mmfuncs.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
|
||||
typedef int (__cdecl *PFN_vsnprintf)(char *buf, size_t cnt, const char *fmt, va_list args);
|
||||
static PFN_vsnprintf p_vsnprintf;
|
||||
|
||||
static BOOL Init(void)
|
||||
{
|
||||
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
|
||||
p_vsnprintf = (PFN_vsnprintf)GetProcAddress(hdll, "_vsnprintf");
|
||||
ok(p_vsnprintf != NULL, "Failed to load _vsnprintf from %s\n", TEST_DLL_NAME);
|
||||
return (p_vsnprintf != NULL);
|
||||
}
|
||||
#define _vsnprintf p_vsnprintf
|
||||
|
||||
#endif // !TEST_STATIC_CRT
|
||||
|
||||
static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -28,6 +44,14 @@ START_TEST(_vsnprintf)
|
||||
{
|
||||
char buffer[255];
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
if (!Init())
|
||||
{
|
||||
skip("Skipping tests, because _vsnprintf is not available\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Here you can mix wide and ANSI strings */
|
||||
call_varargs(buffer, 255, 12, "%S world!", L"hello");
|
||||
call_varargs(buffer, 255, 12, "%s world!", "hello");
|
||||
@@ -49,8 +73,10 @@ START_TEST(_vsnprintf)
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
#endif
|
||||
|
||||
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
|
||||
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
||||
#if defined(TEST_USER32)
|
||||
ok_eq_uint(errno, EINVAL);
|
||||
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
@@ -72,8 +98,10 @@ START_TEST(_vsnprintf)
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
#endif
|
||||
|
||||
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
|
||||
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
||||
#if defined(TEST_USER32)
|
||||
ok_eq_uint(errno, EINVAL);
|
||||
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
@@ -84,10 +112,16 @@ START_TEST(_vsnprintf)
|
||||
/* One more NULL checks */
|
||||
StartSeh()
|
||||
call_varargs(buffer, 255, -1, NULL);
|
||||
#if defined(TEST_CRTDLL)
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
#else
|
||||
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
|
||||
#endif
|
||||
|
||||
#if defined(TEST_USER32) /* NTDLL doesn't use/set errno */
|
||||
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
||||
#if defined(TEST_USER32)
|
||||
ok_eq_uint(errno, EINVAL);
|
||||
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
|
||||
@@ -13,6 +13,22 @@
|
||||
#include <ndk/mmfuncs.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
|
||||
typedef int (__cdecl *PFN_vsnwprintf)(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args);
|
||||
static PFN_vsnwprintf p_vsnwprintf;
|
||||
|
||||
static BOOL Init(void)
|
||||
{
|
||||
HMODULE hdll = LoadLibraryA(TEST_DLL_NAME);
|
||||
p_vsnwprintf = (PFN_vsnwprintf)GetProcAddress(hdll, "_vsnwprintf");
|
||||
ok(p_vsnwprintf != NULL, "Failed to load _vsnwprintf from %s\n", TEST_DLL_NAME);
|
||||
return (p_vsnwprintf != NULL);
|
||||
}
|
||||
#define _vsnwprintf p_vsnwprintf
|
||||
|
||||
#endif // !TEST_STATIC_CRT
|
||||
|
||||
static void call_varargs(wchar_t* buf, size_t buf_size, int expected_ret, LPCWSTR formatString, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -28,6 +44,14 @@ START_TEST(_vsnwprintf)
|
||||
{
|
||||
wchar_t buffer[255];
|
||||
|
||||
#ifndef TEST_STATIC_CRT
|
||||
if (!Init())
|
||||
{
|
||||
skip("Skipping tests, because _vsnwprintf is not available\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Test basic functionality */
|
||||
//call_varargs(buffer, 255, 10, L"%s world!", "hello"); // this test is broken
|
||||
call_varargs(buffer, 255, 12, L"%s world!", L"hello");
|
||||
@@ -49,13 +73,15 @@ START_TEST(_vsnwprintf)
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
#endif
|
||||
|
||||
#if defined(TEST_USER32)/* NTDLL doesn't use/set errno */
|
||||
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
||||
#if defined(TEST_USER32)
|
||||
ok_eq_uint(errno, EINVAL);
|
||||
#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
else
|
||||
ok(errno == 0, "Expected 0, got %u\n", errno);
|
||||
ok_eq_uint(errno, 0);
|
||||
#endif
|
||||
|
||||
/* This one is no better */
|
||||
@@ -66,18 +92,29 @@ START_TEST(_vsnwprintf)
|
||||
call_varargs(NULL, 0, 20, L"%s it really work?", L"does");
|
||||
#endif
|
||||
EndSeh(STATUS_SUCCESS);
|
||||
#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
else
|
||||
ok(errno == 0, "Expected 0, got %u\n", errno);
|
||||
|
||||
ok_eq_uint(errno, 0);
|
||||
#endif
|
||||
|
||||
/* One more NULL checks */
|
||||
StartSeh()
|
||||
call_varargs(buffer, 255, -1, NULL);
|
||||
#if defined(TEST_CRTDLL)
|
||||
EndSeh(STATUS_ACCESS_VIOLATION);
|
||||
#else
|
||||
EndSeh((GetNTVersion() >= _WIN32_WINNT_VISTA) ? 0 : STATUS_ACCESS_VIOLATION);
|
||||
#endif
|
||||
#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
|
||||
ok_eq_uint(errno, 0);
|
||||
#else
|
||||
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
|
||||
ok(errno == ERROR_BAD_COMMAND, "Expected 0, got %u\n", errno);
|
||||
ok_eq_uint(errno, ERROR_BAD_COMMAND);
|
||||
else
|
||||
ok(errno == 0, "Expected 0, got %u\n", errno);
|
||||
ok_eq_uint(errno, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user