2 * Unit test suite for brushes
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
26 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
27 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
29 static void test_constructor_destructor(void)
32 GpSolidFill
*brush
= NULL
;
34 status
= GdipCreateSolidFill((ARGB
)0xdeadbeef, &brush
);
36 ok(brush
!= NULL
, "Expected brush to be initialized\n");
38 status
= GdipDeleteBrush(NULL
);
39 expect(InvalidParameter
, status
);
41 status
= GdipDeleteBrush((GpBrush
*) brush
);
45 static void test_type(void)
49 GpSolidFill
*brush
= NULL
;
51 GdipCreateSolidFill((ARGB
)0xdeadbeef, &brush
);
53 status
= GdipGetBrushType((GpBrush
*)brush
, &bt
);
55 expect(BrushTypeSolidColor
, bt
);
57 GdipDeleteBrush((GpBrush
*) brush
);
59 static GpPointF blendcount_ptf
[] = {{0.0, 0.0},
61 static void test_gradientblendcount(void)
64 GpPathGradient
*brush
;
67 status
= GdipCreatePathGradient(blendcount_ptf
, 2, WrapModeClamp
, &brush
);
70 status
= GdipGetPathGradientBlendCount(NULL
, NULL
);
71 expect(InvalidParameter
, status
);
72 status
= GdipGetPathGradientBlendCount(NULL
, &count
);
73 expect(InvalidParameter
, status
);
74 status
= GdipGetPathGradientBlendCount(brush
, NULL
);
75 expect(InvalidParameter
, status
);
77 status
= GdipGetPathGradientBlendCount(brush
, &count
);
81 GdipDeleteBrush((GpBrush
*) brush
);
84 static GpPointF getblend_ptf
[] = {{0.0, 0.0},
86 static void test_getblend(void)
89 GpPathGradient
*brush
;
93 status
= GdipCreatePathGradient(getblend_ptf
, 2, WrapModeClamp
, &brush
);
96 /* check some invalid parameters combinations */
97 status
= GdipGetPathGradientBlend(NULL
, NULL
, NULL
, -1);
98 expect(InvalidParameter
, status
);
99 status
= GdipGetPathGradientBlend(brush
,NULL
, NULL
, -1);
100 expect(InvalidParameter
, status
);
101 status
= GdipGetPathGradientBlend(NULL
, blends
,NULL
, -1);
102 expect(InvalidParameter
, status
);
103 status
= GdipGetPathGradientBlend(NULL
, NULL
, pos
, -1);
104 expect(InvalidParameter
, status
);
105 status
= GdipGetPathGradientBlend(NULL
, NULL
, NULL
, 1);
106 expect(InvalidParameter
, status
);
108 blends
[0] = (REAL
)0xdeadbeef;
109 pos
[0] = (REAL
)0xdeadbeef;
110 status
= GdipGetPathGradientBlend(brush
, blends
, pos
, 1);
112 expectf(1.0, blends
[0]);
113 expectf((REAL
)0xdeadbeef, pos
[0]);
115 GdipDeleteBrush((GpBrush
*) brush
);
118 static GpPointF getbounds_ptf
[] = {{0.0, 20.0},
122 static void test_getbounds(void)
125 GpPathGradient
*brush
;
128 status
= GdipCreatePathGradient(getbounds_ptf
, 4, WrapModeClamp
, &brush
);
131 status
= GdipGetPathGradientRect(NULL
, NULL
);
132 expect(InvalidParameter
, status
);
133 status
= GdipGetPathGradientRect(brush
, NULL
);
134 expect(InvalidParameter
, status
);
135 status
= GdipGetPathGradientRect(NULL
, &bounds
);
136 expect(InvalidParameter
, status
);
138 status
= GdipGetPathGradientRect(brush
, &bounds
);
140 expectf(0.0, bounds
.X
);
141 expectf(20.0, bounds
.Y
);
142 expectf(50.0, bounds
.Width
);
143 expectf(30.0, bounds
.Height
);
145 GdipDeleteBrush((GpBrush
*) brush
);
148 static void test_getgamma(void)
151 GpLineGradient
*line
;
155 start
.X
= start
.Y
= 0.0;
156 end
.X
= end
.Y
= 100.0;
158 status
= GdipCreateLineBrush(&start
, &end
, (ARGB
)0xdeadbeef, 0xdeadbeef, WrapModeTile
, &line
);
162 status
= GdipGetLineGammaCorrection(NULL
, NULL
);
163 expect(InvalidParameter
, status
);
164 status
= GdipGetLineGammaCorrection(line
, NULL
);
165 expect(InvalidParameter
, status
);
166 status
= GdipGetLineGammaCorrection(NULL
, &gamma
);
167 expect(InvalidParameter
, status
);
169 GdipDeleteBrush((GpBrush
*)line
);
172 static void test_transform(void)
176 GpGraphics
*graphics
= NULL
;
182 status
= GdipCreateMatrix2(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, &m
);
185 status
= GdipCreateFromHDC(hdc
, &graphics
);
187 status
= GdipCreateBitmapFromGraphics(1, 1, graphics
, &bitmap
);
190 status
= GdipCreateTexture((GpImage
*)bitmap
, WrapModeTile
, &texture
);
194 status
= GdipGetTextureTransform(NULL
, NULL
);
195 expect(InvalidParameter
, status
);
196 status
= GdipGetTextureTransform(texture
, NULL
);
197 expect(InvalidParameter
, status
);
199 /* get default value - identity matrix */
200 status
= GdipGetTextureTransform(texture
, m
);
202 status
= GdipIsMatrixIdentity(m
, &res
);
205 /* set and get then */
206 status
= GdipCreateMatrix2(2.0, 0.0, 0.0, 2.0, 0.0, 0.0, &m1
);
208 status
= GdipSetTextureTransform(texture
, m1
);
210 status
= GdipGetTextureTransform(texture
, m
);
212 status
= GdipIsMatrixEqual(m
, m1
, &res
);
216 status
= GdipResetTextureTransform(texture
);
218 status
= GdipGetTextureTransform(texture
, m
);
220 status
= GdipIsMatrixIdentity(m
, &res
);
224 status
= GdipDeleteBrush((GpBrush
*)texture
);
227 status
= GdipDeleteMatrix(m1
);
229 status
= GdipDeleteMatrix(m
);
231 status
= GdipDisposeImage((GpImage
*)bitmap
);
233 status
= GdipDeleteGraphics(graphics
);
238 static void test_texturewrap(void)
242 GpGraphics
*graphics
= NULL
;
247 status
= GdipCreateFromHDC(hdc
, &graphics
);
249 status
= GdipCreateBitmapFromGraphics(1, 1, graphics
, &bitmap
);
252 status
= GdipCreateTexture((GpImage
*)bitmap
, WrapModeTile
, &texture
);
256 status
= GdipGetTextureWrapMode(NULL
, NULL
);
257 expect(InvalidParameter
, status
);
258 status
= GdipGetTextureWrapMode(texture
, NULL
);
259 expect(InvalidParameter
, status
);
260 status
= GdipGetTextureWrapMode(NULL
, &wrap
);
261 expect(InvalidParameter
, status
);
264 wrap
= WrapModeClamp
;
265 status
= GdipGetTextureWrapMode(texture
, &wrap
);
267 expect(WrapModeTile
, wrap
);
269 wrap
= WrapModeClamp
;
270 status
= GdipSetTextureWrapMode(texture
, wrap
);
273 status
= GdipGetTextureWrapMode(texture
, &wrap
);
275 expect(WrapModeClamp
, wrap
);
277 status
= GdipDeleteBrush((GpBrush
*)texture
);
279 status
= GdipDisposeImage((GpImage
*)bitmap
);
281 status
= GdipDeleteGraphics(graphics
);
286 static void test_gradientgetrect(void)
288 GpLineGradient
*brush
;
295 status
= GdipCreateMatrix(&transform
);
299 pt2
.X
= pt2
.Y
= 100.0;
300 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
302 memset(&rectf
, 0, sizeof(GpRectF
));
303 status
= GdipGetLineRect(brush
, &rectf
);
305 expectf(1.0, rectf
.X
);
306 expectf(1.0, rectf
.Y
);
307 expectf(99.0, rectf
.Width
);
308 expectf(99.0, rectf
.Height
);
309 status
= GdipGetLineTransform(brush
, transform
);
310 todo_wine
expect(Ok
, status
);
313 status
= GdipGetMatrixElements(transform
, elements
);
315 expectf(1.0, elements
[0]);
316 expectf(1.0, elements
[1]);
317 expectf(-1.0, elements
[2]);
318 expectf(1.0, elements
[3]);
319 expectf(50.50, elements
[4]);
320 expectf(-50.50, elements
[5]);
322 status
= GdipDeleteBrush((GpBrush
*)brush
);
324 /* vertical gradient */
325 pt1
.X
= pt1
.Y
= pt2
.X
= 0.0;
327 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
329 memset(&rectf
, 0, sizeof(GpRectF
));
330 status
= GdipGetLineRect(brush
, &rectf
);
332 expectf(-5.0, rectf
.X
);
333 expectf(0.0, rectf
.Y
);
334 expectf(10.0, rectf
.Width
);
335 expectf(10.0, rectf
.Height
);
336 status
= GdipGetLineTransform(brush
, transform
);
337 todo_wine
expect(Ok
, status
);
340 status
= GdipGetMatrixElements(transform
, elements
);
342 expectf(0.0, elements
[0]);
343 expectf(1.0, elements
[1]);
344 expectf(-1.0, elements
[2]);
345 expectf(0.0, elements
[3]);
346 expectf(5.0, elements
[4]);
347 expectf(5.0, elements
[5]);
349 status
= GdipDeleteBrush((GpBrush
*)brush
);
351 /* horizontal gradient */
352 pt1
.X
= pt1
.Y
= pt2
.Y
= 0.0;
354 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
356 memset(&rectf
, 0, sizeof(GpRectF
));
357 status
= GdipGetLineRect(brush
, &rectf
);
359 expectf(0.0, rectf
.X
);
360 expectf(-5.0, rectf
.Y
);
361 expectf(10.0, rectf
.Width
);
362 expectf(10.0, rectf
.Height
);
363 status
= GdipGetLineTransform(brush
, transform
);
364 todo_wine
expect(Ok
, status
);
367 status
= GdipGetMatrixElements(transform
, elements
);
369 expectf(1.0, elements
[0]);
370 expectf(0.0, elements
[1]);
371 expectf(0.0, elements
[2]);
372 expectf(1.0, elements
[3]);
373 expectf(0.0, elements
[4]);
374 expectf(0.0, elements
[5]);
376 status
= GdipDeleteBrush((GpBrush
*)brush
);
382 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
384 memset(&rectf
, 0, sizeof(GpRectF
));
385 status
= GdipGetLineRect(brush
, &rectf
);
387 expectf(0.0, rectf
.X
);
388 expectf(-20.0, rectf
.Y
);
389 expectf(20.0, rectf
.Width
);
390 expectf(20.0, rectf
.Height
);
391 status
= GdipGetLineTransform(brush
, transform
);
392 todo_wine
expect(Ok
, status
);
395 status
= GdipGetMatrixElements(transform
, elements
);
397 expectf(1.0, elements
[0]);
398 expectf(-1.0, elements
[1]);
399 expectf(1.0, elements
[2]);
400 expectf(1.0, elements
[3]);
401 expectf(10.0, elements
[4]);
402 expectf(10.0, elements
[5]);
404 status
= GdipDeleteBrush((GpBrush
*)brush
);
410 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
412 memset(&rectf
, 0, sizeof(GpRectF
));
413 status
= GdipGetLineRect(brush
, &rectf
);
415 expectf(0.0, rectf
.X
);
416 expectf(0.0, rectf
.Y
);
417 expectf(100.0, rectf
.Width
);
418 expectf(1.0, rectf
.Height
);
419 status
= GdipGetLineTransform(brush
, transform
);
420 todo_wine
expect(Ok
, status
);
423 status
= GdipGetMatrixElements(transform
, elements
);
425 expectf(1.0, elements
[0]);
426 expectf(0.01, elements
[1]);
427 expectf(-0.02, elements
[2]);
428 /* expectf(2.0, elements[3]); */
429 expectf(0.01, elements
[4]);
430 /* expectf(-1.0, elements[5]); */
432 status
= GdipDeleteBrush((GpBrush
*)brush
);
434 /* zero height rect */
435 rectf
.X
= rectf
.Y
= 10.0;
438 status
= GdipCreateLineBrushFromRect(&rectf
, 0, 0, LinearGradientModeVertical
,
439 WrapModeTile
, &brush
);
440 expect(OutOfMemory
, status
);
441 /* zero width rect */
442 rectf
.X
= rectf
.Y
= 10.0;
444 rectf
.Height
= 100.0;
445 status
= GdipCreateLineBrushFromRect(&rectf
, 0, 0, LinearGradientModeHorizontal
,
446 WrapModeTile
, &brush
);
447 expect(OutOfMemory
, status
);
448 /* from rect with LinearGradientModeHorizontal */
449 rectf
.X
= rectf
.Y
= 10.0;
450 rectf
.Width
= rectf
.Height
= 100.0;
451 status
= GdipCreateLineBrushFromRect(&rectf
, 0, 0, LinearGradientModeHorizontal
,
452 WrapModeTile
, &brush
);
454 memset(&rectf
, 0, sizeof(GpRectF
));
455 status
= GdipGetLineRect(brush
, &rectf
);
457 expectf(10.0, rectf
.X
);
458 expectf(10.0, rectf
.Y
);
459 expectf(100.0, rectf
.Width
);
460 expectf(100.0, rectf
.Height
);
461 status
= GdipGetLineTransform(brush
, transform
);
462 todo_wine
expect(Ok
, status
);
465 status
= GdipGetMatrixElements(transform
, elements
);
467 expectf(1.0, elements
[0]);
468 expectf(0.0, elements
[1]);
469 expectf(0.0, elements
[2]);
470 expectf(1.0, elements
[3]);
471 expectf(0.0, elements
[4]);
472 expectf(0.0, elements
[5]);
474 status
= GdipDeleteBrush((GpBrush
*)brush
);
476 /* passing negative Width/Height to LinearGradientModeHorizontal */
477 rectf
.X
= rectf
.Y
= 10.0;
478 rectf
.Width
= rectf
.Height
= -100.0;
479 status
= GdipCreateLineBrushFromRect(&rectf
, 0, 0, LinearGradientModeHorizontal
,
480 WrapModeTile
, &brush
);
482 memset(&rectf
, 0, sizeof(GpRectF
));
483 status
= GdipGetLineRect(brush
, &rectf
);
485 expectf(10.0, rectf
.X
);
486 expectf(10.0, rectf
.Y
);
487 expectf(-100.0, rectf
.Width
);
488 expectf(-100.0, rectf
.Height
);
489 status
= GdipGetLineTransform(brush
, transform
);
490 todo_wine
expect(Ok
, status
);
493 status
= GdipGetMatrixElements(transform
, elements
);
495 expectf(1.0, elements
[0]);
496 expectf(0.0, elements
[1]);
497 expectf(0.0, elements
[2]);
498 expectf(1.0, elements
[3]);
499 expectf(0.0, elements
[4]);
500 expectf(0.0, elements
[5]);
502 status
= GdipDeleteBrush((GpBrush
*)brush
);
505 GdipDeleteMatrix(transform
);
508 static void test_lineblend(void)
510 GpLineGradient
*brush
;
515 const REAL factors
[5] = {0.0f
, 0.1f
, 0.5f
, 0.9f
, 1.0f
};
516 const REAL positions
[5] = {0.0f
, 0.2f
, 0.5f
, 0.8f
, 1.0f
};
517 const REAL two_positions
[2] = {0.0f
, 1.0f
};
518 const ARGB colors
[5] = {0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffffffff};
519 REAL res_factors
[6] = {0.3f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
520 REAL res_positions
[6] = {0.3f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
521 ARGB res_colors
[6] = {0xdeadbeef, 0, 0, 0, 0};
523 pt1
.X
= pt1
.Y
= pt2
.Y
= pt2
.X
= 1.0;
524 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
525 expect(OutOfMemory
, status
);
528 pt2
.X
= pt2
.Y
= 100.0;
529 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
532 status
= GdipGetLineBlendCount(NULL
, &count
);
533 expect(InvalidParameter
, status
);
535 status
= GdipGetLineBlendCount(brush
, NULL
);
536 expect(InvalidParameter
, status
);
538 status
= GdipGetLineBlendCount(brush
, &count
);
542 status
= GdipGetLineBlend(NULL
, res_factors
, res_positions
, 1);
543 expect(InvalidParameter
, status
);
545 status
= GdipGetLineBlend(brush
, NULL
, res_positions
, 1);
546 expect(InvalidParameter
, status
);
548 status
= GdipGetLineBlend(brush
, res_factors
, NULL
, 1);
549 expect(InvalidParameter
, status
);
551 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 0);
552 expect(InvalidParameter
, status
);
554 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, -1);
555 expect(InvalidParameter
, status
);
557 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 1);
560 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 2);
563 status
= GdipSetLineBlend(NULL
, factors
, positions
, 5);
564 expect(InvalidParameter
, status
);
566 status
= GdipSetLineBlend(brush
, NULL
, positions
, 5);
567 expect(InvalidParameter
, status
);
569 status
= GdipSetLineBlend(brush
, factors
, NULL
, 5);
570 expect(InvalidParameter
, status
);
572 status
= GdipSetLineBlend(brush
, factors
, positions
, 0);
573 expect(InvalidParameter
, status
);
575 status
= GdipSetLineBlend(brush
, factors
, positions
, -1);
576 expect(InvalidParameter
, status
);
578 /* leave off the 0.0 position */
579 status
= GdipSetLineBlend(brush
, &factors
[1], &positions
[1], 4);
580 expect(InvalidParameter
, status
);
582 /* leave off the 1.0 position */
583 status
= GdipSetLineBlend(brush
, factors
, positions
, 4);
584 expect(InvalidParameter
, status
);
586 status
= GdipSetLineBlend(brush
, factors
, positions
, 5);
589 status
= GdipGetLineBlendCount(brush
, &count
);
593 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 4);
594 expect(InsufficientBuffer
, status
);
596 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 5);
601 expectf(factors
[i
], res_factors
[i
]);
602 expectf(positions
[i
], res_positions
[i
]);
605 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 6);
608 status
= GdipSetLineBlend(brush
, factors
, positions
, 1);
611 status
= GdipGetLineBlendCount(brush
, &count
);
615 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 1);
618 status
= GdipGetLinePresetBlendCount(NULL
, &count
);
619 expect(InvalidParameter
, status
);
621 status
= GdipGetLinePresetBlendCount(brush
, NULL
);
622 expect(InvalidParameter
, status
);
624 status
= GdipGetLinePresetBlendCount(brush
, &count
);
628 status
= GdipGetLinePresetBlend(NULL
, res_colors
, res_positions
, 1);
629 expect(InvalidParameter
, status
);
631 status
= GdipGetLinePresetBlend(brush
, NULL
, res_positions
, 1);
632 expect(InvalidParameter
, status
);
634 status
= GdipGetLinePresetBlend(brush
, res_colors
, NULL
, 1);
635 expect(InvalidParameter
, status
);
637 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 0);
638 expect(InvalidParameter
, status
);
640 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, -1);
641 expect(InvalidParameter
, status
);
643 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 1);
644 expect(InvalidParameter
, status
);
646 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 2);
647 expect(GenericError
, status
);
649 status
= GdipSetLinePresetBlend(NULL
, colors
, positions
, 5);
650 expect(InvalidParameter
, status
);
652 status
= GdipSetLinePresetBlend(brush
, NULL
, positions
, 5);
653 expect(InvalidParameter
, status
);
655 status
= GdipSetLinePresetBlend(brush
, colors
, NULL
, 5);
656 expect(InvalidParameter
, status
);
658 status
= GdipSetLinePresetBlend(brush
, colors
, positions
, 0);
659 expect(InvalidParameter
, status
);
661 status
= GdipSetLinePresetBlend(brush
, colors
, positions
, -1);
662 expect(InvalidParameter
, status
);
664 status
= GdipSetLinePresetBlend(brush
, colors
, positions
, 1);
665 expect(InvalidParameter
, status
);
667 /* leave off the 0.0 position */
668 status
= GdipSetLinePresetBlend(brush
, &colors
[1], &positions
[1], 4);
669 expect(InvalidParameter
, status
);
671 /* leave off the 1.0 position */
672 status
= GdipSetLinePresetBlend(brush
, colors
, positions
, 4);
673 expect(InvalidParameter
, status
);
675 status
= GdipSetLinePresetBlend(brush
, colors
, positions
, 5);
678 status
= GdipGetLinePresetBlendCount(brush
, &count
);
682 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 4);
683 expect(InsufficientBuffer
, status
);
685 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 5);
690 expect(colors
[i
], res_colors
[i
]);
691 expectf(positions
[i
], res_positions
[i
]);
694 status
= GdipGetLinePresetBlend(brush
, res_colors
, res_positions
, 6);
697 status
= GdipSetLinePresetBlend(brush
, colors
, two_positions
, 2);
700 status
= GdipDeleteBrush((GpBrush
*)brush
);
704 static void test_linelinearblend(void)
706 GpLineGradient
*brush
;
710 REAL res_factors
[3] = {0.3f
};
711 REAL res_positions
[3] = {0.3f
};
713 status
= GdipSetLineLinearBlend(NULL
, 0.6, 0.8);
714 expect(InvalidParameter
, status
);
717 pt2
.X
= pt2
.Y
= 100.0;
718 status
= GdipCreateLineBrush(&pt1
, &pt2
, 0, 0, WrapModeTile
, &brush
);
722 status
= GdipSetLineLinearBlend(brush
, 0.6, 0.8);
725 status
= GdipGetLineBlendCount(brush
, &count
);
729 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 3);
731 expectf(0.0, res_factors
[0]);
732 expectf(0.0, res_positions
[0]);
733 expectf(0.8, res_factors
[1]);
734 expectf(0.6, res_positions
[1]);
735 expectf(0.0, res_factors
[2]);
736 expectf(1.0, res_positions
[2]);
739 status
= GdipSetLineLinearBlend(brush
, 0.0, 0.8);
742 status
= GdipGetLineBlendCount(brush
, &count
);
746 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 3);
748 expectf(0.8, res_factors
[0]);
749 expectf(0.0, res_positions
[0]);
750 expectf(0.0, res_factors
[1]);
751 expectf(1.0, res_positions
[1]);
754 status
= GdipSetLineLinearBlend(brush
, 1.0, 0.8);
757 status
= GdipGetLineBlendCount(brush
, &count
);
761 status
= GdipGetLineBlend(brush
, res_factors
, res_positions
, 3);
763 expectf(0.0, res_factors
[0]);
764 expectf(0.0, res_positions
[0]);
765 expectf(0.8, res_factors
[1]);
766 expectf(1.0, res_positions
[1]);
768 status
= GdipDeleteBrush((GpBrush
*)brush
);
772 static void test_gradientsurroundcolorcount(void)
775 GpPathGradient
*grad
;
779 status
= GdipCreatePathGradient(blendcount_ptf
, 2, WrapModeClamp
, &grad
);
783 status
= GdipGetPathGradientSurroundColorCount(grad
, &count
);
787 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
789 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
792 expect(0xffffffff, color
[0]);
793 expect(0xffffffff, color
[1]);
794 expect(0xdeadbeef, color
[2]);
796 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
798 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
801 expect(0xffffffff, color
[0]);
802 expect(0xffffffff, color
[1]);
803 expect(0xdeadbeef, color
[2]);
805 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
807 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
808 expect(InvalidParameter
, status
);
810 expect(0xdeadbeef, color
[0]);
811 expect(0xdeadbeef, color
[1]);
812 expect(0xdeadbeef, color
[2]);
814 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
816 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
817 expect(InvalidParameter
, status
);
819 expect(0xdeadbeef, color
[0]);
820 expect(0xdeadbeef, color
[1]);
821 expect(0xdeadbeef, color
[2]);
824 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
825 expect(InvalidParameter
, status
);
829 color
[0] = 0x00ff0000;
830 color
[1] = 0x0000ff00;
832 status
= GdipSetPathGradientSurroundColorsWithCount(NULL
, color
, &count
);
833 expect(InvalidParameter
, status
);
835 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, NULL
, &count
);
836 expect(InvalidParameter
, status
);
838 /* WinXP crashes on this test */
841 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, NULL
);
842 expect(InvalidParameter
, status
);
845 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
849 status
= GdipGetPathGradientSurroundColorCount(NULL
, &count
);
850 expect(InvalidParameter
, status
);
852 status
= GdipGetPathGradientSurroundColorCount(grad
, NULL
);
853 expect(InvalidParameter
, status
);
856 status
= GdipGetPathGradientSurroundColorCount(grad
, &count
);
860 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
862 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
865 expect(0x00ff0000, color
[0]);
866 expect(0x0000ff00, color
[1]);
867 expect(0xdeadbeef, color
[2]);
870 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
875 status
= GdipGetPathGradientSurroundColorCount(grad
, &count
);
879 /* If all colors are the same, count is set to 1. */
880 color
[0] = color
[1] = 0;
882 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
886 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
888 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
891 expect(0x00000000, color
[0]);
892 expect(0x00000000, color
[1]);
893 expect(0xdeadbeef, color
[2]);
895 color
[0] = color
[1] = 0xff00ff00;
897 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
901 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
903 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
906 expect(0xff00ff00, color
[0]);
907 expect(0xff00ff00, color
[1]);
908 expect(0xdeadbeef, color
[2]);
911 status
= GdipSetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
912 expect(InvalidParameter
, status
);
915 GdipDeleteBrush((GpBrush
*)grad
);
917 status
= GdipCreatePathGradient(getbounds_ptf
, 3, WrapModeClamp
, &grad
);
920 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
922 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
925 expect(0xffffffff, color
[0]);
926 expect(0xffffffff, color
[1]);
927 expect(0xffffffff, color
[2]);
929 color
[0] = color
[1] = color
[2] = 0xdeadbeef;
931 status
= GdipGetPathGradientSurroundColorsWithCount(grad
, color
, &count
);
932 expect(InvalidParameter
, status
);
934 expect(0xdeadbeef, color
[0]);
935 expect(0xdeadbeef, color
[1]);
936 expect(0xdeadbeef, color
[2]);
939 status
= GdipGetPathGradientSurroundColorCount(grad
, &count
);
943 GdipDeleteBrush((GpBrush
*)grad
);
946 static void test_pathgradientpath(void)
950 GpPathGradient
*grad
=NULL
;
952 status
= GdipCreatePathGradient(blendcount_ptf
, 2, WrapModeClamp
, &grad
);
955 status
= GdipGetPathGradientPath(grad
, NULL
);
956 expect(NotImplemented
, status
);
958 status
= GdipCreatePath(FillModeWinding
, &path
);
961 status
= GdipGetPathGradientPath(NULL
, path
);
962 expect(NotImplemented
, status
);
964 status
= GdipGetPathGradientPath(grad
, path
);
965 expect(NotImplemented
, status
);
967 status
= GdipDeletePath(path
);
970 status
= GdipDeleteBrush((GpBrush
*)grad
);
974 static void test_pathgradientcenterpoint(void)
976 static const GpPointF path_points
[] = {{0,0}, {3,0}, {0,4}};
978 GpPathGradient
*grad
;
981 status
= GdipCreatePathGradient(path_points
+1, 2, WrapModeClamp
, &grad
);
984 status
= GdipGetPathGradientCenterPoint(NULL
, &point
);
985 expect(InvalidParameter
, status
);
987 status
= GdipGetPathGradientCenterPoint(grad
, NULL
);
988 expect(InvalidParameter
, status
);
990 status
= GdipGetPathGradientCenterPoint(grad
, &point
);
992 expectf(1.5, point
.X
);
993 expectf(2.0, point
.Y
);
995 status
= GdipSetPathGradientCenterPoint(NULL
, &point
);
996 expect(InvalidParameter
, status
);
998 status
= GdipSetPathGradientCenterPoint(grad
, NULL
);
999 expect(InvalidParameter
, status
);
1003 status
= GdipSetPathGradientCenterPoint(grad
, &point
);
1006 point
.X
= point
.Y
= -1;
1007 status
= GdipGetPathGradientCenterPoint(grad
, &point
);
1009 expectf(10.0, point
.X
);
1010 expectf(15.0, point
.Y
);
1012 status
= GdipDeleteBrush((GpBrush
*)grad
);
1015 status
= GdipCreatePathGradient(path_points
, 3, WrapModeClamp
, &grad
);
1018 status
= GdipGetPathGradientCenterPoint(grad
, &point
);
1020 todo_wine
expectf(1.0, point
.X
);
1021 todo_wine
expectf(4.0/3.0, point
.Y
);
1023 status
= GdipDeleteBrush((GpBrush
*)grad
);
1027 static void test_pathgradientpresetblend(void)
1029 static const GpPointF path_points
[] = {{0,0}, {3,0}, {0,4}};
1031 GpPathGradient
*grad
;
1034 const REAL positions
[5] = {0.0f
, 0.2f
, 0.5f
, 0.8f
, 1.0f
};
1035 const REAL two_positions
[2] = {0.0f
, 1.0f
};
1036 const ARGB colors
[5] = {0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffffffff};
1037 REAL res_positions
[6] = {0.3f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
1038 ARGB res_colors
[6] = {0xdeadbeef, 0, 0, 0, 0};
1040 status
= GdipCreatePathGradient(path_points
+1, 2, WrapModeClamp
, &grad
);
1043 status
= GdipGetPathGradientPresetBlendCount(NULL
, &count
);
1044 expect(InvalidParameter
, status
);
1046 status
= GdipGetPathGradientPresetBlendCount(grad
, NULL
);
1047 expect(InvalidParameter
, status
);
1049 status
= GdipGetPathGradientPresetBlendCount(grad
, &count
);
1053 status
= GdipGetPathGradientPresetBlend(NULL
, res_colors
, res_positions
, 1);
1054 expect(InvalidParameter
, status
);
1056 status
= GdipGetPathGradientPresetBlend(grad
, NULL
, res_positions
, 1);
1057 expect(InvalidParameter
, status
);
1059 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, NULL
, 1);
1060 expect(InvalidParameter
, status
);
1062 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 0);
1063 expect(InvalidParameter
, status
);
1065 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, -1);
1066 expect(OutOfMemory
, status
);
1068 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 1);
1069 expect(InvalidParameter
, status
);
1071 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 2);
1072 expect(GenericError
, status
);
1074 status
= GdipSetPathGradientPresetBlend(NULL
, colors
, positions
, 5);
1075 expect(InvalidParameter
, status
);
1077 status
= GdipSetPathGradientPresetBlend(grad
, NULL
, positions
, 5);
1078 expect(InvalidParameter
, status
);
1082 /* crashes on windows xp */
1083 status
= GdipSetPathGradientPresetBlend(grad
, colors
, NULL
, 5);
1084 expect(InvalidParameter
, status
);
1087 status
= GdipSetPathGradientPresetBlend(grad
, colors
, positions
, 0);
1088 expect(InvalidParameter
, status
);
1090 status
= GdipSetPathGradientPresetBlend(grad
, colors
, positions
, -1);
1091 expect(InvalidParameter
, status
);
1093 status
= GdipSetPathGradientPresetBlend(grad
, colors
, positions
, 1);
1094 expect(InvalidParameter
, status
);
1096 /* leave off the 0.0 position */
1097 status
= GdipSetPathGradientPresetBlend(grad
, &colors
[1], &positions
[1], 4);
1098 expect(InvalidParameter
, status
);
1100 /* leave off the 1.0 position */
1101 status
= GdipSetPathGradientPresetBlend(grad
, colors
, positions
, 4);
1102 expect(InvalidParameter
, status
);
1104 status
= GdipSetPathGradientPresetBlend(grad
, colors
, positions
, 5);
1107 status
= GdipGetPathGradientPresetBlendCount(grad
, &count
);
1113 /* Native GdipGetPathGradientPresetBlend seems to copy starting from
1114 * the end of each array and do no bounds checking. This is so braindead
1115 * I'm not going to copy it. */
1117 res_colors
[0] = 0xdeadbeef;
1118 res_positions
[0] = 0.3;
1120 status
= GdipGetPathGradientPresetBlend(grad
, &res_colors
[1], &res_positions
[1], 4);
1123 expect(0xdeadbeef, res_colors
[0]);
1124 expectf(0.3, res_positions
[0]);
1128 expect(colors
[i
], res_colors
[i
]);
1129 expectf(positions
[i
], res_positions
[i
]);
1132 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 6);
1137 expect(colors
[i
], res_colors
[i
+1]);
1138 expectf(positions
[i
], res_positions
[i
+1]);
1142 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 5);
1147 expect(colors
[i
], res_colors
[i
]);
1148 expectf(positions
[i
], res_positions
[i
]);
1151 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 0);
1152 expect(InvalidParameter
, status
);
1154 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, -1);
1155 expect(OutOfMemory
, status
);
1157 status
= GdipGetPathGradientPresetBlend(grad
, res_colors
, res_positions
, 1);
1158 expect(InvalidParameter
, status
);
1160 status
= GdipSetPathGradientPresetBlend(grad
, colors
, two_positions
, 2);
1163 status
= GdipDeleteBrush((GpBrush
*)grad
);
1167 static void test_pathgradientblend(void)
1169 static const GpPointF path_points
[] = {{0,0}, {3,0}, {0,4}};
1170 GpPathGradient
*brush
;
1173 const REAL factors
[5] = {0.0f
, 0.1f
, 0.5f
, 0.9f
, 1.0f
};
1174 const REAL positions
[5] = {0.0f
, 0.2f
, 0.5f
, 0.8f
, 1.0f
};
1175 REAL res_factors
[6] = {0.3f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
1176 REAL res_positions
[6] = {0.3f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
1178 status
= GdipCreatePathGradient(path_points
, 3, WrapModeClamp
, &brush
);
1181 status
= GdipGetPathGradientBlendCount(NULL
, &count
);
1182 expect(InvalidParameter
, status
);
1184 status
= GdipGetPathGradientBlendCount(brush
, NULL
);
1185 expect(InvalidParameter
, status
);
1187 status
= GdipGetPathGradientBlendCount(brush
, &count
);
1191 status
= GdipGetPathGradientBlend(NULL
, res_factors
, res_positions
, 1);
1192 expect(InvalidParameter
, status
);
1194 status
= GdipGetPathGradientBlend(brush
, NULL
, res_positions
, 1);
1195 expect(InvalidParameter
, status
);
1197 status
= GdipGetPathGradientBlend(brush
, res_factors
, NULL
, 1);
1198 expect(InvalidParameter
, status
);
1200 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 0);
1201 expect(InvalidParameter
, status
);
1203 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, -1);
1204 expect(InvalidParameter
, status
);
1206 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 1);
1209 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 2);
1212 status
= GdipSetPathGradientBlend(NULL
, factors
, positions
, 5);
1213 expect(InvalidParameter
, status
);
1215 status
= GdipSetPathGradientBlend(brush
, NULL
, positions
, 5);
1216 expect(InvalidParameter
, status
);
1218 status
= GdipSetPathGradientBlend(brush
, factors
, NULL
, 5);
1219 expect(InvalidParameter
, status
);
1221 status
= GdipSetPathGradientBlend(brush
, factors
, positions
, 0);
1222 expect(InvalidParameter
, status
);
1224 status
= GdipSetPathGradientBlend(brush
, factors
, positions
, -1);
1225 expect(InvalidParameter
, status
);
1227 /* leave off the 0.0 position */
1228 status
= GdipSetPathGradientBlend(brush
, &factors
[1], &positions
[1], 4);
1229 expect(InvalidParameter
, status
);
1231 /* leave off the 1.0 position */
1232 status
= GdipSetPathGradientBlend(brush
, factors
, positions
, 4);
1233 expect(InvalidParameter
, status
);
1235 status
= GdipSetPathGradientBlend(brush
, factors
, positions
, 5);
1238 status
= GdipGetPathGradientBlendCount(brush
, &count
);
1242 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 4);
1243 expect(InsufficientBuffer
, status
);
1245 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 5);
1250 expectf(factors
[i
], res_factors
[i
]);
1251 expectf(positions
[i
], res_positions
[i
]);
1254 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 6);
1257 status
= GdipSetPathGradientBlend(brush
, factors
, positions
, 1);
1260 status
= GdipGetPathGradientBlendCount(brush
, &count
);
1264 status
= GdipGetPathGradientBlend(brush
, res_factors
, res_positions
, 1);
1267 status
= GdipDeleteBrush((GpBrush
*)brush
);
1273 struct GdiplusStartupInput gdiplusStartupInput
;
1274 ULONG_PTR gdiplusToken
;
1276 gdiplusStartupInput
.GdiplusVersion
= 1;
1277 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1278 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1279 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1281 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1283 test_constructor_destructor();
1285 test_gradientblendcount();
1291 test_gradientgetrect();
1293 test_linelinearblend();
1294 test_gradientsurroundcolorcount();
1295 test_pathgradientpath();
1296 test_pathgradientcenterpoint();
1297 test_pathgradientpresetblend();
1298 test_pathgradientblend();
1300 GdiplusShutdown(gdiplusToken
);