Further refactored tests.

This commit is contained in:
Armin Novak 2016-07-15 16:22:09 +02:00
parent 9f0a9c3b92
commit 960bc26e9a
10 changed files with 356 additions and 1556 deletions

View File

@ -16,12 +16,15 @@ set(${MODULE_PREFIX}_TESTS
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})
include_directories(..)
add_library(helpers STATIC
helpers.c)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr freerdp)
target_link_libraries(${MODULE_NAME} winpr freerdp helpers)
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@
#include <freerdp/gdi/pen.h>
#include <freerdp/gdi/region.h>
#include <freerdp/gdi/bitmap.h>
#include <freerdp/gdi/drawing.h>
#include <winpr/crt.h>
@ -29,20 +28,17 @@ static int test_gdi_ClipCoords(void)
}
hdc->format = format;
bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL);
bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL);
gdi_SelectObject(hdc, (HGDIOBJECT) bmp);
gdi_SetNullClipRgn(hdc);
rgn1 = gdi_CreateRectRgn(0, 0, 0, 0);
rgn2 = gdi_CreateRectRgn(0, 0, 0, 0);
rgn1->null = 1;
rgn2->null = 1;
/* null clipping region */
gdi_SetNullClipRgn(hdc);
gdi_SetRgn(rgn1, 20, 20, 100, 100);
gdi_SetRgn(rgn2, 20, 20, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -52,7 +48,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 0, 0, 1024, 768);
gdi_SetRgn(rgn1, 20, 20, 100, 100);
gdi_SetRgn(rgn2, 20, 20, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -62,8 +57,8 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 20, 20, 100, 100);
gdi_SetRgn(rgn2, 0, 0, 0, 0);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL,
NULL);
if (draw)
return -1;
@ -72,8 +67,8 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 420, 420, 100, 100);
gdi_SetRgn(rgn2, 0, 0, 0, 0);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL,
NULL);
if (draw)
return -1;
@ -82,8 +77,8 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 20, 100, 100);
gdi_SetRgn(rgn2, 0, 0, 0, 0);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL,
NULL);
if (draw)
return -1;
@ -92,8 +87,8 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 420, 100, 100);
gdi_SetRgn(rgn2, 0, 0, 0, 0);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL,
NULL);
if (draw)
return -1;
@ -102,7 +97,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 300, 300, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -112,7 +106,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 300, 250, 100);
gdi_SetRgn(rgn2, 300, 300, 50, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -122,7 +115,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 300, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -132,7 +124,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 350, 300, 200, 100);
gdi_SetRgn(rgn2, 350, 300, 50, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -142,7 +133,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 100, 300, 300);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -152,7 +142,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 100, 200);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -162,7 +151,6 @@ static int test_gdi_ClipCoords(void)
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 100, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
@ -177,8 +165,8 @@ static int test_gdi_InvalidateRegion(void)
HGDI_RGN rgn1;
HGDI_RGN rgn2;
HGDI_RGN invalid;
HGDI_BITMAP bmp;
const UINT32 format = PIXEL_FORMAT_XRGB32;
HGDI_BITMAP bmp;
const UINT32 format = PIXEL_FORMAT_XRGB32;
if (!(hdc = gdi_GetDC()))
{
@ -187,28 +175,23 @@ static int test_gdi_InvalidateRegion(void)
}
hdc->format = format;
bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL);
bmp = gdi_CreateBitmapEx(1024, 768, PIXEL_FORMAT_XRGB32, 0, NULL, NULL);
gdi_SelectObject(hdc, (HGDIOBJECT) bmp);
gdi_SetNullClipRgn(hdc);
hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND));
hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
hdc->hwnd->invalid->null = 1;
invalid = hdc->hwnd->invalid;
hdc->hwnd->count = 16;
hdc->hwnd->cinvalid = (HGDI_RGN) calloc(hdc->hwnd->count, sizeof(GDI_RGN));
rgn1 = gdi_CreateRectRgn(0, 0, 0, 0);
rgn2 = gdi_CreateRectRgn(0, 0, 0, 0);
rgn1->null = 1;
rgn2->null = 1;
/* no previous invalid region */
invalid->null = 1;
gdi_SetRgn(rgn1, 300, 300, 100, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -218,7 +201,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 100, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -228,7 +210,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 300, 300, 100);
gdi_SetRgn(rgn2, 100, 300, 300, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -238,7 +219,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 300, 100);
gdi_SetRgn(rgn2, 300, 300, 300, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -248,7 +228,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 100, 100, 300);
gdi_SetRgn(rgn2, 300, 100, 100, 300);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -258,7 +237,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 300, 100, 300);
gdi_SetRgn(rgn2, 300, 300, 100, 300);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -268,7 +246,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 300, 600, 300);
gdi_SetRgn(rgn2, 100, 300, 600, 300);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -278,7 +255,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 100, 100, 500);
gdi_SetRgn(rgn2, 300, 100, 100, 500);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -288,7 +264,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 300, 100, 100);
gdi_SetRgn(rgn2, 100, 300, 300, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -298,7 +273,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 700, 300, 100, 100);
gdi_SetRgn(rgn2, 300, 300, 500, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -308,7 +282,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 100, 100, 100);
gdi_SetRgn(rgn2, 300, 100, 100, 300);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -318,7 +291,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 300, 500, 100, 100);
gdi_SetRgn(rgn2, 300, 300, 100, 300);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -328,7 +300,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 100, 100, 600, 600);
gdi_SetRgn(rgn2, 100, 100, 600, 600);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
@ -338,7 +309,6 @@ static int test_gdi_InvalidateRegion(void)
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_SetRgn(rgn1, 0, 0, 1024, 768);
gdi_SetRgn(rgn2, 0, 0, 1024, 768);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))

