ReactOS 0.4.16-dev-1946-g52006dd
sprintf.c File Reference
#include <apitest.h>
#include <apitest_guard.h>
#include <stdio.h>
#include <tchar.h>
#include <pseh/pseh2.h>
#include <ndk/mmfuncs.h>
#include <ndk/rtlfuncs.h>
Include dependency graph for sprintf.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define sprintf   p_sprintf
 

Typedefs

typedef int(__cdeclPFN_sprintf) (char *_Dest, const char *_Format,...)
 

Functions

static BOOL Init (void)
 
 START_TEST (sprintf)
 

Variables

static PFN_sprintf p_sprintf
 

Macro Definition Documentation

◆ sprintf

#define sprintf   p_sprintf

Definition at line 45 of file sprintf.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file sprintf.c.

Typedef Documentation

◆ PFN_sprintf

typedef int(__cdecl * PFN_sprintf) (char *_Dest, const char *_Format,...)

Definition at line 31 of file sprintf.c.

Function Documentation

◆ Init()

static BOOL Init ( void  )
static

Definition at line 34 of file sprintf.c.

35{
37#ifdef TEST_USER32
39#else
41#endif
42 ok(p_sprintf != NULL, "Failed to load sprintf from %s\n", TEST_DLL_NAME);
43 return (p_sprintf != NULL);
44}
#define ok(value,...)
Definition: atltest.h:57
#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
int(__cdecl * PFN_sprintf)(char *_Dest, const char *_Format,...)
Definition: sprintf.c:31
static PFN_sprintf p_sprintf
Definition: sprintf.c:32
#define TEST_DLL_NAME
Definition: wsprintf.c:3
static PVOID hdll
Definition: shimdbg.c:126

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( sprintf  )

Definition at line 51 of file sprintf.c.

