ReactOS 0.4.16-dev-2491-g3dc6630
wsprintf.c File Reference
#include <stdarg.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winnls.h"
Include dependency graph for wsprintf.c:

Go to the source code of this file.

Functions

static void wsprintfATest (void)
 
static WCHAR my_btowc (BYTE c)
 
static void wsprintfWTest (void)
 
static void CharUpperTest (void)
 
static void CharLowerTest (void)
 
 START_TEST (wsprintf)
 

Variables

struct {
   const char *   fmt
 
   ULONGLONG   value
 
   const char *   res
 
i64_formats []
 

Function Documentation

◆ CharLowerTest()

static void CharLowerTest ( void  )
static

Definition at line 252 of file wsprintf.c.

253{
254 INT_PTR i, out;
255 BOOL failed = FALSE;
256
257 for (i=0;i<256;i++)
258 {
260 if ((out >> 16) != 0)
261 {
262 failed = TRUE;
263 break;
264 }
265 }
266 ok(!failed,"CharLower failed - 16bit input (0x%0Ix) returned 32bit result (0x%0Ix)\n",i,out);
267}
#define ok(value,...)
Definition: atltest.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LPSTR WINAPI CharLowerA(char *str)
Definition: string.c:1043
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int32_t INT_PTR
Definition: typedefs.h:64
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
char * LPSTR
Definition: xmlstorage.h:182

Referenced by START_TEST().

◆ CharUpperTest()

static void CharUpperTest ( void  )
static

Definition at line 235 of file wsprintf.c.

236{
237 INT_PTR i, out;
238 BOOL failed = FALSE;
239
240 for (i=0;i<256;i++)
241 {
243 if ((out >> 16) != 0)
244 {
245 failed = TRUE;
246 break;
247 }
248 }
249 ok(!failed,"CharUpper failed - 16bit input (0x%0Ix) returned 32bit result (0x%0Ix)\n",i,out);
250}
LPSTR WINAPI CharUpperA(LPSTR str)
Definition: string.c:1156

Referenced by START_TEST().

◆ my_btowc()

static WCHAR my_btowc ( BYTE  c)
static

Definition at line 124 of file wsprintf.c.

125{
126 WCHAR wc;
127 if (!IsDBCSLeadByte(c) &&
128 MultiByteToWideChar(CP_ACP, 0, (const char *)&c, 1, &wc, 1) > 0)
129 return wc;
130 return 0;
131}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI IsDBCSLeadByte(BYTE testchar)
Definition: locale.c:2126
const GLubyte * c
Definition: glext.h:8905
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wsprintfWTest().

◆ START_TEST()

START_TEST ( wsprintf  )

Definition at line 270 of file wsprintf.c.

271{
276}
static void wsprintfATest(void)
Definition: wsprintf.c:53
static void CharLowerTest(void)
Definition: wsprintf.c:252
static void CharUpperTest(void)
Definition: wsprintf.c:235
static void wsprintfWTest(void)
Definition: wsprintf.c:133

◆ wsprintfATest()

static void wsprintfATest ( void  )
static

Definition at line 53 of file wsprintf.c.

54{
55 char buf[25], star[4], partial[4];
56 static const WCHAR starW[] = L"\x2606";
57 static const WCHAR fffeW[] = L"\xfffe";
58 static const WCHAR wineW[] = L"\xd83c\xdf77"; /* U+1F377: wine glass */
59 const struct {
60 const void *input;
61 const char *fmt;
62 const char *str;
63 int rc;
64 }
65 testcase[] = {
66 { starW, "%.1S", partial, 1 },
67 { starW, "%.2S", star, 2 },
68 { starW, "%.3S", star, 2 },
69 { fffeW, "%.1S", "?", 1 },
70 { fffeW, "%.2S", "?", 1 },
71 { wineW, "%.2S", "??", 2 },
72 { star, "%.1s", partial, 1 },
73 { (void *)0x2606, "%2C", star, 2 },
74 { (void *)0xfffd, "%C", "?", 1 },
75 { (void *)0xe199, "%2c", " \x99", 2 },
76 };
77 CPINFO cpinfo;
78 unsigned int i;
79 int rc;
80
81 rc=wsprintfA(buf, "%010ld", -1);
82 ok(rc == 10, "wsprintfA length failure: rc=%d error=%ld\n",rc,GetLastError());
83 ok((lstrcmpA(buf, "-000000001") == 0),
84 "wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
85 rc = wsprintfA(buf, "%I64X", (ULONGLONG)0);
86 if (rc == 4 && !lstrcmpA(buf, "I64X"))
87 {
88 win_skip( "I64 formats not supported\n" );
89 return;
90 }
91 for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
92 {
94 ok(rc == strlen(i64_formats[i].res), "%u: wsprintfA length failure: rc=%d\n", i, rc);
95 ok(!strcmp(buf, i64_formats[i].res), "%u: wrong result [%s]\n", i, buf);
96 }
97
98 if (!GetCPInfo(CP_ACP, &cpinfo) || cpinfo.MaxCharSize != 2)
99 {
100 skip("Multi-byte wsprintfA test isn't available for the current codepage\n");
101 return;
102 }
103
104 rc = WideCharToMultiByte(CP_ACP, 0, starW, -1, star, sizeof(star), NULL, NULL);
105 ok(rc == 3, "unexpected rc, got %d\n", rc);
106 partial[0] = star[0];
107 partial[1] = '\0';
108
109 for (i = 0; i < ARRAY_SIZE(testcase); i++)
110 {
111 memset(buf, 0x11, sizeof(buf));
112 rc = wsprintfA(buf, testcase[i].fmt, testcase[i].input);
113
114 ok(rc == testcase[i].rc,
115 "%u: expected %d, got %d\n",
116 i, testcase[i].rc, rc);
117
118 ok(!strcmp(buf, testcase[i].str),
119 "%u: expected %s, got %s\n",
120 i, wine_dbgstr_a(testcase[i].str), wine_dbgstr_an(buf, rc));
121 }
122}
#define skip(...)
Definition: atltest.h:64
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
const char * wine_dbgstr_an(const char *str, int n)
Definition: compat.c:313
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI GetCPInfo(UINT codepage, LPCPINFO cpinfo)
Definition: locale.c:2146
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4104
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
#define L(x)
Definition: resources.c:13
GLuint res
Definition: glext.h:9613
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum GLenum input
Definition: glext.h:9031
static WCHAR wineW[]
Definition: localmon.c:128
#define win_skip
Definition: minitest.h:67
const char * fmt
Definition: wsprintf.c:30
static const struct @1869 i64_formats[]
const WCHAR * str
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:187
#define memset(x, y, z)
Definition: compat.h:39
UINT MaxCharSize
Definition: winnls.h:650
Definition: dsound.c:943
static const WCHAR starW[]
Definition: symbol.c:43
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: pdh_main.c:96
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
int WINAPIV wsprintfA(_Out_ LPSTR, _In_ _Printf_format_string_ LPCSTR,...)

Referenced by START_TEST().

◆ wsprintfWTest()

static void wsprintfWTest ( void  )
static

Definition at line 133 of file wsprintf.c.

134{
135 static const WCHAR stars[] = L"*\x2606\x2605";
136 WCHAR def_spc[] = L"*?\x2605 ";
137 WCHAR buf[25], fmt[25], res[25], wcA1, wc99;
138 char stars_mb[8], partial00[8], partialFF[8];
139 const struct {
140 const char *input;
141 const WCHAR *fmt;
142 const WCHAR *str;
143 int rc;
144 }
145 testcase[] = {
146 { stars_mb, L"%.3S", stars, 3 },
147 { partial00, L"%-4S", L"*\0 ", 4 },
148 { partialFF, L"%-4S", def_spc, 4 },
149 };
150 CPINFOEXW cpinfoex;
151 unsigned int i;
152 int rc;
153
154 rc=wsprintfW(buf, L"%010ld", -1);
156 {
157 win_skip("wsprintfW is not implemented\n");
158 return;
159 }
160 ok(rc == 10, "wsPrintfW length failure: rc=%d error=%ld\n",rc,GetLastError());
161 ok((lstrcmpW(buf, L"-000000001") == 0),
162 "wsprintfW zero padded negative value failure\n");
163 rc = wsprintfW(buf, L"%I64x", (ULONGLONG)0 );
164 if (rc == 4 && !lstrcmpW(buf, L"I64x"))
165 {
166 win_skip( "I64 formats not supported\n" );
167 return;
168 }
169 for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
170 {
174 ok(rc == lstrlenW(res), "%u: wsprintfW length failure: rc=%d\n", i, rc);
175 ok(!lstrcmpW(buf, res), "%u: wrong result [%s]\n", i, wine_dbgstr_w(buf));
176 }
177
178 rc = wsprintfW(buf, L"%2c", L'*');
179 ok(rc == 2, "expected 2, got %d\n", rc);
180 ok(buf[0] == L' ', "expected \\x0020, got \\x%04x\n", buf[0]);
181 ok(buf[1] == L'*', "expected \\x%04x, got \\x%04x\n", L'*', buf[1]);
182
183 rc = wsprintfW(buf, L"%c", L'\x2605');
184 ok(rc == 1, "expected 1, got %d\n", rc);
185 ok(buf[0] == L'\x2605', "expected \\x%04x, got \\x%04x\n", L'\x2605', buf[0]);
186
187 wcA1 = my_btowc(0xA1);
188 rc = wsprintfW(buf, L"%C", 0xA1);
189 ok(rc == 1, "expected 1, got %d\n", rc);
190 ok(buf[0] == wcA1, "expected \\x%04x, got \\x%04x\n", wcA1, buf[0]);
191
192 rc = wsprintfW(buf, L"%C", 0x81A1);
193 ok(rc == 1, "expected 1, got %d\n", rc);
194 ok(buf[0] == wcA1, "expected \\x%04x, got \\x%04x\n", wcA1, buf[0]);
195
196 wc99 = my_btowc(0x99);
197 rc = wsprintfW(buf, L"%2C", 0xe199);
198 ok(rc == 2, "expected 1, got %d\n", rc);
199 ok(buf[0] == L' ', "expected \\x0020, got \\x%04x\n", buf[0]);
200 ok(buf[1] == wc99, "expected \\x%04x, got \\x%04x\n", wc99, buf[1]);
201
202 if (!GetCPInfoExW(CP_ACP, 0, &cpinfoex) || cpinfoex.MaxCharSize != 2)
203 {
204 skip("Multi-byte wsprintfW test isn't available for the current codepage\n");
205 return;
206 }
207 def_spc[1] = cpinfoex.UnicodeDefaultChar;
208
209 rc = WideCharToMultiByte(CP_ACP, 0, stars, -1, stars_mb, sizeof(stars_mb), NULL, NULL);
210 ok(rc == 6, "expected 6, got %d\n", rc);
211 strcpy(partial00, stars_mb);
212 partial00[2] = '\0';
213 strcpy(partialFF, stars_mb);
214 partialFF[2] = 0xff;
215
216 for (i = 0; i < ARRAY_SIZE(testcase); i++)
217 {
218 memset(buf, 0x11, sizeof(buf));
219 rc = wsprintfW(buf, testcase[i].fmt, testcase[i].input);
220
221 ok(rc == testcase[i].rc,
222 "%u: expected %d, got %d\n",
223 i, testcase[i].rc, rc);
224
225 ok(!memcmp(buf, testcase[i].str, (testcase[i].rc + 1) * sizeof(WCHAR)),
226 "%u: expected %s, got %s\n", i,
227 wine_dbgstr_wn(testcase[i].str, testcase[i].rc + 1),
228 wine_dbgstr_wn(buf, rc + 1));
229 }
230}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define lstrlenW
Definition: compat.h:750
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
BOOL WINAPI GetCPInfoExW(UINT codepage, DWORD dwFlags, LPCPINFOEXW cpinfo)
Definition: locale.c:2222
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
#define wine_dbgstr_w
Definition: kernel32.h:34
STAR * stars
Definition: screensaver.c:45
static WCHAR my_btowc(BYTE c)
Definition: wsprintf.c:124
#define wine_dbgstr_wn
Definition: testlist.c:2
strcpy
Definition: string.h:131
WCHAR UnicodeDefaultChar
Definition: winnls.h:666
UINT MaxCharSize
Definition: winnls.h:663
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)

Referenced by START_TEST().

Variable Documentation

◆ fmt

Definition at line 30 of file wsprintf.c.

Referenced by wsprintfATest(), and wsprintfWTest().

◆ 

const struct { ... } i64_formats[]
Initial value:
=
{
{ "%I64X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890A" },
{ "%I32X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890A" },
{ "%I64d", (ULONGLONG)543210 * 1000000, "543210000000" },
{ "%I64X", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
{ "%I32x", (LONGLONG)-0x12345, "fffedcbb" },
{ "%I64u", (LONGLONG)-123, "18446744073709551493" },
{ "%Id", (LONGLONG)-12345, "-12345" },
{ "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890a" },
{ "%Ix", (LONGLONG)-0x12345, "fffedcbb" },
{ "%p", (LONGLONG)-0x12345, "FFFEDCBB" },
}
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by wsprintfATest(), and wsprintfWTest().

◆ res

Definition at line 32 of file wsprintf.c.

◆ value

Definition at line 31 of file wsprintf.c.