Added a few more Unicode digits from Unicode version 4.1.
[wine] / dlls / gdi / tests / bitmap.c
1 /*
2  * Unit test suite for bitmaps
3  *
4  * Copyright 2004 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22 #include <assert.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "mmsystem.h"
29
30 #include "wine/test.h"
31
32 static BOOL is_win9x;
33
34 static void test_createdibitmap(void)
35 {
36     HDC hdc, hdcmem;
37     BITMAPINFOHEADER bmih;
38     BITMAP bm;
39     HBITMAP hbm, hbm_colour, hbm_old;
40     INT screen_depth;
41
42     hdc = GetDC(0);
43     screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
44     memset(&bmih, 0, sizeof(bmih));
45     bmih.biSize = sizeof(bmih);
46     bmih.biWidth = 10;
47     bmih.biHeight = 10;
48     bmih.biPlanes = 1;
49     bmih.biBitCount = 32;
50     bmih.biCompression = BI_RGB;
51  
52     /* First create an un-initialised bitmap.  The depth of the bitmap
53        should match that of the hdc and not that supplied in bmih.
54     */
55
56     /* First try 32 bits */
57     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
58     ok(hbm != NULL, "CreateDIBitmap failed\n");
59     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
60
61     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
62     DeleteObject(hbm);
63     
64     /* Then 16 */
65     bmih.biBitCount = 16;
66     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
67     ok(hbm != NULL, "CreateDIBitmap failed\n");
68     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
69
70     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
71     DeleteObject(hbm);
72
73     /* Then 1 */
74     bmih.biBitCount = 1;
75     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
76     ok(hbm != NULL, "CreateDIBitmap failed\n");
77     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
78
79     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
80     DeleteObject(hbm);
81
82     /* Now with a monochrome dc we expect a monochrome bitmap */
83     hdcmem = CreateCompatibleDC(hdc);
84
85     /* First try 32 bits */
86     bmih.biBitCount = 32;
87     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
88     ok(hbm != NULL, "CreateDIBitmap failed\n");
89     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
90
91     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
92     DeleteObject(hbm);
93     
94     /* Then 16 */
95     bmih.biBitCount = 16;
96     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
97     ok(hbm != NULL, "CreateDIBitmap failed\n");
98     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
99
100     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
101     DeleteObject(hbm);
102     
103     /* Then 1 */
104     bmih.biBitCount = 1;
105     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
106     ok(hbm != NULL, "CreateDIBitmap failed\n");
107     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
108
109     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
110     DeleteObject(hbm);
111
112     /* Now select a polychrome bitmap into the dc and we expect
113        screen_depth bitmaps again */
114     hbm_colour = CreateCompatibleBitmap(hdc, 1, 1);
115     hbm_old = SelectObject(hdcmem, hbm_colour);
116
117     /* First try 32 bits */
118     bmih.biBitCount = 32;
119     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
120     ok(hbm != NULL, "CreateDIBitmap failed\n");
121     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
122
123     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
124     DeleteObject(hbm);
125     
126     /* Then 16 */
127     bmih.biBitCount = 16;
128     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
129     ok(hbm != NULL, "CreateDIBitmap failed\n");
130     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
131
132     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
133     DeleteObject(hbm);
134     
135     /* Then 1 */
136     bmih.biBitCount = 1;
137     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
138     ok(hbm != NULL, "CreateDIBitmap failed\n");
139     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
140
141     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
142     DeleteObject(hbm);
143
144     SelectObject(hdcmem, hbm_old);
145     DeleteObject(hbm_colour);
146     DeleteDC(hdcmem);
147
148     /* If hdc == 0 then we get a 1 bpp bitmap */
149     if (!is_win9x) {
150         bmih.biBitCount = 32;
151         hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
152         ok(hbm != NULL, "CreateDIBitmap failed\n");
153         ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
154
155         ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
156         DeleteObject(hbm);
157     }
158     
159     ReleaseDC(0, hdc);
160 }
161
162 #define test_color_todo(got, exp, txt, todo) \
163     if (!todo && got != exp && screen_depth < 24) { \
164       todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
165                    screen_depth, (UINT)got, (UINT)exp); \
166       return; \
167     } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
168     else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
169
170 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
171 { \
172     COLORREF c; \
173     c = SetPixel(hdc, 0, 0, color); \
174     if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
175     c = GetPixel(hdc, 0, 0); \
176     test_color_todo(c, exp, GetPixel, todo_getp); \
177 }
178
179 static void test_dibsections(void)
180 {
181     HDC hdc, hdcmem, hdcmem2;
182     HBITMAP hdib, oldbm, hdib2, oldbm2;
183     char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
184     char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
185     BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
186     BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
187     HBITMAP hcoredib;
188     char coreBits[256];
189     BYTE *bits;
190     RGBQUAD rgb[256];
191     int ret;
192     char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
193     LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
194     WORD *index;
195     DWORD *bits32;
196     HPALETTE hpal, oldpal;
197     DIBSECTION dibsec;
198     COLORREF c0, c1;
199     int i;
200     int screen_depth;
201
202     hdc = GetDC(0);
203     screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
204     memset(pbmi, 0, sizeof(bmibuf));
205     pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
206     pbmi->bmiHeader.biHeight = 16;
207     pbmi->bmiHeader.biWidth = 16;
208     pbmi->bmiHeader.biBitCount = 1;
209     pbmi->bmiHeader.biPlanes = 1;
210     pbmi->bmiHeader.biCompression = BI_RGB;
211     pbmi->bmiColors[0].rgbRed = 0xff;
212     pbmi->bmiColors[0].rgbGreen = 0;
213     pbmi->bmiColors[0].rgbBlue = 0;
214     pbmi->bmiColors[1].rgbRed = 0;
215     pbmi->bmiColors[1].rgbGreen = 0;
216     pbmi->bmiColors[1].rgbBlue = 0xff;
217
218     hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
219     ok(hdib != NULL, "CreateDIBSection failed\n");
220     ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
221     ok(dibsec.dsBmih.biClrUsed == 2,
222         "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
223
224     /* Test if the old BITMAPCOREINFO structure is supported */    
225         
226     pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
227     pbci->bmciHeader.bcBitCount = 0;
228
229     if (!is_win9x) {
230         ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
231         ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
232         ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
233             && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
234         "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
235
236         ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
237         ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
238         ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
239             (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
240             (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
241             "The color table has not been translated to the old BITMAPCOREINFO format\n");
242
243         hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
244         ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
245
246         ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
247         ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
248         ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
249         ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
250             (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
251             (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
252             "The color table has not been translated to the old BITMAPCOREINFO format\n");
253
254         DeleteObject(hcoredib);
255     }
256
257     hdcmem = CreateCompatibleDC(hdc);
258     oldbm = SelectObject(hdcmem, hdib);
259
260     ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
261     ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
262     ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
263        "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
264        rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
265        rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
266
267     c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
268     c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
269
270     test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
271     test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
272     test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
273     test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
274     test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
275     test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
276     test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
277         pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
278     test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
279         pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
280     test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
281     test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
282     test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
283
284     SelectObject(hdcmem, oldbm);
285     DeleteObject(hdib);
286
287     pbmi->bmiHeader.biBitCount = 4;
288     for (i = 0; i < 16; i++) {
289         pbmi->bmiColors[i].rgbRed = i;
290         pbmi->bmiColors[i].rgbGreen = 16-i;
291         pbmi->bmiColors[i].rgbBlue = 0;
292     }
293     hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
294     ok(hdib != NULL, "CreateDIBSection failed\n");
295     ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
296     ok(dibsec.dsBmih.biClrUsed == 16,
297        "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
298     DeleteObject(hdib);
299
300     pbmi->bmiHeader.biBitCount = 8;
301
302     for (i = 0; i < 128; i++) {
303         pbmi->bmiColors[i].rgbRed = 255 - i * 2;
304         pbmi->bmiColors[i].rgbGreen = i * 2;
305         pbmi->bmiColors[i].rgbBlue = 0;
306         pbmi->bmiColors[255 - i].rgbRed = 0;
307         pbmi->bmiColors[255 - i].rgbGreen = i * 2;
308         pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
309     }
310     hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
311     ok(hdib != NULL, "CreateDIBSection failed\n");
312     ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
313     ok(dibsec.dsBmih.biClrUsed == 256,
314         "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
315
316     oldbm = SelectObject(hdcmem, hdib);
317
318     for (i = 0; i < 256; i++) {
319         test_color(hdcmem, DIBINDEX(i), 
320             RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
321         test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 
322             RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
323     }
324
325     SelectObject(hdcmem, oldbm);
326     DeleteObject(hdib);
327
328     pbmi->bmiHeader.biBitCount = 1;
329
330     /* Now create a palette and a palette indexed dib section */
331     memset(plogpal, 0, sizeof(logpalbuf));
332     plogpal->palVersion = 0x300;
333     plogpal->palNumEntries = 2;
334     plogpal->palPalEntry[0].peRed = 0xff;
335     plogpal->palPalEntry[0].peBlue = 0xff;
336     plogpal->palPalEntry[1].peGreen = 0xff;
337
338     index = (WORD*)pbmi->bmiColors;
339     *index++ = 0;
340     *index = 1;
341     hpal = CreatePalette(plogpal);
342     ok(hpal != NULL, "CreatePalette failed\n");
343     oldpal = SelectPalette(hdc, hpal, TRUE);
344     hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
345     ok(hdib != NULL, "CreateDIBSection failed\n");
346     ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
347     ok(dibsec.dsBmih.biClrUsed == 2,
348         "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
349
350     /* The colour table has already been grabbed from the dc, so we select back the
351        old palette */
352
353     SelectPalette(hdc, oldpal, TRUE);
354     oldbm = SelectObject(hdcmem, hdib);
355     oldpal = SelectPalette(hdcmem, hpal, TRUE);
356
357     ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
358     ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
359     ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
360        rgb[1].rgbRed == 0    && rgb[1].rgbBlue == 0    && rgb[1].rgbGreen == 0xff,
361        "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
362        rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
363        rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
364
365     c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
366     c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
367
368     test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
369     test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
370     test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
371     test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
372     test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
373     test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
374     test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
375         plogpal->palPalEntry[0].peBlue), c0, 1, 1);
376     test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
377         plogpal->palPalEntry[1].peBlue), c1, 1, 1);
378     test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
379     test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
380     test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
381     test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
382     test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
383     test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
384
385     /* Bottom and 2nd row from top green, everything else magenta */
386     bits[0] = bits[1] = 0xff;
387     bits[13 * 4] = bits[13*4 + 1] = 0xff;
388
389
390     pbmi->bmiHeader.biBitCount = 32;
391
392     hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
393     ok(hdib2 != NULL, "CreateDIBSection failed\n");
394     hdcmem2 = CreateCompatibleDC(hdc);
395     oldbm2 = SelectObject(hdcmem2, hdib2);
396
397     BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
398
399     ok(bits32[0] == 0xff00, "lower left pixel is %08lx\n", bits32[0]);
400     ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08lx\n", bits32[17]);
401
402     SelectObject(hdcmem2, oldbm2);
403     DeleteObject(hdib2);
404
405     SelectObject(hdcmem, oldbm);
406     SelectObject(hdcmem, oldpal);
407     DeleteObject(hdib);
408     DeleteObject(hpal);
409
410
411     pbmi->bmiHeader.biBitCount = 8;
412
413     memset(plogpal, 0, sizeof(logpalbuf));
414     plogpal->palVersion = 0x300;
415     plogpal->palNumEntries = 256;
416
417     for (i = 0; i < 128; i++) {
418         plogpal->palPalEntry[i].peRed = 255 - i * 2;
419         plogpal->palPalEntry[i].peBlue = i * 2;
420         plogpal->palPalEntry[i].peGreen = 0;
421         plogpal->palPalEntry[255 - i].peRed = 0;
422         plogpal->palPalEntry[255 - i].peGreen = i * 2;
423         plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
424     }
425
426     index = (WORD*)pbmi->bmiColors;
427     for (i = 0; i < 256; i++) {
428         *index++ = i;
429     }
430
431     hpal = CreatePalette(plogpal);
432     ok(hpal != NULL, "CreatePalette failed\n");
433     oldpal = SelectPalette(hdc, hpal, TRUE);
434     hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
435     ok(hdib != NULL, "CreateDIBSection failed\n");
436     ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
437     ok(dibsec.dsBmih.biClrUsed == 256,
438         "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
439
440     SelectPalette(hdc, oldpal, TRUE);
441     oldbm = SelectObject(hdcmem, hdib);
442     oldpal = SelectPalette(hdcmem, hpal, TRUE);
443
444     ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
445     ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
446     for (i = 0; i < 256; i++) {
447         ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed && 
448             rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue && 
449             rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen, 
450             "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
451             i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
452     }
453
454     for (i = 0; i < 256; i++) {
455         test_color(hdcmem, DIBINDEX(i), 
456             RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
457         test_color(hdcmem, PALETTEINDEX(i), 
458             RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
459         test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 
460             RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
461     }
462
463     SelectPalette(hdcmem, oldpal, TRUE);
464     SelectObject(hdcmem, oldbm);
465     DeleteObject(hdib);
466     DeleteObject(hpal);
467
468
469     DeleteDC(hdcmem);
470     ReleaseDC(0, hdc);
471 }    
472
473 START_TEST(bitmap)
474 {
475     HWND hWnd;
476
477     hWnd = CreateWindowExA(0, "EDIT", NULL, 0,
478                            10, 10, 300, 300,
479                            NULL, NULL, NULL, NULL);
480     assert(hWnd);
481     is_win9x = GetWindowLongPtrW(hWnd, GWLP_WNDPROC) == 0;
482     DestroyWindow(hWnd);
483
484     test_createdibitmap();
485     test_dibsections();
486 }