mshtml: Added IHTMLStyleSheet::get_rules implementation.
[wine] / dlls / gdiplus / tests / pen.c
1 /*
2  * Unit test suite for pens (and init)
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 <math.h>
22
23 #include "windows.h"
24 #include "gdiplus.h"
25 #include "wine/test.h"
26
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)
29
30 static void test_startup(void)
31 {
32     GpPen *pen;
33     Status status;
34     struct GdiplusStartupInput gdiplusStartupInput;
35     ULONG_PTR gdiplusToken;
36
37     gdiplusStartupInput.GdiplusVersion              = 1;
38     gdiplusStartupInput.DebugEventCallback          = NULL;
39     gdiplusStartupInput.SuppressBackgroundThread    = 0;
40     gdiplusStartupInput.SuppressExternalCodecs      = 0;
41
42     status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
43     expect(Ok, status);
44     GdiplusShutdown(gdiplusToken);
45
46     gdiplusStartupInput.GdiplusVersion = 2;
47
48     status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
49     expect(UnsupportedGdiplusVersion, status);
50     GdiplusShutdown(gdiplusToken);
51
52     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
53
54     todo_wine
55         expect(GdiplusNotInitialized, status);
56
57     GdipDeletePen(pen);
58 }
59
60 static void test_constructor_destructor(void)
61 {
62     GpStatus status;
63     GpPen *pen = NULL;
64
65     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
66     expect(Ok, status);
67     ok(pen != NULL, "Expected pen to be initialized\n");
68
69     status = GdipDeletePen(NULL);
70     expect(InvalidParameter, status);
71
72     status = GdipDeletePen(pen);
73     expect(Ok, status);
74 }
75
76 static void test_brushfill(void)
77 {
78     GpStatus status;
79     GpPen *pen;
80     GpBrush *brush, *brush2;
81     GpBrushType type;
82     ARGB color = 0;
83
84     /* default solid */
85     GdipCreatePen1(0xdeadbeef, 4.5, UnitWorld, &pen);
86     status = GdipGetPenBrushFill(pen, &brush);
87     expect(Ok, status);
88     GdipGetBrushType(brush, &type);
89     expect(BrushTypeSolidColor, type);
90     GdipGetPenColor(pen, &color);
91     expect(0xdeadbeef, color);
92     GdipDeleteBrush(brush);
93
94     /* color controlled by brush */
95     GdipCreateSolidFill(0xabaddeed, (GpSolidFill**)&brush);
96     status = GdipSetPenBrushFill(pen, brush);
97     expect(Ok, status);
98     GdipGetPenColor(pen, &color);
99     expect(0xabaddeed, color);
100     GdipDeleteBrush(brush);
101     color = 0;
102
103     /* get returns a clone, not a reference */
104     GdipGetPenBrushFill(pen, &brush);
105     GdipSetSolidFillColor((GpSolidFill*)brush, 0xbeadfeed);
106     GdipGetPenBrushFill(pen, &brush2);
107     ok(brush != brush2, "Expected to get a clone, not a copy of the reference\n");
108     GdipGetSolidFillColor((GpSolidFill*)brush2, &color);
109     expect(0xabaddeed, color);
110     GdipDeleteBrush(brush);
111     GdipDeleteBrush(brush2);
112
113     /* brush cannot be NULL */
114     status = GdipSetPenBrushFill(pen, NULL);
115     expect(InvalidParameter, status);
116
117     GdipDeletePen(pen);
118 }
119
120 static void test_dasharray(void)
121 {
122     GpPen *pen;
123     GpDashStyle style;
124     GpStatus status;
125     REAL dashes[12];
126
127     GdipCreatePen1(0xdeadbeef, 10.0, UnitWorld, &pen);
128     dashes[0] = 10.0;
129     dashes[1] = 11.0;
130     dashes[2] = 12.0;
131     dashes[3] = 13.0;
132     dashes[4] = 14.0;
133     dashes[5] = -100.0;
134     dashes[6] = -100.0;
135     dashes[7] = dashes[8] = dashes[9] = dashes[10] = dashes[11] = 0.0;
136
137     /* setting the array sets the type to custom */
138     GdipGetPenDashStyle(pen, &style);
139     expect(DashStyleSolid, style);
140     status = GdipSetPenDashArray(pen, dashes, 2);
141     expect(Ok, status);
142     GdipGetPenDashStyle(pen, &style);
143     expect(DashStyleCustom, style);
144
145     /* Getting the array on a non-custom pen returns invalid parameter (unless
146      * you are getting 0 elements).*/
147     GdipSetPenDashStyle(pen, DashStyleSolid);
148     status = GdipGetPenDashArray(pen, &dashes[5], 2);
149     expect(InvalidParameter, status);
150     status = GdipGetPenDashArray(pen, &dashes[5], 0);
151     expect(Ok, status);
152
153     /* What does setting DashStyleCustom do to the array length? */
154     GdipSetPenDashArray(pen, dashes, 2);
155     GdipSetPenDashStyle(pen, DashStyleCustom);
156     status = GdipGetPenDashArray(pen, &dashes[5], 2);
157     expect(Ok, status);
158     expectf(10.0, dashes[5]);
159     expectf(11.0, dashes[6]);
160
161     /* Set the array, then get with different sized buffers. */
162     status = GdipSetPenDashArray(pen, dashes, 5);
163     expect(Ok, status);
164     dashes[5] = -100.0;
165     dashes[6] = -100.0;
166     status = GdipGetPenDashArray(pen, &dashes[5], 1);
167     expect(Ok, status); /* not InsufficientBuffer! */
168     expectf(10.0, dashes[5]);
169     expectf(-100.0, dashes[6]);
170     dashes[5] = -100.0;
171     status = GdipGetPenDashArray(pen, &dashes[5], 6);
172     expect(InvalidParameter, status); /* not Ok! */
173     expectf(-100.0, dashes[5]);
174     expectf(-100.0, dashes[6]);
175
176     /* Some invalid array values. */
177     status = GdipSetPenDashArray(pen, &dashes[7], 5);
178     expect(InvalidParameter, status);
179     dashes[9] = -1.0;
180     status = GdipSetPenDashArray(pen, &dashes[7], 5);
181     expect(InvalidParameter, status);
182
183     /* Try to set with count = 0. */
184     GdipSetPenDashStyle(pen, DashStyleDot);
185     status = GdipSetPenDashArray(pen, dashes, 0);
186     expect(OutOfMemory, status);
187     GdipGetPenDashStyle(pen, &style);
188     expect(DashStyleDot, style);
189
190     GdipDeletePen(pen);
191 }
192
193 START_TEST(pen)
194 {
195     struct GdiplusStartupInput gdiplusStartupInput;
196     ULONG_PTR gdiplusToken;
197
198     test_startup();
199
200     gdiplusStartupInput.GdiplusVersion              = 1;
201     gdiplusStartupInput.DebugEventCallback          = NULL;
202     gdiplusStartupInput.SuppressBackgroundThread    = 0;
203     gdiplusStartupInput.SuppressExternalCodecs      = 0;
204
205     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
206
207     test_constructor_destructor();
208     test_brushfill();
209     test_dasharray();
210
211     GdiplusShutdown(gdiplusToken);
212 }