2 * Unit test suite for pens (and init)
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
25 #include "wine/test.h"
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf(expected, got) ok(fabs(got - expected) < 0.1, "Expected %.2f, got %.2f\n", expected, got)
30 static void test_startup(void)
34 struct GdiplusStartupInput gdiplusStartupInput
;
35 ULONG_PTR gdiplusToken
;
37 gdiplusStartupInput
.GdiplusVersion
= 1;
38 gdiplusStartupInput
.DebugEventCallback
= NULL
;
39 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
40 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
42 status
= GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
44 GdiplusShutdown(gdiplusToken
);
46 gdiplusStartupInput
.GdiplusVersion
= 42;
48 status
= GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
49 expect(UnsupportedGdiplusVersion
, status
);
50 GdiplusShutdown(gdiplusToken
);
52 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
55 expect(GdiplusNotInitialized
, status
);
60 static void test_constructor_destructor(void)
65 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, NULL
);
66 expect(InvalidParameter
, status
);
67 ok(pen
== NULL
, "Expected pen to be NULL\n");
69 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
71 ok(pen
!= NULL
, "Expected pen to be initialized\n");
73 status
= GdipDeletePen(NULL
);
74 expect(InvalidParameter
, status
);
76 status
= GdipDeletePen(pen
);
80 static void test_constructor_destructor2(void)
84 GpBrush
*brush
= NULL
;
87 status
= GdipCreatePen2(NULL
, 10.0f
, UnitPixel
, &pen
);
88 expect(InvalidParameter
, status
);
89 ok(pen
== NULL
, "Expected pen to be NULL\n");
96 status
= GdipCreateLineBrush(&points
[0], &points
[1], (ARGB
)0xffff00ff,
97 (ARGB
)0xff0000ff, WrapModeTile
, (GpLineGradient
**)&brush
);
99 ok(brush
!= NULL
, "Expected brush to be initialized\n");
101 status
= GdipCreatePen2(brush
, 10.0f
, UnitPixel
, &pen
);
103 ok(pen
!= NULL
, "Expected pen to be initialized\n");
105 status
= GdipDeletePen(pen
);
108 status
= GdipDeleteBrush(brush
);
112 static void test_brushfill(void)
116 GpBrush
*brush
, *brush2
;
121 GdipCreatePen1(0xdeadbeef, 4.5, UnitWorld
, &pen
);
122 status
= GdipGetPenBrushFill(pen
, &brush
);
124 GdipGetBrushType(brush
, &type
);
125 expect(BrushTypeSolidColor
, type
);
126 GdipGetPenColor(pen
, &color
);
127 expect(0xdeadbeef, color
);
128 GdipDeleteBrush(brush
);
130 /* color controlled by brush */
131 GdipCreateSolidFill(0xabaddeed, (GpSolidFill
**)&brush
);
132 status
= GdipSetPenBrushFill(pen
, brush
);
134 GdipGetPenColor(pen
, &color
);
135 expect(0xabaddeed, color
);
136 GdipDeleteBrush(brush
);
139 /* get returns a clone, not a reference */
140 GdipGetPenBrushFill(pen
, &brush
);
141 GdipSetSolidFillColor((GpSolidFill
*)brush
, 0xbeadfeed);
142 GdipGetPenBrushFill(pen
, &brush2
);
143 ok(brush
!= brush2
, "Expected to get a clone, not a copy of the reference\n");
144 GdipGetSolidFillColor((GpSolidFill
*)brush2
, &color
);
145 expect(0xabaddeed, color
);
146 GdipDeleteBrush(brush
);
147 GdipDeleteBrush(brush2
);
149 /* brush cannot be NULL */
150 status
= GdipSetPenBrushFill(pen
, NULL
);
151 expect(InvalidParameter
, status
);
156 static void test_dasharray(void)
163 GdipCreatePen1(0xdeadbeef, 10.0, UnitWorld
, &pen
);
171 dashes
[7] = dashes
[8] = dashes
[9] = dashes
[10] = dashes
[11] = 0.0;
173 /* setting the array sets the type to custom */
174 GdipGetPenDashStyle(pen
, &style
);
175 expect(DashStyleSolid
, style
);
176 status
= GdipSetPenDashArray(pen
, dashes
, 2);
178 GdipGetPenDashStyle(pen
, &style
);
179 expect(DashStyleCustom
, style
);
181 /* Getting the array on a non-custom pen returns invalid parameter (unless
182 * you are getting 0 elements).*/
183 GdipSetPenDashStyle(pen
, DashStyleSolid
);
184 status
= GdipGetPenDashArray(pen
, &dashes
[5], 2);
185 expect(InvalidParameter
, status
);
186 status
= GdipGetPenDashArray(pen
, &dashes
[5], 0);
189 /* What does setting DashStyleCustom do to the array length? */
190 GdipSetPenDashArray(pen
, dashes
, 2);
191 GdipSetPenDashStyle(pen
, DashStyleCustom
);
192 status
= GdipGetPenDashArray(pen
, &dashes
[5], 2);
194 expectf(10.0, dashes
[5]);
195 expectf(11.0, dashes
[6]);
197 /* Set the array, then get with different sized buffers. */
198 status
= GdipSetPenDashArray(pen
, dashes
, 5);
202 status
= GdipGetPenDashArray(pen
, &dashes
[5], 1);
203 expect(Ok
, status
); /* not InsufficientBuffer! */
204 expectf(10.0, dashes
[5]);
205 expectf(-100.0, dashes
[6]);
207 status
= GdipGetPenDashArray(pen
, &dashes
[5], 6);
208 expect(InvalidParameter
, status
); /* not Ok! */
209 expectf(-100.0, dashes
[5]);
210 expectf(-100.0, dashes
[6]);
212 /* Some invalid array values. */
213 status
= GdipSetPenDashArray(pen
, &dashes
[7], 5);
214 expect(InvalidParameter
, status
);
216 status
= GdipSetPenDashArray(pen
, &dashes
[7], 5);
217 expect(InvalidParameter
, status
);
219 /* Try to set with count = 0. */
220 GdipSetPenDashStyle(pen
, DashStyleDot
);
221 status
= GdipSetPenDashArray(pen
, dashes
, 0);
222 ok(status
== OutOfMemory
|| status
== InvalidParameter
,
223 "Expected OutOfMemory or InvalidParameter, got %.8x\n", status
);
224 GdipGetPenDashStyle(pen
, &style
);
225 expect(DashStyleDot
, style
);
230 static void test_customcap(void)
234 GpCustomLineCap
*custom
;
236 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
240 status
= GdipGetPenCustomStartCap(NULL
, NULL
);
241 expect(InvalidParameter
, status
);
242 status
= GdipGetPenCustomStartCap(pen
, NULL
);
243 expect(InvalidParameter
, status
);
244 status
= GdipGetPenCustomStartCap(NULL
, &custom
);
245 expect(InvalidParameter
, status
);
247 status
= GdipGetPenCustomEndCap(NULL
, NULL
);
248 expect(InvalidParameter
, status
);
249 status
= GdipGetPenCustomEndCap(pen
, NULL
);
250 expect(InvalidParameter
, status
);
251 status
= GdipGetPenCustomEndCap(NULL
, &custom
);
252 expect(InvalidParameter
, status
);
254 /* native crashes on pen == NULL, custom != NULL */
255 status
= GdipSetPenCustomStartCap(NULL
, NULL
);
256 expect(InvalidParameter
, status
);
257 status
= GdipSetPenCustomStartCap(pen
, NULL
);
258 expect(InvalidParameter
, status
);
260 status
= GdipSetPenCustomEndCap(NULL
, NULL
);
261 expect(InvalidParameter
, status
);
262 status
= GdipSetPenCustomEndCap(pen
, NULL
);
263 expect(InvalidParameter
, status
);
265 /* get without setting previously */
266 custom
= (GpCustomLineCap
*)0xdeadbeef;
267 status
= GdipGetPenCustomEndCap(pen
, &custom
);
269 ok(custom
== NULL
,"Expect CustomCap == NULL\n");
271 custom
= (GpCustomLineCap
*)0xdeadbeef;
272 status
= GdipGetPenCustomStartCap(pen
, &custom
);
274 ok(custom
== NULL
,"Expect CustomCap == NULL\n");
279 static void test_penfilltype(void)
283 GpLineGradient
*line
;
289 status
= GdipGetPenFillType(NULL
, NULL
);
290 expect(InvalidParameter
, status
);
292 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
294 status
= GdipGetPenFillType(pen
, NULL
);
295 expect(InvalidParameter
, status
);
297 /* created with GdipCreatePen1() */
298 status
= GdipGetPenFillType(pen
, &type
);
300 expect(PenTypeSolidColor
, type
);
303 /* based on SolidBrush */
304 status
= GdipCreateSolidFill((ARGB
)0xffff00ff, &solid
);
306 status
= GdipCreatePen2((GpBrush
*)solid
, 10.0f
, UnitPixel
, &pen
);
308 status
= GdipGetPenFillType(pen
, &type
);
310 expect(PenTypeSolidColor
, type
);
312 GdipDeleteBrush((GpBrush
*)solid
);
314 /* based on LinearGradientBrush */
317 status
= GdipCreateLineBrush(&a
, &b
, (ARGB
)0xffff00ff, (ARGB
)0xffff0000,
318 WrapModeTile
, &line
);
320 status
= GdipCreatePen2((GpBrush
*)line
, 10.0f
, UnitPixel
, &pen
);
322 status
= GdipGetPenFillType(pen
, &type
);
324 expect(PenTypeLinearGradient
, type
);
326 GdipDeleteBrush((GpBrush
*)line
);
329 static void test_compoundarray(void)
333 static const REAL testvalues
[] = {0.2, 0.4, 0.6, 0.8};
335 status
= GdipSetPenCompoundArray(NULL
, testvalues
, 4);
336 expect(InvalidParameter
, status
);
338 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
341 status
= GdipSetPenCompoundArray(pen
, NULL
, 4);
342 expect(InvalidParameter
, status
);
343 status
= GdipSetPenCompoundArray(pen
, testvalues
, 3);
344 expect(InvalidParameter
, status
);
345 status
= GdipSetPenCompoundArray(pen
, testvalues
, 0);
346 expect(InvalidParameter
, status
);
347 status
= GdipSetPenCompoundArray(pen
, testvalues
, -2);
348 expect(InvalidParameter
, status
);
350 status
= GdipSetPenCompoundArray(pen
, testvalues
, 4);
351 todo_wine
expect(Ok
, status
);
358 struct GdiplusStartupInput gdiplusStartupInput
;
359 ULONG_PTR gdiplusToken
;
363 gdiplusStartupInput
.GdiplusVersion
= 1;
364 gdiplusStartupInput
.DebugEventCallback
= NULL
;
365 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
366 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
368 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
370 test_constructor_destructor();
371 test_constructor_destructor2();
376 test_compoundarray();
378 GdiplusShutdown(gdiplusToken
);