View File

@ -5,7 +5,6 @@
#include <freerdp/gdi/pen.h>
#include <freerdp/gdi/region.h>
#include <freerdp/gdi/bitmap.h>
#include <freerdp/gdi/drawing.h>
#include <winpr/crt.h>
@ -22,7 +21,7 @@ static int test_gdi_GetDC(void)
return -1;
}
if (hdc->format != PIXEL_FORMAT_XRGB32)
if (hdc->format != PIXEL_FORMAT_XRGB32)
return -1;
if (hdc->drawMode != GDI_R2_BLACK)
@ -67,9 +66,9 @@ static int test_gdi_CreateBitmap(void)
UINT32 height;
BYTE* data;
HGDI_BITMAP hBitmap;
width = 32;
height = 16;
if (!(data = (BYTE*) _aligned_malloc(width * height * 4, 16)))
{
printf("failed to allocate aligned bitmap data memory\n");
@ -98,7 +97,6 @@ static int test_gdi_CreateBitmap(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
}
@ -116,7 +114,6 @@ static int test_gdi_CreateCompatibleBitmap(void)
}
hdc->format = PIXEL_FORMAT_ARGB32;
width = 32;
height = 16;
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
@ -137,13 +134,14 @@ static int test_gdi_CreateCompatibleBitmap(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
}
static int test_gdi_CreatePen(void)
{
HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD);
const UINT32 format = PIXEL_FORMAT_RGBA32;
HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD,
format, NULL);
if (!hPen)
{
@ -161,7 +159,6 @@ static int test_gdi_CreatePen(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hPen);
return 0;
}
@ -179,7 +176,6 @@ static int test_gdi_CreateSolidBrush(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBrush);
return 0;
}
@ -187,7 +183,6 @@ static int test_gdi_CreatePatternBrush(void)
{
HGDI_BRUSH hBrush;
HGDI_BITMAP hBitmap;
hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
hBrush = gdi_CreatePatternBrush(hBitmap);
@ -201,7 +196,6 @@ static int test_gdi_CreatePatternBrush(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
}
@ -211,7 +205,6 @@ static int test_gdi_CreateRectRgn(void)
int y1 = 64;
int x2 = 128;
int y2 = 256;
HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
if (hRegion->objectType != GDIOBJECT_REGION)
@ -233,7 +226,6 @@ static int test_gdi_CreateRectRgn(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hRegion);
return 0;
}
@ -267,7 +259,6 @@ static int test_gdi_CreateRect(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hRect);
return 0;
}
@ -285,10 +276,8 @@ static int test_gdi_GetPixel(void)
}
hdc->format = PIXEL_FORMAT_ARGB32;
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
hBitmap->data[(64 * width * 4) + 32 * 4 + 0] = 0xDD;
hBitmap->data[(64 * width * 4) + 32 * 4 + 1] = 0xCC;
hBitmap->data[(64 * width * 4) + 32 * 4 + 2] = 0xBB;
@ -298,7 +287,6 @@ static int test_gdi_GetPixel(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
}
@ -316,10 +304,8 @@ static int test_gdi_SetPixel(void)
}
hdc->format = PIXEL_FORMAT_ARGB32;
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
gdi_SetPixel(hdc, 32, 64, 0xAABBCCDD);
if (gdi_GetPixel(hdc, 32, 64) != 0xAABBCCDD)
@ -331,7 +317,6 @@ static int test_gdi_SetPixel(void)
return -1;
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
}
@ -358,6 +343,8 @@ static int test_gdi_MoveToEx(void)
HGDI_DC hdc;
HGDI_PEN hPen;
HGDI_POINT prevPoint;
const UINT32 format = PIXEL_FORMAT_RGBA32;
rdpPalette* palette = NULL;
if (!(hdc = gdi_GetDC()))
{
@ -365,7 +352,7 @@ static int test_gdi_MoveToEx(void)
return -1;
}
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD)))
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette)))
{
printf("gdi_CreatePen failed\n");
return -1;
@ -382,7 +369,6 @@ static int test_gdi_MoveToEx(void)
prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT));
ZeroMemory(prevPoint, sizeof(GDI_POINT));
gdi_MoveToEx(hdc, 64, 128, prevPoint);
if (prevPoint->x != 128)

