[WIN32KNT_APITEST] NtGdiSetBitmapBits: Add tests for maximum buffer size (#1311)
[reactos.git] / modules / rostests / apitests / win32nt / ntgdi / NtGdiSetBitmapBits.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtGdiSetBitmapBits
5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8 #include <win32nt.h>
9
10 START_TEST(NtGdiSetBitmapBits)
11 {
12 BYTE Bits[100] = {0,1,2,3,4,5,6,7,8,9};
13 HBITMAP hBitmap;
14 HDC hDC;
15 BITMAPINFO bmi;
16 LPVOID pvBits;
17
18 SetLastError(0xDEADFACE);
19 ok_long(NtGdiSetBitmapBits(0, 0, 0), 0);
20 ok_long(GetLastError(), 0xDEADFACE);
21
22 /* Test NULL bitnap handle */
23 SetLastError(0xDEADFACE);
24 ok_long(NtGdiSetBitmapBits(0, 5, Bits), 0);
25 ok_long(GetLastError(), ERROR_INVALID_HANDLE);
26
27 /* Test invalid bitmap handle */
28 hBitmap = (HBITMAP)CreatePen(PS_SOLID, 1, RGB(1,2,3));
29 SetLastError(0xDEADFACE);
30 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 0);
31 ok_long(GetLastError(), ERROR_INVALID_HANDLE);
32 DeleteObject(hBitmap);
33
34 hBitmap = CreateBitmap(3, 3, 1, 8, NULL);
35 ok(hBitmap != NULL, "hBitmap was NULL.\n");
36
37 /* test NULL pointer and count buffer size != 0 */
38 SetLastError(0xDEADFACE);
39 ok_long(NtGdiSetBitmapBits(hBitmap, 5, NULL), 0);
40 ok_long(GetLastError(), 0xDEADFACE);
41
42 /* test NULL pointer and buffer size == 0*/
43 SetLastError(0xDEADFACE);
44 ok_long(NtGdiSetBitmapBits(hBitmap, 0, NULL), 0);
45 ok_long(GetLastError(), 0xDEADFACE);
46
47 /* test bad pointer */
48 SetLastError(0xDEADFACE);
49 ok_long(NtGdiSetBitmapBits(hBitmap, 5, (PBYTE)0x500), 0);
50 ok_long(GetLastError(), 0xDEADFACE);
51
52 /* Test if we can set a number of bytes between lines */
53 SetLastError(0xDEADFACE);
54 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 5);
55 ok_long(GetLastError(), 0xDEADFACE);
56
57 /* Test alignment */
58 SetLastError(0xDEADFACE);
59 ok_long(NtGdiSetBitmapBits(hBitmap, 4, Bits+1), 4);
60 ok_long(GetLastError(), 0xDEADFACE);
61
62 /* Test 1 byte too much */
63 SetLastError(0xDEADFACE);
64 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
65 ok_long(GetLastError(), 0xDEADFACE);
66
67 /* Test one row too much */
68 SetLastError(0xDEADFACE);
69 ok_long(NtGdiSetBitmapBits(hBitmap, 12, Bits), 12);
70 ok_long(GetLastError(), 0xDEADFACE);
71
72 SetLastError(0xDEADFACE);
73 ok_long(NtGdiSetBitmapBits(hBitmap, 13, Bits), 12);
74 ok_long(GetLastError(), 0xDEADFACE);
75
76 SetLastError(0xDEADFACE);
77 ok_long(NtGdiSetBitmapBits(hBitmap, 100, Bits), 12);
78 ok_long(GetLastError(), 0xDEADFACE);
79
80 /* Test huge bytes count */
81 SetLastError(0xDEADFACE);
82 ok_long(NtGdiSetBitmapBits(hBitmap, 12345678, Bits), 0);
83 ok_long(GetLastError(), 0xDEADFACE);
84
85 SetLastError(0xDEADFACE);
86 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100, Bits), 0xC);
87 ok_long(GetLastError(), 0xDEADFACE);
88
89 SetLastError(0xDEADFACE);
90 ok_long(NtGdiSetBitmapBits(hBitmap, 564, Bits), 0xC);
91 ok_long(GetLastError(), 0xDEADFACE);
92
93 SetLastError(0xDEADFACE);
94 ok_long(NtGdiSetBitmapBits(hBitmap, 565, Bits), 0);
95 ok_long(GetLastError(), 0xDEADFACE);
96
97 SetLastError(0xDEADFACE);
98 ok_long(NtGdiSetBitmapBits(hBitmap, 0x7FFF, Bits), 0);
99 ok_long(GetLastError(), 0xDEADFACE);
100
101 SetLastError(0xDEADFACE);
102 ok_long(NtGdiSetBitmapBits(hBitmap, 0x8000, Bits), 0);
103 ok_long(GetLastError(), 0xDEADFACE);
104
105 SetLastError(0xDEADFACE);
106 ok_long(NtGdiSetBitmapBits(hBitmap, 0xFFFF, Bits), 0);
107 ok_long(GetLastError(), 0xDEADFACE);
108
109 SetLastError(0xDEADFACE);
110 ok_long(NtGdiSetBitmapBits(hBitmap, 0x10000, Bits), 0);
111 ok_long(GetLastError(), 0xDEADFACE);
112
113 /* Test negative bytes count */
114 SetLastError(0xDEADFACE);
115 ok_long(NtGdiSetBitmapBits(hBitmap, -5, Bits), 0);
116 ok_long(GetLastError(), 0xDEADFACE);
117
118 DeleteObject(hBitmap);
119
120 /* ------------------------- */
121
122 hBitmap = CreateBitmap(16, 16, 1, 1, NULL);
123 ok(hBitmap != NULL, "hBitmap was NULL.\n");
124
125 FillMemory(Bits, sizeof(Bits), 0x55);
126 SetLastError(0xDEADFACE);
127 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
128 ok_long(GetLastError(), 0xDEADFACE);
129 ok_int(Bits[0], 0x55);
130
131 FillMemory(Bits, sizeof(Bits), 0x55);
132
133 SetLastError(0xDEADFACE);
134 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
135 ok_long(GetLastError(), 0xDEADFACE);
136 ok_int(Bits[0], 0);
137 ok_int(Bits[1], 0x55);
138
139 FillMemory(Bits, sizeof(Bits), 0x55);
140 SetLastError(0xDEADFACE);
141 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
142 ok_long(GetLastError(), 0xDEADFACE);
143 ok_int(Bits[0], 0);
144 ok_int(Bits[1], 0);
145 ok_int(Bits[2], 0x55);
146
147 FillMemory(Bits, sizeof(Bits), 0x33);
148 SetLastError(0xDEADFACE);
149 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
150 ok_long(GetLastError(), 0xDEADFACE);
151
152 FillMemory(Bits, sizeof(Bits), 0xAA);
153 SetLastError(0xDEADFACE);
154 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
155 ok_long(GetLastError(), 0xDEADFACE);
156 FillMemory(Bits, sizeof(Bits), 0x55);
157 SetLastError(0xDEADFACE);
158 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
159 ok_long(GetLastError(), 0xDEADFACE);
160 ok_int(Bits[0], 0xAA);
161 ok_int(Bits[1], 0x55);
162 SetLastError(0xDEADFACE);
163 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
164 ok_long(GetLastError(), 0xDEADFACE);
165 ok_int(Bits[0], 0xAA);
166 ok_int(Bits[1], 0x33);
167 ok_int(Bits[2], 0x55);
168
169 FillMemory(Bits, sizeof(Bits), 0xAA);
170 SetLastError(0xDEADFACE);
171 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
172 ok_long(GetLastError(), 0xDEADFACE);
173 FillMemory(Bits, sizeof(Bits), 0x55);
174 SetLastError(0xDEADFACE);
175 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
176 ok_long(GetLastError(), 0xDEADFACE);
177 ok_int(Bits[0], 0xAA);
178 ok_int(Bits[1], 0xAA);
179 ok_int(Bits[2], 0x55);
180 SetLastError(0xDEADFACE);
181 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
182 ok_long(GetLastError(), 0xDEADFACE);
183 ok_int(Bits[0], 0xAA);
184 ok_int(Bits[1], 0xAA);
185 ok_int(Bits[2], 0x33);
186 ok_int(Bits[3], 0x55);
187
188 FillMemory(Bits, sizeof(Bits), 0xAA);
189 SetLastError(0xDEADFACE);
190 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
191 ok_long(GetLastError(), 0xDEADFACE);
192 FillMemory(Bits, sizeof(Bits), 0x55);
193 SetLastError(0xDEADFACE);
194 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
195 ok_long(GetLastError(), 0xDEADFACE);
196 ok_int(Bits[0], 0xAA);
197 ok_int(Bits[1], 0xAA);
198 ok_int(Bits[2], 0xAA);
199 ok_int(Bits[3], 0x55);
200 SetLastError(0xDEADFACE);
201 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
202 ok_long(GetLastError(), 0xDEADFACE);
203 ok_int(Bits[0], 0xAA);
204 ok_int(Bits[1], 0xAA);
205 ok_int(Bits[2], 0xAA);
206 ok_int(Bits[3], 0x33);
207 ok_int(Bits[4], 0x55);
208
209 DeleteObject(hBitmap);
210
211 /* ------------------------- */
212
213 hDC = CreateCompatibleDC(NULL);
214
215 ZeroMemory(&bmi, sizeof(bmi));
216 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
217 bmi.bmiHeader.biWidth = 15;
218 bmi.bmiHeader.biHeight = 15; /* positive */
219 bmi.bmiHeader.biPlanes = 1;
220 bmi.bmiHeader.biBitCount = 24;
221 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
222 ok(hBitmap != NULL, "hBitmap was NULL.\n");
223
224 FillMemory(Bits, sizeof(Bits), 0x55);
225 SetLastError(0xDEADFACE);
226 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
227 ok_long(GetLastError(), 0xDEADFACE);
228 ok_int(Bits[0], 0x55);
229
230 FillMemory(Bits, sizeof(Bits), 0x55);
231 SetLastError(0xDEADFACE);
232 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
233 ok_long(GetLastError(), 0xDEADFACE);
234 ok_int(Bits[0], 0);
235 ok_int(Bits[1], 0x55);
236
237 FillMemory(Bits, sizeof(Bits), 0x55);
238 SetLastError(0xDEADFACE);
239 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
240 ok_long(GetLastError(), 0xDEADFACE);
241 ok_int(Bits[0], 0);
242 ok_int(Bits[1], 0);
243 ok_int(Bits[2], 0x55);
244
245 FillMemory(Bits, sizeof(Bits), 0x33);
246 SetLastError(0xDEADFACE);
247 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
248 ok_long(GetLastError(), 0xDEADFACE);
249
250 FillMemory(Bits, sizeof(Bits), 0xAA);
251 SetLastError(0xDEADFACE);
252 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
253 ok_long(GetLastError(), 0xDEADFACE);
254 FillMemory(Bits, sizeof(Bits), 0x55);
255 SetLastError(0xDEADFACE);
256 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
257 ok_long(GetLastError(), 0xDEADFACE);
258 ok_int(Bits[0], 0xAA);
259 ok_int(Bits[1], 0x55);
260 SetLastError(0xDEADFACE);
261 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
262 ok_long(GetLastError(), 0xDEADFACE);
263 ok_int(Bits[0], 0xAA);
264 ok_int(Bits[1], 0x33);
265 ok_int(Bits[2], 0x55);
266
267 FillMemory(Bits, sizeof(Bits), 0xAA);
268 SetLastError(0xDEADFACE);
269 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
270 ok_long(GetLastError(), 0xDEADFACE);
271 FillMemory(Bits, sizeof(Bits), 0x55);
272 SetLastError(0xDEADFACE);
273 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
274 ok_long(GetLastError(), 0xDEADFACE);
275 ok_int(Bits[0], 0xAA);
276 ok_int(Bits[1], 0xAA);
277 ok_int(Bits[2], 0x55);
278 SetLastError(0xDEADFACE);
279 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
280 ok_long(GetLastError(), 0xDEADFACE);
281 ok_int(Bits[0], 0xAA);
282 ok_int(Bits[1], 0xAA);
283 ok_int(Bits[2], 0x33);
284 ok_int(Bits[3], 0x55);
285
286 FillMemory(Bits, sizeof(Bits), 0xAA);
287 SetLastError(0xDEADFACE);
288 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
289 ok_long(GetLastError(), 0xDEADFACE);
290 FillMemory(Bits, sizeof(Bits), 0x55);
291 SetLastError(0xDEADFACE);
292 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
293 ok_long(GetLastError(), 0xDEADFACE);
294 ok_int(Bits[0], 0xAA);
295 ok_int(Bits[1], 0xAA);
296 ok_int(Bits[2], 0xAA);
297 ok_int(Bits[3], 0x55);
298 SetLastError(0xDEADFACE);
299 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
300 ok_long(GetLastError(), 0xDEADFACE);
301 ok_int(Bits[0], 0xAA);
302 ok_int(Bits[1], 0xAA);
303 ok_int(Bits[2], 0xAA);
304 ok_int(Bits[3], 0x33);
305 ok_int(Bits[4], 0x55);
306
307 DeleteObject(hBitmap);
308 DeleteDC(hDC);
309
310 /* ------------------------- */
311
312 hDC = CreateCompatibleDC(NULL);
313
314 ZeroMemory(&bmi, sizeof(bmi));
315 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
316 bmi.bmiHeader.biWidth = 15;
317 bmi.bmiHeader.biHeight = -15; /* negative */
318 bmi.bmiHeader.biPlanes = 1;
319 bmi.bmiHeader.biBitCount = 24;
320 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
321 ok(hBitmap != NULL, "hBitmap was NULL.\n");
322
323 FillMemory(Bits, sizeof(Bits), 0x55);
324 SetLastError(0xDEADFACE);
325 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
326 ok_long(GetLastError(), 0xDEADFACE);
327 ok_int(Bits[0], 0x55);
328
329 FillMemory(Bits, sizeof(Bits), 0x55);
330 SetLastError(0xDEADFACE);
331 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
332 ok_long(GetLastError(), 0xDEADFACE);
333 ok_int(Bits[0], 0);
334 ok_int(Bits[1], 0x55);
335
336 FillMemory(Bits, sizeof(Bits), 0x55);
337 SetLastError(0xDEADFACE);
338 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
339 ok_long(GetLastError(), 0xDEADFACE);
340 ok_int(Bits[0], 0);
341 ok_int(Bits[1], 0);
342 ok_int(Bits[2], 0x55);
343
344 FillMemory(Bits, sizeof(Bits), 0x33);
345 SetLastError(0xDEADFACE);
346 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
347 ok_long(GetLastError(), 0xDEADFACE);
348
349 FillMemory(Bits, sizeof(Bits), 0xAA);
350 SetLastError(0xDEADFACE);
351 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
352 ok_long(GetLastError(), 0xDEADFACE);
353 FillMemory(Bits, sizeof(Bits), 0x55);
354 SetLastError(0xDEADFACE);
355 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
356 ok_long(GetLastError(), 0xDEADFACE);
357 ok_int(Bits[0], 0xAA);
358 ok_int(Bits[1], 0x55);
359 SetLastError(0xDEADFACE);
360 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
361 ok_long(GetLastError(), 0xDEADFACE);
362 ok_int(Bits[0], 0xAA);
363 ok_int(Bits[1], 0x33);
364 ok_int(Bits[2], 0x55);
365
366 FillMemory(Bits, sizeof(Bits), 0xAA);
367 SetLastError(0xDEADFACE);
368 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
369 ok_long(GetLastError(), 0xDEADFACE);
370 FillMemory(Bits, sizeof(Bits), 0x55);
371 SetLastError(0xDEADFACE);
372 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
373 ok_long(GetLastError(), 0xDEADFACE);
374 ok_int(Bits[0], 0xAA);
375 ok_int(Bits[1], 0xAA);
376 ok_int(Bits[2], 0x55);
377 SetLastError(0xDEADFACE);
378 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
379 ok_long(GetLastError(), 0xDEADFACE);
380 ok_int(Bits[0], 0xAA);
381 ok_int(Bits[1], 0xAA);
382 ok_int(Bits[2], 0x33);
383 ok_int(Bits[3], 0x55);
384
385 FillMemory(Bits, sizeof(Bits), 0xAA);
386 SetLastError(0xDEADFACE);
387 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
388 ok_long(GetLastError(), 0xDEADFACE);
389 FillMemory(Bits, sizeof(Bits), 0x55);
390 SetLastError(0xDEADFACE);
391 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
392 ok_long(GetLastError(), 0xDEADFACE);
393 ok_int(Bits[0], 0xAA);
394 ok_int(Bits[1], 0xAA);
395 ok_int(Bits[2], 0xAA);
396 ok_int(Bits[3], 0x55);
397 SetLastError(0xDEADFACE);
398 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
399 ok_long(GetLastError(), 0xDEADFACE);
400 ok_int(Bits[0], 0xAA);
401 ok_int(Bits[1], 0xAA);
402 ok_int(Bits[2], 0xAA);
403 ok_int(Bits[3], 0x33);
404 ok_int(Bits[4], 0x55);
405
406 DeleteObject(hBitmap);
407 DeleteDC(hDC);
408 }