2012-07-21 17:15:08 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for _vsnprintf
|
|
|
|
*/
|
|
|
|
|
2013-09-22 17:52:42 +00:00
|
|
|
#include <apitest.h>
|
|
|
|
|
2012-07-21 17:15:08 +00:00
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <pseh/pseh2.h>
|
|
|
|
#include <ndk/mmfuncs.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
|
2012-07-21 17:15:08 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
/* Test the basic functionality */
|
|
|
|
va_start(args, formatString);
|
|
|
|
ret = _vsnprintf(buf, 255, formatString, args);
|
|
|
|
ok(expected_ret == ret, "Test failed: expected %i, got %i.\n", expected_ret, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(_vsnprintf)
|
|
|
|
{
|
|
|
|
char buffer[255];
|
2013-09-22 19:07:35 +00:00
|
|
|
|
2012-07-21 20:00:56 +00:00
|
|
|
/* Here you can mix wide and ANSI strings */
|
|
|
|
call_varargs(buffer, 255, 12, "%S world!", L"hello");
|
2012-07-21 17:15:08 +00:00
|
|
|
call_varargs(buffer, 255, 12, "%s world!", "hello");
|
2012-07-21 20:00:56 +00:00
|
|
|
call_varargs(buffer, 255, 11, "%u cookies", 100);
|
2012-07-21 17:15:08 +00:00
|
|
|
/* This is how WINE implements _vcsprintf, and they are obviously wrong */
|
|
|
|
StartSeh()
|
|
|
|
call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
|
|
|
|
#if defined(TEST_CRTDLL) || defined(TEST_USER32)
|
|
|
|
EndSeh(STATUS_ACCESS_VIOLATION);
|
|
|
|
#else
|
|
|
|
EndSeh(STATUS_SUCCESS);
|
2012-07-21 20:15:12 +00:00
|
|
|
#endif
|
|
|
|
#if defined(TEST_MSVCRT) /* NTDLL doesn't use/set errno */
|
|
|
|
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
2012-07-21 17:15:08 +00:00
|
|
|
#endif
|
|
|
|
/* This one is no better */
|
2012-07-21 20:00:56 +00:00
|
|
|
StartSeh()
|
2012-07-21 17:15:08 +00:00
|
|
|
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);
|
2012-07-21 20:15:12 +00:00
|
|
|
#endif
|
|
|
|
#if defined(TEST_MSVCRT) /* NTDLL doesn't use/set errno */
|
|
|
|
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
2012-07-21 20:00:56 +00:00
|
|
|
#endif
|
|
|
|
/* One more NULL checks */
|
|
|
|
StartSeh()
|
|
|
|
call_varargs(buffer, 255, -1, NULL);
|
|
|
|
#if defined(TEST_CRTDLL)
|
|
|
|
EndSeh(STATUS_ACCESS_VIOLATION);
|
|
|
|
#else
|
|
|
|
EndSeh(STATUS_SUCCESS);
|
2012-07-21 17:15:08 +00:00
|
|
|
#endif
|
2012-07-21 20:15:12 +00:00
|
|
|
#if defined(TEST_MSVCRT) /* NTDLL doesn't use/set errno */
|
|
|
|
ok(errno == EINVAL, "Expected EINVAL, got %u\n", errno);
|
|
|
|
#endif
|
2012-07-21 17:15:08 +00:00
|
|
|
}
|