gdiplus/tests: Fix tests compilation with __WINESRC__ defined.
[wine.git] / dlls / gdiplus / tests / matrix.c
blob83b57ef7e2d59dbc991791d42ad06cc8ed427270
1 /*
2 * Unit test suite for matrices
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
21 #include <math.h>
23 #include "objbase.h"
24 #include "gdiplus.h"
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(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
30 static void test_constructor_destructor(void)
32 GpStatus status;
33 GpMatrix *matrix = NULL;
35 status = GdipCreateMatrix2(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &matrix);
36 expect(Ok, status);
37 ok(matrix != NULL, "Expected matrix to be initialized\n");
39 status = GdipDeleteMatrix(NULL);
40 expect(InvalidParameter, status);
42 status = GdipDeleteMatrix(matrix);
43 expect(Ok, status);
46 typedef struct{
47 REAL X;
48 REAL Y;
49 } real_point;
51 static real_point transform_points[] = {
52 {1000.00, 2600.00}, /*0*/
53 {855.00, 2390.00}, /*1*/
54 {700.00, 2200.00}, /*2*/
55 {565.00, 1970.00}, /*3*/
56 {400.00, 1800.00}, /*4*/
57 {275.00, 1550.00}, /*5*/
58 {100.00, 1400.00}, /*6*/
59 {-15.00, 1130.00}, /*7*/
60 {-200.00, 1000.00}, /*8*/
61 {-305.00, 710.00} /*9*/
64 static void test_transform(void)
66 GpStatus status;
67 GpMatrix *matrix = NULL;
68 GpPointF pts[10];
69 INT i;
70 BOOL match;
72 for(i = 0; i < 10; i ++){
73 pts[i].X = i * 5.0 * (REAL)(i % 2);
74 pts[i].Y = 50.0 - i * 5.0;
77 GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix);
79 status = GdipTransformMatrixPoints(matrix, pts, 0);
80 expect(InvalidParameter, status);
82 status = GdipTransformMatrixPoints(matrix, pts, 10);
83 expect(Ok, status);
85 for(i = 0; i < 10; i ++){
86 match = fabs(transform_points[i].X - pts[i].X) < 2.0
87 && fabs(transform_points[i].Y - pts[i].Y) < 2.0;
89 ok(match, "Expected #%d to be (%.2f, %.2f) but got (%.2f, %.2f)\n", i,
90 transform_points[i].X, transform_points[i].Y, pts[i].X, pts[i].Y);
93 GdipDeleteMatrix(matrix);
96 static void test_isinvertible(void)
98 GpStatus status;
99 GpMatrix *matrix = NULL;
100 BOOL result;
102 /* NULL arguments */
103 status = GdipIsMatrixInvertible(NULL, &result);
104 expect(InvalidParameter, status);
105 status = GdipIsMatrixInvertible((GpMatrix*)0xdeadbeef, NULL);
106 expect(InvalidParameter, status);
107 status = GdipIsMatrixInvertible(NULL, NULL);
108 expect(InvalidParameter, status);
110 /* invertible */
111 GdipCreateMatrix2(1.0, 1.2, 2.3, -1.0, 2.0, 3.0, &matrix);
112 status = GdipIsMatrixInvertible(matrix, &result);
113 expect(Ok, status);
114 expect(TRUE, result);
115 GdipDeleteMatrix(matrix);
117 /* noninvertible */
118 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix);
119 status = GdipIsMatrixInvertible(matrix, &result);
120 expect(Ok, status);
121 expect(FALSE, result);
122 GdipDeleteMatrix(matrix);
125 static void test_invert(void)
127 GpStatus status;
128 GpMatrix *matrix = NULL;
129 GpMatrix *inverted = NULL;
130 BOOL equal = FALSE;
132 /* NULL */
133 status = GdipInvertMatrix(NULL);
134 expect(InvalidParameter, status);
136 /* noninvertible */
137 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix);
138 status = GdipInvertMatrix(matrix);
139 expect(InvalidParameter, status);
140 GdipDeleteMatrix(matrix);
142 /* invertible */
143 GdipCreateMatrix2(3.0, -2.0, 5.0, 2.0, 6.0, 3.0, &matrix);
144 status = GdipInvertMatrix(matrix);
145 expect(Ok, status);
146 GdipCreateMatrix2(2.0/16.0, 2.0/16.0, -5.0/16.0, 3.0/16.0, 3.0/16.0, -21.0/16.0, &inverted);
147 GdipIsMatrixEqual(matrix, inverted, &equal);
148 expect(TRUE, equal);
150 GdipDeleteMatrix(inverted);
151 GdipDeleteMatrix(matrix);
154 static void test_shear(void)
156 GpStatus status;
157 GpMatrix *matrix = NULL;
158 GpMatrix *sheared = NULL;
159 BOOL equal;
161 /* NULL */
162 status = GdipShearMatrix(NULL, 0.0, 0.0, MatrixOrderPrepend);
163 expect(InvalidParameter, status);
165 /* X only shearing, MatrixOrderPrepend */
166 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
167 status = GdipShearMatrix(matrix, 1.5, 0.0, MatrixOrderPrepend);
168 expect(Ok, status);
169 GdipCreateMatrix2(1.0, 2.0, 5.5, 2.0, 6.0, 3.0, &sheared);
170 GdipIsMatrixEqual(matrix, sheared, &equal);
171 expect(TRUE, equal);
172 GdipDeleteMatrix(sheared);
173 GdipDeleteMatrix(matrix);
175 /* X only shearing, MatrixOrderAppend */
176 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
177 status = GdipShearMatrix(matrix, 1.5, 0.0, MatrixOrderAppend);
178 expect(Ok, status);
179 GdipCreateMatrix2(4.0, 2.0, 2.5, -1.0, 10.5, 3.0, &sheared);
180 GdipIsMatrixEqual(matrix, sheared, &equal);
181 expect(TRUE, equal);
182 GdipDeleteMatrix(sheared);
183 GdipDeleteMatrix(matrix);
185 /* Y only shearing, MatrixOrderPrepend */
186 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
187 status = GdipShearMatrix(matrix, 0.0, 1.5, MatrixOrderPrepend);
188 expect(Ok, status);
189 GdipCreateMatrix2(7.0, 0.5, 4.0, -1.0, 6.0, 3.0, &sheared);
190 GdipIsMatrixEqual(matrix, sheared, &equal);
191 expect(TRUE, equal);
192 GdipDeleteMatrix(sheared);
193 GdipDeleteMatrix(matrix);
195 /* Y only shearing, MatrixOrderAppend */
196 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
197 status = GdipShearMatrix(matrix, 0.0, 1.5, MatrixOrderAppend);
198 expect(Ok, status);
199 GdipCreateMatrix2(1.0, 3.5, 4.0, 5.0, 6.0, 12.0, &sheared);
200 GdipIsMatrixEqual(matrix, sheared, &equal);
201 expect(TRUE, equal);
202 GdipDeleteMatrix(sheared);
203 GdipDeleteMatrix(matrix);
205 /* X,Y shearing, MatrixOrderPrepend */
206 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
207 status = GdipShearMatrix(matrix, 4.0, 1.5, MatrixOrderPrepend);
208 expect(Ok, status);
209 GdipCreateMatrix2(7.0, 0.5, 8.0, 7.0, 6.0, 3.0, &sheared);
210 GdipIsMatrixEqual(matrix, sheared, &equal);
211 expect(TRUE, equal);
212 GdipDeleteMatrix(sheared);
213 GdipDeleteMatrix(matrix);
215 /* X,Y shearing, MatrixOrderAppend */
216 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
217 status = GdipShearMatrix(matrix, 4.0, 1.5, MatrixOrderAppend);
218 expect(Ok, status);
219 GdipCreateMatrix2(9.0, 3.5, 0.0, 5.0, 18.0, 12.0, &sheared);
220 GdipIsMatrixEqual(matrix, sheared, &equal);
221 expect(TRUE, equal);
222 GdipDeleteMatrix(sheared);
223 GdipDeleteMatrix(matrix);
226 static void test_constructor3(void)
228 /* MSDN is on crack. GdipCreateMatrix3 makes a matrix that transforms the
229 * corners of the given rectangle to the three points given. */
230 GpMatrix *matrix;
231 REAL values[6];
232 GpRectF rc;
233 GpPointF pt[3];
234 GpStatus stat;
236 rc.X = 10;
237 rc.Y = 10;
238 rc.Width = 10;
239 rc.Height = 10;
241 pt[0].X = 10;
242 pt[0].Y = 10;
243 pt[1].X = 20;
244 pt[1].Y = 10;
245 pt[2].X = 10;
246 pt[2].Y = 20;
248 stat = GdipCreateMatrix3(&rc, pt, &matrix);
249 expect(Ok, stat);
251 stat = GdipGetMatrixElements(matrix, values);
252 expect(Ok, stat);
254 expectf(1.0, values[0]);
255 expectf(0.0, values[1]);
256 expectf(0.0, values[2]);
257 expectf(1.0, values[3]);
258 expectf(0.0, values[4]);
259 expectf(0.0, values[5]);
261 GdipDeleteMatrix(matrix);
263 pt[0].X = 20;
264 pt[0].Y = 10;
265 pt[1].X = 40;
266 pt[1].Y = 10;
267 pt[2].X = 20;
268 pt[2].Y = 20;
270 stat = GdipCreateMatrix3(&rc, pt, &matrix);
271 expect(Ok, stat);
273 stat = GdipGetMatrixElements(matrix, values);
274 expect(Ok, stat);
276 expectf(2.0, values[0]);
277 expectf(0.0, values[1]);
278 expectf(0.0, values[2]);
279 expectf(1.0, values[3]);
280 expectf(0.0, values[4]);
281 expectf(0.0, values[5]);
283 GdipDeleteMatrix(matrix);
285 pt[0].X = 10;
286 pt[0].Y = 20;
287 pt[1].X = 20;
288 pt[1].Y = 30;
289 pt[2].X = 10;
290 pt[2].Y = 30;
292 stat = GdipCreateMatrix3(&rc, pt, &matrix);
293 expect(Ok, stat);
295 stat = GdipGetMatrixElements(matrix, values);
296 expect(Ok, stat);
298 expectf(1.0, values[0]);
299 expectf(1.0, values[1]);
300 expectf(0.0, values[2]);
301 expectf(1.0, values[3]);
302 expectf(0.0, values[4]);
303 expectf(0.0, values[5]);
305 GdipDeleteMatrix(matrix);}
307 START_TEST(matrix)
309 struct GdiplusStartupInput gdiplusStartupInput;
310 ULONG_PTR gdiplusToken;
312 gdiplusStartupInput.GdiplusVersion = 1;
313 gdiplusStartupInput.DebugEventCallback = NULL;
314 gdiplusStartupInput.SuppressBackgroundThread = 0;
315 gdiplusStartupInput.SuppressExternalCodecs = 0;
317 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
319 test_constructor_destructor();
320 test_transform();
321 test_isinvertible();
322 test_invert();
323 test_shear();
324 test_constructor3();
326 GdiplusShutdown(gdiplusToken);