mirror of
https://github.com/reactos/reactos.git
synced 2025-07-29 16:31:44 +00:00
[GDI32_APITEST]
Add more tests for CreateDIBitmap and CreateDIBPatternBrushPt svn path=/trunk/; revision=56542
This commit is contained in:
parent
812d4b73e0
commit
6743cf9776
2 changed files with 407 additions and 2 deletions
|
@ -57,7 +57,7 @@ void Test_CreateDIBPatternBrushPt()
|
|||
|
||||
/* Create a DIB brush with palette indices */
|
||||
hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n");
|
||||
ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
|
||||
if (!hbr) return;
|
||||
|
||||
/* Select the brush into the dc */
|
||||
|
@ -135,6 +135,33 @@ void Test_CreateDIBPatternBrushPt()
|
|||
|
||||
}
|
||||
|
||||
void Test_CreateDIBPatternBrushPt_RLE8()
|
||||
{
|
||||
struct
|
||||
{
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
WORD wColors[4];
|
||||
BYTE ajBuffer[20];
|
||||
} PackedDIB =
|
||||
{
|
||||
{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
|
||||
{0, 1, 2, 7},
|
||||
{4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
|
||||
};
|
||||
HBRUSH hbr;
|
||||
|
||||
HDC hdc = CreateCompatibleDC(0);
|
||||
HBITMAP hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed, skipping tests.\n");
|
||||
|
||||
/* Create a DIB brush with palette indices */
|
||||
hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
|
||||
if (!hbr) return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
START_TEST(CreateDIBPatternBrush)
|
||||
{
|
||||
|
@ -142,5 +169,6 @@ START_TEST(CreateDIBPatternBrush)
|
|||
|
||||
Test_CreateDIBPatternBrush();
|
||||
Test_CreateDIBPatternBrushPt();
|
||||
Test_CreateDIBPatternBrushPt_RLE8();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,300 @@
|
|||
#include <stdio.h>
|
||||
#include <wine/test.h>
|
||||
#include <windows.h>
|
||||
#include "init.h"
|
||||
|
||||
#define CBM_CREATDIB 2
|
||||
|
||||
BOOL
|
||||
GetExpected(
|
||||
DWORD *pdwError,
|
||||
HDC hdc,
|
||||
const BITMAPINFOHEADER *lpbmih,
|
||||
DWORD fdwInit,
|
||||
const VOID *lpbInit,
|
||||
const BITMAPINFO *lpbmi,
|
||||
UINT fuUsage)
|
||||
{
|
||||
if (fuUsage > 2)
|
||||
{
|
||||
*pdwError = ERROR_INVALID_PARAMETER;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fuUsage != 0)
|
||||
{
|
||||
if (hdc == (HDC)-1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (fdwInit & CBM_INIT)
|
||||
{
|
||||
if (!lpbmih)
|
||||
{
|
||||
if (!lpbInit || (lpbInit == (PVOID)0xC0000000)) return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lpbInit)
|
||||
{
|
||||
if (lpbInit == (PVOID)0xC0000000) return FALSE;
|
||||
if (!lpbmi || (lpbmi == (PVOID)0xC0000000)) return FALSE;
|
||||
if (lpbmi->bmiHeader.biSize == 0) return FALSE;
|
||||
if (fuUsage == 2) return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fdwInit & CBM_CREATDIB)
|
||||
{
|
||||
if (fuUsage == 2) return FALSE;
|
||||
if ((fuUsage == DIB_PAL_COLORS) && !hdc)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((fdwInit & CBM_INIT))
|
||||
{
|
||||
if (!lpbInit || (lpbInit == (PVOID)0xC0000000)) return FALSE;
|
||||
}
|
||||
|
||||
if ((!lpbmi) || (lpbmi == (PVOID)0xc0000000) || (lpbmi->bmiHeader.biSize == 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (lpbmih && (lpbmih != (PVOID)0xc0000000) && (lpbmih->biSize != 0))
|
||||
{
|
||||
if (hdc == (HDC)-1)
|
||||
{
|
||||
*pdwError = ERROR_INVALID_PARAMETER;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((lpbmih == NULL) ||
|
||||
(lpbmih == (PVOID)0xC0000000) ||
|
||||
(lpbmih->biSize == 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (lpbmi == (PVOID)0xc0000000) return FALSE;
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Test_CreateDIBitmap_Params(void)
|
||||
{
|
||||
HBITMAP hbmp;
|
||||
HDC hdc;
|
||||
BITMAPINFO bmi =
|
||||
{{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RGB, 0, 1, 1, 1, 0}, {{0,0,0,0}}};
|
||||
BITMAPINFO bmiBroken =
|
||||
{{0, -2, -4, 55, 42, 21, 0, 1, 1, 1, 0}, {{0,0,0,0}}};
|
||||
BYTE ajBits[10];
|
||||
|
||||
hdc = CreateCompatibleDC(0);
|
||||
ok(hdc != 0, "failed\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, ajBits, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, NULL, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, NULL, NULL, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, 0, (PVOID)0xc0000000, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(NULL, &bmi.bmiHeader, CBM_INIT, NULL, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, NULL, &bmiBroken, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
hbmp = CreateDIBitmap(NULL, NULL, 2, NULL, &bmi, 0);
|
||||
ok(hbmp != 0, "\n");
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, NULL, CBM_INIT, ajBits, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(ERROR_INVALID_PARAMETER);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, NULL, CBM_INIT, NULL, &bmiBroken, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(ERROR_INVALID_PARAMETER);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, ajBits, &bmi, 2);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(ERROR_INVALID_PARAMETER);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, ajBits, NULL, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(0xbadbad00);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, (PVOID)0xc0000000, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(0xbadbad00);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
_SEH2_TRY
|
||||
{
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, 0, ajBits, (PVOID)0xc0000000, DIB_PAL_COLORS);
|
||||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
hbmp = (HBITMAP)-1;
|
||||
}
|
||||
_SEH2_END;
|
||||
ok(hbmp == (HBITMAP)-1, "\n");
|
||||
ok_err(0xbadbad00);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, NULL, NULL, 5);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(ERROR_INVALID_PARAMETER);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap((HDC)-1, &bmi.bmiHeader, CBM_INIT, NULL, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(0xbadbad00);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &bmiBroken.bmiHeader, CBM_INIT, NULL, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "\n");
|
||||
ok_err(ERROR_INVALID_PARAMETER);
|
||||
|
||||
if (1)
|
||||
{
|
||||
ULONG i1, i2, i3, i4, i5, i6;
|
||||
HDC ahdc[3] = {0, hdc, (HDC)-1};
|
||||
PBITMAPINFOHEADER apbih[4] = {NULL, &bmi.bmiHeader, &bmiBroken.bmiHeader, (PVOID)0xC0000000};
|
||||
ULONG afInitf[12] = {0, 1, 2, 3, CBM_INIT, 4, 5, 6, 7, 8, 0x10, 0x20};
|
||||
PVOID apvBits[3] = {NULL, ajBits, (PVOID)0xc0000000};
|
||||
PBITMAPINFO apbmi[4] = {NULL, &bmi, &bmiBroken, (PVOID)0xC0000000};
|
||||
ULONG aiUsage[5] = {0, 1, 2, 3, 23};
|
||||
DWORD dwExpError;
|
||||
BOOL bExpSuccess;
|
||||
|
||||
for (i1 = 0; i1 < 3; i1++)
|
||||
{
|
||||
for (i2 = 0; i2 < 4; i2++)
|
||||
{
|
||||
for (i3 = 0; i3 < 8; i3++)
|
||||
{
|
||||
for (i4 = 0; i4 < 3; i4++)
|
||||
{
|
||||
for (i5 = 0; i5 < 4; i5++)
|
||||
{
|
||||
for (i6 = 0; i6 < 5; i6++)
|
||||
{
|
||||
SetLastError(0xbadbad00);
|
||||
dwExpError = 0xbadbad00;
|
||||
|
||||
bExpSuccess = GetExpected(&dwExpError, ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
|
||||
|
||||
_SEH2_TRY
|
||||
{
|
||||
hbmp = CreateDIBitmap(ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
|
||||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
hbmp = (HBITMAP)0;
|
||||
}
|
||||
_SEH2_END;
|
||||
|
||||
if (bExpSuccess)
|
||||
{
|
||||
ok(hbmp != 0, "Expected success for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
|
||||
i1, i2, i3, i4, i5, i6,
|
||||
ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok(hbmp == 0, "Expected failure for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
|
||||
i1, i2, i3, i4, i5, i6,
|
||||
ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
|
||||
}
|
||||
|
||||
// ok(GetLastError() == dwExpError, "Expected error %ld got %ld for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
|
||||
// dwExpError, GetLastError(), i1, i2, i3, i4, i5, i6,
|
||||
// ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Test_CreateDIBitmap_DIB_PAL_COLORS(void)
|
||||
{
|
||||
struct
|
||||
{
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
WORD bmiColors[8];
|
||||
} bmibuffer;
|
||||
BITMAPINFO *pbmi = (PVOID)&bmibuffer;
|
||||
HBITMAP hbmp;
|
||||
ULONG bits[16] = {0};
|
||||
HDC hdc;
|
||||
HPALETTE hpalOld;
|
||||
USHORT i;
|
||||
|
||||
hdc = CreateCompatibleDC(0);
|
||||
ok(hdc != 0, "failed\n");
|
||||
|
||||
/* Select a palette */
|
||||
hpalOld = SelectPalette(hdc, ghpal, FALSE);
|
||||
ok(hpalOld != NULL, "error=%ld\n", GetLastError());
|
||||
|
||||
/* Initialize a BITMAPINFO */
|
||||
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
pbmi->bmiHeader.biWidth = 2;
|
||||
pbmi->bmiHeader.biHeight = -2;
|
||||
pbmi->bmiHeader.biPlanes = 1;
|
||||
pbmi->bmiHeader.biBitCount = 8;
|
||||
pbmi->bmiHeader.biCompression = BI_RGB;
|
||||
pbmi->bmiHeader.biSizeImage = 0;
|
||||
pbmi->bmiHeader.biXPelsPerMeter = 1;
|
||||
pbmi->bmiHeader.biYPelsPerMeter = 1;
|
||||
pbmi->bmiHeader.biClrUsed = 8;
|
||||
pbmi->bmiHeader.biClrImportant = 0;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
bmibuffer.bmiColors[i] = i;
|
||||
}
|
||||
|
||||
/* Create the bitmap */
|
||||
hbmp = CreateDIBitmap(hdc, &pbmi->bmiHeader, CBM_INIT, bits, pbmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "failed\n");
|
||||
|
||||
SelectObject(hdc, hbmp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Test_CreateDIBitmap1(void)
|
||||
|
@ -51,7 +345,8 @@ Test_CreateDIBitmap1(void)
|
|||
bmi.bmiHeader.biCompression = BI_RLE8;
|
||||
bmi.bmiHeader.biBitCount = 8;
|
||||
bmi.bmiHeader.biSizeImage = 8;
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, rlebits, &bmi, DIB_RGB_COLORS);
|
||||
bmi.bmiHeader.biClrUsed = 1;
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, rlebits, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "failed\n");
|
||||
ok(GetLastError() == 0, "GetLastError() == %ld\n", GetLastError());
|
||||
|
||||
|
@ -68,10 +363,92 @@ Test_CreateDIBitmap1(void)
|
|||
|
||||
}
|
||||
|
||||
void Test_CreateDIBitmap_RLE8()
|
||||
{
|
||||
struct
|
||||
{
|
||||
BITMAPINFOHEADER bmiHeader;
|
||||
WORD wColors[4];
|
||||
BYTE ajBuffer[20];
|
||||
} PackedDIB =
|
||||
{
|
||||
{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
|
||||
{0, 1, 2, 7},
|
||||
{4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
|
||||
};
|
||||
HDC hdc;
|
||||
HBITMAP hbmp;
|
||||
|
||||
hdc = CreateCompatibleDC(0);
|
||||
|
||||
SetLastError(0xbadbad00);
|
||||
hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed.\n");
|
||||
ok_err(0xbadbad00);
|
||||
DeleteObject(hbmp);
|
||||
|
||||
PackedDIB.bmiHeader.biSizeImage = 2;
|
||||
hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed.\n");
|
||||
ok_err(0xbadbad00);
|
||||
DeleteObject(hbmp);
|
||||
|
||||
PackedDIB.bmiHeader.biSizeImage = 1;
|
||||
hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed.\n");
|
||||
ok_err(0xbadbad00);
|
||||
DeleteObject(hbmp);
|
||||
|
||||
PackedDIB.bmiHeader.biSizeImage = 0;
|
||||
hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp == 0, "CreateDIBitmap succeeded, expeted failure\n");
|
||||
ok_err(0xbadbad00);
|
||||
|
||||
/* Test a line that is too long */
|
||||
PackedDIB.bmiHeader.biSizeImage = 20;
|
||||
PackedDIB.ajBuffer[0] = 17;
|
||||
hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed\n");
|
||||
ok_err(0xbadbad00);
|
||||
DeleteObject(hbmp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Test_CreateDIBitmap_CBM_CREATDIB(void)
|
||||
{
|
||||
HBITMAP hbmp;
|
||||
HDC hdc;
|
||||
BITMAPINFO bmi =
|
||||
{{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RGB, 0, 1, 1, 1, 0}, {{0,0,0,0}}};
|
||||
BYTE ajBits[10];
|
||||
BITMAP bitmap;
|
||||
|
||||
hdc = CreateCompatibleDC(0);
|
||||
ok(hdc != 0, "failed\n");
|
||||
|
||||
hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_CREATDIB, ajBits, &bmi, DIB_PAL_COLORS);
|
||||
ok(hbmp != 0, "CreateDIBitmap failed.\n");
|
||||
|
||||
ok_long(GetObject(hbmp, sizeof(DIBSECTION), &bitmap), sizeof(BITMAP));
|
||||
ok_int(bitmap.bmType, 0);
|
||||
ok_int(bitmap.bmWidth, 4);
|
||||
ok_int(bitmap.bmHeight, 4);
|
||||
ok_int(bitmap.bmWidthBytes, 4);
|
||||
ok_int(bitmap.bmPlanes, 1);
|
||||
ok_int(bitmap.bmBitsPixel, 8);
|
||||
ok_ptr(bitmap.bmBits, 0);
|
||||
|
||||
}
|
||||
|
||||
START_TEST(CreateDIBitmap)
|
||||
{
|
||||
InitStuff();
|
||||
Test_CreateDIBitmap_Params();
|
||||
Test_CreateDIBitmap1();
|
||||
Test_CreateDIBitmap_DIB_PAL_COLORS();
|
||||
Test_CreateDIBitmap_RLE8();
|
||||
Test_CreateDIBitmap_CBM_CREATDIB();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue