ReactOS 0.4.16-dev-297-gc569aee
IsValidDevmode.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
#include <wchar.h>
Include dependency graph for IsValidDevmode.c:

Go to the source code of this file.

Classes

struct  _MINIMUM_SIZE_TABLE
 

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef struct _MINIMUM_SIZE_TABLE MINIMUM_SIZE_TABLE
 
typedef struct _MINIMUM_SIZE_TABLEPMINIMUM_SIZE_TABLE
 

Functions

 START_TEST (IsValidDevmodeA)
 
 START_TEST (IsValidDevmodeW)
 

Variables

static MINIMUM_SIZE_TABLE MinimumSizeA []
 
static MINIMUM_SIZE_TABLE MinimumSizeW []
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file IsValidDevmode.c.

Typedef Documentation

◆ MINIMUM_SIZE_TABLE

◆ PMINIMUM_SIZE_TABLE

Function Documentation

◆ START_TEST() [1/2]

START_TEST ( IsValidDevmodeA  )

Definition at line 94 of file IsValidDevmode.c.

95{
96 DEVMODEA DevMode;
98
99 // Give no Devmode at all, this has to fail without crashing.
100 SetLastError(0xDEADBEEF);
101 ok(!IsValidDevmodeA(NULL, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
102 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
103
104 // Give a zeroed Devmode, this has to fail, because dmSize isn't set.
105 ZeroMemory(&DevMode, sizeof(DEVMODEA));
106 SetLastError(0xDEADBEEF);
107 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
108 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
109
110 // Now set only the dmSize member, IsValidDevmodeA should return TRUE now. The Last Error isn't touched again.
111 ZeroMemory(&DevMode, sizeof(DEVMODEA));
112 DevMode.dmSize = sizeof(DEVMODEA);
113 SetLastError(0xDEADBEEF);
114 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns FALSE!\n");
115 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
116
117 // IsValidDevmodeA should also succeed if the DevMode appears to be larger.
118 ZeroMemory(&DevMode, sizeof(DEVMODEA));
119 DevMode.dmSize = sizeof(DEVMODEA) + 1;
120 SetLastError(0xDEADBEEF);
121 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
122 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
123
124 // The DevmodeSize parameter may be larger than dmSize, but not the other way round!
125 ZeroMemory(&DevMode, sizeof(DEVMODEA));
126 DevMode.dmSize = sizeof(DEVMODEA);
127 SetLastError(0xDEADBEEF);
128 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
129 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
130
131 ZeroMemory(&DevMode, sizeof(DEVMODEA));
132 DevMode.dmSize = sizeof(DEVMODEA) + 1;
133 SetLastError(0xDEADBEEF);
134 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
135 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
136
137 // dmDriverExtra is also taken into account.
138 ZeroMemory(&DevMode, sizeof(DEVMODEA));
139 DevMode.dmSize = sizeof(DEVMODEA);
140 DevMode.dmDriverExtra = 1;
141 SetLastError(0xDEADBEEF);
142 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
143 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
144
145 SetLastError(0xDEADBEEF);
146 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
147 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
148
149 // dmSize must be a multiple of 4 if any dmDriverExtra is given.
150 for (DevMode.dmDriverExtra = 1; DevMode.dmDriverExtra <= 4; DevMode.dmDriverExtra++)
151 {
152 for (DevMode.dmSize = sizeof(DEVMODEA); DevMode.dmSize < sizeof(DEVMODEA) + 4; DevMode.dmSize++)
153 {
154 BOOL bExpected = (DevMode.dmSize % 4 == 0);
155 DWORD dwExpectedError = (bExpected ? 0xDEADBEEF : ERROR_INVALID_DATA);
156
157 SetLastError(0xDEADBEEF);
158 ok(IsValidDevmodeA(&DevMode, DevMode.dmSize + DevMode.dmDriverExtra) == bExpected, "IsValidDevmodeA returns %d!\n", !bExpected);
159 ok(GetLastError() == dwExpectedError, "IsValidDevmodeA returns error %lu!\n", GetLastError());
160 }
161 }
162
163 // IsValidDevmodeA also fixes missing null-terminations if the corresponding fields are used.
164 ZeroMemory(&DevMode, sizeof(DEVMODEA));
165 DevMode.dmSize = sizeof(DEVMODEA);
166 memset(DevMode.dmDeviceName, 'A', 32);
167 memset(DevMode.dmFormName, 'A', 32);
168 ok(IsValidDevmodeA(&DevMode, DevMode.dmSize), "IsValidDevmodeA returns FALSE!\n");
169 ok(DevMode.dmDeviceName[31] == '\0', "Expected dmDeviceName to be '\\0', but is '%c'\n", DevMode.dmDeviceName[31]);
170 ok(DevMode.dmFormName[31] == 'A', "Expected dmFormName to be 'A', but is '%c'\n", DevMode.dmDeviceName[31]);
171
172 ZeroMemory(&DevMode, sizeof(DEVMODEA));
173 DevMode.dmSize = sizeof(DEVMODEA);
174 DevMode.dmFields = DM_FORMNAME;
175 memset(DevMode.dmDeviceName, 'A', 32);
176 memset(DevMode.dmFormName, 'A', 32);
177 ok(IsValidDevmodeA(&DevMode, DevMode.dmSize), "IsValidDevmodeA returns FALSE!\n");
178 ok(DevMode.dmDeviceName[31] == '\0', "Expected dmDeviceName to be '\\0', but is '%c'\n", DevMode.dmDeviceName[31]);
179 ok(DevMode.dmFormName[31] == '\0', "Expected dmFormName to be '\\0', but is '%c'\n", DevMode.dmDeviceName[31]);
180
181 // Depending on which fields are given in dmFields, the minimum value for dmSize is different.
182 ZeroMemory(&DevMode, sizeof(DEVMODEA));
183
184 do
185 {
186 DevMode.dmFields = pTable->dwField;
187 DevMode.dmSize = pTable->wSize;
188
189 // This size should succeed!
190 ok(IsValidDevmodeA(&DevMode, DevMode.dmSize), "IsValidDevmodeA returns FALSE!\n");
191
192 // One byte less should not succeed!
193 DevMode.dmSize--;
194 ok(!IsValidDevmodeA(&DevMode, DevMode.dmSize), "IsValidDevmodeA returns TRUE!\n");
195
196 pTable++;
197 }
198 while (pTable->dwField);
199}
static MINIMUM_SIZE_TABLE MinimumSizeA[]
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memset(x, y, z)
Definition: compat.h:39
BYTE dmFormName[CCHFORMNAME]
Definition: wingdi.h:1593
DWORD dmFields
Definition: wingdi.h:1570
WORD dmDriverExtra
Definition: wingdi.h:1569
BYTE dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1565
WORD dmSize
Definition: wingdi.h:1568
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
#define ZeroMemory
Definition: winbase.h:1737
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define DM_FORMNAME
Definition: wingdi.h:1266
struct _devicemodeA DEVMODEA
WINBOOL WINAPI IsValidDevmodeA(PDEVMODEA pDevmode, size_t DevmodeSize)
Definition: devmode.c:134

◆ START_TEST() [2/2]

START_TEST ( IsValidDevmodeW  )

Definition at line 201 of file IsValidDevmode.c.

202{
203 DEVMODEW DevMode;
205
206 // Give no Devmode at all, this has to fail without crashing.
207 SetLastError(0xDEADBEEF);
208 ok(!IsValidDevmodeW(NULL, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
209 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
210
211 // Give a zeroed Devmode, this has to fail, because dmSize isn't set.
212 ZeroMemory(&DevMode, sizeof(DEVMODEW));
213 SetLastError(0xDEADBEEF);
214 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
215 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
216
217 // Now set only the dmSize member, IsValidDevmodeW should return TRUE now. The Last Error isn't touched again.
218 ZeroMemory(&DevMode, sizeof(DEVMODEW));
219 DevMode.dmSize = sizeof(DEVMODEW);
220 SetLastError(0xDEADBEEF);
221 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns FALSE!\n");
222 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
223
224 // IsValidDevmodeW should also succeed if the DevMode appears to be larger.
225 ZeroMemory(&DevMode, sizeof(DEVMODEW));
226 DevMode.dmSize = sizeof(DEVMODEW) + 1;
227 SetLastError(0xDEADBEEF);
228 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
229 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
230
231 // The DevmodeSize parameter may be larger than dmSize, but not the other way round!
232 ZeroMemory(&DevMode, sizeof(DEVMODEW));
233 DevMode.dmSize = sizeof(DEVMODEW);
234 SetLastError(0xDEADBEEF);
235 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
236 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
237
238 ZeroMemory(&DevMode, sizeof(DEVMODEW));
239 DevMode.dmSize = sizeof(DEVMODEW) + 1;
240 SetLastError(0xDEADBEEF);
241 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
242 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
243
244 // dmDriverExtra is also taken into account.
245 ZeroMemory(&DevMode, sizeof(DEVMODEW));
246 DevMode.dmSize = sizeof(DEVMODEW);
247 DevMode.dmDriverExtra = 1;
248 SetLastError(0xDEADBEEF);
249 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
250 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
251
252 SetLastError(0xDEADBEEF);
253 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
254 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
255
256 // dmSize must be a multiple of 4 if any dmDriverExtra is given.
257 for (DevMode.dmDriverExtra = 1; DevMode.dmDriverExtra <= 4; DevMode.dmDriverExtra++)
258 {
259 for (DevMode.dmSize = sizeof(DEVMODEW); DevMode.dmSize < sizeof(DEVMODEW) + 4; DevMode.dmSize++)
260 {
261 BOOL bExpected = (DevMode.dmSize % 4 == 0);
262 DWORD dwExpectedError = (bExpected ? 0xDEADBEEF : ERROR_INVALID_DATA);
263
264 SetLastError(0xDEADBEEF);
265 ok(IsValidDevmodeW(&DevMode, DevMode.dmSize + DevMode.dmDriverExtra) == bExpected, "IsValidDevmodeW returns %d!\n", !bExpected);
266 ok(GetLastError() == dwExpectedError, "IsValidDevmodeW returns error %lu!\n", GetLastError());
267 }
268 }
269
270 // IsValidDevmodeW also fixes missing null-terminations if the corresponding fields are used.
271 ZeroMemory(&DevMode, sizeof(DEVMODEW));
272 DevMode.dmSize = sizeof(DEVMODEW);
273 wmemset(DevMode.dmDeviceName, L'A', 32);
274 wmemset(DevMode.dmFormName, L'A', 32);
275 ok(IsValidDevmodeW(&DevMode, DevMode.dmSize), "IsValidDevmodeW returns FALSE!\n");
276 ok(DevMode.dmDeviceName[31] == L'\0', "Expected dmDeviceName to be '\\0', but is '%C'\n", DevMode.dmDeviceName[31]);
277 ok(DevMode.dmFormName[31] == L'A', "Expected dmFormName to be 'A', but is '%C'\n", DevMode.dmDeviceName[31]);
278
279 ZeroMemory(&DevMode, sizeof(DEVMODEW));
280 DevMode.dmSize = sizeof(DEVMODEW);
281 DevMode.dmFields = DM_FORMNAME;
282 wmemset(DevMode.dmDeviceName, L'A', 32);
283 wmemset(DevMode.dmFormName, L'A', 32);
284 ok(IsValidDevmodeW(&DevMode, DevMode.dmSize), "IsValidDevmodeW returns FALSE!\n");
285 ok(DevMode.dmDeviceName[31] == L'\0', "Expected dmDeviceName to be '\\0', but is '%C'\n", DevMode.dmDeviceName[31]);
286 ok(DevMode.dmFormName[31] == L'\0', "Expected dmFormName to be '\\0', but is '%C'\n", DevMode.dmDeviceName[31]);
287
288 // Depending on which fields are given in dmFields, the minimum value for dmSize is different.
289 ZeroMemory(&DevMode, sizeof(DEVMODEW));
290
291 do
292 {
293 DevMode.dmFields = pTable->dwField;
294 DevMode.dmSize = pTable->wSize;
295
296 // This size should succeed!
297 ok(IsValidDevmodeW(&DevMode, DevMode.dmSize), "IsValidDevmodeW returns FALSE!\n");
298
299 // One byte less should not succeed!
300 DevMode.dmSize--;
301 ok(!IsValidDevmodeW(&DevMode, DevMode.dmSize), "IsValidDevmodeW returns TRUE!\n");
302
303 pTable++;
304 }
305 while (pTable->dwField);
306}
static MINIMUM_SIZE_TABLE MinimumSizeW[]
wchar_t *__cdecl wmemset(_Out_writes_all_(_N) wchar_t *_S, _In_ wchar_t _C, _In_ size_t _N)
Definition: wchar.h:2663
#define L(x)
Definition: ntvdm.h:50
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1617
DWORD dmFields
Definition: wingdi.h:1622
WORD dmDriverExtra
Definition: wingdi.h:1621
WCHAR dmFormName[CCHFORMNAME]
Definition: wingdi.h:1645
WORD dmSize
Definition: wingdi.h:1620
struct _devicemodeW DEVMODEW
WINBOOL WINAPI IsValidDevmodeW(PDEVMODEW pDevmode, size_t DevmodeSize)
Definition: devmode.c:186

Variable Documentation

◆ MinimumSizeA

MINIMUM_SIZE_TABLE MinimumSizeA[]
static

Definition at line 24 of file IsValidDevmode.c.

Referenced by START_TEST().

◆ MinimumSizeW

MINIMUM_SIZE_TABLE MinimumSizeW[]
static

Definition at line 58 of file IsValidDevmode.c.

Referenced by START_TEST().