View File

@ -6,7 +6,6 @@
#include <freerdp/gdi/shape.h>
#include <freerdp/gdi/region.h>
#include <freerdp/gdi/bitmap.h>
#include <freerdp/gdi/drawing.h>
#include <winpr/crt.h>
#include <winpr/print.h>
@ -14,10 +13,11 @@
#include "line.h"
#include "brush.h"
#include "clipping.h"
#include "helpers.h"
/* Ellipse() Test Data */
static BYTE ellipse_case_1[256] =
static const BYTE ellipse_case_1[256] =
{
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF"
@ -37,7 +37,7 @@ static BYTE ellipse_case_1[256] =
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF"
};
static BYTE ellipse_case_2[256] =
static const BYTE ellipse_case_2[256] =
{
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF"
@ -57,7 +57,7 @@ static BYTE ellipse_case_2[256] =
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF"
};
static BYTE ellipse_case_3[256] =
static const BYTE ellipse_case_3[256] =
{
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
@ -79,55 +79,106 @@ static BYTE ellipse_case_3[256] =
int TestGdiEllipse(int argc, char* argv[])
{
int rc = -1;
UINT32 i, j;
HGDI_DC hdc;
HGDI_PEN pen;
BYTE* data;
HGDI_BITMAP hBmp;
HGDI_BITMAP hBmp_Ellipse_1;
HGDI_BITMAP hBmp_Ellipse_2;
HGDI_BITMAP hBmp_Ellipse_3;
rdpPalette* hPalette;
const UINT32 format = PIXEL_FORMAT_RGB8;
if (!(hdc = gdi_GetDC()))
const UINT32 RawFormat = PIXEL_FORMAT_RGB8;
const UINT32 colorFormats[] =
{
printf("failed to get gdi device context\n");
return -1;
PIXEL_FORMAT_RGB15,
PIXEL_FORMAT_ARGB15,
PIXEL_FORMAT_RGB16,
PIXEL_FORMAT_RGB24,
PIXEL_FORMAT_ARGB32,
PIXEL_FORMAT_XRGB32,
PIXEL_FORMAT_RGBA32,
PIXEL_FORMAT_RGBX32,
PIXEL_FORMAT_BGR15,
PIXEL_FORMAT_ABGR15,
PIXEL_FORMAT_BGR16,
PIXEL_FORMAT_BGR24,
PIXEL_FORMAT_ABGR32,
PIXEL_FORMAT_XBGR32,
PIXEL_FORMAT_BGRA32,
PIXEL_FORMAT_BGRX32
};
const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]);
gdiPalette g;
for (i = 0; i < number_formats; i++)
{
const UINT32 format = colorFormats[i];
rdpPalette* hPalette = &g;
g.format = format;
for (i = 0; i < 256; i++)
g.palette[i] = GetColor(format, i, i, i, 0xFF);
rc = -1;
if (!(hdc = gdi_GetDC()))
{
printf("failed to get gdi device context\n");
goto fail;
}
hdc->format = format;
gdi_SetNullClipRgn(hdc);
if (!(pen = gdi_CreatePen(1, 1, 0, format, hPalette)))
{
printf("gdi_CreatePen failed\n");
goto fail;
}
gdi_SelectObject(hdc, (HGDIOBJECT) pen);
hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16);
gdi_SelectObject(hdc, (HGDIOBJECT) hBmp);
hBmp_Ellipse_1 = test_convert_to_bitmap(ellipse_case_1, RawFormat, 0, 0, 0,
format, 0, 0, 0, 16, 16, hPalette);
if (!hBmp_Ellipse_1)
goto fail;
hBmp_Ellipse_2 = test_convert_to_bitmap(ellipse_case_2, RawFormat, 0, 0, 0,
format, 0, 0, 0, 16, 16, hPalette);
if (!hBmp_Ellipse_2)
goto fail;
hBmp_Ellipse_3 = test_convert_to_bitmap(ellipse_case_3, RawFormat, 0, 0, 0,
format, 0, 0, 0, 16, 16, hPalette);
if (!hBmp_Ellipse_3)
goto fail;
/* Test Case 1: (0,0) -> (16, 16) */
if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
{
printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
return -1;
}
if (!gdi_Ellipse(hdc, 0, 0, 16, 16))
goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_1);
gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_2);
gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_3);
gdi_DeleteObject((HGDIOBJECT) pen);
gdi_DeleteDC(hdc);
if (rc != 0)
break;
}
hdc->format = format;
gdi_SetNullClipRgn(hdc);
if (!(pen = gdi_CreatePen(1, 1, 0)))
{
printf("gdi_CreatePen failed\n");
return -1;
}
gdi_SelectObject(hdc, (HGDIOBJECT) pen);
hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16);
gdi_SelectObject(hdc, (HGDIOBJECT) hBmp);
hPalette = (rdpPalette*) gdi_GetSystemPalette();
data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_1, NULL, 16, 16, 8, format, hPalette);
hBmp_Ellipse_1 = gdi_CreateBitmap(16, 16, format, data);
data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_2, NULL, 16, 16, 8, format, hPalette);
hBmp_Ellipse_2 = gdi_CreateBitmap(16, 16, format, data);
data = (BYTE*) freerdp_image_convert((BYTE*) ellipse_case_3, NULL, 16, 16, 8, format, hPalette);
hBmp_Ellipse_3 = gdi_CreateBitmap(16, 16, format, data);
/* Test Case 1: (0,0) -> (16, 16) */
if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS))
{
printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
return -1;
}
gdi_Ellipse(hdc, 0, 0, 16, 16);
return 0;
return rc;
}

