kernel32: GetModuleHandleEx already clears the module handle on failure.
[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         expect(Ok, status);
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]);
321     }
322     status = GdipDeleteBrush((GpBrush*)brush);
323     expect(Ok, status);
324     /* vertical gradient */
325     pt1.X = pt1.Y = pt2.X = 0.0;
326     pt2.Y = 10.0;
327     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
328     expect(Ok, status);
329     memset(&rectf, 0, sizeof(GpRectF));
330     status = GdipGetLineRect(brush, &rectf);
331     expect(Ok, status);
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);
338     if (status == Ok)
339     {
340         status = GdipGetMatrixElements(transform, elements);
341         expect(Ok, status);
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]);
348     }
349     status = GdipDeleteBrush((GpBrush*)brush);
350     expect(Ok, status);
351     /* horizontal gradient */
352     pt1.X = pt1.Y = pt2.Y = 0.0;
353     pt2.X = 10.0;
354     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
355     expect(Ok, status);
356     memset(&rectf, 0, sizeof(GpRectF));
357     status = GdipGetLineRect(brush, &rectf);
358     expect(Ok, status);
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);
365     if (status == Ok)
366     {
367         status = GdipGetMatrixElements(transform, elements);
368         expect(Ok, status);
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]);
375     }
376     status = GdipDeleteBrush((GpBrush*)brush);
377     expect(Ok, status);
378     /* slope = -1 */
379     pt1.X = pt1.Y = 0.0;
380     pt2.X = 20.0;
381     pt2.Y = -20.0;
382     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
383     expect(Ok, status);
384     memset(&rectf, 0, sizeof(GpRectF));
385     status = GdipGetLineRect(brush, &rectf);
386     expect(Ok, status);
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);
393     if (status == Ok)
394     {
395         status = GdipGetMatrixElements(transform, elements);
396         expect(Ok, status);
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]);
403     }
404     status = GdipDeleteBrush((GpBrush*)brush);
405     expect(Ok, status);
406     /* slope = 1/100 */
407     pt1.X = pt1.Y = 0.0;
408     pt2.X = 100.0;
409     pt2.Y = 1.0;
410     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
411     expect(Ok, status);
412     memset(&rectf, 0, sizeof(GpRectF));
413     status = GdipGetLineRect(brush, &rectf);
414     expect(Ok, status);
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);
421     if (status == Ok)
422     {
423         status = GdipGetMatrixElements(transform, elements);
424         expect(Ok,status);
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]); */
431     }
432     status = GdipDeleteBrush((GpBrush*)brush);
433     expect(Ok,status);
434     /* zero height rect */
435     rectf.X = rectf.Y = 10.0;
436     rectf.Width = 100.0;
437     rectf.Height = 0.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;
443     rectf.Width = 0.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);
453     expect(Ok, status);
454     memset(&rectf, 0, sizeof(GpRectF));
455     status = GdipGetLineRect(brush, &rectf);
456     expect(Ok, status);
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);
463     if (status == Ok)
464     {
465         status = GdipGetMatrixElements(transform, elements);
466         expect(Ok,status);
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]);
473     }
474     status = GdipDeleteBrush((GpBrush*)brush);
475     expect(Ok,status);
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);
481     expect(Ok, status);
482     memset(&rectf, 0, sizeof(GpRectF));
483     status = GdipGetLineRect(brush, &rectf);
484     expect(Ok, status);
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);
491     if (status == Ok)
492     {
493         status = GdipGetMatrixElements(transform, elements);
494         expect(Ok,status);
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]);
501     }
502     status = GdipDeleteBrush((GpBrush*)brush);
503     expect(Ok,status);
504
505     GdipDeleteMatrix(transform);
506 }
507
508 static void test_lineblend(void)
509 {
510     GpLineGradient *brush;
511     GpStatus status;
512     GpPointF pt1, pt2;
513     INT count=10;
514     int i;
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};
522
523     pt1.X = pt1.Y = pt2.Y = pt2.X = 1.0;
524     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
525     expect(OutOfMemory, status);
526
527     pt1.X = pt1.Y = 1.0;
528     pt2.X = pt2.Y = 100.0;
529     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
530     expect(Ok, status);
531
532     status = GdipGetLineBlendCount(NULL, &count);
533     expect(InvalidParameter, status);
534
535     status = GdipGetLineBlendCount(brush, NULL);
536     expect(InvalidParameter, status);
537
538     status = GdipGetLineBlendCount(brush, &count);
539     expect(Ok, status);
540     expect(1, count);
541
542     status = GdipGetLineBlend(NULL, res_factors, res_positions, 1);
543     expect(InvalidParameter, status);
544
545     status = GdipGetLineBlend(brush, NULL, res_positions, 1);
546     expect(InvalidParameter, status);
547
548     status = GdipGetLineBlend(brush, res_factors, NULL, 1);
549     expect(InvalidParameter, status);
550
551     status = GdipGetLineBlend(brush, res_factors, res_positions, 0);
552     expect(InvalidParameter, status);
553
554     status = GdipGetLineBlend(brush, res_factors, res_positions, -1);
555     expect(InvalidParameter, status);
556
557     status = GdipGetLineBlend(brush, res_factors, res_positions, 1);
558     expect(Ok, status);
559
560     status = GdipGetLineBlend(brush, res_factors, res_positions, 2);
561     expect(Ok, status);
562
563     status = GdipSetLineBlend(NULL, factors, positions, 5);
564     expect(InvalidParameter, status);
565
566     status = GdipSetLineBlend(brush, NULL, positions, 5);
567     expect(InvalidParameter, status);
568
569     status = GdipSetLineBlend(brush, factors, NULL, 5);
570     expect(InvalidParameter, status);
571
572     status = GdipSetLineBlend(brush, factors, positions, 0);
573     expect(InvalidParameter, status);
574
575     status = GdipSetLineBlend(brush, factors, positions, -1);
576     expect(InvalidParameter, status);
577
578     /* leave off the 0.0 position */
579     status = GdipSetLineBlend(brush, &factors[1], &positions[1], 4);
580     expect(InvalidParameter, status);
581
582     /* leave off the 1.0 position */
583     status = GdipSetLineBlend(brush, factors, positions, 4);
584     expect(InvalidParameter, status);
585
586     status = GdipSetLineBlend(brush, factors, positions, 5);
587     expect(Ok, status);
588
589     status = GdipGetLineBlendCount(brush, &count);
590     expect(Ok, status);
591     expect(5, count);
592
593     status = GdipGetLineBlend(brush, res_factors, res_positions, 4);
594     expect(InsufficientBuffer, status);
595
596     status = GdipGetLineBlend(brush, res_factors, res_positions, 5);
597     expect(Ok, status);
598
599     for (i=0; i<5; i++)
600     {
601         expectf(factors[i], res_factors[i]);
602         expectf(positions[i], res_positions[i]);
603     }
604
605     status = GdipGetLineBlend(brush, res_factors, res_positions, 6);
606     expect(Ok, status);
607
608     status = GdipSetLineBlend(brush, factors, positions, 1);
609     expect(Ok, status);
610
611     status = GdipGetLineBlendCount(brush, &count);
612     expect(Ok, status);
613     expect(1, count);
614
615     status = GdipGetLineBlend(brush, res_factors, res_positions, 1);
616     expect(Ok, status);
617
618     status = GdipGetLinePresetBlendCount(NULL, &count);
619     expect(InvalidParameter, status);
620
621     status = GdipGetLinePresetBlendCount(brush, NULL);
622     expect(InvalidParameter, status);
623
624     status = GdipGetLinePresetBlendCount(brush, &count);
625     expect(Ok, status);
626     expect(0, count);
627
628     status = GdipGetLinePresetBlend(NULL, res_colors, res_positions, 1);
629     expect(InvalidParameter, status);
630
631     status = GdipGetLinePresetBlend(brush, NULL, res_positions, 1);
632     expect(InvalidParameter, status);
633
634     status = GdipGetLinePresetBlend(brush, res_colors, NULL, 1);
635     expect(InvalidParameter, status);
636
637     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 0);
638     expect(InvalidParameter, status);
639
640     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, -1);
641     expect(InvalidParameter, status);
642
643     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 1);
644     expect(InvalidParameter, status);
645
646     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 2);
647     expect(GenericError, status);
648
649     status = GdipSetLinePresetBlend(NULL, colors, positions, 5);
650     expect(InvalidParameter, status);
651
652     status = GdipSetLinePresetBlend(brush, NULL, positions, 5);
653     expect(InvalidParameter, status);
654
655     status = GdipSetLinePresetBlend(brush, colors, NULL, 5);
656     expect(InvalidParameter, status);
657
658     status = GdipSetLinePresetBlend(brush, colors, positions, 0);
659     expect(InvalidParameter, status);
660
661     status = GdipSetLinePresetBlend(brush, colors, positions, -1);
662     expect(InvalidParameter, status);
663
664     status = GdipSetLinePresetBlend(brush, colors, positions, 1);
665     expect(InvalidParameter, status);
666
667     /* leave off the 0.0 position */
668     status = GdipSetLinePresetBlend(brush, &colors[1], &positions[1], 4);
669     expect(InvalidParameter, status);
670
671     /* leave off the 1.0 position */
672     status = GdipSetLinePresetBlend(brush, colors, positions, 4);
673     expect(InvalidParameter, status);
674
675     status = GdipSetLinePresetBlend(brush, colors, positions, 5);
676     expect(Ok, status);
677
678     status = GdipGetLinePresetBlendCount(brush, &count);
679     expect(Ok, status);
680     expect(5, count);
681
682     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 4);
683     expect(InsufficientBuffer, status);
684
685     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 5);
686     expect(Ok, status);
687
688     for (i=0; i<5; i++)
689     {
690         expect(colors[i], res_colors[i]);
691         expectf(positions[i], res_positions[i]);
692     }
693
694     status = GdipGetLinePresetBlend(brush, res_colors, res_positions, 6);
695     expect(Ok, status);
696
697     status = GdipSetLinePresetBlend(brush, colors, two_positions, 2);
698     expect(Ok, status);
699
700     status = GdipDeleteBrush((GpBrush*)brush);
701     expect(Ok, status);
702 }
703
704 static void test_linelinearblend(void)
705 {
706     GpLineGradient *brush;
707     GpStatus status;
708     GpPointF pt1, pt2;
709     INT count=10;
710     REAL res_factors[3] = {0.3f};
711     REAL res_positions[3] = {0.3f};
712
713     status = GdipSetLineLinearBlend(NULL, 0.6, 0.8);
714     expect(InvalidParameter, status);
715
716     pt1.X = pt1.Y = 1.0;
717     pt2.X = pt2.Y = 100.0;
718     status = GdipCreateLineBrush(&pt1, &pt2, 0, 0, WrapModeTile, &brush);
719     expect(Ok, status);
720
721
722     status = GdipSetLineLinearBlend(brush, 0.6, 0.8);
723     expect(Ok, status);
724
725     status = GdipGetLineBlendCount(brush, &count);
726     expect(Ok, status);
727     expect(3, count);
728
729     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
730     expect(Ok, status);
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]);
737
738
739     status = GdipSetLineLinearBlend(brush, 0.0, 0.8);
740     expect(Ok, status);
741
742     status = GdipGetLineBlendCount(brush, &count);
743     expect(Ok, status);
744     expect(2, count);
745
746     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
747     expect(Ok, status);
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]);
752
753
754     status = GdipSetLineLinearBlend(brush, 1.0, 0.8);
755     expect(Ok, status);
756
757     status = GdipGetLineBlendCount(brush, &count);
758     expect(Ok, status);
759     expect(2, count);
760
761     status = GdipGetLineBlend(brush, res_factors, res_positions, 3);
762     expect(Ok, status);
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]);
767
768     status = GdipDeleteBrush((GpBrush*)brush);
769     expect(Ok, status);
770 }
771
772 static void test_gradientsurroundcolorcount(void)
773 {
774     GpStatus status;
775     GpPathGradient *grad;
776     ARGB color[3];
777     INT count;
778
779     status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad);
780     expect(Ok, status);
781
782     count = 0;
783     status = GdipGetPathGradientSurroundColorCount(grad, &count);
784     expect(Ok, status);
785     expect(2, count);
786
787     color[0] = color[1] = color[2] = 0xdeadbeef;
788     count = 3;
789     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
790     expect(Ok, status);
791     expect(1, count);
792     expect(0xffffffff, color[0]);
793     expect(0xffffffff, color[1]);
794     expect(0xdeadbeef, color[2]);
795
796     color[0] = color[1] = color[2] = 0xdeadbeef;
797     count = 2;
798     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
799     expect(Ok, status);
800     expect(1, count);
801     expect(0xffffffff, color[0]);
802     expect(0xffffffff, color[1]);
803     expect(0xdeadbeef, color[2]);
804
805     color[0] = color[1] = color[2] = 0xdeadbeef;
806     count = 1;
807     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
808     expect(InvalidParameter, status);
809     expect(1, count);
810     expect(0xdeadbeef, color[0]);
811     expect(0xdeadbeef, color[1]);
812     expect(0xdeadbeef, color[2]);
813
814     color[0] = color[1] = color[2] = 0xdeadbeef;
815     count = 0;
816     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
817     expect(InvalidParameter, status);
818     expect(0, count);
819     expect(0xdeadbeef, color[0]);
820     expect(0xdeadbeef, color[1]);
821     expect(0xdeadbeef, color[2]);
822
823     count = 3;
824     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
825     expect(InvalidParameter, status);
826
827     count = 2;
828
829     color[0] = 0x00ff0000;
830     color[1] = 0x0000ff00;
831
832     status = GdipSetPathGradientSurroundColorsWithCount(NULL, color, &count);
833     expect(InvalidParameter, status);
834
835     status = GdipSetPathGradientSurroundColorsWithCount(grad, NULL, &count);
836     expect(InvalidParameter, status);
837
838     /* WinXP crashes on this test */
839     if(0)
840     {
841         status = GdipSetPathGradientSurroundColorsWithCount(grad, color, NULL);
842         expect(InvalidParameter, status);
843     }
844
845     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
846     expect(Ok, status);
847     expect(2, count);
848
849     status = GdipGetPathGradientSurroundColorCount(NULL, &count);
850     expect(InvalidParameter, status);
851
852     status = GdipGetPathGradientSurroundColorCount(grad, NULL);
853     expect(InvalidParameter, status);
854
855     count = 0;
856     status = GdipGetPathGradientSurroundColorCount(grad, &count);
857     expect(Ok, status);
858     expect(2, count);
859
860     color[0] = color[1] = color[2] = 0xdeadbeef;
861     count = 2;
862     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
863     expect(Ok, status);
864     expect(2, count);
865     expect(0x00ff0000, color[0]);
866     expect(0x0000ff00, color[1]);
867     expect(0xdeadbeef, color[2]);
868
869     count = 1;
870     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
871     expect(Ok, status);
872     expect(1, count);
873
874     count = 0;
875     status = GdipGetPathGradientSurroundColorCount(grad, &count);
876     expect(Ok, status);
877     expect(2, count);
878
879     count = 0;
880     status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
881     expect(InvalidParameter, status);
882     expect(0, count);
883
884     GdipDeleteBrush((GpBrush*)grad);
885
886     status = GdipCreatePathGradient(getbounds_ptf, 3, WrapModeClamp, &grad);
887     expect(Ok, status);
888
889     color[0] = color[1] = color[2] = 0xdeadbeef;
890     count = 3;
891     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
892     expect(Ok, status);
893     expect(1, count);
894     expect(0xffffffff, color[0]);
895     expect(0xffffffff, color[1]);
896     expect(0xffffffff, color[2]);
897
898     color[0] = color[1] = color[2] = 0xdeadbeef;
899     count = 2;
900     status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
901     expect(InvalidParameter, status);
902     expect(2, count);
903     expect(0xdeadbeef, color[0]);
904     expect(0xdeadbeef, color[1]);
905     expect(0xdeadbeef, color[2]);
906
907     count = 0;
908     status = GdipGetPathGradientSurroundColorCount(grad, &count);
909     expect(Ok, status);
910     expect(3, count);
911
912     GdipDeleteBrush((GpBrush*)grad);
913 }
914
915 static void test_pathgradientpath(void)
916 {
917     GpStatus status;
918     GpPath *path=NULL;
919     GpPathGradient *grad=NULL;
920
921     status = GdipCreatePathGradient(blendcount_ptf, 2, WrapModeClamp, &grad);
922     expect(Ok, status);
923
924     status = GdipGetPathGradientPath(grad, NULL);
925     expect(NotImplemented, status);
926
927     status = GdipCreatePath(FillModeWinding, &path);
928     expect(Ok, status);
929
930     status = GdipGetPathGradientPath(NULL, path);
931     expect(NotImplemented, status);
932
933     status = GdipGetPathGradientPath(grad, path);
934     expect(NotImplemented, status);
935
936     status = GdipDeletePath(path);
937     expect(Ok, status);
938
939     status = GdipDeleteBrush((GpBrush*)grad);
940     expect(Ok, status);
941 }
942
943 static void test_pathgradientcenterpoint(void)
944 {
945     static const GpPointF path_points[] = {{0,0}, {3,0}, {0,4}};
946     GpStatus status;
947     GpPathGradient *grad;
948     GpPointF point;
949
950     status = GdipCreatePathGradient(path_points+1, 2, WrapModeClamp, &grad);
951     expect(Ok, status);
952
953     status = GdipGetPathGradientCenterPoint(NULL, &point);
954     expect(InvalidParameter, status);
955
956     status = GdipGetPathGradientCenterPoint(grad, NULL);
957     expect(InvalidParameter, status);
958
959     status = GdipGetPathGradientCenterPoint(grad, &point);
960     expect(Ok, status);
961     expectf(1.5, point.X);
962     expectf(2.0, point.Y);
963
964     status = GdipSetPathGradientCenterPoint(NULL, &point);
965     expect(InvalidParameter, status);
966
967     status = GdipSetPathGradientCenterPoint(grad, NULL);
968     expect(InvalidParameter, status);
969
970     point.X = 10.0;
971     point.Y = 15.0;
972     status = GdipSetPathGradientCenterPoint(grad, &point);
973     expect(Ok, status);
974
975     point.X = point.Y = -1;
976     status = GdipGetPathGradientCenterPoint(grad, &point);
977     expect(Ok, status);
978     expectf(10.0, point.X);
979     expectf(15.0, point.Y);
980
981     status = GdipDeleteBrush((GpBrush*)grad);
982     expect(Ok, status);
983
984     status = GdipCreatePathGradient(path_points, 3, WrapModeClamp, &grad);
985     expect(Ok, status);
986
987     status = GdipGetPathGradientCenterPoint(grad, &point);
988     expect(Ok, status);
989     todo_wine expectf(1.0, point.X);
990     todo_wine expectf(4.0/3.0, point.Y);
991
992     status = GdipDeleteBrush((GpBrush*)grad);
993     expect(Ok, status);
994 }
995
996 void test_pathgradientpresetblend(void)
997 {
998     static const GpPointF path_points[] = {{0,0}, {3,0}, {0,4}};
999     GpStatus status;
1000     GpPathGradient *grad;
1001     INT count;
1002     int i;
1003     const REAL positions[5] = {0.0f, 0.2f, 0.5f, 0.8f, 1.0f};
1004     const REAL two_positions[2] = {0.0f, 1.0f};
1005     const ARGB colors[5] = {0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffffffff};
1006     REAL res_positions[6] = {0.3f, 0.0f, 0.0f, 0.0f, 0.0f};
1007     ARGB res_colors[6] = {0xdeadbeef, 0, 0, 0, 0};
1008
1009     status = GdipCreatePathGradient(path_points+1, 2, WrapModeClamp, &grad);
1010     expect(Ok, status);
1011
1012     status = GdipGetPathGradientPresetBlendCount(NULL, &count);
1013     expect(InvalidParameter, status);
1014
1015     status = GdipGetPathGradientPresetBlendCount(grad, NULL);
1016     expect(InvalidParameter, status);
1017
1018     status = GdipGetPathGradientPresetBlendCount(grad, &count);
1019     expect(Ok, status);
1020     expect(0, count);
1021
1022     status = GdipGetPathGradientPresetBlend(NULL, res_colors, res_positions, 1);
1023     expect(InvalidParameter, status);
1024
1025     status = GdipGetPathGradientPresetBlend(grad, NULL, res_positions, 1);
1026     expect(InvalidParameter, status);
1027
1028     status = GdipGetPathGradientPresetBlend(grad, res_colors, NULL, 1);
1029     expect(InvalidParameter, status);
1030
1031     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 0);
1032     expect(InvalidParameter, status);
1033
1034     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, -1);
1035     expect(OutOfMemory, status);
1036
1037     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 1);
1038     expect(InvalidParameter, status);
1039
1040     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 2);
1041     expect(GenericError, status);
1042
1043     status = GdipSetPathGradientPresetBlend(NULL, colors, positions, 5);
1044     expect(InvalidParameter, status);
1045
1046     status = GdipSetPathGradientPresetBlend(grad, NULL, positions, 5);
1047     expect(InvalidParameter, status);
1048
1049     if (0)
1050     {
1051         /* crashes on windows xp */
1052         status = GdipSetPathGradientPresetBlend(grad, colors, NULL, 5);
1053         expect(InvalidParameter, status);
1054     }
1055
1056     status = GdipSetPathGradientPresetBlend(grad, colors, positions, 0);
1057     expect(InvalidParameter, status);
1058
1059     status = GdipSetPathGradientPresetBlend(grad, colors, positions, -1);
1060     expect(InvalidParameter, status);
1061
1062     status = GdipSetPathGradientPresetBlend(grad, colors, positions, 1);
1063     expect(InvalidParameter, status);
1064
1065     /* leave off the 0.0 position */
1066     status = GdipSetPathGradientPresetBlend(grad, &colors[1], &positions[1], 4);
1067     expect(InvalidParameter, status);
1068
1069     /* leave off the 1.0 position */
1070     status = GdipSetPathGradientPresetBlend(grad, colors, positions, 4);
1071     expect(InvalidParameter, status);
1072
1073     status = GdipSetPathGradientPresetBlend(grad, colors, positions, 5);
1074     expect(Ok, status);
1075
1076     status = GdipGetPathGradientPresetBlendCount(grad, &count);
1077     expect(Ok, status);
1078     expect(5, count);
1079
1080     if (0)
1081     {
1082         /* Native GdipGetPathGradientPresetBlend seems to copy starting from
1083          * the end of each array and do no bounds checking. This is so braindead
1084          * I'm not going to copy it. */
1085
1086         res_colors[0] = 0xdeadbeef;
1087         res_positions[0] = 0.3;
1088
1089         status = GdipGetPathGradientPresetBlend(grad, &res_colors[1], &res_positions[1], 4);
1090         expect(Ok, status);
1091
1092         expect(0xdeadbeef, res_colors[0]);
1093         expectf(0.3, res_positions[0]);
1094
1095         for (i=1; i<5; i++)
1096         {
1097             expect(colors[i], res_colors[i]);
1098             expectf(positions[i], res_positions[i]);
1099         }
1100
1101         status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 6);
1102         expect(Ok, status);
1103
1104         for (i=0; i<5; i++)
1105         {
1106             expect(colors[i], res_colors[i+1]);
1107             expectf(positions[i], res_positions[i+1]);
1108         }
1109     }
1110
1111     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 5);
1112     expect(Ok, status);
1113
1114     for (i=0; i<5; i++)
1115     {
1116         expect(colors[i], res_colors[i]);
1117         expectf(positions[i], res_positions[i]);
1118     }
1119
1120     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 0);
1121     expect(InvalidParameter, status);
1122
1123     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, -1);
1124     expect(OutOfMemory, status);
1125
1126     status = GdipGetPathGradientPresetBlend(grad, res_colors, res_positions, 1);
1127     expect(InvalidParameter, status);
1128
1129     status = GdipSetPathGradientPresetBlend(grad, colors, two_positions, 2);
1130     expect(Ok, status);
1131
1132     status = GdipDeleteBrush((GpBrush*)grad);
1133     expect(Ok, status);
1134 }
1135
1136 START_TEST(brush)
1137 {
1138     struct GdiplusStartupInput gdiplusStartupInput;
1139     ULONG_PTR gdiplusToken;
1140
1141     gdiplusStartupInput.GdiplusVersion              = 1;
1142     gdiplusStartupInput.DebugEventCallback          = NULL;
1143     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1144     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1145
1146     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1147
1148     test_constructor_destructor();
1149     test_type();
1150     test_gradientblendcount();
1151     test_getblend();
1152     test_getbounds();
1153     test_getgamma();
1154     test_transform();
1155     test_texturewrap();
1156     test_gradientgetrect();
1157     test_lineblend();
1158     test_linelinearblend();
1159     test_gradientsurroundcolorcount();
1160     test_pathgradientpath();
1161     test_pathgradientcenterpoint();
1162     test_pathgradientpresetblend();
1163
1164     GdiplusShutdown(gdiplusToken);
1165 }