ReactOS 0.4.15-dev-8428-g6910fa6
atlconv.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for <atlconv.h>
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#ifdef HAVE_APITEST
9 #include <apitest.h>
10#else
11 #include "atltest.h"
12#endif
13#include <atlbase.h>
14#include <atlconv.h>
15
16START_TEST(atlconv)
17{
18 char dataA[MAX_PATH];
19 wchar_t dataW[MAX_PATH];
20 const char *dataAX = "test12345";
21 const wchar_t *dataWX = L"test12345";
22 using namespace ATL;
23
24 //
25 // Initialize long data
26 //
27 FillMemory(dataA, sizeof(dataA), 'A');
28 dataA[_countof(dataA) - 1] = 0;
29
30 for (size_t i = 0; i < _countof(dataW); ++i)
31 dataW[i] = L'A';
32 dataW[_countof(dataW) - 1] = 0;
33
34 //
35 // The NULL strings
36 //
37 {
38 CA2A a2a(NULL);
39 ok_ptr((LPSTR)a2a, NULL);
40 ok_ptr(a2a.m_psz, NULL);
41 ok_int(a2a.m_szBuffer[0], 0);
42
43 CW2A w2a(NULL);
45 ok_ptr(w2a.m_psz, NULL);
46 ok_int(w2a.m_szBuffer[0], 0);
47
48 CA2W a2w(NULL);
50 ok_ptr(a2w.m_psz, NULL);
51 ok_int(a2w.m_szBuffer[0], 0);
52
53 CW2W w2w(NULL);
54 ok_ptr((LPWSTR)w2w, NULL);
55 ok_ptr(w2w.m_psz, NULL);
56 ok_int(w2w.m_szBuffer[0], 0);
57 }
58
59 //
60 // The zero-length strings
61 //
62 {
63 CA2A a2a("");
64 ok_str((LPSTR)a2a, "");
65 ok_str(a2a.m_psz, "");
66 ok_int(a2a.m_szBuffer[0], 0);
67 ok_ptr(a2a.m_psz, a2a.m_szBuffer);
68
69 CW2A w2a(L"");
70 ok_str((LPSTR)w2a, "");
71 ok_str(w2a.m_psz, "");
72 ok_int(w2a.m_szBuffer[0], 0);
73 ok_ptr(w2a.m_psz, w2a.m_szBuffer);
74
75 CA2W a2w("");
76 ok_wstr((LPWSTR)a2w, L"");
77 ok_wstr(a2w.m_psz, L"");
78 ok_int(a2w.m_szBuffer[0], 0);
79 ok_ptr(a2w.m_psz, a2w.m_szBuffer);
80
81 CW2W w2w(L"");
82 ok_wstr((LPWSTR)w2w, L"");
83 ok_wstr(w2w.m_psz, L"");
84 ok_int(w2w.m_szBuffer[0], 0);
85 ok_ptr(w2w.m_psz, w2w.m_szBuffer);
86 }
87
88 //
89 // The short strings
90 //
91 {
92 CA2A a2a("TEST123");
93 ok_str((LPSTR)a2a, "TEST123");
94 ok_str(a2a.m_psz, "TEST123");
95 ok_ptr(a2a.m_psz, a2a.m_szBuffer);
96
97 CW2A w2a(L"TEST123");
98 ok_str((LPSTR)w2a, "TEST123");
99 ok_str(w2a.m_psz, "TEST123");
100 ok_ptr(w2a.m_psz, w2a.m_szBuffer);
101
102 CA2W a2w("TEST123");
103 ok_wstr((LPWSTR)a2w, L"TEST123");
104 ok_wstr(a2w.m_psz, L"TEST123");
105 ok_ptr(a2w.m_psz, a2w.m_szBuffer);
106
107 CW2W w2w(L"TEST123");
108 ok_wstr((LPWSTR)w2w, L"TEST123");
109 ok_wstr(w2w.m_psz, L"TEST123");
110 ok_ptr(w2w.m_psz, w2w.m_szBuffer);
111 }
112
113 //
114 // The short strings (EX)
115 //
116 {
117 CA2AEX<5> a2ax("123");
118 ok_str((LPSTR)a2ax, "123");
119 ok_str(a2ax.m_psz, "123");
120 ok_ptr(a2ax.m_psz, a2ax.m_szBuffer);
121
122 CW2AEX<5> w2ax(L"123");
123 ok_str((LPSTR)w2ax, "123");
124 ok_str(w2ax.m_psz, "123");
125 //ok(w2ax.m_psz != w2ax.m_szBuffer, "w2ax.m_psz == w2ax.m_szBuffer\n"); // corner case
126
127 CA2WEX<5> a2wx("123");
128 ok_wstr((LPWSTR)a2wx, L"123");
129 ok_wstr(a2wx.m_psz, L"123");
130 ok_ptr(a2wx.m_psz, a2wx.m_szBuffer);
131
132 CW2WEX<5> w2wx(L"123");
133 ok_wstr((LPWSTR)w2wx, L"123");
134 ok_wstr(w2wx.m_psz, L"123");
135 ok_ptr(w2wx.m_psz, w2wx.m_szBuffer);
136 }
137
138 //
139 // The long strings
140 //
141 {
142 CA2A a2a2(dataA);
143 ok_str((LPSTR)a2a2, dataA);
144 ok_str(a2a2.m_psz, dataA);
145 ok_str(a2a2.m_szBuffer, "");
146 ok(a2a2.m_psz != dataA, "a2a2.m_psz == dataA\n");
147 ok(a2a2.m_psz != a2a2.m_szBuffer, "a2a2.m_psz == a2a2.m_szBuffer\n");
148
149 CW2A w2a2(dataW);
150 ok_str((LPSTR)w2a2, dataA);
151 ok_str(w2a2.m_psz, dataA);
152 ok_str(w2a2.m_szBuffer, "");
153 ok(w2a2.m_psz != dataA, "w2a2.m_psz == dataA\n");
154 ok(w2a2.m_psz != w2a2.m_szBuffer, "w2a2.m_psz == w2a2.m_szBuffer\n");
155
156 CA2W a2w2(dataA);
157 ok_wstr((LPWSTR)a2w2, dataW);
158 ok_wstr(a2w2.m_psz, dataW);
159 ok_wstr(a2w2.m_szBuffer, L"");
160 ok(a2w2.m_psz != dataW, "a2w2.m_psz == dataW\n");
161 ok(a2w2.m_psz != a2w2.m_szBuffer, "a2w2.m_psz == a2w2.m_szBuffer\n");
162
163 CW2W w2w2(dataW);
164 ok_wstr((LPWSTR)w2w2, dataW);
165 ok_wstr(w2w2.m_psz, dataW);
166 ok_wstr(w2w2.m_szBuffer, L"");
167 ok(w2w2.m_psz != dataW, "w2w2.m_psz == dataW\n");
168 ok(w2w2.m_psz != w2w2.m_szBuffer, "w2w2.m_psz == w2w2.m_szBuffer\n");
169 }
170
171 //
172 // The long strings (EX)
173 //
174 {
175 CA2AEX<5> a2a2x(dataAX);
176 ok_str((LPSTR)a2a2x, dataAX);
177 ok_str(a2a2x.m_psz, dataAX);
178 ok_str(a2a2x.m_szBuffer, "");
179 ok(a2a2x.m_psz != dataAX, "a2a2x.m_psz == dataAX\n");
180 ok(a2a2x.m_psz != a2a2x.m_szBuffer, "a2a2x.m_psz == a2a2x.m_szBuffer\n");
181
182 CW2AEX<5> w2a2x(dataWX);
183 ok_str((LPSTR)w2a2x, dataAX);
184 ok_str(w2a2x.m_psz, dataAX);
185 ok_str(w2a2x.m_szBuffer, "");
186 ok(w2a2x.m_psz != dataAX, "w2a2x.m_psz == dataAX\n");
187 ok(w2a2x.m_psz != w2a2x.m_szBuffer, "w2a2x.m_psz == w2a2x.m_szBuffer\n");
188
189 CA2WEX<5> a2w2x(dataAX);
190 ok_wstr((LPWSTR)a2w2x, dataWX);
191 ok_wstr(a2w2x.m_psz, dataWX);
192 ok_wstr(a2w2x.m_szBuffer, L"");
193 ok(a2w2x.m_psz != dataWX, "a2w2x.m_psz == dataWX\n");
194 ok(a2w2x.m_psz != a2w2x.m_szBuffer, "a2w2x.m_psz == a2w2x.m_szBuffer\n");
195
196 CW2WEX<5> w2w2x(dataWX);
197 ok_wstr((LPWSTR)w2w2x, dataWX);
198 ok_wstr(w2w2x.m_psz, dataWX);
199 ok_wstr(w2w2x.m_szBuffer, L"");
200 ok(w2w2x.m_psz != dataWX, "w2w2x.m_psz == dataWX\n");
201 ok(w2w2x.m_psz != w2w2x.m_szBuffer, "w2w2x.m_psz == w2w2x.m_szBuffer\n");
202 }
203
204 //
205 // The const strings
206 //
207 {
208 CA2CA a2ca(dataA);
209 ok_str((LPCSTR)a2ca, dataA);
210 ok_str(a2ca.m_psz, dataA);
211 ok_ptr(a2ca.m_psz, dataA);
212
213 CW2CW w2cw(dataW);
214 ok_wstr((LPCWSTR)w2cw, dataW);
215 ok_wstr(w2cw.m_psz, dataW);
216 ok_ptr(w2cw.m_psz, dataW);
217 }
218}
#define ok_str(x, y)
Definition: atltest.h:127
#define ok(value,...)
Definition: atltest.h:57
#define ok_wstr(x, y)
Definition: atltest.h:130
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define ok_ptr(expression, result)
Definition: atltest.h:108
char m_szBuffer[t_nBufferLength]
Definition: atlconv.h:71
LPSTR m_psz
Definition: atlconv.h:70
LPCSTR m_psz
Definition: atlconv.h:23
LPWSTR m_psz
Definition: atlconv.h:192
wchar_t m_szBuffer[t_nBufferLength]
Definition: atlconv.h:193
char m_szBuffer[t_nBufferLength]
Definition: atlconv.h:260
LPSTR m_psz
Definition: atlconv.h:259
LPCWSTR m_psz
Definition: atlconv.h:47
LPWSTR m_psz
Definition: atlconv.h:131
wchar_t m_szBuffer[t_nBufferLength]
Definition: atlconv.h:132
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
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
static const char * w2a(LPCWSTR str)
Definition: protocol.c:232
Definition: rosdlgs.h:6
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
wchar_t * a2w(char *a, wchar_t *w)
Definition: wmain.c:13
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185