52{
53 int Length;
54 CHAR Buffer[128];
56
57#ifndef TEST_STATIC_CRT
58 if (!Init())
59 {
60 skip("Skipping tests, because sprintf is not available\n");
61 return;
62 }
63#endif
64
65 /* basic parameter tests */
66 StartSeh()
68#if defined(TEST_CRTDLL) || defined(TEST_USER32)
70#else
72#endif
73
74 StartSeh()
75 Length = sprintf(NULL, "");
77#if defined(TEST_CRTDLL) || defined(TEST_USER32)
79#else
81#endif
82
83 StartSeh()
84 Length = sprintf(NULL, "Hello");
86#if defined(TEST_CRTDLL) || defined(TEST_USER32)
88#else
90#endif
91
92 /* some basic formats */
93 Length = sprintf(Buffer, "abcde");
94 ok_str(Buffer, "abcde");
95 ok_int(Length, 5);
96
97 Length = sprintf(Buffer, "%%");
98 ok_str(Buffer, "%");
99 ok_int(Length, 1);
100
101 Length = sprintf(Buffer, "%");
102 ok_str(Buffer, "");
103 ok_int(Length, 0);
104
105 Length = sprintf(Buffer, "%%%");
106 ok_str(Buffer, "%");
107 ok_int(Length, 1);
108
109 Length = sprintf(Buffer, "%d", 8);
110 ok_str(Buffer, "8");
111 ok_int(Length, 1);
112
113 Length = sprintf(Buffer, "%s", "hello");
114 ok_str(Buffer, "hello");
115 ok_int(Length, 5);
116
117 /* field width for %s */
118 Length = sprintf(Buffer, "%8s", "hello");
119 ok_str(Buffer, " hello");
120 ok_int(Length, 8);
121
122 Length = sprintf(Buffer, "%4s", "hello");
123 ok_str(Buffer, "hello");
124 ok_int(Length, 5);
125
126 Length = sprintf(Buffer, "%-8s", "hello");
127 ok_str(Buffer, "hello ");
128 ok_int(Length, 8);
129
130 Length = sprintf(Buffer, "%-5s", "hello");
131 ok_str(Buffer, "hello");
132 ok_int(Length, 5);
133
134 Length = sprintf(Buffer, "%0s", "hello");
135 ok_str(Buffer, "hello");
136 ok_int(Length, 5);
137
138 Length = sprintf(Buffer, "%-0s", "hello");
139 ok_str(Buffer, "hello");
140 ok_int(Length, 5);
141
142 Length = sprintf(Buffer, "%*s", -8, "hello");
143#ifdef TEST_USER32
144 ok_str(Buffer, "*s");
145 ok_int(Length, 2);
146#else
147 ok_str(Buffer, "hello ");
148 ok_int(Length, 8);
149#endif
150
151 /* precision for %s */
152 Length = sprintf(Buffer, "%.s", "hello");
153 ok_str(Buffer, "");
154 ok_int(Length, 0);
155
156 Length = sprintf(Buffer, "%.0s", "hello");
157 ok_str(Buffer, "");
158 ok_int(Length, 0);
159
160 Length = sprintf(Buffer, "%.10s", "hello");
161 ok_str(Buffer, "hello");
162 ok_int(Length, 5);
163
164 Length = sprintf(Buffer, "%.5s", "hello");
165 ok_str(Buffer, "hello");
166 ok_int(Length, 5);
167
168 Length = sprintf(Buffer, "%.4s", "hello");
169 ok_str(Buffer, "hell");
170 ok_int(Length, 4);
171
172 StartSeh()
173 Length = sprintf(Buffer, "%.*s", -1, "hello");
174#ifdef TEST_USER32
175 ok_str(Buffer, "*s");
176 ok_int(Length, 2);
177#else
178 ok_str(Buffer, "hello");
179 ok_int(Length, 5);
180#endif
182
184 if (!String)
185 {
186 skip("Guarded allocation failure\n");
187 return;
188 }
189
190 strcpy(String, "hello");
191 StartSeh()
192 Length = sprintf(Buffer, "%.8s", String);
193 ok_str(Buffer, "hello");
194 ok_int(Length, 5);
196
197 StartSeh()
198 Length = sprintf(Buffer, "%.6s", String);
199 ok_str(Buffer, "hello");
200 ok_int(Length, 5);
202
203 StartSeh()
204 Length = sprintf(Buffer, "%.5s", String);
205 ok_str(Buffer, "hello");
206 ok_int(Length, 5);
208
209 StartSeh()
210 Length = sprintf(Buffer, "%.4s", String);
211 ok_str(Buffer, "hell");
212 ok_int(Length, 4);
214
215 String[5] = '!';
216 StartSeh()
217 Length = sprintf(Buffer, "%.5s", String);
218 ok_str(Buffer, "hello");
219 ok_int(Length, 5);
220#ifdef TEST_USER32
222#else
224#endif
225
226 StartSeh()
227 Length = sprintf(Buffer, "%.6s", String);
228 ok_str(Buffer, "hello!");
229 ok_int(Length, 6);
230#ifdef TEST_USER32
232#else
234#endif
235
236 StartSeh()
237 Length = sprintf(Buffer, "%.*s", 5, String);
238#ifdef TEST_USER32
239 ok_str(Buffer, "*s");
240 ok_int(Length, 2);
241#else
242 ok_str(Buffer, "hello");
243 ok_int(Length, 5);
244#endif
246
247 StartSeh()
248 Length = sprintf(Buffer, "%.*s", 6, String);
249#ifdef TEST_USER32
250 ok_str(Buffer, "*s");
251 ok_int(Length, 2);
252#else
253 ok_str(Buffer, "hello!");
254 ok_int(Length, 6);
255#endif
257
258 /* both field width and precision */
259 StartSeh()
260 Length = sprintf(Buffer, "%8.5s", String);
261 ok_str(Buffer, " hello");
262 ok_int(Length, 8);
263#ifdef TEST_USER32
265#else
267#endif
268
269 StartSeh()
270 Length = sprintf(Buffer, "%-*.6s", -8, String);
271#ifdef TEST_USER32
272 ok_str(Buffer, "*.6s");
273 ok_int(Length, 4);
274#else
275 ok_str(Buffer, "hello! ");
276 ok_int(Length, 8);
277#endif
279
280 StartSeh()
281 Length = sprintf(Buffer, "%*.*s", -8, 6, String);
282#ifdef TEST_USER32
283 ok_str(Buffer, "*.*s");
284 ok_int(Length, 4);
285#else
286 ok_str(Buffer, "hello! ");
287 ok_int(Length, 8);
288#endif
290
292}
#define GetNTVersion()
Definition: apitest.h:17
#define StartSeh()
Definition: apitest.h:93
#define EndSeh(ExpectedStatus)
Definition: apitest.h:99
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define ok_str(x, y)
Definition: atltest.h:127
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
Definition: bufpool.h:45
#define STATUS_ACCESS_VIOLATION
GLdouble s
Definition: gl.h:2039
Definition: ctx.idl:7
static BOOL Init(void)
Definition: sprintf.c:34
#define sprintf
Definition: sprintf.c:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
strcpy
Definition: string.h:131
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ p_sprintf

PFN_sprintf p_sprintf
static

Definition at line 32 of file sprintf.c.

Referenced by Init(), init(), test__get_output_format(), test_sprintf(), and test_sscanf().