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
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(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
31 static void test_constructor_destructor(void)
34 GpMatrix
*matrix
= NULL
;
36 status
= GdipCreateMatrix2(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &matrix
);
38 ok(matrix
!= NULL
, "Expected matrix to be initialized\n");
40 status
= GdipDeleteMatrix(NULL
);
41 expect(InvalidParameter
, status
);
43 status
= GdipDeleteMatrix(matrix
);
52 static real_point transform_points
[] = {
53 {1000.00, 2600.00}, /*0*/
54 {855.00, 2390.00}, /*1*/
55 {700.00, 2200.00}, /*2*/
56 {565.00, 1970.00}, /*3*/
57 {400.00, 1800.00}, /*4*/
58 {275.00, 1550.00}, /*5*/
59 {100.00, 1400.00}, /*6*/
60 {-15.00, 1130.00}, /*7*/
61 {-200.00, 1000.00}, /*8*/
62 {-305.00, 710.00} /*9*/
65 static void test_transform(void)
68 GpMatrix
*matrix
= NULL
;
73 for(i
= 0; i
< 10; i
++){
74 pts
[i
].X
= i
* 5.0 * (REAL
)(i
% 2);
75 pts
[i
].Y
= 50.0 - i
* 5.0;
78 GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix
);
80 status
= GdipTransformMatrixPoints(matrix
, pts
, 10);
83 for(i
= 0; i
< 10; i
++){
84 match
= fabs(transform_points
[i
].X
- pts
[i
].X
) < 2.0
85 && fabs(transform_points
[i
].Y
- pts
[i
].Y
) < 2.0;
87 ok(match
, "Expected #%d to be (%.2f, %.2f) but got (%.2f, %.2f)\n", i
,
88 transform_points
[i
].X
, transform_points
[i
].Y
, pts
[i
].X
, pts
[i
].Y
);
91 GdipDeleteMatrix(matrix
);
94 static void test_isinvertible(void)
97 GpMatrix
*matrix
= NULL
;
101 status
= GdipIsMatrixInvertible(NULL
, &result
);
102 expect(InvalidParameter
, status
);
103 status
= GdipIsMatrixInvertible((GpMatrix
*)0xdeadbeef, NULL
);
104 expect(InvalidParameter
, status
);
105 status
= GdipIsMatrixInvertible(NULL
, NULL
);
106 expect(InvalidParameter
, status
);
109 GdipCreateMatrix2(1.0, 1.2, 2.3, -1.0, 2.0, 3.0, &matrix
);
110 status
= GdipIsMatrixInvertible(matrix
, &result
);
112 expect(TRUE
, result
);
113 GdipDeleteMatrix(matrix
);
116 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix
);
117 status
= GdipIsMatrixInvertible(matrix
, &result
);
119 expect(FALSE
, result
);
120 GdipDeleteMatrix(matrix
);
123 static void test_invert(void)
126 GpMatrix
*matrix
= NULL
;
127 GpMatrix
*inverted
= NULL
;
131 status
= GdipInvertMatrix(NULL
);
132 expect(InvalidParameter
, status
);
135 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix
);
136 status
= GdipInvertMatrix(matrix
);
137 expect(InvalidParameter
, status
);
138 GdipDeleteMatrix(matrix
);
141 GdipCreateMatrix2(3.0, -2.0, 5.0, 2.0, 6.0, 3.0, &matrix
);
142 status
= GdipInvertMatrix(matrix
);
144 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
);
145 GdipIsMatrixEqual(matrix
, inverted
, &equal
);
148 GdipDeleteMatrix(inverted
);
149 GdipDeleteMatrix(matrix
);
152 static void test_shear(void)
155 GpMatrix
*matrix
= NULL
;
156 GpMatrix
*sheared
= NULL
;
160 status
= GdipShearMatrix(NULL
, 0.0, 0.0, MatrixOrderPrepend
);
161 expect(InvalidParameter
, status
);
163 /* X only shearing, MatrixOrderPrepend */
164 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
165 status
= GdipShearMatrix(matrix
, 1.5, 0.0, MatrixOrderPrepend
);
167 GdipCreateMatrix2(1.0, 2.0, 5.5, 2.0, 6.0, 3.0, &sheared
);
168 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
170 GdipDeleteMatrix(sheared
);
171 GdipDeleteMatrix(matrix
);
173 /* X only shearing, MatrixOrderAppend */
174 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
175 status
= GdipShearMatrix(matrix
, 1.5, 0.0, MatrixOrderAppend
);
177 GdipCreateMatrix2(4.0, 2.0, 2.5, -1.0, 10.5, 3.0, &sheared
);
178 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
180 GdipDeleteMatrix(sheared
);
181 GdipDeleteMatrix(matrix
);
183 /* Y only shearing, MatrixOrderPrepend */
184 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
185 status
= GdipShearMatrix(matrix
, 0.0, 1.5, MatrixOrderPrepend
);
187 GdipCreateMatrix2(7.0, 0.5, 4.0, -1.0, 6.0, 3.0, &sheared
);
188 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
190 GdipDeleteMatrix(sheared
);
191 GdipDeleteMatrix(matrix
);
193 /* Y only shearing, MatrixOrderAppend */
194 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
195 status
= GdipShearMatrix(matrix
, 0.0, 1.5, MatrixOrderAppend
);
197 GdipCreateMatrix2(1.0, 3.5, 4.0, 5.0, 6.0, 12.0, &sheared
);
198 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
200 GdipDeleteMatrix(sheared
);
201 GdipDeleteMatrix(matrix
);
203 /* X,Y shearing, MatrixOrderPrepend */
204 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
205 status
= GdipShearMatrix(matrix
, 4.0, 1.5, MatrixOrderPrepend
);
207 GdipCreateMatrix2(7.0, 0.5, 8.0, 7.0, 6.0, 3.0, &sheared
);
208 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
210 GdipDeleteMatrix(sheared
);
211 GdipDeleteMatrix(matrix
);
213 /* X,Y shearing, MatrixOrderAppend */
214 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
215 status
= GdipShearMatrix(matrix
, 4.0, 1.5, MatrixOrderAppend
);
217 GdipCreateMatrix2(9.0, 3.5, 0.0, 5.0, 18.0, 12.0, &sheared
);
218 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
220 GdipDeleteMatrix(sheared
);
221 GdipDeleteMatrix(matrix
);
224 static void test_constructor3(void)
226 /* MSDN is on crack. GdipCreateMatrix3 makes a matrix that transforms the
227 * corners of the given rectangle to the three points given. */
246 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
249 stat
= GdipGetMatrixElements(matrix
, values
);
252 expectf(1.0, values
[0]);
253 expectf(0.0, values
[1]);
254 expectf(0.0, values
[2]);
255 expectf(1.0, values
[3]);
256 expectf(0.0, values
[4]);
257 expectf(0.0, values
[5]);
259 GdipDeleteMatrix(matrix
);
268 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
271 stat
= GdipGetMatrixElements(matrix
, values
);
274 expectf(2.0, values
[0]);
275 expectf(0.0, values
[1]);
276 expectf(0.0, values
[2]);
277 expectf(1.0, values
[3]);
278 expectf(0.0, values
[4]);
279 expectf(0.0, values
[5]);
281 GdipDeleteMatrix(matrix
);
290 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
293 stat
= GdipGetMatrixElements(matrix
, values
);
296 expectf(1.0, values
[0]);
297 expectf(1.0, values
[1]);
298 expectf(0.0, values
[2]);
299 expectf(1.0, values
[3]);
300 expectf(0.0, values
[4]);
301 expectf(0.0, values
[5]);
303 GdipDeleteMatrix(matrix
);}
307 struct GdiplusStartupInput gdiplusStartupInput
;
308 ULONG_PTR gdiplusToken
;
310 gdiplusStartupInput
.GdiplusVersion
= 1;
311 gdiplusStartupInput
.DebugEventCallback
= NULL
;
312 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
313 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
315 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
317 test_constructor_destructor();
324 GdiplusShutdown(gdiplusToken
);