Skip to content

Commit dd49012

Browse files
committed
[GDI32_APITEST]
Add/fix some tests for CreateDIBPatternBrush, GetDIBits, PatBlt and SetWindowExtEx svn path=/trunk/; revision=67051
1 parent d030b7f commit dd49012

File tree

4 files changed

+90
-15
lines changed

4 files changed

+90
-15
lines changed

rostests/apitests/gdi32/CreateDIBPatternBrush.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <wingdi.h>
1111
#include "init.h"
1212

13+
/* New color use parameter. See support.microsoft.com/kb/kbview/108497 */
14+
#define DIB_PAL_INDICES 2
15+
1316
void Test_CreateDIBPatternBrush()
1417
{
1518

@@ -30,6 +33,7 @@ void Test_CreateDIBPatternBrushPt()
3033
};
3134
HBRUSH hbr, hbrOld;
3235
HPALETTE hpalOld;
36+
LOGBRUSH logbrush;
3337

3438
SetLastError(0);
3539
ok_hdl(CreateDIBPatternBrushPt(NULL, 0), NULL);
@@ -59,6 +63,13 @@ void Test_CreateDIBPatternBrushPt()
5963
ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
6064
if (!hbr) return;
6165

66+
/* Check the logbrush */
67+
ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
68+
ok_int(logbrush.lbStyle, BS_DIBPATTERN);
69+
ok_hex(logbrush.lbColor, 0);
70+
ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
71+
"invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
72+
6273
/* Select the brush into the dc */
6374
hbrOld = SelectObject(ghdcDIB32, hbr);
6475

@@ -100,11 +111,18 @@ void Test_CreateDIBPatternBrushPt()
100111
PackedDIB.ajBuffer[2] = 1;
101112
PackedDIB.ajBuffer[3] = 0;
102113

103-
/* Create a DIB brush with unkdocumented iUsage == 2 */
104-
hbr = CreateDIBPatternBrushPt(&PackedDIB, 2);
114+
/* Create a DIB brush with DIB_PAL_INDICES */
115+
hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_INDICES);
105116
ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n");
106117
if (!hbr) return;
107118

119+
/* Check the logbrush */
120+
ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
121+
ok_int(logbrush.lbStyle, BS_DIBPATTERN);
122+
ok_hex(logbrush.lbColor, 0);
123+
ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
124+
"invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
125+
108126
/* Select the brush into the dc */
109127
hbrOld = SelectObject(ghdcDIB32, hbr);
110128
ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n");
@@ -155,8 +173,7 @@ void Test_CreateDIBPatternBrushPt_RLE8()
155173

156174
/* Create a DIB brush with palette indices */
157175
hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
158-
ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
159-
if (!hbr) return;
176+
ok(hbr == 0, "CreateDIBPatternBrushPt should fail.\n");
160177

161178

162179
}

rostests/apitests/gdi32/GetDIBits.c

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,25 @@ void Test_GetDIBits()
271271

272272
/* Test with different biBitCount set */
273273
pbi->bmiHeader.biBitCount = 4;
274-
pbi->bmiHeader.biSizeImage = 0;
274+
pbi->bmiHeader.biSizeImage = 1;
275275
ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
276276
ok_int(pbi->bmiHeader.biSizeImage, 36);
277277
ok_int(pbi->bmiHeader.biBitCount, 4);
278278

279+
/* Test with different biBitCount set */
280+
pbi->bmiHeader.biBitCount = 8;
281+
pbi->bmiHeader.biSizeImage = 1000;
282+
ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
283+
ok_int(pbi->bmiHeader.biSizeImage, 60);
284+
ok_int(pbi->bmiHeader.biBitCount, 8);
285+
286+
/* Test with invalid biBitCount set */
287+
pbi->bmiHeader.biBitCount = 123;
288+
pbi->bmiHeader.biSizeImage = -12;
289+
ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0);
290+
ok_int(pbi->bmiHeader.biSizeImage, -12);
291+
ok_int(pbi->bmiHeader.biBitCount, 123);
292+
279293
/* Set bitmap dimensions */
280294
ok_int(SetBitmapDimensionEx(hbmp, 110, 220, NULL), 1);
281295
ZeroMemory(pbi, bisize);
@@ -320,16 +334,21 @@ void Test_GetDIBits()
320334
ok_int(pbi->bmiHeader.biCompression, 0);
321335
ok_int(pbi->bmiHeader.biSizeImage, 0);
322336

