ReactOS 0.4.16-dev-1946-g52006dd
_vsnprintf.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 _vsnprintf
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_vsnprintf)(char *buf, size_t cnt, const char *fmt, va_list args);
20
21static BOOL Init(void)
22{
25 ok(p_vsnprintf != NULL, "Failed to load _vsnprintf from %s\n", TEST_DLL_NAME);
26 return (p_vsnprintf != NULL);
27}
28#define _vsnprintf p_vsnprintf
29
30#endif // !TEST_STATIC_CRT
31
32static void call_varargs(char* buf, size_t buf_size, int expected_ret, LPCSTR formatString, ...)
33{
35 int ret;
36 /* Test the basic functionality */
37 va_start(args, formatString);
38 ret = _vsnprintf(buf, buf_size, formatString, args);
39 va_end(args);
40 ok(expected_ret == ret, "Test failed for `%s`: expected %i, got %i.\n", formatString, expected_ret, ret);
41}
42
44{
45 char buffer[255];
46
47#ifndef TEST_STATIC_CRT
48 if (!Init())
49 {
50 skip("Skipping tests, because _vsnprintf is not available\n");
51 return;
52 }
53#endif
54
55 /* Here you can mix wide and ANSI strings */
56 call_varargs(buffer, 255, 12, "%S world!", L"hello");
57 call_varargs(buffer, 255, 12, "%s world!", "hello");
58 call_varargs(buffer, 255, 11, "%u cookies", 100);
59
60 StartSeh()
61#if defined(TEST_CRTDLL)||defined(TEST_USER32)
62 call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
63#else
65 call_varargs(NULL, INT_MAX, -1, "%s it really work?", "does");
66 else
67 call_varargs(NULL, INT_MAX, 20, "%s it really work?", "does");
68#endif
69
70#if defined(TEST_CRTDLL)||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)||defined(TEST_USER32)
90 call_varargs(NULL, 0, -1, "%s it really work?", "does");
91#else
92 call_varargs(NULL, 0, 20, "%s it really work?", "does");
93#endif
94
95#if defined(TEST_USER32)
97#else
99#endif
100
101#if defined(TEST_USER32)
103#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
104 ok_eq_uint(errno, 0);
105#else
108 else
109 ok_eq_uint(errno, 0);
110#endif
111
112 /* One more NULL checks */
113 StartSeh()
114 call_varargs(buffer, 255, -1, NULL);
115#if defined(TEST_CRTDLL)
117#else
119#endif
120
121#if defined(TEST_USER32)
123#elif defined(TEST_NTDLL) || defined(TEST_CRTDLL)
124 ok_eq_uint(errno, 0);
125#else
128 else
129 ok_eq_uint(errno, 0);
130#endif
131}
#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
#define _vsnprintf
Definition: _vsnprintf.c:28
static PFN_vsnprintf p_vsnprintf
Definition: _vsnprintf.c:19
static BOOL Init(void)
Definition: _vsnprintf.c:21
static void call_varargs(char *buf, size_t buf_size, int expected_ret, LPCSTR formatString,...)
Definition: _vsnprintf.c:32
int(__cdecl * PFN_vsnprintf)(char *buf, size_t cnt, const char *fmt, va_list args)
Definition: _vsnprintf.c:18
#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 char * LPCSTR
Definition: xmlstorage.h:183