2 * Unit test suite for customlinecap
4 * Copyright (C) 2008 Nikolay Sivov
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
24 #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(got == expected, "Expected %.2f, got %.2f\n", expected, got)
29 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
39 if (abs(x
- y
) > ulps
)
45 static void test_constructor_destructor(void)
47 GpCustomLineCap
*custom
;
51 stat
= GdipCreatePath(FillModeAlternate
, &path
);
53 stat
= GdipAddPathRectangle(path
, 5.0, 5.0, 10.0, 10.0);
56 stat
= GdipCreatePath(FillModeAlternate
, &path2
);
58 stat
= GdipAddPathRectangle(path2
, 5.0, 5.0, 10.0, 10.0);
62 stat
= GdipCreateCustomLineCap(NULL
, NULL
, LineCapFlat
, 0.0, NULL
);
63 expect(InvalidParameter
, stat
);
64 stat
= GdipCreateCustomLineCap(path
, NULL
, LineCapFlat
, 0.0, NULL
);
65 expect(InvalidParameter
, stat
);
66 stat
= GdipCreateCustomLineCap(NULL
, path
, LineCapFlat
, 0.0, NULL
);
67 expect(InvalidParameter
, stat
);
68 stat
= GdipCreateCustomLineCap(NULL
, NULL
, LineCapFlat
, 0.0, &custom
);
69 expect(InvalidParameter
, stat
);
70 stat
= GdipDeleteCustomLineCap(NULL
);
71 expect(InvalidParameter
, stat
);
74 stat
= GdipCreateCustomLineCap(NULL
, path2
, LineCapFlat
, 0.0, &custom
);
76 stat
= GdipDeleteCustomLineCap(custom
);
78 /* it's strange but native returns NotImplemented on stroke == NULL */
80 stat
= GdipCreateCustomLineCap(path
, NULL
, LineCapFlat
, 10.0, &custom
);
81 todo_wine
expect(NotImplemented
, stat
);
82 todo_wine
ok(custom
== NULL
, "Expected a failure on creation\n");
83 if(stat
== Ok
) GdipDeleteCustomLineCap(custom
);
85 GdipDeletePath(path2
);
89 static void test_linejoin(void)
91 GpCustomLineCap
*custom
;
96 stat
= GdipCreatePath(FillModeAlternate
, &path
);
98 stat
= GdipAddPathRectangle(path
, 5.0, 5.0, 10.0, 10.0);
101 stat
= GdipCreateCustomLineCap(NULL
, path
, LineCapFlat
, 0.0, &custom
);
105 stat
= GdipGetCustomLineCapStrokeJoin(NULL
, NULL
);
106 expect(InvalidParameter
, stat
);
107 stat
= GdipGetCustomLineCapStrokeJoin(custom
, NULL
);
108 expect(InvalidParameter
, stat
);
109 stat
= GdipGetCustomLineCapStrokeJoin(NULL
, &join
);
110 expect(InvalidParameter
, stat
);
111 stat
= GdipSetCustomLineCapStrokeJoin(NULL
, LineJoinBevel
);
112 expect(InvalidParameter
, stat
);
114 /* LineJoinMiter is default */
115 stat
= GdipGetCustomLineCapStrokeJoin(custom
, &join
);
117 expect(LineJoinMiter
, join
);
120 stat
= GdipSetCustomLineCapStrokeJoin(custom
, LineJoinBevel
);
122 stat
= GdipGetCustomLineCapStrokeJoin(custom
, &join
);
124 expect(LineJoinBevel
, join
);
125 stat
= GdipSetCustomLineCapStrokeJoin(custom
, LineJoinRound
);
127 stat
= GdipGetCustomLineCapStrokeJoin(custom
, &join
);
129 expect(LineJoinRound
, join
);
130 stat
= GdipSetCustomLineCapStrokeJoin(custom
, LineJoinMiterClipped
);
132 stat
= GdipGetCustomLineCapStrokeJoin(custom
, &join
);
134 expect(LineJoinMiterClipped
, join
);
136 GdipDeleteCustomLineCap(custom
);
137 GdipDeletePath(path
);
140 static void test_inset(void)
142 GpCustomLineCap
*custom
;
147 stat
= GdipCreatePath(FillModeAlternate
, &path
);
149 stat
= GdipAddPathRectangle(path
, 5.0, 5.0, 10.0, 10.0);
152 stat
= GdipCreateCustomLineCap(NULL
, path
, LineCapFlat
, 0.0, &custom
);
156 stat
= GdipGetCustomLineCapBaseInset(NULL
, NULL
);
157 expect(InvalidParameter
, stat
);
158 stat
= GdipGetCustomLineCapBaseInset(NULL
, &inset
);
159 expect(InvalidParameter
, stat
);
160 stat
= GdipGetCustomLineCapBaseInset(custom
, NULL
);
161 expect(InvalidParameter
, stat
);
163 inset
= (REAL
)0xdeadbeef;
164 stat
= GdipGetCustomLineCapBaseInset(custom
, &inset
);
168 GdipDeleteCustomLineCap(custom
);
169 GdipDeletePath(path
);
172 static void test_scale(void)
174 GpCustomLineCap
*custom
;
179 stat
= GdipCreatePath(FillModeAlternate
, &path
);
181 stat
= GdipAddPathRectangle(path
, 5.0, 5.0, 10.0, 10.0);
184 stat
= GdipCreateCustomLineCap(NULL
, path
, LineCapFlat
, 0.0, &custom
);
188 stat
= GdipGetCustomLineCapWidthScale(NULL
, NULL
);
189 expect(InvalidParameter
, stat
);
190 stat
= GdipGetCustomLineCapWidthScale(NULL
, &scale
);
191 expect(InvalidParameter
, stat
);
192 stat
= GdipGetCustomLineCapWidthScale(custom
, NULL
);
193 expect(InvalidParameter
, stat
);
195 stat
= GdipSetCustomLineCapWidthScale(NULL
, 2.0);
196 expect(InvalidParameter
, stat
);
198 /* valid args: read default */
199 scale
= (REAL
)0xdeadbeef;
200 stat
= GdipGetCustomLineCapWidthScale(custom
, &scale
);
204 /* set and read back some scale values: there is no limit for the scale */
205 stat
= GdipSetCustomLineCapWidthScale(custom
, 2.5);
207 scale
= (REAL
)0xdeadbeef;
208 stat
= GdipGetCustomLineCapWidthScale(custom
, &scale
);
212 stat
= GdipSetCustomLineCapWidthScale(custom
, 42.0);
214 scale
= (REAL
)0xdeadbeef;
215 stat
= GdipGetCustomLineCapWidthScale(custom
, &scale
);
217 expectf(42.0, scale
);
219 stat
= GdipSetCustomLineCapWidthScale(custom
, 3000.0);
221 scale
= (REAL
)0xdeadbeef;
222 stat
= GdipGetCustomLineCapWidthScale(custom
, &scale
);
224 expectf(3000.0, scale
);
226 stat
= GdipSetCustomLineCapWidthScale(custom
, 0.0);
228 scale
= (REAL
)0xdeadbeef;
229 stat
= GdipGetCustomLineCapWidthScale(custom
, &scale
);
233 GdipDeleteCustomLineCap(custom
);
234 GdipDeletePath(path
);
237 static void test_create_adjustable_cap(void)
239 REAL inset
, scale
, height
, width
;
240 GpAdjustableArrowCap
*cap
;
246 stat
= GdipCreateAdjustableArrowCap(10.0, 10.0, TRUE
, NULL
);
247 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
249 stat
= GdipCreateAdjustableArrowCap(17.0, 15.0, TRUE
, &cap
);
250 ok(stat
== Ok
, "Failed to create adjustable cap, %d\n", stat
);
252 stat
= GdipGetAdjustableArrowCapFillState(cap
, NULL
);
253 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
256 stat
= GdipGetAdjustableArrowCapFillState(cap
, &ret
);
257 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
258 ok(ret
, "Unexpected fill state %d\n", ret
);
260 stat
= GdipGetAdjustableArrowCapHeight(cap
, NULL
);
261 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
263 stat
= GdipGetAdjustableArrowCapHeight(cap
, &height
);
264 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
265 ok(height
== 17.0, "Unexpected cap height %f\n", height
);
267 stat
= GdipGetAdjustableArrowCapWidth(cap
, NULL
);
268 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
270 stat
= GdipGetAdjustableArrowCapWidth(cap
, &width
);
271 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
272 ok(width
== 15.0, "Unexpected cap width %f\n", width
);
274 stat
= GdipGetAdjustableArrowCapMiddleInset(cap
, NULL
);
275 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
277 stat
= GdipGetAdjustableArrowCapMiddleInset(cap
, &inset
);
278 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
279 ok(inset
== 0.0f
, "Unexpected middle inset %f\n", inset
);
281 stat
= GdipGetCustomLineCapBaseCap((GpCustomLineCap
*)cap
, &base
);
282 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
283 ok(base
== LineCapTriangle
, "Unexpected base cap %d\n", base
);
285 stat
= GdipSetCustomLineCapBaseCap((GpCustomLineCap
*)cap
, LineCapSquare
);
287 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
289 stat
= GdipGetCustomLineCapBaseCap((GpCustomLineCap
*)cap
, &base
);
290 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
292 ok(base
== LineCapSquare
, "Unexpected base cap %d\n", base
);
295 stat
= GdipGetAdjustableArrowCapWidth(cap
, &width
);
296 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
298 stat
= GdipGetAdjustableArrowCapHeight(cap
, &height
);
299 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
302 stat
= GdipGetCustomLineCapBaseInset((GpCustomLineCap
*)cap
, &inset
);
303 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
304 ok(compare_float(inset
, height
/ width
, 1), "Unexpected inset %f\n", inset
);
306 stat
= GdipSetAdjustableArrowCapMiddleInset(cap
, 1.0);
307 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
310 stat
= GdipGetCustomLineCapBaseInset((GpCustomLineCap
*)cap
, &inset
);
311 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
312 ok(compare_float(inset
, height
/ width
, 1), "Unexpected inset %f\n", inset
);
314 stat
= GdipSetAdjustableArrowCapHeight(cap
, 2.0 * height
);
315 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
318 stat
= GdipGetCustomLineCapBaseInset((GpCustomLineCap
*)cap
, &inset
);
319 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
320 ok(compare_float(inset
, 2.0 * height
/ width
, 1), "Unexpected inset %f\n", inset
);
322 stat
= GdipGetCustomLineCapWidthScale((GpCustomLineCap
*)cap
, &scale
);
323 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
324 ok(scale
== 1.0f
, "Unexpected width scale %f\n", scale
);
326 stat
= GdipGetCustomLineCapStrokeJoin((GpCustomLineCap
*)cap
, &join
);
327 ok(stat
== Ok
, "Unexpected return code, %d\n", stat
);
328 ok(join
== LineJoinMiter
, "Unexpected stroke join %d\n", join
);
330 GdipDeleteCustomLineCap((GpCustomLineCap
*)cap
);
333 static void test_captype(void)
335 GpAdjustableArrowCap
*arrowcap
;
336 GpCustomLineCap
*custom
;
337 CustomLineCapType type
;
341 stat
= GdipGetCustomLineCapType(NULL
, NULL
);
342 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
345 stat
= GdipGetCustomLineCapType(NULL
, &type
);
346 ok(stat
== InvalidParameter
, "Unexpected return code, %d\n", stat
);
347 ok(type
== 10, "Unexpected cap type, %d\n", type
);
350 stat
= GdipCreatePath(FillModeAlternate
, &path
);
351 ok(stat
== Ok
, "Failed to create path, %d\n", stat
);
352 stat
= GdipAddPathRectangle(path
, 5.0, 5.0, 10.0, 10.0);
353 ok(stat
== Ok
, "AddPathRectangle failed, %d\n", stat
);
355 stat
= GdipCreateCustomLineCap(NULL
, path
, LineCapFlat
, 0.0, &custom
);
356 ok(stat
== Ok
, "Failed to create cap, %d\n", stat
);
357 stat
= GdipGetCustomLineCapType(custom
, &type
);
358 ok(stat
== Ok
, "Failed to get cap type, %d\n", stat
);
359 ok(type
== CustomLineCapTypeDefault
, "Unexpected cap type %d\n", stat
);
360 GdipDeleteCustomLineCap(custom
);
361 GdipDeletePath(path
);
364 stat
= GdipCreateAdjustableArrowCap(17.0, 15.0, TRUE
, &arrowcap
);
365 ok(stat
== Ok
, "Failed to create adjustable cap, %d\n", stat
);
367 stat
= GdipGetCustomLineCapType((GpCustomLineCap
*)arrowcap
, &type
);
368 ok(stat
== Ok
, "Failed to get cap type, %d\n", stat
);
369 ok(type
== CustomLineCapTypeAdjustableArrow
, "Unexpected cap type %d\n", stat
);
371 GdipDeleteCustomLineCap((GpCustomLineCap
*)arrowcap
);
374 START_TEST(customlinecap
)
376 struct GdiplusStartupInput gdiplusStartupInput
;
377 ULONG_PTR gdiplusToken
;
379 int (CDECL
* _controlfp_s
)(unsigned int *cur
, unsigned int newval
, unsigned int mask
);
381 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
382 hmsvcrt
= LoadLibraryA("msvcrt");
383 _controlfp_s
= (void*)GetProcAddress(hmsvcrt
, "_controlfp_s");
384 if (_controlfp_s
) _controlfp_s(0, 0, 0x0008001e);
386 gdiplusStartupInput
.GdiplusVersion
= 1;
387 gdiplusStartupInput
.DebugEventCallback
= NULL
;
388 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
389 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
391 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
393 test_constructor_destructor();
397 test_create_adjustable_cap();
400 GdiplusShutdown(gdiplusToken
);