Beispiel #1
0
/*
 * @implemented
 */
HBITMAP
WINAPI
CreateBitmap(
    INT Width,
    INT Height,
    UINT Planes,
    UINT BitsPixel,
    CONST VOID* pUnsafeBits)
{
    if (Width && Height)
    {
        return NtGdiCreateBitmap(Width, Height, Planes, BitsPixel, (LPBYTE) pUnsafeBits);
    }
    else
    {
        /* Return 1x1 bitmap */
        return GetStockObject(DEFAULT_BITMAP);
    }
}
Beispiel #2
0
INT
Test_NtGdiBitBlt(PTESTINFO pti)
{
	BOOL bRet;
	HDC hdc1, hdc2;
	HBITMAP hbmp1, hOldBmp1, hbmp2, hOldBmp2;
	DWORD bytes1[4] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff};
	DWORD bytes2[4] = {0x00000000, 0x0000000, 0x0000000, 0x00000000};

	/* Test NULL dc */
	SetLastError(ERROR_SUCCESS);
	bRet = NtGdiBitBlt((HDC)0, 0, 0, 10, 10, (HDC)0, 10, 10, SRCCOPY, 0, 0);
	TEST(bRet == FALSE);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test invalid dc */
	SetLastError(ERROR_SUCCESS);
	bRet = NtGdiBitBlt((HDC)0x123456, 0, 0, 10, 10, (HDC)0x123456, 10, 10, SRCCOPY, 0, 0);
	TEST(bRet == FALSE);
	TEST(GetLastError() == ERROR_SUCCESS);
	
	hdc1 = NtGdiCreateCompatibleDC(0);
	TEST(hdc1 != NULL);
	
	hdc2 = NtGdiCreateCompatibleDC(0);
	TEST(hdc2 != NULL);
	
	hbmp1 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes1 );
	TEST(hbmp1 != NULL);
	hOldBmp1 = SelectObject(hdc1, hbmp1);
	
	TESTX(NtGdiGetPixel(hdc1, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc1, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc1, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc1, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	hbmp2 = NtGdiCreateBitmap(2, 2, 1, 32, (LPBYTE)bytes2 );
	TEST(hbmp2 != NULL);
	hOldBmp2 = SelectObject(hdc2, hbmp2);
	
	bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 1, 1, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
	
	bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 0, 0, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00000000, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	bRet = NtGdiBitBlt(hdc2, 1, 1, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x00ffffff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00000000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x00000000, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00000000, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
	
	bRet = NtGdiBitBlt(hdc2, 2, 2, -2, -2, hdc1, 2, 2, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	NtGdiSetPixel(hdc2, 0, 0, 0x00000000);
	NtGdiSetPixel(hdc2, 1, 0, 0x00000000);
	NtGdiSetPixel(hdc2, 0, 1, 0x00000000);
	NtGdiSetPixel(hdc2, 1, 1, 0x00000000);
	
	bRet = NtGdiBitBlt(hdc2, 0, 0, 2, 2, hdc1, 0, 0, SRCCOPY, 0, 0);
	TEST(bRet == TRUE);
	TEST(GetLastError() == ERROR_SUCCESS);
	TESTX(NtGdiGetPixel(hdc2, 0, 0) == 0x000000ff, "Pixel[0][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 0));
	TESTX(NtGdiGetPixel(hdc2, 0, 1) == 0x00ff0000, "Pixel[0][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 0, 1));
	TESTX(NtGdiGetPixel(hdc2, 1, 0) == 0x0000ff00, "Pixel[1][0] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 0));
	TESTX(NtGdiGetPixel(hdc2, 1, 1) == 0x00ffffff, "Pixel[1][1] 0x%08x\n", (UINT)NtGdiGetPixel(hdc2, 1, 1));
	
	SelectObject(hdc2, hOldBmp2);
	SelectObject(hdc1, hOldBmp1);
	
	DeleteObject(hbmp2);
	DeleteObject(hbmp1);
	
	DeleteDC(hdc1);
	DeleteDC(hdc2);

	return APISTATUS_NORMAL;
}
Beispiel #3
0
void Test_NtGdiCreateBitmap_Params(void)
{
	HBITMAP hBmp;
	BITMAP bitmap;
	BYTE BitmapData[10] = {0x11, 0x22, 0x33};

	/* Test simple params */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 1, NULL)) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	DeleteObject(hBmp);

	/* Test all zero */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(0, 0, 0, 0, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test cx == 0 */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(0, 1, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test negative cx */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(-10, 1, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test cy == 0 */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, 0, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test negative cy */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, -2, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test negative cy and valid bits */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, -2, 1, 1, BitmapData) == NULL);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test negative cy and invalid bits */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, -2, 1, 1, (BYTE*)0x80001234) == NULL);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test huge size */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(100000, 100000, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_NOT_ENOUGH_MEMORY);

	/* Test huge size and valid bits */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1000, 1000, 1, 1, BitmapData) == NULL);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test huge size and invalid bits */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(100000, 100000, 1, 1, (BYTE*)0x80001234) == NULL);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test cPlanes == 0 */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 0, 1, NULL)) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmType == 0);
	TEST(bitmap.bmWidth == 1);
	TEST(bitmap.bmHeight == 1);
	TEST(bitmap.bmWidthBytes == 2);
	TEST(bitmap.bmPlanes == 1);
	TEST(bitmap.bmBitsPixel == 1);
	DeleteObject(hBmp);

	/* Test big cPlanes */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 32, 1, NULL)) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	DeleteObject(hBmp);

	TEST(NtGdiCreateBitmap(1, 1, 33, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test cBPP == 0 */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 0, NULL)) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmType == 0);
	TEST(bitmap.bmWidth == 1);
	TEST(bitmap.bmHeight == 1);
	TEST(bitmap.bmWidthBytes == 2);
	TEST(bitmap.bmPlanes == 1);
	TEST(bitmap.bmBitsPixel == 1);
	DeleteObject(hBmp);

	/* Test negative cBPP */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, 1, 1, -1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test bad cBPP */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 3, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 4);
	DeleteObject(hBmp);

	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 6, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 8);
	DeleteObject(hBmp);

	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 15, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 16);
	DeleteObject(hBmp);

	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 17, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 24);
	DeleteObject(hBmp);

	TEST((hBmp = NtGdiCreateBitmap(1, 1, 3, 7, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 24);
	DeleteObject(hBmp);

	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 25, NULL)) != NULL);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmBitsPixel == 32);
	DeleteObject(hBmp);

	TEST(GetLastError() == ERROR_SUCCESS);

	TEST(NtGdiCreateBitmap(1, 1, 1, 33, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test bad pointer */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, 1, 1, 1, (BYTE*)0x80001234) == NULL);
	TEST(GetLastError() == ERROR_SUCCESS);

	/* Test pointer alignment */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 1, &BitmapData[1])) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	DeleteObject(hBmp);

	/* Test normal params */
	SetLastError(ERROR_SUCCESS);
	TEST((hBmp = NtGdiCreateBitmap(5, 7, 2, 4, NULL)) != NULL);
	TEST(GetLastError() == ERROR_SUCCESS);
	ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
	TEST(bitmap.bmType == 0);
	TEST(bitmap.bmWidth == 5);
	TEST(bitmap.bmHeight == 7);
	TEST(bitmap.bmWidthBytes == 6);
	TEST(bitmap.bmPlanes == 1);
	TEST(bitmap.bmBitsPixel == 8);
	DeleteObject(hBmp);


	/* Test height 0 params */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, 0, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test height -1 params */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(1, -1, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test witdth 0 params */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(0, 1, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);

	/* Test witdth -1 params */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(-1, 0, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);


    /* Test witdth -1 params */
	SetLastError(ERROR_SUCCESS);
	TEST(NtGdiCreateBitmap(0, 0, 1, 1, NULL) == NULL);
	TEST(GetLastError() == ERROR_INVALID_PARAMETER);
}