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
26 #include "wine/test.h"
28 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
29 #define expectf(expected, got) ok(fabs(got - expected) < 0.1, "Expected %.2f, got %.2f\n", expected, got)
31 static void test_startup(void)
35 struct GdiplusStartupInput gdiplusStartupInput;
36 ULONG_PTR gdiplusToken;
38 gdiplusStartupInput.GdiplusVersion = 1;
39 gdiplusStartupInput.DebugEventCallback = NULL;
40 gdiplusStartupInput.SuppressBackgroundThread = 0;
41 gdiplusStartupInput.SuppressExternalCodecs = 0;
43 status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
45 GdiplusShutdown(gdiplusToken);
47 gdiplusStartupInput.GdiplusVersion = 2;
49 status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
50 expect(UnsupportedGdiplusVersion, status);
51 GdiplusShutdown(gdiplusToken);
53 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
56 expect(GdiplusNotInitialized, status);
61 static void test_constructor_destructor(void)
66 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
68 ok(pen != NULL, "Expected pen to be initialized\n");
70 status = GdipDeletePen(NULL);
71 expect(InvalidParameter, status);
73 status = GdipDeletePen(pen);
77 static void test_brushfill(void)
81 GpBrush *brush, *brush2;
86 GdipCreatePen1(0xdeadbeef, 4.5, UnitWorld, &pen);
87 status = GdipGetPenBrushFill(pen, &brush);
89 GdipGetBrushType(brush, &type);
90 expect(BrushTypeSolidColor, type);
91 GdipGetPenColor(pen, &color);
92 expect(0xdeadbeef, color);
93 GdipDeleteBrush(brush);
95 /* color controlled by brush */
96 GdipCreateSolidFill(0xabaddeed, (GpSolidFill**)&brush);
97 status = GdipSetPenBrushFill(pen, brush);
99 GdipGetPenColor(pen, &color);
100 expect(0xabaddeed, color);
101 GdipDeleteBrush(brush);
104 /* get returns a clone, not a reference */
105 GdipGetPenBrushFill(pen, &brush);
106 GdipSetSolidFillColor((GpSolidFill*)brush, 0xbeadfeed);
107 GdipGetPenBrushFill(pen, &brush2);
108 ok(brush != brush2, "Expected to get a clone, not a copy of the reference\n");
109 GdipGetSolidFillColor((GpSolidFill*)brush2, &color);
110 expect(0xabaddeed, color);
111 GdipDeleteBrush(brush);
112 GdipDeleteBrush(brush2);
114 /* brush cannot be NULL */
115 status = GdipSetPenBrushFill(pen, NULL);
116 expect(InvalidParameter, status);
121 static void test_dasharray(void)
128 GdipCreatePen1(0xdeadbeef, 10.0, UnitWorld, &pen);
136 dashes[7] = dashes[8] = dashes[9] = dashes[10] = dashes[11] = 0.0;
138 /* setting the array sets the type to custom */
139 GdipGetPenDashStyle(pen, &style);
140 expect(DashStyleSolid, style);
141 status = GdipSetPenDashArray(pen, dashes, 2);
143 GdipGetPenDashStyle(pen, &style);
144 expect(DashStyleCustom, style);
146 /* Getting the array on a non-custom pen returns invalid parameter (unless
147 * you are getting 0 elements).*/
148 GdipSetPenDashStyle(pen, DashStyleSolid);
149 status = GdipGetPenDashArray(pen, &dashes[5], 2);
150 expect(InvalidParameter, status);
151 status = GdipGetPenDashArray(pen, &dashes[5], 0);
154 /* What does setting DashStyleCustom do to the array length? */
155 GdipSetPenDashArray(pen, dashes, 2);
156 GdipSetPenDashStyle(pen, DashStyleCustom);
157 status = GdipGetPenDashArray(pen, &dashes[5], 2);
159 expectf(10.0, dashes[5]);
160 expectf(11.0, dashes[6]);
162 /* Set the array, then get with different sized buffers. */
163 status = GdipSetPenDashArray(pen, dashes, 5);
167 status = GdipGetPenDashArray(pen, &dashes[5], 1);
168 expect(Ok, status); /* not InsufficientBuffer! */
169 expectf(10.0, dashes[5]);
170 expectf(-100.0, dashes[6]);
172 status = GdipGetPenDashArray(pen, &dashes[5], 6);
173 expect(InvalidParameter, status); /* not Ok! */
174 expectf(-100.0, dashes[5]);
175 expectf(-100.0, dashes[6]);
177 /* Some invalid array values. */
178 status = GdipSetPenDashArray(pen, &dashes[7], 5);
179 expect(InvalidParameter, status);
181 status = GdipSetPenDashArray(pen, &dashes[7], 5);
182 expect(InvalidParameter, status);
184 /* Try to set with count = 0. */
185 GdipSetPenDashStyle(pen, DashStyleDot);
186 status = GdipSetPenDashArray(pen, dashes, 0);
187 expect(OutOfMemory, status);
188 GdipGetPenDashStyle(pen, &style);
189 expect(DashStyleDot, style);
196 struct GdiplusStartupInput gdiplusStartupInput;
197 ULONG_PTR gdiplusToken;
201 gdiplusStartupInput.GdiplusVersion = 1;
202 gdiplusStartupInput.DebugEventCallback = NULL;
203 gdiplusStartupInput.SuppressBackgroundThread = 0;
204 gdiplusStartupInput.SuppressExternalCodecs = 0;
206 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
208 test_constructor_destructor();
212 GdiplusShutdown(gdiplusToken);