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
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)
33 GpMatrix
*matrix
= NULL
;
35 status
= GdipCreateMatrix2(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &matrix
);
37 ok(matrix
!= NULL
, "Expected matrix to be initialized\n");
39 status
= GdipDeleteMatrix(NULL
);
40 expect(InvalidParameter
, status
);
42 status
= GdipDeleteMatrix(matrix
);
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)
67 GpMatrix
*matrix
= NULL
;
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);
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)
99 GpMatrix
*matrix
= NULL
;
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
);
111 GdipCreateMatrix2(1.0, 1.2, 2.3, -1.0, 2.0, 3.0, &matrix
);
112 status
= GdipIsMatrixInvertible(matrix
, &result
);
114 expect(TRUE
, result
);
115 GdipDeleteMatrix(matrix
);
118 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix
);
119 status
= GdipIsMatrixInvertible(matrix
, &result
);
121 expect(FALSE
, result
);
122 GdipDeleteMatrix(matrix
);
125 static void test_invert(void)
128 GpMatrix
*matrix
= NULL
;
129 GpMatrix
*inverted
= NULL
;
133 status
= GdipInvertMatrix(NULL
);
134 expect(InvalidParameter
, status
);
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
);
143 GdipCreateMatrix2(3.0, -2.0, 5.0, 2.0, 6.0, 3.0, &matrix
);
144 status
= GdipInvertMatrix(matrix
);
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
);
150 GdipDeleteMatrix(inverted
);
151 GdipDeleteMatrix(matrix
);
154 static void test_shear(void)
157 GpMatrix
*matrix
= NULL
;
158 GpMatrix
*sheared
= 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
);
169 GdipCreateMatrix2(1.0, 2.0, 5.5, 2.0, 6.0, 3.0, &sheared
);
170 GdipIsMatrixEqual(matrix
, sheared
, &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
);
179 GdipCreateMatrix2(4.0, 2.0, 2.5, -1.0, 10.5, 3.0, &sheared
);
180 GdipIsMatrixEqual(matrix
, sheared
, &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
);
189 GdipCreateMatrix2(7.0, 0.5, 4.0, -1.0, 6.0, 3.0, &sheared
);
190 GdipIsMatrixEqual(matrix
, sheared
, &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
);
199 GdipCreateMatrix2(1.0, 3.5, 4.0, 5.0, 6.0, 12.0, &sheared
);
200 GdipIsMatrixEqual(matrix
, sheared
, &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
);
209 GdipCreateMatrix2(7.0, 0.5, 8.0, 7.0, 6.0, 3.0, &sheared
);
210 GdipIsMatrixEqual(matrix
, sheared
, &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
);
219 GdipCreateMatrix2(9.0, 3.5, 0.0, 5.0, 18.0, 12.0, &sheared
);
220 GdipIsMatrixEqual(matrix
, sheared
, &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. */
248 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
251 stat
= GdipGetMatrixElements(matrix
, values
);
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
);
270 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
273 stat
= GdipGetMatrixElements(matrix
, values
);
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
);
292 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
295 stat
= GdipGetMatrixElements(matrix
, values
);
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
);}
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();
326 GdiplusShutdown(gdiplusToken
);