ReactOS 0.4.15-dev-7788-g1ad9096
wsprintf.c
Go to the documentation of this file.
1 /* Unit test suite for the wsprintf functions
2 *
3 * Copyright 2002 Bill Medland
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20#include <stdarg.h>
21
22#include "wine/test.h"
23#include "windef.h"
24#include "winbase.h"
25#include "winuser.h"
26#include "winnls.h"
27
28static const struct
29{
30 const char *fmt;
32 const char *res;
33} i64_formats[] =
34{
35 { "%I64X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890A" },
36 { "%I32X", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890A" },
37 { "%I64d", (ULONGLONG)543210 * 1000000, "543210000000" },
38 { "%I64X", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
39 { "%I32x", (LONGLONG)-0x12345, "fffedcbb" },
40 { "%I64u", (LONGLONG)-123, "18446744073709551493" },
41 { "%Id", (LONGLONG)-12345, "-12345" },
42#ifdef _WIN64
43 { "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "123450067890a" },
44 { "%Ix", (LONGLONG)-0x12345, "fffffffffffedcbb" },
45 { "%p", (LONGLONG)-0x12345, "FFFFFFFFFFFEDCBB" },
46#else
47 { "%Ix", ((ULONGLONG)0x12345 << 32) | 0x67890a, "67890a" },
48 { "%Ix", (LONGLONG)-0x12345, "fffedcbb" },
49 { "%p", (LONGLONG)-0x12345, "FFFEDCBB" },
50#endif
51};
52
53static void wsprintfATest(void)
54{
55 char buf[25];
56 unsigned int i;
57 int rc;
58
59 rc=wsprintfA(buf, "%010ld", -1);
60 ok(rc == 10, "wsprintfA length failure: rc=%d error=%d\n",rc,GetLastError());
61 ok((lstrcmpA(buf, "-000000001") == 0),
62 "wsprintfA zero padded negative value failure: buf=[%s]\n",buf);
63 rc = wsprintfA(buf, "%I64X", (ULONGLONG)0);
64 if (rc == 4 && !lstrcmpA(buf, "I64X"))
65 {
66 win_skip( "I64 formats not supported\n" );
67 return;
68 }
69 for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
70 {
72 ok(rc == strlen(i64_formats[i].res), "%u: wsprintfA length failure: rc=%d\n", i, rc);
73 ok(!strcmp(buf, i64_formats[i].res), "%u: wrong result [%s]\n", i, buf);
74 }
75}
76
77static void wsprintfWTest(void)
78{
79 static const WCHAR fmt_010ld[] = {'%','0','1','0','l','d','\0'};
80 static const WCHAR res_010ld[] = {'-','0','0','0','0','0','0','0','0','1', '\0'};
81 static const WCHAR fmt_I64x[] = {'%','I','6','4','x',0};
82 WCHAR buf[25], fmt[25], res[25];
83 unsigned int i;
84 int rc;
85
86 rc=wsprintfW(buf, fmt_010ld, -1);
88 {
89 win_skip("wsprintfW is not implemented\n");
90 return;
91 }
92 ok(rc == 10, "wsPrintfW length failure: rc=%d error=%d\n",rc,GetLastError());
93 ok((lstrcmpW(buf, res_010ld) == 0),
94 "wsprintfW zero padded negative value failure\n");
95 rc = wsprintfW(buf, fmt_I64x, (ULONGLONG)0 );
96 if (rc == 4 && !lstrcmpW(buf, fmt_I64x + 1))
97 {
98 win_skip( "I64 formats not supported\n" );
99 return;
100 }
101 for (i = 0; i < ARRAY_SIZE(i64_formats); i++)
102 {
106 ok(rc == lstrlenW(res), "%u: wsprintfW length failure: rc=%d\n", i, rc);
107 ok(!lstrcmpW(buf, res), "%u: wrong result [%s]\n", i, wine_dbgstr_w(buf));
108 }
109}
110
111/* Test if the CharUpper / CharLower functions return true 16 bit results,
112 if the input is a 16 bit input value. */
113
114static void CharUpperTest(void)
115{
116 INT_PTR i, out;
117 BOOL failed = FALSE;
118
119 for (i=0;i<256;i++)
120 {
122 if ((out >> 16) != 0)
123 {
124 failed = TRUE;
125 break;
126 }
127 }
128 ok(!failed,"CharUpper failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i,out);
129}
130
131static void CharLowerTest(void)
132{
133 INT_PTR i, out;
134 BOOL failed = FALSE;
135
136 for (i=0;i<256;i++)
137 {
139 if ((out >> 16) != 0)
140 {
141 failed = TRUE;
142 break;
143 }
144 }
145 ok(!failed,"CharLower failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i,out);
146}
147
148
150{
155}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:33
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
#define lstrlenW
Definition: compat.h:750
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
#define wine_dbgstr_w
Definition: kernel32.h:34
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
int WINAPI lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:18
static void wsprintfATest(void)
Definition: wsprintf.c:53
static void CharLowerTest(void)
Definition: wsprintf.c:131
const char * fmt
Definition: wsprintf.c:30
ULONGLONG value
Definition: wsprintf.c:31
static const struct @1727 i64_formats[]
static void CharUpperTest(void)
Definition: wsprintf.c:114
static void wsprintfWTest(void)
Definition: wsprintf.c:77
static FILE * out
Definition: regtests2xml.c:44
#define win_skip
Definition: test.h:160
Definition: dsound.c:943
int32_t INT_PTR
Definition: typedefs.h:64
int64_t LONGLONG
Definition: typedefs.h:68
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: pdh_main.c:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
LPSTR WINAPI CharLowerA(_Inout_ LPSTR)
LPSTR WINAPI CharUpperA(_Inout_ LPSTR)
int WINAPIV wsprintfA(_Out_ LPSTR, _In_ _Printf_format_string_ LPCSTR,...)
#define wsprintf
Definition: winuser.h:5865
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180