ReactOS 0.4.16-dev-1946-g52006dd
_vsnwprintf.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for _vsnwprintf
5 */
6
7#include <apitest.h>
8
9#define WIN32_NO_STATUS
10#include <stdio.h>
11#include <tchar.h>
12#include <pseh/pseh2.h>
13#include <ndk/mmfuncs.h>
14#include <ndk/rtlfuncs.h>
15
16#ifndef TEST_STATIC_CRT
17
18typedef int (__cdecl *PFN_vsnwprintf)(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args);
20
21static BOOL Init(void)
22{
25 ok(p_vsnwprintf != NULL, "Failed to load _vsnwprintf from %s\n", TEST_DLL_NAME);
26 return (p_vsnwprintf != NULL);
27}
28#define _vsnwprintf p_vsnwprintf
29
30#endif // !TEST_STATIC_CRT
31
32static void call_varargs(wchar_t* buf, size_t buf_size, int expected_ret, LPCWSTR formatString, ...)
33{
35 int ret;
36 /* Test the basic functionality */
37 va_start(args, formatString);
38 ret = _vsnwprintf(buf, buf_size, formatString, args);
39 va_end(args);
40 ok(expected_ret == ret, "Test failed for `%ls`: expected %i, got %i.\n", formatString, expected_ret, ret);
41}
42
44{
45 wchar_t buffer[255];
46
47#ifndef TEST_STATIC_CRT
48 if (!Init())
49 {
50 skip("Skipping tests, because _vsnwprintf is not available\n");
51 return;
52 }
53#endif
54
55 /* Test basic functionality */
56 //call_varargs(buffer, 255, 10, L"%s world!", "hello"); // this test is broken
57 call_varargs(buffer, 255, 12, L"%s world!", L"hello");
58 call_varargs(buffer, 255, 11, L"%u cookies", 100);
59 /* This is how WINE implements _vcsprintf, and they are obviously wrong */
60 StartSeh()
61#if defined(TEST_CRTDLL)
62 call_varargs(NULL, INT_MAX, -1, L"%s it really work?", L"does");
63#else
65 call_varargs(NULL, INT_MAX, -1, L"%s it really work?", L"does");
66 else
67 call_varargs(NULL, INT_MAX, 20, L"%s it really work?", L"does");
68#endif
69
70#if defined(TEST_USER32)
72#else
74#endif
75
76#if defined(TEST_USER32)
78#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
79 ok_eq_uint(errno, 0);
80#else
83 else
84 ok_eq_uint(errno, 0);
85#endif
86
87 /* This one is no better */
88 StartSeh()
89#if defined(TEST_CRTDLL)
90 call_varargs(NULL, 0, -1, L"%s it really work?", L"does");
91#else
92 call_varargs(NULL, 0, 20, L"%s it really work?", L"does");
93#endif
95#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
96 ok_eq_uint(errno, 0);
97#else
100 else
101 ok_eq_uint(errno, 0);
102#endif
103
104 /* One more NULL checks */
105 StartSeh()
106 call_varargs(buffer, 255, -1, NULL);
107#if defined(TEST_CRTDLL)
109#else
111#endif
112#if defined(TEST_NTDLL) || defined(TEST_CRTDLL)
113 ok_eq_uint(errno, 0);
114#else
117 else
118 ok_eq_uint(errno, 0);
119#endif
120}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define GetNTVersion()
Definition: apitest.h:17
#define ok_eq_uint(value, expected)
Definition: apitest.h:118
#define StartSeh()
Definition: apitest.h:93
#define EndSeh(ExpectedStatus)
Definition: apitest.h:99
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STATUS_ACCESS_VIOLATION
GLuint buffer
Definition: glext.h:5915
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define INT_MAX
Definition: intsafe.h:150
static PFN_vsnwprintf p_vsnwprintf
Definition: _vsnwprintf.c:19
int(__cdecl * PFN_vsnwprintf)(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args)
Definition: _vsnwprintf.c:18
static BOOL Init(void)
Definition: _vsnwprintf.c:21
#define _vsnwprintf
Definition: _vsnwprintf.c:28
static void call_varargs(wchar_t *buf, size_t buf_size, int expected_ret, LPCWSTR formatString,...)
Definition: _vsnwprintf.c:32
#define TEST_DLL_NAME
Definition: wsprintf.c:3
#define errno
Definition: errno.h:18
#define args
Definition: format.c:66
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
static PVOID hdll
Definition: shimdbg.c:126
Definition: match.c:390
Definition: dsound.c:943
_In_ size_t cnt
Definition: wcstombs.cpp:43
#define ERROR_BAD_COMMAND
Definition: winerror.h:247
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185