ReactOS  0.4.15-dev-1201-gb2cf5a4
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
 

Functions

 START_TEST (sprintf)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file sprintf.c.

Function Documentation

◆ START_TEST()

START_TEST ( sprintf  )

Definition at line 31 of file sprintf.c.

32 {
33  int Length;
34  CHAR Buffer[128];
35  PCHAR String;
36 
37  /* basic parameter tests */
38  StartSeh()
39  Length = sprintf(NULL, NULL);
41 
42  StartSeh()
43  Length = sprintf(NULL, "");
44  ok_int(Length, 0);
45 #if TEST_CRTDLL || TEST_USER32
47 #else
49 #endif
50 
51  StartSeh()
52  Length = sprintf(NULL, "Hello");
53  ok_int(Length, 5);
54 #if TEST_CRTDLL || TEST_USER32
56 #else
58 #endif
59 
60  /* some basic formats */
61  Length = sprintf(Buffer, "abcde");
62  ok_str(Buffer, "abcde");
63  ok_int(Length, 5);
64 
65  Length = sprintf(Buffer, "%%");
66  ok_str(Buffer, "%");
67  ok_int(Length, 1);
68 
69  Length = sprintf(Buffer, "%");
70  ok_str(Buffer, "");
71  ok_int(Length, 0);
72 
73  Length = sprintf(Buffer, "%%%");
74  ok_str(Buffer, "%");
75  ok_int(Length, 1);
76 
77  Length = sprintf(Buffer, "%d", 8);
78  ok_str(Buffer, "8");
79  ok_int(Length, 1);
80 
81  Length = sprintf(Buffer, "%s", "hello");
82  ok_str(Buffer, "hello");
83  ok_int(Length, 5);
84 
85  /* field width for %s */
86  Length = sprintf(Buffer, "%8s", "hello");
87  ok_str(Buffer, " hello");
88  ok_int(Length, 8);
89 
90  Length = sprintf(Buffer, "%4s", "hello");
91  ok_str(Buffer, "hello");
92  ok_int(Length, 5);
93 
94  Length = sprintf(Buffer, "%-8s", "hello");
95  ok_str(Buffer, "hello ");
96  ok_int(Length, 8);
97 
98  Length = sprintf(Buffer, "%-5s", "hello");
99  ok_str(Buffer, "hello");
100  ok_int(Length, 5);
101 
102  Length = sprintf(Buffer, "%0s", "hello");
103  ok_str(Buffer, "hello");
104  ok_int(Length, 5);
105 
106  Length = sprintf(Buffer, "%-0s", "hello");
107  ok_str(Buffer, "hello");
108  ok_int(Length, 5);
109 
110  Length = sprintf(Buffer, "%*s", -8, "hello");
111 #ifdef TEST_USER32
112  ok_str(Buffer, "*s");
113  ok_int(Length, 2);
114 #else
115  ok_str(Buffer, "hello ");
116  ok_int(Length, 8);
117 #endif
118 
119  /* precision for %s */
120  Length = sprintf(Buffer, "%.s", "hello");
121  ok_str(Buffer, "");
122  ok_int(Length, 0);
123 
124  Length = sprintf(Buffer, "%.0s", "hello");
125  ok_str(Buffer, "");
126  ok_int(Length, 0);
127 
128  Length = sprintf(Buffer, "%.10s", "hello");
129  ok_str(Buffer, "hello");
130  ok_int(Length, 5);
131 
132  Length = sprintf(Buffer, "%.5s", "hello");
133  ok_str(Buffer, "hello");
134  ok_int(Length, 5);
135 
136  Length = sprintf(Buffer, "%.4s", "hello");
137  ok_str(Buffer, "hell");
138  ok_int(Length, 4);
139 
140  StartSeh()
141  Length = sprintf(Buffer, "%.*s", -1, "hello");
142 #ifdef TEST_USER32
143  ok_str(Buffer, "*s");
144  ok_int(Length, 2);
145 #else
146  ok_str(Buffer, "hello");
147  ok_int(Length, 5);
148 #endif
150 
151  String = AllocateGuarded(6);
152  if (!String)
153  {
154  skip("Guarded allocation failure\n");
155  return;
156  }
157 
158  strcpy(String, "hello");
159  StartSeh()
160  Length = sprintf(Buffer, "%.8s", String);
161  ok_str(Buffer, "hello");
162  ok_int(Length, 5);
164 
165  StartSeh()
166  Length = sprintf(Buffer, "%.6s", String);
167  ok_str(Buffer, "hello");
168  ok_int(Length, 5);
170 
171  StartSeh()
172  Length = sprintf(Buffer, "%.5s", String);
173  ok_str(Buffer, "hello");
174  ok_int(Length, 5);
176 
177  StartSeh()
178  Length = sprintf(Buffer, "%.4s", String);
179  ok_str(Buffer, "hell");
180  ok_int(Length, 4);
182 
183  String[5] = '!';
184  StartSeh()
185  Length = sprintf(Buffer, "%.5s", String);
186  ok_str(Buffer, "hello");
187  ok_int(Length, 5);
188 #ifdef TEST_USER32
190 #else
192 #endif
193 
194  StartSeh()
195  Length = sprintf(Buffer, "%.6s", String);
196  ok_str(Buffer, "hello!");
197  ok_int(Length, 6);
198 #ifdef TEST_USER32
200 #else
202 #endif
203 
204  StartSeh()
205  Length = sprintf(Buffer, "%.*s", 5, String);
206 #ifdef TEST_USER32
207  ok_str(Buffer, "*s");
208  ok_int(Length, 2);
209 #else
210  ok_str(Buffer, "hello");
211  ok_int(Length, 5);
212 #endif
214 
215  StartSeh()
216  Length = sprintf(Buffer, "%.*s", 6, String);
217 #ifdef TEST_USER32
218  ok_str(Buffer, "*s");
219  ok_int(Length, 2);
220 #else
221  ok_str(Buffer, "hello!");
222  ok_int(Length, 6);
223 #endif
225 
226  /* both field width and precision */
227  StartSeh()
228  Length = sprintf(Buffer, "%8.5s", String);
229  ok_str(Buffer, " hello");
230  ok_int(Length, 8);
231 #ifdef TEST_USER32
233 #else
235 #endif
236 
237  StartSeh()
238  Length = sprintf(Buffer, "%-*.6s", -8, String);
239 #ifdef TEST_USER32
240  ok_str(Buffer, "*.6s");
241  ok_int(Length, 4);
242 #else
243  ok_str(Buffer, "hello! ");
244  ok_int(Length, 8);
245 #endif
247 
248  StartSeh()
249  Length = sprintf(Buffer, "%*.*s", -8, 6, String);
250 #ifdef TEST_USER32
251  ok_str(Buffer, "*.*s");
252  ok_int(Length, 4);
253 #else
254  ok_str(Buffer, "hello! ");
255  ok_int(Length, 8);
256 #endif
258 
260 }
signed char * PCHAR
Definition: retypes.h:7
#define ok_str(x, y)
Definition: sprintf.c:18
#define ok_int(x, y)
Definition: sprintf.c:21
char CHAR
Definition: xmlstorage.h:175
static WCHAR String[]
Definition: stringtable.c:55
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
#define StartSeh()
Definition: _sntprintf.h:16
Definition: ctx.idl:6
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
GLdouble s
Definition: gl.h:2039
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
int sprintf(char *buf, const char *fmt,...)
Definition: sprintf.c:703
#define skip(...)
Definition: atltest.h:64
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17