diff --git a/rostests/apitests/crt/_vscprintf.c b/rostests/apitests/crt/_vscprintf.c new file mode 100644 index 00000000000..c3717abaa6a --- /dev/null +++ b/rostests/apitests/crt/_vscprintf.c @@ -0,0 +1,29 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for _vscprintf + */ + +#include +#include +#include + +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); +} diff --git a/rostests/apitests/crt/_vscwprintf.c b/rostests/apitests/crt/_vscwprintf.c new file mode 100644 index 00000000000..0c35e2a5b77 --- /dev/null +++ b/rostests/apitests/crt/_vscwprintf.c @@ -0,0 +1,30 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for _vscprintf + */ + +#include +#include +#include + +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); +} diff --git a/rostests/apitests/crt/_vsnprintf.c b/rostests/apitests/crt/_vsnprintf.c index a6b116559c6..739b2c9d48f 100644 --- a/rostests/apitests/crt/_vsnprintf.c +++ b/rostests/apitests/crt/_vsnprintf.c @@ -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 } diff --git a/rostests/apitests/crt/_vsnwprintf.c b/rostests/apitests/crt/_vsnwprintf.c new file mode 100644 index 00000000000..042e0f00ce8 --- /dev/null +++ b/rostests/apitests/crt/_vsnwprintf.c @@ -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 +#include +#include +#include +#include +#include + +#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 +} diff --git a/rostests/apitests/crt/crtdll_crt_apitest.cmake b/rostests/apitests/crt/crtdll_crt_apitest.cmake index 5cf8dd26ee1..d8b8571f7a5 100644 --- a/rostests/apitests/crt/crtdll_crt_apitest.cmake +++ b/rostests/apitests/crt/crtdll_crt_apitest.cmake @@ -315,7 +315,7 @@ list(APPEND SOURCE_CRTDLL # _unloaddll.c # _utime.c _vsnprintf.c -# _vsnwprintf.c + _vsnwprintf.c # _wcsdup.c # _wcsicmp.c # _wcsicoll.c diff --git a/rostests/apitests/crt/msvcrt_crt_apitest.cmake b/rostests/apitests/crt/msvcrt_crt_apitest.cmake index 3994110f1f1..3bf1d6ebe1a 100644 --- a/rostests/apitests/crt/msvcrt_crt_apitest.cmake +++ b/rostests/apitests/crt/msvcrt_crt_apitest.cmake @@ -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 diff --git a/rostests/apitests/crt/ntdll_crt_apitest.cmake b/rostests/apitests/crt/ntdll_crt_apitest.cmake index 55421141ec1..74509517af2 100644 --- a/rostests/apitests/crt/ntdll_crt_apitest.cmake +++ b/rostests/apitests/crt/ntdll_crt_apitest.cmake @@ -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 diff --git a/rostests/apitests/crt/testlist.c b/rostests/apitests/crt/testlist.c index 780c73954c3..f84b4959381 100644 --- a/rostests/apitests/crt/testlist.c +++ b/rostests/apitests/crt/testlist.c @@ -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 }