[APITESTS/CRT]

- Add more tests for _vsnprintf
- Add tests for _vsnwprintf, _vscprintf, _vscwprintf

svn path=/trunk/; revision=56928
This commit is contained in:
Jérôme Gardou 2012-07-21 20:00:56 +00:00
parent ab3aa90f77
commit 221e348e01
8 changed files with 150 additions and 9 deletions

View file

@ -0,0 +1,29 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL - See COPYING in the top level directory
* PURPOSE: Test for _vscprintf
*/
#include <stdio.h>
#include <wine/test.h>
#include <tchar.h>
static void call_varargs(int expected_ret, LPCSTR formatString, ...)
{
va_list args;
int ret;
/* Test the basic functionality */
va_start(args, formatString);
ret = _vscprintf(formatString, args);
ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
}
START_TEST(_vscprintf)
{
/* Here you can mix wide and ANSI strings */
call_varargs(12, "%S world!", L"hello");
call_varargs(12, "%s world!", "hello");
call_varargs(11, "%u cookies", 100);
/* Test NULL argument */
call_varargs(-1, NULL);
}

View file

@ -0,0 +1,30 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL - See COPYING in the top level directory
* PURPOSE: Test for _vscprintf
*/
#include <stdio.h>
#include <wine/test.h>
#include <tchar.h>
static void call_varargs(int expected_ret, LPCWSTR formatString, ...)
{
va_list args;
int ret;
/* Test the basic functionality */
va_start(args, formatString);
ret = _vscwprintf(formatString, args);
ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
}
START_TEST(_vscwprintf)
{
/* Lesson of the day: don't mix wide and ansi char */
call_varargs(19, L"%s world!", "hello");
call_varargs(12, L"%s world!", L"hello");
call_varargs(17, L"Jack ate %u pies", 100);
/* Test NULL argument */
call_varargs(-1, NULL);
}

View file

@ -15,7 +15,7 @@
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
{
va_list args;
int ret;
@ -29,8 +29,10 @@ START_TEST(_vsnprintf)
{
char buffer[255];
NTSTATUS ExceptionStatus;
/* Test basic functionality */
/* 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");
call_varargs(buffer, 255, 11, "%u cookies", 100);
/* This is how WINE implements _vcsprintf, and they are obviously wrong */
StartSeh()
call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
@ -40,11 +42,19 @@ START_TEST(_vsnprintf)
EndSeh(STATUS_SUCCESS);
#endif
/* This one is no better */
StartSeh()
StartSeh()
call_varargs(NULL, 0, -1, "%s it really work?", "does");
#if defined(TEST_CRTDLL) || defined(TEST_USER32)
EndSeh(STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);
#endif
/* One more NULL checks */
StartSeh()
call_varargs(buffer, 255, -1, NULL);
#if defined(TEST_CRTDLL)
EndSeh(STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);
#endif
}

View file

@ -0,0 +1,60 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL - See COPYING in the top level directory
* PURPOSE: Test for _vsnprintf
*/
#define WIN32_NO_STATUS
#include <stdio.h>
#include <wine/test.h>
#include <tchar.h>
#include <pseh/pseh2.h>
#include <ndk/mmfuncs.h>
#include <ndk/rtlfuncs.h>
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
static void call_varargs(wchar_t* buf, size_t buf_size, int expected_ret, LPCWSTR formatString, ...)
{
va_list args;
int ret;
/* Test the basic functionality */
va_start(args, formatString);
ret = _vsnwprintf(buf, 255, formatString, args);
ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
}
START_TEST(_vsnwprintf)
{
wchar_t buffer[255];
NTSTATUS ExceptionStatus;
/* Test basic functionality */
call_varargs(buffer, 255, 19, L"%s world!", "hello");
call_varargs(buffer, 255, 12, L"%s world!", L"hello");
call_varargs(buffer, 255, 11, L"%u cookies", 100);
/* This is how WINE implements _vcsprintf, and they are obviously wrong */
StartSeh()
call_varargs(NULL, INT_MAX, -1, L"%s it really work?", L"does");
#if defined(TEST_CRTDLL)
EndSeh(STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);
#endif
/* This one is no better */
StartSeh()
call_varargs(NULL, 0, -1, L"%s it really work?", L"does");
#if defined(TEST_CRTDLL)
EndSeh(STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);
#endif
/* One more NULL checks */
StartSeh()
call_varargs(buffer, 255, -1, NULL);
#if defined(TEST_CRTDLL)
EndSeh(STATUS_ACCESS_VIOLATION);
#else
EndSeh(STATUS_SUCCESS);
#endif
}

View file

@ -315,7 +315,7 @@ list(APPEND SOURCE_CRTDLL
# _unloaddll.c
# _utime.c
_vsnprintf.c
# _vsnwprintf.c
_vsnwprintf.c
# _wcsdup.c
# _wcsicmp.c
# _wcsicoll.c

View file

@ -826,10 +826,10 @@ list(APPEND SOURCE_MSVCRT
# _vprintf_p_l
# _vprintf_s_l
# _utime.c
# _vscprintf.c
_vscprintf.c
# _vscprintf_l
# _vscprintf_p_l
# _vscwprintf.c
_vscwprintf.c
# _vscwprintf_l
# _vscwprintf_p_l
_vsnprintf.c
@ -838,7 +838,7 @@ list(APPEND SOURCE_MSVCRT
# _vsnprintf_l.c
# _vsnprintf_s.c
# _vsnprintf_s_l.c
# _vsnwprintf.c
_vsnwprintf.c
# _vsnwprintf_l.c
# _vsnwprintf_s.c
# _vsnwprintf_s_l.c

View file

@ -33,9 +33,9 @@ list(APPEND SOURCE_NTDLL
# _ui64tow.c
# _ultoa.c
# _ultow.c
# _vscwprintf.c
_vscwprintf.c
_vsnprintf.c
# _vsnwprintf.c
_vsnwprintf.c
# _wcsicmp.c
# _wcslwr.c
# _wcsnicmp.c

View file

@ -5,13 +5,22 @@
#define STANDALONE
#include "wine/test.h"
#if defined(TEST_MSVCRT)
extern void func__vscprintf(void);
extern void func__vscwprintf(void);
#endif
#if defined(TEST_NTDLL)
extern void func__vscwprintf(void);
#endif
extern void func__vsnprintf(void);
extern void func__vsnwprintf(void);
extern void func_sprintf(void);
extern void func_strcpy(void);
const struct test winetest_testlist[] =
{
{ "_vsnprintf", func__vsnprintf },
{ "_vsnwprintf", func__vsnwprintf },
{ "sprintf", func_sprintf },
{ "strcpy", func_strcpy },
#if defined(TEST_CRTDLL) || defined(TEST_MSVCRT) || defined(TEST_STATIC_CRT)
@ -22,7 +31,10 @@ const struct test winetest_testlist[] =
#endif
#if defined(TEST_STATIC_CRT)
#elif defined(TEST_MSVCRT)
{ "_vscprintf", func__vscprintf },
{ "_vscwprintf", func__vscwprintf },
#elif defined(TEST_NTDLL)
{ "_vscwprintf", func__vscwprintf },
#elif defined(TEST_CRTDLL)
#endif
{ 0, 0 }