View File

@ -246,10 +246,9 @@ static const BYTE* line_to_case[] =
line_to_case_6,
line_to_case_7,
line_to_case_8,
line_to_case_1,
line_to_case_1,
line_to_case_1,
line_to_case_1,
line_to_case_9,
line_to_case_10,
line_to_case_11
};
static const BYTE line_to_R2_BLACK[256] =
@ -623,20 +622,19 @@ struct ropMap
};
static BOOL test_line(HGDI_DC hdc, const gdiPalette* hPalette, UINT32 mX,
UINT32 mY,
UINT32 lX, UINT32 lY, HGDI_BITMAP hBmp, HGDI_BITMAP hOrgBmp)
UINT32 mY, UINT32 lX, UINT32 lY, HGDI_BITMAP hBmp,
HGDI_BITMAP hOrgBmp, UINT32 cX, UINT32 cY, UINT32 cW, UINT32 cH)
{
/* Test Case 10: (12,12) -> (4,4) */
if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
{
printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
return FALSE;
}
if ((cX > 0) || (cY > 0) || (cW > 0) || (cH > 0))
gdi_SetClipRgn(hdc, cX, cY, cW, cH);
gdi_MoveToEx(hdc, mX, mY, hPalette);
gdi_LineTo(hdc, lX, lY);
if (!test_assert_bitmaps_equal(hBmp, hOrgBmp, "Case 10") < 0)
if (!test_assert_bitmaps_equal(hBmp, hOrgBmp, "Case 10", hPalette))
return FALSE;
return TRUE;
@ -645,7 +643,8 @@ static BOOL test_line(HGDI_DC hdc, const gdiPalette* hPalette, UINT32 mX,
int TestGdiLine(int argc, char* argv[])
{
int rc = -1;
UINT32 x, i;
UINT32 x, i, j;
gdiPalette g;
const UINT32 RawFormat = PIXEL_FORMAT_RGB8;
const UINT32 colorFormats[] =
{
@ -694,13 +693,14 @@ int TestGdiLine(int argc, char* argv[])
};
const UINT32 map_size = sizeof(rop_map) / sizeof(rop_map[0]);
HGDI_BITMAP hBmp_LineTo[LINTETO_NUMBER] = {NULL};
gdiPalette p;
gdiPalette* hPalette = &p;
gdiPalette* hPalette = &g;
const UINT32 format = colorFormats[i];
rc = -1;
p.format = format;
g.format = format;
// TODO: Initialize palette!!!
for (i = 0; i < 256; i++)
g.palette[i] = GetColor(format, i, i, i, 0xFF);
rc = -1;
if (!(hdc = gdi_GetDC()))
{
@ -739,56 +739,39 @@ int TestGdiLine(int argc, char* argv[])
goto fail;
}
if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0]))
if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1]))
if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2]))
if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3]))
if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4]))
if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5]))
if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6]))
if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7]))
if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8]))
if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8], 0, 0, 16, 16))
goto fail;
if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9]))
if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9], 5, 5, 8, 8))
goto fail;
/* Test Case 11: (0,0) -> (+10,+10) */
if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
{
printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
if (!test_line(hdc, hPalette, 0, 0, 26, 26, hBmp, hBmp_LineTo[10], 0, 0, 16,
16))
goto fail;
}
gdi_SetClipRgn(hdc, 0, 0, 16, 16);
gdi_MoveToEx(hdc, 0, 0, NULL);
gdi_LineTo(hdc, 16 + 10, 16 + 10);
if (!test_assert_bitmaps_equal(hBmp, hBmp_LineTo[10], "Case 11") < 0)
goto fail;
/* Test Case 12: (0,0) -> (16,16), R2_BLACK */
if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
{
printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
goto fail;
}
for (x = 0; x < map_size; x++)
{
@ -804,7 +787,9 @@ int TestGdiLine(int argc, char* argv[])
gdi_SetROP2(hdc, rop_map[x].rop);
gdi_LineTo(hdc, 16, 16);
if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp, "Case 12") < 0)
if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp,
gdi_rop_to_string(rop_map[x].rop),
hPalette))
goto fail;
}