323-
/* Get the bitmap bits */
337+
/* Get the bitmap info */
324338
pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
325339
pbi->bmiHeader.biWidth = 4;
326340
pbi->bmiHeader.biHeight = 4;
327-
pbi->bmiHeader.biPlanes = 1;
341+
pbi->bmiHeader.biPlanes = 3;
328342
pbi->bmiHeader.biBitCount = 32;
329343
pbi->bmiHeader.biCompression = BI_RGB;
330344
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
345+
ok_int(pbi->bmiHeader.biSizeImage, 64);
346+
ok_int(pbi->bmiHeader.biPlanes, 1);
331347
pbi->bmiHeader.biWidth = 0;
332348
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
349+
pbi->bmiHeader.biWidth = 2;
350+
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
351+
ok_int(pbi->bmiHeader.biSizeImage, 32);
333352
pbi->bmiHeader.biWidth = -3;
334353
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
335354
pbi->bmiHeader.biWidth = 4;
@@ -343,12 +362,24 @@ void Test_GetDIBits()
343362
pbi->bmiHeader.biPlanes = 23;
344363
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
345364
ok_int(pbi->bmiHeader.biPlanes, 1);
365+
SetLastError(0xdeadbabe);
366+
ok_int(GetDIBits((HDC)0xff00ff00, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
367+
ok_err(0x57);
368+
SetLastError(0xdeadbabe);
369+
ok_int(GetDIBits(hdcScreen, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
370+
ok_err(0xdeadbabe);
371+
SetLastError(0xdeadbabe);
372+
ok_int(GetDIBits((HDC)0xff00ff00, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
373+
ok_err(0x57);
374+
SetLastError(0xdeadbabe);
375+
ok_int(GetDIBits(NULL, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
376+
ok_err(0x57);
377+
346378
pbi->bmiHeader.biCompression = BI_JPEG;
347379
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
348380
pbi->bmiHeader.biCompression = BI_PNG;
349381
ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
350382

351-
352383
/* Get the bitmap bits */
353384
pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
354385
pbi->bmiHeader.biWidth = 4;
@@ -364,10 +395,22 @@ void Test_GetDIBits()
364395
cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
365396
pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 512);
366397
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
398+
ok_int(pbi->bmiHeader.biSize, sizeof(BITMAPINFOHEADER));
399+
ok_int(pbi->bmiHeader.biWidth, 4);
400+
ok_int(pbi->bmiHeader.biHeight, 4);
401+
ok_int(pbi->bmiHeader.biPlanes, 1);
402+
ok_int(pbi->bmiHeader.biBitCount, 32);
403+
ok_int(pbi->bmiHeader.biCompression, BI_RGB);
404+
ok_int(pbi->bmiHeader.biSizeImage, 64);
405+
ok_int(pbi->bmiHeader.biXPelsPerMeter, 0);
406+
ok_int(pbi->bmiHeader.biYPelsPerMeter, 0);
407+
ok_int(pbi->bmiHeader.biClrUsed, 0);
408+
ok_int(pbi->bmiHeader.biClrImportant, 0);
367409

368410
/* Set biBitCount to 0 */
369411
pbi->bmiHeader.biBitCount = 0;
370412
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
413+
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, (PVOID)(LONG_PTR)-1, pbi, DIB_RGB_COLORS), 0);
371414
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 1);
372415
ok_int(GetDIBits(NULL, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 0);
373416

@@ -381,6 +424,10 @@ void Test_GetDIBits()
381424
pbi->bmiHeader.biWidth = 3;
382425
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
383426

427+
/* Try invalid biBitCount */
428+
pbi->bmiHeader.biBitCount = 17;
429+
ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
430+
384431
/* Set only biBitCount and pjInit */
385432
ZeroMemory(pbi, bisize);
386433
pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
@@ -405,19 +452,19 @@ void Test_GetDIBits()
405452
pbi->bmiHeader.biSizeImage = 0;
406453
ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0);
407454

455+
/* Calculate bitmap size and allocate a buffer */
408456
cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
457+
ok_int(cjSizeImage, 20);
409458
pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cjSizeImage);
410459

460+
/* Test using a compatible DC */
411461
hdcMem = CreateCompatibleDC(0);
412462
ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n");
413463
if (hdcMem == NULL) return;
464+
ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
465+
ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
414466

415-
// FIXME: broken
416-
//ok(SelectObject(hdcMem, ghbmpDIB4) != 0, "Failed to select 4bpp DIB %p into DC %p\n", ghbmpDIB4, hdcMem);;
417-
//ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
418-
//ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 3);
419-
420-
467+
HeapFree(GetProcessHeap(), 0, pvBits);
421468
DeleteDC(hdcMem);
422469
ReleaseDC(NULL, hdcScreen);
423470
}

rostests/apitests/gdi32/PatBlt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ void Test_PatBlt_Params()
2424
ret = PatBlt(hdcTarget, 0, 0, 1, 1, PATCOPY & 0x00FF0000);
2525
ok_long(ret, 1);
2626

27+
/* Test a rop that contains arbitrary values outside the operation index */
28+
ret = PatBlt(hdcTarget, 0, 0, 1, 1, (PATCOPY & 0x00FF0000) | 0xab00cdef);
29+
ok_long(ret, 1);
30+
2731
/* Test an invalid rop */
2832
SetLastError(0);
2933
ok_long(PatBlt(hdcTarget, 0, 0, 1, 1, SRCCOPY) , 0);

rostests/apitests/gdi32/SetWindowExtEx.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ void Test_SetWindowExtEx()
9696
//pDC_Attr = pEntry->UserData;
9797
//ASSERT(pDC_Attr);
9898

99-
/* Test setting it without changing the map mode (MM_TEXT) */
99+
/* Test setting 0 extents without changing the map mode (MM_TEXT) */
100+
ret = SetWindowExtEx(hDC, 0, 0, &WindowExt);
101+
TEST(ret == 1);
102+
TEST(WindowExt.cx == 1);
103+
TEST(WindowExt.cy == 1);
104+
105+
/* Test setting proper extents without changing the map mode (MM_TEXT) */
106+
WindowExt.cx = WindowExt.cy = 0;
100107
ret = SetWindowExtEx(hDC, 10, 20, &WindowExt);
101108
TEST(ret == 1);
102109
TEST(WindowExt.cx == 1);

0 commit comments

Comments
 (0)