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