View File

@ -6,7 +6,6 @@
#include <freerdp/gdi/shape.h>
#include <freerdp/gdi/region.h>
#include <freerdp/gdi/bitmap.h>
#include <freerdp/gdi/drawing.h>
#include <winpr/crt.h>
#include <winpr/print.h>
@ -14,9 +13,8 @@
#include "line.h"
#include "brush.h"
#include "clipping.h"
#include "32bpp.h"
int test_gdi_PtInRect(void)
static int test_gdi_PtInRect(void)
{
HGDI_RECT hRect;
int left = 20;
@ -62,6 +60,7 @@ int test_gdi_PtInRect(void)
int test_gdi_FillRect(void)
{
int rc = -1;
HGDI_DC hdc;
HGDI_RECT hRect;
HGDI_BRUSH hBrush;
@ -82,7 +81,7 @@ int test_gdi_FillRect(void)
if (!(hdc = gdi_GetDC()))
{
printf("failed to get gdi device context\n");
return -1;
goto fail;
}
hdc->format = PIXEL_FORMAT_XRGB32;
@ -90,7 +89,7 @@ int test_gdi_FillRect(void)
if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
{
printf("gdi_CreateRect failed\n");
return -1;
goto fail;
}
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
@ -136,14 +135,16 @@ int test_gdi_FillRect(void)
}
if (goodPixels != width * height)
return -1;
goto fail;
if (badPixels != 0)
return -1;
goto fail;
rc = 0;
fail:
gdi_DeleteObject((HGDIOBJECT) hBrush);
gdi_DeleteObject((HGDIOBJECT) hBitmap);
return 0;
return rc;
}
int TestGdiRect(int argc, char* argv[])

View File

