Commit 1f95fd48 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

gdiplus/tests: Add more tests for gradient brush rectangles.

parent 0046c1f5
...@@ -621,141 +621,103 @@ static void test_texturewrap(void) ...@@ -621,141 +621,103 @@ static void test_texturewrap(void)
static void test_gradientgetrect(void) static void test_gradientgetrect(void)
{ {
static const struct
{
LinearGradientMode mode;
GpRectF rect;
REAL transform[6];
}
create_from_rect[] =
{
{ LinearGradientModeHorizontal, { 10.0f, 10.0f, -100.0f, -100.0f } },
{ LinearGradientModeHorizontal, { 10.0f, 10.0f, 100.0f, 100.0f } },
{ LinearGradientModeHorizontal, { 10.0f, -5.0f, 100.0f, 50.0f } },
{ LinearGradientModeHorizontal, { -5.0f, 10.0f, 100.0f, 50.0f } },
{ LinearGradientModeVertical, { 0.0f, 0.0f, 100.0f, 10.0f }, { 0.0f, 0.1f, -10.0f, -0.0f, 100.0f, 0.0f } },
{ LinearGradientModeVertical, { 10.0f, -12.0f, 100.0f, 105.0f }, { 0.0f, 1.05f, -0.952f, 0.0f, 98.571f, -22.5f } },
};
static const struct
{
GpPointF pt1, pt2;
GpRectF rect;
REAL transform[6];
}
create_from_pt[] =
{
{ { 1.0f, 1.0f }, { 100.0f, 100.0f }, { 1.0f, 1.0f, 99.0f, 99.0f }, { 1.0f, 1.0f, -1.0f, 1.0f, 50.50f, -50.50f } },
{ { 0.0f, 0.0f }, { 0.0f, 10.0f }, { -5.0f, 0.0f, 10.0f, 10.0f }, { 0.0f, 1.0f, -1.0f, 0.0f, 5.0f, 5.0f } },
{ { 0.0f, 0.0f }, { 10.0f, 0.0f }, { 0.0f, -5.0f, 10.0f, 10.0f }, { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f } },
/* Slope = -1 */
{ { 0.0f, 0.0f }, { 20.0f, -20.0f }, { 0.0f, -20.0f, 20.0f, 20.0f }, { 1.0f, -1.0f, 1.0f, 1.0f, 10.0f, 10.0f } },
/* Slope = 1/100 */
{ { 0.0f, 0.0f }, { 100.0f, 1.0f }, { 0.0f, 0.0f, 100.0f, 1.0f }, { 1.0f, 0.01f, -0.02f, 2.0f, 0.01f, -1.0f } },
{ { 10.0f, 10.0f }, { -90.0f, 10.0f }, { -90.0f, -40.0f, 100.0f, 100.0f }, { -1.0f, 0.0f, 0.0f, -1.0f, -80.0f, 20.0f } },
};
static const struct
{
GpRectF rect;
REAL angle;
BOOL is_scalable;
REAL transform[6];
}
create_with_angle[] =
{
{ { 10.0f, 10.0f, -100.0f, -100.0f }, 0.0f, TRUE },
{ { 10.0f, 10.0f, -100.0f, -100.0f }, 0.0f, FALSE },
{ { 10.0f, 10.0f, 100.0f, 100.0f }, 0.0f, FALSE },
{ { 10.0f, 10.0f, 100.0f, 100.0f }, 0.0f, TRUE },
{ { 10.0f, -5.0f, 100.0f, 50.0f }, 0.0f, FALSE },
{ { 10.0f, -5.0f, 100.0f, 50.0f }, 0.0f, TRUE },
{ { -5.0f, 10.0f, 100.0f, 50.0f }, 0.0f, FALSE },
{ { -5.0f, 10.0f, 100.0f, 50.0f }, 0.0f, TRUE },
{ { 0.0f, 0.0f, 100.0f, 10.0f }, -90.0f, TRUE, { 0.0f, -0.1f, 10.0f, 0.0f, 0.0f, 10.0f } },
{ { 10.0f, -12.0f, 100.0f, 105.0f }, -90.0f, TRUE, { 0.0f, -1.05f, 0.952f, 0.0f, 21.429f, 103.5f } },
{ { 0.0f, 0.0f, 100.0f, 10.0f }, -90.0f, FALSE, { 0.0f, -0.1f, 10.0f, -0.0f, 0.0f, 10.0f } },
{ { 10.0f, -12.0f, 100.0f, 105.0f }, -90.0f, FALSE, { 0.0f, -1.05f, 0.952f, 0.0f, 21.429f, 103.5f } },
};
GpLineGradient *brush; GpLineGradient *brush;
GpMatrix *transform; GpMatrix *transform;
REAL elements[6]; REAL elements[6];
GpRectF rectf;
GpStatus status; GpStatus status;
GpPointF pt1, pt2; unsigned int i;
ARGB colors[2];
GpRectF rectf;
status = GdipCreateMatrix(&transform); status = GdipCreateMatrix(&transform);
expect(Ok, status); expect(Ok, status);
pt1.X = pt1.Y = 1.0; for (i = 0; i < ARRAY_SIZE(create_from_pt); ++i)
pt2.X = pt2.Y = 100.0; {
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush); status = GdipCreateLineBrush(&create_from_pt[i].pt1, &create_from_pt[i].pt2, 0x1, 0x2, WrapModeTile, &brush);
expect(Ok, status); ok(status == Ok, "Failed to create a brush, %d.\n", status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf);
expect(Ok, status);
expectf(1.0, rectf.X);
expectf(1.0, rectf.Y);
expectf(99.0, rectf.Width);
expectf(99.0, rectf.Height);
status = GdipGetLineTransform(brush, transform);
expect(Ok, status);
status = GdipGetMatrixElements(transform, elements);
expect(Ok, status);
expectf(1.0, elements[0]);
expectf(1.0, elements[1]);
expectf(-1.0, elements[2]);
expectf(1.0, elements[3]);
expectf(50.50, elements[4]);
expectf(-50.50, elements[5]);
status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok, status);
/* vertical gradient */
pt1.X = pt1.Y = pt2.X = 0.0;
pt2.Y = 10.0;
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
expect(Ok, status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf);
expect(Ok, status);
expectf(-5.0, rectf.X);
expectf(0.0, rectf.Y);
expectf(10.0, rectf.Width);
expectf(10.0, rectf.Height);
status = GdipGetLineTransform(brush, transform);
expect(Ok, status);
status = GdipGetMatrixElements(transform, elements);
expect(Ok, status);
expectf(0.0, elements[0]);
expectf(1.0, elements[1]);
expectf(-1.0, elements[2]);
expectf(0.0, elements[3]);
expectf(5.0, elements[4]);
expectf(5.0, elements[5]);
status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok, status);
/* horizontal gradient */ memset(&rectf, 0, sizeof(rectf));
pt1.X = pt1.Y = pt2.Y = 0.0;
pt2.X = 10.0;
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
expect(Ok, status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf); status = GdipGetLineRect(brush, &rectf);
expect(Ok, status); ok(status == Ok, "Failed to get brush rect, %d.\n", status);
expectf(0.0, rectf.X); ok(!memcmp(&rectf, &create_from_pt[i].rect, sizeof(rectf)), "Unexpected brush rect.\n");
expectf(-5.0, rectf.Y);
expectf(10.0, rectf.Width);
expectf(10.0, rectf.Height);
status = GdipGetLineTransform(brush, transform);
expect(Ok, status);
status = GdipGetMatrixElements(transform, elements);
expect(Ok, status);
expectf(1.0, elements[0]);
expectf(0.0, elements[1]);
expectf(0.0, elements[2]);
expectf(1.0, elements[3]);
expectf(0.0, elements[4]);
expectf(0.0, elements[5]);
status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok, status);
/* slope = -1 */
pt1.X = pt1.Y = 0.0;
pt2.X = 20.0;
pt2.Y = -20.0;
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
expect(Ok, status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf);
expect(Ok, status);
expectf(0.0, rectf.X);
expectf(-20.0, rectf.Y);
expectf(20.0, rectf.Width);
expectf(20.0, rectf.Height);
status = GdipGetLineTransform(brush, transform); status = GdipGetLineTransform(brush, transform);
expect(Ok, status); ok(status == Ok, "Failed to get brush transform, %d.\n", status);
status = GdipGetMatrixElements(transform, elements);
expect(Ok, status);
expectf(1.0, elements[0]);
expectf(-1.0, elements[1]);
expectf(1.0, elements[2]);
expectf(1.0, elements[3]);
expectf(10.0, elements[4]);
expectf(10.0, elements[5]);
status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok, status);
/* slope = 1/100 */
pt1.X = pt1.Y = 0.0;
pt2.X = 100.0;
pt2.Y = 1.0;
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
expect(Ok, status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf);
expect(Ok, status);
expectf(0.0, rectf.X);
expectf(0.0, rectf.Y);
expectf(100.0, rectf.Width);
expectf(1.0, rectf.Height);
status = GdipGetLineTransform(brush, transform);
expect(Ok, status);
status = GdipGetMatrixElements(transform, elements); status = GdipGetMatrixElements(transform, elements);
expect(Ok,status); ok(status == Ok, "Failed to get matrix elements, %d.\n", status);
expectf(1.0, elements[0]);
expectf(0.01, elements[1]); #define expectf2(expected, got) ok(fabs(expected - got) < 0.001, "%u: expected %.3f, got %.3f.\n", i, expected, got)
expectf(-0.02, elements[2]); expectf2(create_from_pt[i].transform[0], elements[0]);
/* expectf(2.0, elements[3]); */ expectf2(create_from_pt[i].transform[1], elements[1]);
expectf(0.01, elements[4]); expectf2(create_from_pt[i].transform[2], elements[2]);
/* expectf(-1.0, elements[5]); */ expectf2(create_from_pt[i].transform[3], elements[3]);
status = GdipDeleteBrush((GpBrush*)brush); expectf2(create_from_pt[i].transform[4], elements[4]);
expect(Ok,status); expectf2(create_from_pt[i].transform[5], elements[5]);
#undef expect2f
status = GdipGetLineColors(brush, colors);
ok(status == Ok, "Failed to get line colors, %d.\n", status);
ok(colors[0] == 0x1 && colors[1] == 0x2, "Unexpected brush colors.\n");
status = GdipDeleteBrush((GpBrush *)brush);
ok(status == Ok, "Failed to delete a brush, %d.\n", status);
}
/* zero height rect */ /* zero height rect */
rectf.X = rectf.Y = 10.0; rectf.X = rectf.Y = 10.0;
...@@ -773,84 +735,100 @@ static void test_gradientgetrect(void) ...@@ -773,84 +735,100 @@ static void test_gradientgetrect(void)
WrapModeTile, &brush); WrapModeTile, &brush);
expect(OutOfMemory, status); expect(OutOfMemory, status);
/* from rect with LinearGradientModeHorizontal */ for (i = 0; i < ARRAY_SIZE(create_from_rect); ++i)
rectf.X = rectf.Y = 10.0; {
rectf.Width = rectf.Height = 100.0; ARGB colors[2];
status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeHorizontal, BOOL ret;
WrapModeTile, &brush);
expect(Ok, status);
memset(&rectf, 0, sizeof(GpRectF));
status = GdipGetLineRect(brush, &rectf);
expect(Ok, status);
expectf(10.0, rectf.X);
expectf(10.0, rectf.Y);
expectf(100.0, rectf.Width);
expectf(100.0, rectf.Height);
status = GdipGetLineTransform(brush, transform);
expect(Ok, status);
status = GdipGetMatrixElements(transform, elements);
expect(Ok,status);
expectf(1.0, elements[0]);
expectf(0.0, elements[1]);
expectf(0.0, elements[2]);
expectf(1.0, elements[3]);
expectf(0.0, elements[4]);
expectf(0.0, elements[5]);
status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok,status);
/* passing negative Width/Height to LinearGradientModeHorizontal */ status = GdipCreateLineBrushFromRect(&create_from_rect[i].rect, 0x1, 0x2, create_from_rect[i].mode,
rectf.X = rectf.Y = 10.0;
rectf.Width = rectf.Height = -100.0;
status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeHorizontal,
WrapModeTile, &brush); WrapModeTile, &brush);
expect(Ok, status); ok(status == Ok, "Failed to create a brush, %d.\n", status);
memset(&rectf, 0, sizeof(GpRectF));
memset(&rectf, 0, sizeof(rectf));
status = GdipGetLineRect(brush, &rectf); status = GdipGetLineRect(brush, &rectf);
expect(Ok, status); ok(status == Ok, "Failed to get brush rect, %d.\n", status);
expectf(10.0, rectf.X); ok(!memcmp(&rectf, &create_from_rect[i].rect, sizeof(rectf)), "Unexpected brush rect.\n");
expectf(10.0, rectf.Y);
expectf(-100.0, rectf.Width);
expectf(-100.0, rectf.Height);
status = GdipGetLineTransform(brush, transform); status = GdipGetLineTransform(brush, transform);
expect(Ok, status); ok(status == Ok, "Failed to get brush transform, %d.\n", status);
if (create_from_rect[i].mode == LinearGradientModeHorizontal)
{
status = GdipIsMatrixIdentity(transform, &ret);
ok(status == Ok, "Unexpected ret value %d.\n", status);
}
else
{
status = GdipGetMatrixElements(transform, elements); status = GdipGetMatrixElements(transform, elements);
expect(Ok,status); ok(status == Ok, "Failed to get matrix elements, %d.\n", status);
expectf(1.0, elements[0]);
expectf(0.0, elements[1]); #define expectf2(expected, got) ok(fabs(expected - got) < 0.001, "%u: expected %.3f, got %.3f.\n", i, expected, got)
expectf(0.0, elements[2]); expectf2(create_from_rect[i].transform[0], elements[0]);
expectf(1.0, elements[3]); todo_wine_if(create_from_rect[i].mode == LinearGradientModeVertical) {
expectf(0.0, elements[4]); expectf2(create_from_rect[i].transform[1], elements[1]);
expectf(0.0, elements[5]); expectf2(create_from_rect[i].transform[2], elements[2]);
}
expectf2(create_from_rect[i].transform[3], elements[3]);
todo_wine_if(create_from_rect[i].mode == LinearGradientModeVertical) {
expectf2(create_from_rect[i].transform[4], elements[4]);
expectf2(create_from_rect[i].transform[5], elements[5]);
}
#undef expectf2
}
status = GdipGetLineColors(brush, colors);
ok(status == Ok, "Failed to get line colors, %d.\n", status);
ok(colors[0] == 0x1 && colors[1] == 0x2, "Unexpected brush colors.\n");
status = GdipDeleteBrush((GpBrush*)brush); status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok,status); ok(status == Ok, "Failed to delete a brush, %d.\n", status);
}
/* reverse gradient line as immediately previous */ for (i = 0; i < ARRAY_SIZE(create_with_angle); ++i)
pt1.X = 10.0; {
pt1.Y = 10.0; ARGB colors[2];
pt2.X = -90.0; BOOL ret;
pt2.Y = 10.0;
status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush); status = GdipCreateLineBrushFromRectWithAngle(&create_with_angle[i].rect, 0x1, 0x2, create_with_angle[i].angle,
expect(Ok, status); create_with_angle[i].is_scalable, WrapModeTile, &brush);
memset(&rectf, 0, sizeof(GpRectF)); ok(status == Ok, "Failed to create a brush, %d.\n", status);
memset(&rectf, 0, sizeof(rectf));
status = GdipGetLineRect(brush, &rectf); status = GdipGetLineRect(brush, &rectf);
expect(Ok, status); ok(status == Ok, "Failed to get brush rect, %d.\n", status);
expectf(-90.0, rectf.X); ok(!memcmp(&rectf, &create_with_angle[i].rect, sizeof(rectf)), "%u: unexpected brush rect {%f,%f,%f,%f}.\n",
expectf(-40.0, rectf.Y); i, rectf.X, rectf.Y, rectf.Width, rectf.Height);
expectf(100.0, rectf.Width);
expectf(100.0, rectf.Height);
status = GdipGetLineTransform(brush, transform); status = GdipGetLineTransform(brush, transform);
expect(Ok, status); ok(status == Ok, "Failed to get brush transform, %d.\n", status);
if (create_with_angle[i].angle == 0.0f)
{
status = GdipIsMatrixIdentity(transform, &ret);
ok(status == Ok, "Unexpected ret value %d.\n", status);
}
else
{
status = GdipGetMatrixElements(transform, elements); status = GdipGetMatrixElements(transform, elements);
expect(Ok, status); ok(status == Ok, "Failed to get matrix elements, %d.\n", status);
expectf(-1.0, elements[0]);
expectf(0.0, elements[1]); #define expectf2(expected, got) ok(fabs(expected - got) < 0.001, "%u: expected %.3f, got %.3f.\n", i, expected, got)
expectf(0.0, elements[2]); expectf2(create_with_angle[i].transform[0], elements[0]);
expectf(-1.0, elements[3]); expectf2(create_with_angle[i].transform[1], elements[1]);
expectf(-80.0, elements[4]); expectf2(create_with_angle[i].transform[2], elements[2]);
expectf(20.0, elements[5]); expectf2(create_with_angle[i].transform[3], elements[3]);
expectf2(create_with_angle[i].transform[4], elements[4]);
expectf2(create_with_angle[i].transform[5], elements[5]);
#undef expectf2
}
status = GdipGetLineColors(brush, colors);
ok(status == Ok, "Failed to get line colors, %d.\n", status);
ok(colors[0] == 0x1 && colors[1] == 0x2, "Unexpected brush colors.\n");
status = GdipDeleteBrush((GpBrush*)brush); status = GdipDeleteBrush((GpBrush*)brush);
expect(Ok, status); ok(status == Ok, "Failed to delete a brush, %d.\n", status);
}
GdipDeleteMatrix(transform); GdipDeleteMatrix(transform);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment