2012-07-21 20:00:56 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2014-09-30 21:10:15 +00:00
|
|
|
* PURPOSE: Test for _vsnwprintf
|
2012-07-21 20:00:56 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-22 17:52:42 +00:00
|
|
|
#include <apitest.h>
|
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <pseh/pseh2.h>
|
|
|
|
#include <ndk/mmfuncs.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
|
|
|
|
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);
|
2014-09-08 07:00:00 +00:00
|
|
|
ret = _vsnwprintf(buf, buf_size, formatString, args);
|
2012-07-21 20:00:56 +00:00
|
|
|
ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(_vsnwprintf)
|
|
|
|
{
|
|
|
|
wchar_t buffer[255];
|
2013-09-22 19:07:35 +00:00
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
/* Test basic functionality */
|
2015-04-04 13:42:41 +00:00
|
|
|
//call_varargs(buffer, 255, 10, L"%s world!", "hello"); // this test is broken
|
2012-07-21 20:00:56 +00:00
|
|
|
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()
|
|
|
|
#if defined(TEST_CRTDLL)
|
2014-09-30 21:10:15 +00:00
|
|
|
call_varargs(NULL, INT_MAX, -1, L"%s it really work?", L"does");
|
2015-04-04 13:42:41 +00:00
|
|
|
#else
|
2014-09-30 21:10:15 +00:00
|
|
|
call_varargs(NULL, INT_MAX, 20, L"%s it really work?", L"does");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TEST_USER32)
|
2012-07-21 20:00:56 +00:00
|
|
|
EndSeh(STATUS_ACCESS_VIOLATION);
|
2015-04-04 13:42:41 +00:00
|
|
|
#else
|
2012-07-21 20:00:56 +00:00
|
|
|
EndSeh(STATUS_SUCCESS);
|
2012-07-21 20:15:12 +00:00
|
|
|
#endif
|
2014-09-30 21:10:15 +00:00
|
|
|
|
|
|
|
#if defined(TEST_USER32)/* NTDLL doesn't use/set errno */
|
2012-07-21 20:15:12 +00:00
|
|
|
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
2015-04-04 13:42:41 +00:00
|
|
|
#else
|
2014-09-30 21:10:15 +00:00
|
|
|
ok(errno == 0, "Expected 0, got %u\n", errno);
|
2012-07-21 20:00:56 +00:00
|
|
|
#endif
|
2015-04-04 13:42:41 +00:00
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
/* This one is no better */
|
|
|
|
StartSeh()
|
|
|
|
#if defined(TEST_CRTDLL)
|
2014-09-30 21:10:15 +00:00
|
|
|
call_varargs(NULL, 0, -1, L"%s it really work?", L"does");
|
2015-04-04 13:42:41 +00:00
|
|
|
#else
|
2014-09-30 21:10:15 +00:00
|
|
|
call_varargs(NULL, 0, 20, L"%s it really work?", L"does");
|
2012-07-21 20:00:56 +00:00
|
|
|
#endif
|
2014-09-30 21:10:15 +00:00
|
|
|
EndSeh(STATUS_SUCCESS);
|
|
|
|
ok(errno == 0, "Expected 0, got %u\n", errno);
|
|
|
|
|
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
/* One more NULL checks */
|
|
|
|
StartSeh()
|
|
|
|
call_varargs(buffer, 255, -1, NULL);
|
|
|
|
EndSeh(STATUS_ACCESS_VIOLATION);
|
2014-09-30 21:10:15 +00:00
|
|
|
ok(errno == 0, "Expected 0, got %u\n", errno);
|
2012-07-21 20:00:56 +00:00
|
|
|
}
|