mshtml: Added IHTMLWindow2::focus implementation.
[wine] / dlls / gdiplus / tests / brush.c
1 /*
2  * Unit test suite for brushes
3  *
4  * Copyright (C) 2007 Google (Evan Stade)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wine/test.h"
24 #include <math.h>
25
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)
28
29 static void test_constructor_destructor(void)
30 {
31     GpStatus status;
32     GpSolidFill *brush = NULL;
33
34     status = GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
35     expect(Ok, status);
36     ok(brush != NULL, "Expected brush to be initialized\n");
37
38     status = GdipDeleteBrush(NULL);
39     expect(InvalidParameter, status);
40
41     status = GdipDeleteBrush((GpBrush*) brush);
42     expect(Ok, status);
43 }
44
45 static void test_type(void)
46 {
47     GpStatus status;
48     GpBrushType bt;
49     GpSolidFill *brush = NULL;
50
51     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
52
53     status = GdipGetBrushType((GpBrush*)brush, &bt);
54     expect(Ok, status);
55     expect(BrushTypeSolidColor, bt);
56
57     GdipDeleteBrush((GpBrush*) brush);
58 }
59 static GpPointF blendcount_ptf[] = {{0.0, 0.0},
60                                     {50.0, 50.0}};
61 static void test_gradientblendcount(void)
62 {
63     GpStatus status;
64     GpPathGradient *brush;
65     INT count;
66
67     status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &brush);
68     expect(Ok, status);
69
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);
76
77     status = GdipGetPathGradientBlendCount(brush, &count);
78     expect(Ok, status);
79     expect(1, count);
80
81     GdipDeleteBrush((GpBrush*) brush);
82 }
83
84 static GpPointF getblend_ptf[] = {{0.0, 0.0},
85                                   {50.0, 50.0}};
86 static void test_getblend(void)
87 {
88     GpStatus status;
89     GpPathGradient *brush;
90     REAL blends[4];
91     REAL pos[4];
92
93     status = GdipCreatePathGradient(getblend_ptf, 2, WrapModeClamp, &brush);
94     expect(Ok, status);
95
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);
107
108     blends[0] = (REAL)0xdeadbeef;
109     pos[0]    = (REAL)0xdeadbeef;
110     status = GdipGetPathGradientBlend(brush, blends, pos, 1);
111     expect(Ok, status);
112     expectf(1.0, blends[0]);
113     expectf((REAL)0xdeadbeef, pos[0]);
114
115     GdipDeleteBrush((GpBrush*) brush);
116 }
117
118 static GpPointF getbounds_ptf[] = {{0.0, 20.0},
119                                    {50.0, 50.0},
120                                    {21.0, 25.0},
121                                    {25.0, 46.0}};
122 static void test_getbounds(void)
123 {
124     GpStatus status;
125     GpPathGradient *brush;
126     GpRectF bounds;
127
128     status = GdipCreatePathGradient(getbounds_ptf, 4, WrapModeClamp, &brush);
129     expect(Ok, status);
130
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);
137
138     status = GdipGetPathGradientRect(brush, &bounds);
139     expect(Ok, status);
140     expectf(0.0, bounds.X);
141     expectf(20.0, bounds.Y);
142     expectf(50.0, bounds.Width);
143     expectf(30.0, bounds.Height);
144
145     GdipDeleteBrush((GpBrush*) brush);
146 }
147
148 static void test_getgamma(void)
149 {
150     GpStatus status;
151     GpLineGradient *line;
152     GpPointF start, end;
153     BOOL gamma;
154
155     start.X = start.Y = 0.0;
156     end.X = end.Y = 100.0;
157
158     status = GdipCreateLineBrush(&start, &end, (ARGB)0xdeadbeef, 0xdeadbeef, WrapModeTile, &line);
159     expect(Ok, status);
160
161     /* NULL arguments */
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);
168
169     GdipDeleteBrush((GpBrush*)line);
170 }
171
172 static void test_transform(void)
173 {
174     GpStatus status;
175     GpTexture *texture;
176     GpGraphics *graphics = NULL;
177     GpBitmap *bitmap;
178     HDC hdc = GetDC(0);
179     GpMatrix *m, *m1;
180     BOOL res;
181
182     status = GdipCreateMatrix2(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, &m);
183     expect(Ok, status);
184
185     status = GdipCreateFromHDC(hdc, &graphics);
186     expect(Ok, status);
187     status = GdipCreateBitmapFromGraphics(1, 1, graphics, &bitmap);
188     expect(Ok, status);
189
190     status = GdipCreateTexture((GpImage*)bitmap, WrapModeTile, &texture);
191     expect(Ok, status);
192
193     /* NULL */
194     status = GdipGetTextureTransform(NULL, NULL);
195     expect(InvalidParameter, status);
196     status = GdipGetTextureTransform(texture, NULL);
197     expect(InvalidParameter, status);
198
199     /* get default value - identity matrix */
200     status = GdipGetTextureTransform(texture, m);
201     expect(Ok, status);
202     status = GdipIsMatrixIdentity(m, &res);
203     expect(Ok, status);
204     expect(TRUE, res);
205     /* set and get then */
206     status = GdipCreateMatrix2(2.0, 0.0, 0.0, 2.0, 0.0, 0.0, &m1);
207     expect(Ok, status);
208     status = GdipSetTextureTransform(texture, m1);
209     expect(Ok, status);
210     status = GdipGetTextureTransform(texture, m);
211     expect(Ok, status);
212     status = GdipIsMatrixEqual(m, m1, &res);
213     expect(Ok, status);
214     expect(TRUE, res);
215     /* reset */
216     status = GdipResetTextureTransform(texture);
217     expect(Ok, status);
218     status = GdipGetTextureTransform(texture, m);
219     expect(Ok, status);
220     status = GdipIsMatrixIdentity(m, &res);
221     expect(Ok, status);
222     expect(TRUE, res);
223
224     status = GdipDeleteBrush((GpBrush*)texture);
225     expect(Ok, status);
226
227     status = GdipDeleteMatrix(m1);
228     expect(Ok, status);
229     status = GdipDeleteMatrix(m);
230     expect(Ok, status);
231     status = GdipDisposeImage((GpImage*)bitmap);
232     expect(Ok, status);
233     status = GdipDeleteGraphics(graphics);
234     expect(Ok, status);
235     ReleaseDC(0, hdc);
236 }
237
238 static void test_texturewrap(void)
239 {
240     GpStatus status;
241     GpTexture *texture;
242     GpGraphics *graphics = NULL;
243     GpBitmap *bitmap;
244     HDC hdc = GetDC(0);
245     GpWrapMode wrap;
246
247     status = GdipCreateFromHDC(hdc, &graphics);
248     expect(Ok, status);
249     status = GdipCreateBitmapFromGraphics(1, 1, graphics, &bitmap);
250     expect(Ok, status);
251
252     status = GdipCreateTexture((GpImage*)bitmap, WrapModeTile, &texture);
253     expect(Ok, status);
254
255     /* NULL */
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);
262
263     /* get */
264     wrap = WrapModeClamp;
265     status = GdipGetTextureWrapMode(texture, &wrap);
266     expect(Ok, status);
267     expect(WrapModeTile, wrap);
268     /* set, then get */
269     wrap = WrapModeClamp;
270     status = GdipSetTextureWrapMode(texture, wrap);
271     expect(Ok, status);
272     wrap = WrapModeTile;
273     status = GdipGetTextureWrapMode(texture, &wrap);
274     expect(Ok, status);
275     expect(WrapModeClamp, wrap);
276
277     status = GdipDeleteBrush((GpBrush*)texture);
278     expect(Ok, status);
279     status = GdipDisposeImage((GpImage*)bitmap);
280     expect(Ok, status);
281     status = GdipDeleteGraphics(graphics);
282     expect(Ok, status);
283     ReleaseDC(0, hdc);
284 }
285
286 static void test_gradientgetrect(void)
287 {
288     GpLineGradient *brush;
289     GpMatrix *transform;
290     REAL elements[6];
291     GpRectF rectf;
292     GpStatus status;
293     GpPointF pt1, pt2;
294
295     status = GdipCreateMatrix(&transform);
296     expect(Ok, status);
297
298     pt1.X = pt1.Y = 1.0;
299     pt2.X = pt2.Y = 100.0;
300     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
301     expect(Ok, status);
302     memset(&rectf, 0, sizeof(GpRectF));
303     status = GdipGetLineRect(brush, &rectf);
304     expect(Ok, status);
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);
311     if (status == Ok)
312     {
313         status = GdipGetMatrixElements(transform, elements);
314         expectf(1.0, elements[0]);
315         expectf(1.0, elements[1]);
316         expectf(-1.0, elements[2]);
317         expectf(1.0, elements[3]);
318         expectf(50.50, elements[4]);
319         expectf(-50.50, elements[5]);
320     }
321     status = GdipDeleteBrush((GpBrush*)brush);
322     /* vertical gradient */
323     pt1.X = pt1.Y = pt2.X = 0.0;
324     pt2.Y = 10.0;
325     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
326     expect(Ok, status);
327     memset(&rectf, 0, sizeof(GpRectF));
328     status = GdipGetLineRect(brush, &rectf);
329     expect(Ok, status);
330     expectf(-5.0, rectf.X);
331     expectf(0.0, rectf.Y);
332     expectf(10.0, rectf.Width);
333     expectf(10.0, rectf.Height);
334     status = GdipGetLineTransform(brush, transform);
335     todo_wine expect(Ok, status);
336     if (status == Ok)
337     {
338         status = GdipGetMatrixElements(transform, elements);
339         expectf(0.0, elements[0]);
340         expectf(1.0, elements[1]);
341         expectf(-1.0, elements[2]);
342         expectf(0.0, elements[3]);
343         expectf(5.0, elements[4]);
344         expectf(5.0, elements[5]);
345     }
346     status = GdipDeleteBrush((GpBrush*)brush);
347     /* horizontal gradient */
348     pt1.X = pt1.Y = pt2.Y = 0.0;
349     pt2.X = 10.0;
350     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
351     expect(Ok, status);
352     memset(&rectf, 0, sizeof(GpRectF));
353     status = GdipGetLineRect(brush, &rectf);
354     expect(Ok, status);
355     expectf(0.0, rectf.X);
356     expectf(-5.0, rectf.Y);
357     expectf(10.0, rectf.Width);
358     expectf(10.0, rectf.Height);
359     status = GdipGetLineTransform(brush, transform);
360     todo_wine expect(Ok, status);
361     if (status == Ok)
362     {
363         status = GdipGetMatrixElements(transform, elements);
364         expectf(1.0, elements[0]);
365         expectf(0.0, elements[1]);
366         expectf(0.0, elements[2]);
367         expectf(1.0, elements[3]);
368         expectf(0.0, elements[4]);
369         expectf(0.0, elements[5]);
370     }
371     status = GdipDeleteBrush((GpBrush*)brush);
372     /* slope = -1 */
373     pt1.X = pt1.Y = 0.0;
374     pt2.X = 20.0;
375     pt2.Y = -20.0;
376     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
377     expect(Ok, status);
378     memset(&rectf, 0, sizeof(GpRectF));
379     status = GdipGetLineRect(brush, &rectf);
380     expect(Ok, status);
381     expectf(0.0, rectf.X);
382     expectf(-20.0, rectf.Y);
383     expectf(20.0, rectf.Width);
384     expectf(20.0, rectf.Height);
385     status = GdipGetLineTransform(brush, transform);
386     todo_wine expect(Ok, status);
387     if (status == Ok)
388     {
389         status = GdipGetMatrixElements(transform, elements);
390         expectf(1.0, elements[0]);
391         expectf(-1.0, elements[1]);
392         expectf(1.0, elements[2]);
393         expectf(1.0, elements[3]);
394         expectf(10.0, elements[4]);
395         expectf(10.0, elements[5]);
396     }
397     status = GdipDeleteBrush((GpBrush*)brush);
398     /* slope = 1/100 */
399     pt1.X = pt1.Y = 0.0;
400     pt2.X = 100.0;
401     pt2.Y = 1.0;
402     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
403     expect(Ok, status);
404     memset(&rectf, 0, sizeof(GpRectF));
405     status = GdipGetLineRect(brush, &rectf);
406     expect(Ok, status);
407     expectf(0.0, rectf.X);
408     expectf(0.0, rectf.Y);
409     expectf(100.0, rectf.Width);
410     expectf(1.0, rectf.Height);
411     status = GdipGetLineTransform(brush, transform);
412     todo_wine expect(Ok, status);
413     if (status == Ok)
414     {
415         status = GdipGetMatrixElements(transform, elements);
416         expectf(1.0, elements[0]);
417         expectf(0.01, elements[1]);
418         expectf(-0.02, elements[2]);
419         /* expectf(2.0, elements[3]); */
420         expectf(0.01, elements[4]);
421         /* expectf(-1.0, elements[5]); */
422     }
423     status = GdipDeleteBrush((GpBrush*)brush);
424     /* zero height rect */
425     rectf.X = rectf.Y = 10.0;
426     rectf.Width = 100.0;
427     rectf.Height = 0.0;
428     status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeVertical,
429         WrapModeTile, &brush);
430     expect(OutOfMemory, status);
431     /* zero width rect */
432     rectf.X = rectf.Y = 10.0;
433     rectf.Width = 0.0;
434     rectf.Height = 100.0;
435     status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeHorizontal,
436         WrapModeTile, &brush);
437     expect(OutOfMemory, status);
438     /* from rect with LinearGradientModeHorizontal */
439     rectf.X = rectf.Y = 10.0;
440     rectf.Width = rectf.Height = 100.0;
441     status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeHorizontal,
442         WrapModeTile, &brush);
443     expect(Ok, status);
444     memset(&rectf, 0, sizeof(GpRectF));
445     status = GdipGetLineRect(brush, &rectf);
446     expect(Ok, status);
447     expectf(10.0, rectf.X);
448     expectf(10.0, rectf.Y);
449     expectf(100.0, rectf.Width);
450     expectf(100.0, rectf.Height);
451     status = GdipGetLineTransform(brush, transform);
452     todo_wine expect(Ok, status);
453     if (status == Ok)
454     {
455         status = GdipGetMatrixElements(transform, elements);
456         expectf(1.0, elements[0]);
457         expectf(0.0, elements[1]);
458         expectf(0.0, elements[2]);
459         expectf(1.0, elements[3]);
460         expectf(0.0, elements[4]);
461         expectf(0.0, elements[5]);
462     }
463     status = GdipDeleteBrush((GpBrush*)brush);
464     /* passing negative Width/Height to LinearGradientModeHorizontal */
465     rectf.X = rectf.Y = 10.0;
466     rectf.Width = rectf.Height = -100.0;
467     status = GdipCreateLineBrushFromRect(&rectf, 0, 0, LinearGradientModeHorizontal,
468         WrapModeTile, &brush);
469     expect(Ok, status);
470     memset(&rectf, 0, sizeof(GpRectF));
471     status = GdipGetLineRect(brush, &rectf);
472     expect(Ok, status);
473     expectf(10.0, rectf.X);
474     expectf(10.0, rectf.Y);
475     expectf(-100.0, rectf.Width);
476     expectf(-100.0, rectf.Height);
477     status = GdipGetLineTransform(brush, transform);
478     todo_wine expect(Ok, status);
479     if (status == Ok)
480     {
481         status = GdipGetMatrixElements(transform, elements);
482         expectf(1.0, elements[0]);
483         expectf(0.0, elements[1]);
484         expectf(0.0, elements[2]);
485         expectf(1.0, elements[3]);
486         expectf(0.0, elements[4]);
487         expectf(0.0, elements[5]);
488     }
489     status = GdipDeleteBrush((GpBrush*)brush);
490
491     GdipDeleteMatrix(transform);
492 }
493
494 static void test_lineblend(void)
495 {
496     GpLineGradient *brush;
497     GpStatus status;
498     GpPointF pt1, pt2;
499     INT count=10;
500     int i;
501     const REAL factors[5] = {0.0f, 0.1f, 0.5f, 0.9f, 1.0f};
502     const REAL positions[5] = {0.0f, 0.2f, 0.5f, 0.8f, 1.0f};
503     const REAL two_positions[2] = {0.0f, 1.0f};
504     const ARGB colors[5] = {0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffffffff};
505     REAL res_factors[6] = {0.3f, 0.0f, 0.0f, 0.0f, 0.0f};
506     REAL res_positions[6] = {0.3f, 0.0f, 0.0f, 0.0f, 0.0f};
507     ARGB res_colors[6] = {0xdeadbeef, 0, 0, 0, 0};
508
509     pt1.X = pt1.Y = pt2.Y = pt2.X = 1.0;
510     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
511     expect(OutOfMemory, status);
512
513     pt1.X = pt1.Y = 1.0;
514     pt2.X = pt2.Y = 100.0;
515     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
516     expect(Ok, status);
517
518     status = GdipGetLineBlendCount(NULL, &count);
519     expect(InvalidParameter, status);
520
521     status = GdipGetLineBlendCount(brush, NULL);
522     expect(InvalidParameter, status);
523
524     status = GdipGetLineBlendCount(brush, &count);
525     expect(Ok, status);
526     expect(1, count);
527
528     status = GdipGetLineBlend(NULL, res_factors, res_positions, 1);
529     expect(InvalidParameter, status);
530
531     status = GdipGetLineBlend(brush, NULL, res_positions, 1);
532     expect(InvalidParameter, status);
533
534     status = GdipGetLineBlend(brush, res_factors, NULL, 1);
535     expect(InvalidParameter, status);
536
537     status = GdipGetLineBlend(brush, res_factors, res_positions, 0);
538     expect(InvalidParameter, status);
539
540     status = GdipGetLineBlend(brush, res_factors, res_positions, -1);
541     expect(InvalidParameter, status);
542
543     status = GdipGetLineBlend(brush, res_factors, res_positions, 1);
544     expect(Ok, status);
545
546     status = GdipGetLineBlend(brush, res_factors, res_positions, 2);
547     expect(Ok, status);
548
549     status = GdipSetLineBlend(NULL, factors, positions, 5);
550     expect(InvalidParameter, status);
551
552     status = GdipSetLineBlend(brush, NULL, positions, 5);
553     expect(InvalidParameter, status);
554
555     status = GdipSetLineBlend(brush, factors, NULL, 5);
556     expect(InvalidParameter, status);
557
558     status = GdipSetLineBlend(brush, factors, positions, 0);
559     expect(InvalidParameter, status);
560
561     status = GdipSetLineBlend(brush, factors, positions, -1);
562     expect(InvalidParameter, status);
563
564     /* leave off the 0.0 position */
565     status = GdipSetLineBlend(brush, &factors[1], &positions[1], 4);
566     expect(InvalidParameter, status);
567
568     /* leave off the 1.0 position */
569     status = GdipSetLineBlend(brush, factors, positions, 4);
570     expect(InvalidParameter, status);
571
572     status = GdipSetLineBlend(brush, factors, positions, 5);
573     expect(Ok, status);
574
575     status = GdipGetLineBlendCount(brush, &count);
576     expect(Ok, status);
577     expect(5, count);
578
579     status = GdipGetLineBlend(brush, res_factors, res_positions, 4);
580     expect(InsufficientBuffer, status);
581
582     status = GdipGetLineBlend(brush, res_factors, res_positions, 5);
583     expect(Ok, status);
584
585     for (i=0; i<5; i++)
586     {
587         expectf(factors[i], res_factors[i]);
588         expectf(positions[i], res_positions[i]);
589     }
590
591     status = GdipGetLineBlend(brush, res_factors, res_positions, 6);
592     expect(Ok, status);
593
594     status = GdipSetLineBlend(brush, factors, positions, 1);
595     expect(Ok, status);
596
597     status = GdipGetLineBlendCount(brush, &count);
598     expect(Ok, status);
599     expect(1, count);
600
601     status = GdipGetLineBlend(brush, res_factors, res_positions, 1);
602     expect(Ok, status);
603
604     status = GdipGetLinePresetBlendCount(NULL, &count);
605     expect(InvalidParameter, status);
606
607     status = GdipGetLinePresetBlendCount(brush, NULL);
608     expect(InvalidParameter, status);
609
610     status = GdipGetLinePresetBlendCount(brush, &count);
611     expect(Ok, status);
612     expect(0, count);
613
614     status = GdipGetLinePresetBlend(NULL, res_colors, res_positions, 1);
615     expect(InvalidParameter, status);
616
617     status = GdipGetLinePresetBlend(brush, NULL, res_positions, 1);
618     expect(InvalidParameter, status);
619
620     status = GdipGetLinePresetBlend(brush, res_colors, NULL, 1);
621     expect(InvalidParameter, status);
622
623     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 0);
624     expect(InvalidParameter, status);
625
626     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, -1);
627     expect(InvalidParameter, status);
628
629     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 1);
630     expect(InvalidParameter, status);
631
632     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 2);
633     expect(GenericError, status);
634
635     status = GdipSetLinePresetBlend(NULL, colors, positions, 5);
636     expect(InvalidParameter, status);
637
638     status = GdipSetLinePresetBlend(brush, NULL, positions, 5);
639     expect(InvalidParameter, status);
640
641     status = GdipSetLinePresetBlend(brush, colors, NULL, 5);
642     expect(InvalidParameter, status);
643
644     status = GdipSetLinePresetBlend(brush, colors, positions, 0);
645     expect(InvalidParameter, status);
646
647     status = GdipSetLinePresetBlend(brush, colors, positions, -1);
648     expect(InvalidParameter, status);
649
650     status = GdipSetLinePresetBlend(brush, colors, positions, 1);
651     expect(InvalidParameter, status);
652
653     /* leave off the 0.0 position */
654     status = GdipSetLinePresetBlend(brush, &colors[1], &positions[1], 4);
655     expect(InvalidParameter, status);
656
657     /* leave off the 1.0 position */
658     status = GdipSetLinePresetBlend(brush, colors, positions, 4);
659     expect(InvalidParameter, status);
660
661     status = GdipSetLinePresetBlend(brush, colors, positions, 5);
662     expect(Ok, status);
663
664     status = GdipGetLinePresetBlendCount(brush, &count);
665     expect(Ok, status);
666     expect(5, count);
667
668     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 4);
669     expect(InsufficientBuffer, status);
670
671     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 5);
672     expect(Ok, status);
673
674     for (i=0; i<5; i++)
675     {
676         expect(colors[i], res_colors[i]);
677         expectf(positions[i], res_positions[i]);
678     }
679
680     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 6);
681     expect(Ok, status);
682
683     status = GdipSetLinePresetBlend(brush, colors, two_positions, 2);
684     expect(Ok, status);
685
686     status = GdipDeleteBrush((GpBrush*)brush);
687     expect(Ok, status);
688 }
689
690 static void test_linelinearblend(void)
691 {
692     GpLineGradient *brush;
693     GpStatus status;
694     GpPointF pt1, pt2;
695     INT count=10;
696     REAL res_factors[3] = {0.3f};
697     REAL res_positions[3] = {0.3f};
698
699     status = GdipSetLineLinearBlend(NULL, 0.6, 0.8);
700     expect(InvalidParameter, status);
701
702     pt1.X = pt1.Y = 1.0;
703     pt2.X = pt2.Y = 100.0;
704     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
705     expect(Ok, status);
706
707
708     status = GdipSetLineLinearBlend(brush, 0.6, 0.8);
709     expect(Ok, status);
710
711     status = GdipGetLineBlendCount(brush, &count);
712     expect(Ok, status);
713     expect(3, count);
714
715     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
716     expect(Ok, status);
717     expectf(0.0, res_factors[0]);
718     expectf(0.0, res_positions[0]);
719     expectf(0.8, res_factors[1]);
720     expectf(0.6, res_positions[1]);
721     expectf(0.0, res_factors[2]);
722     expectf(1.0, res_positions[2]);
723
724
725     status = GdipSetLineLinearBlend(brush, 0.0, 0.8);
726     expect(Ok, status);
727
728     status = GdipGetLineBlendCount(brush, &count);
729     expect(Ok, status);
730     expect(2, count);
731
732     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
733     expect(Ok, status);
734     expectf(0.8, res_factors[0]);
735     expectf(0.0, res_positions[0]);
736     expectf(0.0, res_factors[1]);
737     expectf(1.0, res_positions[1]);
738
739
740     status = GdipSetLineLinearBlend(brush, 1.0, 0.8);
741     expect(Ok, status);
742
743     status = GdipGetLineBlendCount(brush, &count);
744     expect(Ok, status);
745     expect(2, count);
746
747     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
748     expect(Ok, status);
749     expectf(0.0, res_factors[0]);
750     expectf(0.0, res_positions[0]);
751     expectf(0.8, res_factors[1]);
752     expectf(1.0, res_positions[1]);
753
754     status = GdipDeleteBrush((GpBrush*)brush);
755     expect(Ok, status);
756 }
757
758 static void test_gradientsurroundcolorcount(void)
759 {
760     GpStatus status;
761     GpPathGradient *grad;
762     ARGB *color;
763     INT count = 3;
764
765     status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad);
766     expect(Ok, status);
767
768     color = GdipAlloc(sizeof(ARGB[3]));
769
770     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
771     expect(InvalidParameter, status);
772     GdipFree(color);
773
774     count = 2;
775
776     color = GdipAlloc(sizeof(ARGB[2]));
777
778     color[0] = 0x00ff0000;
779     color[1] = 0x0000ff00;
780
781     status = GdipSetPathGradientSurroundColorsWithCount(NULL, color, &count);
782     expect(InvalidParameter, status);
783
784     status = GdipSetPathGradientSurroundColorsWithCount(grad, NULL, &count);
785     expect(InvalidParameter, status);
786
787     /* WinXP crashes on this test */
788     if(0)
789     {
790         status = GdipSetPathGradientSurroundColorsWithCount(grad, color, NULL);
791         expect(InvalidParameter, status);
792     }
793
794     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
795     todo_wine expect(Ok, status);
796     expect(2, count);
797
798     status = GdipGetPathGradientSurroundColorCount(NULL, &count);
799     expect(InvalidParameter, status);
800
801     status = GdipGetPathGradientSurroundColorCount(grad, NULL);
802     expect(InvalidParameter, status);
803
804     count = 0;
805     status = GdipGetPathGradientSurroundColorCount(grad, &count);
806     todo_wine expect(Ok, status);
807     todo_wine expect(2, count);
808
809     GdipFree(color);
810     GdipDeleteBrush((GpBrush*)grad);
811 }
812
813 START_TEST(brush)
814 {
815     struct GdiplusStartupInput gdiplusStartupInput;
816     ULONG_PTR gdiplusToken;
817
818     gdiplusStartupInput.GdiplusVersion              = 1;
819     gdiplusStartupInput.DebugEventCallback          = NULL;
820     gdiplusStartupInput.SuppressBackgroundThread    = 0;
821     gdiplusStartupInput.SuppressExternalCodecs      = 0;
822
823     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
824
825     test_constructor_destructor();
826     test_type();
827     test_gradientblendcount();
828     test_getblend();
829     test_getbounds();
830     test_getgamma();
831     test_transform();
832     test_texturewrap();
833     test_gradientgetrect();
834     test_lineblend();
835     test_linelinearblend();
836     test_gradientsurroundcolorcount();
837
838     GdiplusShutdown(gdiplusToken);
839 }