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     ok_long(*(LPDWORD)pvBits, 0);
298 
299     DeleteObject(hBitmap);
300     DeleteDC(hDC);
301 
302     /* ------------------------- */
303 
304     hDC = CreateCompatibleDC(NULL);
305 
306     ZeroMemory(&bmi, sizeof(bmi));
307     bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
308     bmi.bmiHeader.biWidth = 15;
309     bmi.bmiHeader.biHeight = -15;   /* negative */
310     bmi.bmiHeader.biPlanes = 1;
311     bmi.bmiHeader.biBitCount = 24;
312     hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
313     ok(hBitmap != NULL, "hBitmap was NULL.\n");
314 
315     FillMemory(Bits, sizeof(Bits), 0x55);
316     SetLastError(0xDEADFACE);
317     ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0);
318     ok_long(GetLastError(), 0xDEADFACE);
319     ok_int(Bits[0], 0x55);
320 
321     FillMemory(Bits, sizeof(Bits), 0x55);
322     SetLastError(0xDEADFACE);
323     ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
324     ok_long(GetLastError(), 0xDEADFACE);
325     ok_int(Bits[0], 0);
326     ok_int(Bits[1], 0x55);
327 
328     FillMemory(Bits, sizeof(Bits), 0x55);
329     SetLastError(0xDEADFACE);
330     ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
331     ok_long(GetLastError(), 0xDEADFACE);
332     ok_int(Bits[0], 0);
333     ok_int(Bits[1], 0);
334     ok_int(Bits[2], 0x55);
335 
336     FillMemory(Bits, sizeof(Bits), 0x33);
337     SetLastError(0xDEADFACE);
338     ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10);
339     ok_long(GetLastError(), 0xDEADFACE);
340 
341     FillMemory(Bits, sizeof(Bits), 0xAA);
342     SetLastError(0xDEADFACE);
343     ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1);
344     ok_long(GetLastError(), 0xDEADFACE);
345     FillMemory(Bits, sizeof(Bits), 0x55);
346     SetLastError(0xDEADFACE);
347     ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1);
348     ok_long(GetLastError(), 0xDEADFACE);
349     ok_int(Bits[0], 0xAA);
350     ok_int(Bits[1], 0x55);
351     SetLastError(0xDEADFACE);
352     ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
353     ok_long(GetLastError(), 0xDEADFACE);
354     ok_int(Bits[0], 0xAA);
355     ok_int(Bits[1], 0x33);
356     ok_int(Bits[2], 0x55);
357 
358     FillMemory(Bits, sizeof(Bits), 0xAA);
359     SetLastError(0xDEADFACE);
360     ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2);
361     ok_long(GetLastError(), 0xDEADFACE);
362     FillMemory(Bits, sizeof(Bits), 0x55);
363     SetLastError(0xDEADFACE);
364     ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2);
365     ok_long(GetLastError(), 0xDEADFACE);
366     ok_int(Bits[0], 0xAA);
367     ok_int(Bits[1], 0xAA);
368     ok_int(Bits[2], 0x55);
369     SetLastError(0xDEADFACE);
370     ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
371     ok_long(GetLastError(), 0xDEADFACE);
372     ok_int(Bits[0], 0xAA);
373     ok_int(Bits[1], 0xAA);
374     ok_int(Bits[2], 0x33);
375     ok_int(Bits[3], 0x55);
376 
377     FillMemory(Bits, sizeof(Bits), 0xAA);
378     SetLastError(0xDEADFACE);
379     ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3);
380     ok_long(GetLastError(), 0xDEADFACE);
381     FillMemory(Bits, sizeof(Bits), 0x55);
382     SetLastError(0xDEADFACE);
383     ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3);
384     ok_long(GetLastError(), 0xDEADFACE);
385     ok_int(Bits[0], 0xAA);
386     ok_int(Bits[1], 0xAA);
387     ok_int(Bits[2], 0xAA);
388     ok_int(Bits[3], 0x55);
389     SetLastError(0xDEADFACE);
390     ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4);
391     ok_long(GetLastError(), 0xDEADFACE);
392     ok_int(Bits[0], 0xAA);
393     ok_int(Bits[1], 0xAA);
394     ok_int(Bits[2], 0xAA);
395     ok_int(Bits[3], 0x33);
396     ok_int(Bits[4], 0x55);
397 
398     ok_long(*(LPDWORD)pvBits, 0x33AAAAAA);
399 
400     DeleteObject(hBitmap);
401     DeleteDC(hDC);
402 }
403