@ -93,22 +93,20 @@
*
*/
const BYTE rop_P = 0xF0; /* 11110000 */
const BYTE rop_S = 0xCC; /* 11001100 */
const BYTE rop_D = 0xAA; /* 10101010 */
static const BYTE rop_P = 0xF0; /* 11110000 */
static const BYTE rop_S = 0xCC; /* 11001100 */
static const BYTE rop_D = 0xAA; /* 10101010 */
char* gdi_convert_postfix_to_infix(char* postfix)
static char* gdi_convert_postfix_to_infix(const char* postfix)
{
int i;
int length;
BOOL unary;
wStack* stack;
int al, bl, cl, dl;
char *a, *b, *c, *d;
al = bl = cl = dl =0;
char* a, *b, *c, *d;
al = bl = cl = dl = 0;
stack = Stack_New(FALSE);
length = strlen(postfix);
for (i = 0; i < length; i++)
@ -116,21 +114,16 @@ char* gdi_convert_postfix_to_infix(char* postfix)
if ((postfix[i] == 'P') || (postfix[i] == 'D') || (postfix[i] == 'S'))
{
/* token is an operand, push on the stack */
a = malloc(2);
a[0] = postfix[i];
a[1] = '\0';
//printf("Operand: %s\n", a);
Stack_Push(stack, a);
}
else
{
/* token is an operator */
unary = FALSE;
c = malloc(2);
c[0] = postfix[i];
c[1] = '\0';
@ -158,7 +151,6 @@ char* gdi_convert_postfix_to_infix(char* postfix)
}
//printf("Operator: %s\n", c);
a = (char*) Stack_Pop(stack);
if (unary)
@ -172,14 +164,10 @@ char* gdi_convert_postfix_to_infix(char* postfix)
bl = strlen(b);
cl = 1;
dl = al + bl + cl + 3;
d = malloc(dl + 1);
sprintf_s(d, dl, "(%s%s%s)", b ? b : "", c, a);
Stack_Push(stack, d);
free(a);
free(b);
free(c);
@ -188,11 +176,10 @@ char* gdi_convert_postfix_to_infix(char* postfix)
d = (char*) Stack_Pop(stack);
Stack_Free(stack);
return d;
}
static char* test_ROP3[] =
static const char* test_ROP3[] =
{
"DSPDxax",
"PSDPxax",
@ -224,13 +211,15 @@ static char* test_ROP3[] =
int TestGdiRop3(int argc, char* argv[])
{
int index;
char* infix;
char* postfix;
for (index = 0; index < sizeof(test_ROP3) / sizeof(test_ROP3[0]); index++)
{
postfix = test_ROP3[index];
infix = gdi_convert_postfix_to_infix(postfix);
const char* postfix = test_ROP3[index];
char* infix = gdi_convert_postfix_to_infix(postfix);
if (!infix)
return -1;
printf("%s\t\t%s\n", postfix, infix);
free(infix);
}

View File

@ -90,7 +90,8 @@ static void test_dump_bitmap(HGDI_BITMAP hBmp, const char* name)
test_dump_data(hBmp->data, hBmp->height * stride, stride, name);
}
static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2)
static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2,
const gdiPalette* palette)
{
UINT32 x, y;
const BYTE* p1 = hBmp1->data;
@ -99,9 +100,6 @@ static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2)
UINT32 minw = (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width;
UINT32 minh = (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height;
if (hBmp1->format != hBmp2->format)
return FALSE;
for (y = 0; y < minh; y++)
{
for (x = 0; x < minw; x++)
@ -111,6 +109,9 @@ static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2)
p1 += GetBytesPerPixel(hBmp1->format);
p2 += GetBytesPerPixel(hBmp2->format);
if (hBmp1->format != hBmp2->format)
colorB = ConvertColor(colorB, hBmp2->format, hBmp1->format, palette);
if (colorA != colorB)
return FALSE;
}
@ -121,15 +122,18 @@ static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2)
BOOL test_assert_bitmaps_equal(HGDI_BITMAP hBmpActual,
HGDI_BITMAP hBmpExpected,
const char* name)
const char* name,
const gdiPalette* palette)
{
BOOL bitmapsEqual = CompareBitmaps(hBmpActual, hBmpExpected);
BOOL bitmapsEqual = CompareBitmaps(hBmpActual, hBmpExpected, palette);
if (!bitmapsEqual)
{
printf("\n%s\n", name);
test_dump_bitmap(hBmpActual, "Actual");
test_dump_bitmap(hBmpExpected, "Expected");
fflush(stdout);
fflush(stderr);
}
return bitmapsEqual;

View File

@ -31,6 +31,7 @@ HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat,
const gdiPalette* hPalette);
BOOL test_assert_bitmaps_equal(HGDI_BITMAP hBmpActual,
HGDI_BITMAP hBmpExpected, const char* name);
HGDI_BITMAP hBmpExpected, const char* name,
const gdiPalette* palette);
#endif /* __GDI_CORE_H */