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
23 #define WIN32_NO_STATUS
25 #define COM_NO_WINDOWS_H
27 //#include "windows.h"
28 #include <wine/test.h>
32 #include <wine/test.h>
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
35 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
37 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
47 if (abs(x
- y
) > ulps
)
53 static void test_constructor_destructor(void)
56 GpMatrix
*matrix
= NULL
;
58 status
= GdipCreateMatrix2(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &matrix
);
60 ok(matrix
!= NULL
, "Expected matrix to be initialized\n");
62 status
= GdipDeleteMatrix(NULL
);
63 expect(InvalidParameter
, status
);
65 status
= GdipDeleteMatrix(matrix
);
74 static real_point transform_points
[] = {
75 {1000.00, 2600.00}, /*0*/
76 {855.00, 2390.00}, /*1*/
77 {700.00, 2200.00}, /*2*/
78 {565.00, 1970.00}, /*3*/
79 {400.00, 1800.00}, /*4*/
80 {275.00, 1550.00}, /*5*/
81 {100.00, 1400.00}, /*6*/
82 {-15.00, 1130.00}, /*7*/
83 {-200.00, 1000.00}, /*8*/
84 {-305.00, 710.00} /*9*/
87 static void test_transform(void)
90 GpMatrix
*matrix
= NULL
;
95 for(i
= 0; i
< 10; i
++){
96 pts
[i
].X
= i
* 5.0 * (REAL
)(i
% 2);
97 pts
[i
].Y
= 50.0 - i
* 5.0;
100 GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix
);
102 status
= GdipTransformMatrixPoints(matrix
, pts
, 0);
103 expect(InvalidParameter
, status
);
105 status
= GdipTransformMatrixPoints(matrix
, pts
, 10);
108 for(i
= 0; i
< 10; i
++){
109 match
= fabs(transform_points
[i
].X
- pts
[i
].X
) < 2.0
110 && fabs(transform_points
[i
].Y
- pts
[i
].Y
) < 2.0;
112 ok(match
, "Expected #%d to be (%.2f, %.2f) but got (%.2f, %.2f)\n", i
,
113 transform_points
[i
].X
, transform_points
[i
].Y
, pts
[i
].X
, pts
[i
].Y
);
116 GdipDeleteMatrix(matrix
);
119 static void test_isinvertible(void)
122 GpMatrix
*matrix
= NULL
;
126 status
= GdipIsMatrixInvertible(NULL
, &result
);
127 expect(InvalidParameter
, status
);
128 status
= GdipIsMatrixInvertible((GpMatrix
*)0xdeadbeef, NULL
);
129 expect(InvalidParameter
, status
);
130 status
= GdipIsMatrixInvertible(NULL
, NULL
);
131 expect(InvalidParameter
, status
);
134 GdipCreateMatrix2(1.0, 1.2, 2.3, -1.0, 2.0, 3.0, &matrix
);
135 status
= GdipIsMatrixInvertible(matrix
, &result
);
137 expect(TRUE
, result
);
138 GdipDeleteMatrix(matrix
);
141 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix
);
142 status
= GdipIsMatrixInvertible(matrix
, &result
);
144 expect(FALSE
, result
);
145 GdipDeleteMatrix(matrix
);
148 static void test_invert(void)
151 GpMatrix
*matrix
= NULL
;
152 GpMatrix
*inverted
= NULL
;
157 status
= GdipInvertMatrix(NULL
);
158 expect(InvalidParameter
, status
);
161 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix
);
162 status
= GdipInvertMatrix(matrix
);
163 expect(InvalidParameter
, status
);
164 GdipDeleteMatrix(matrix
);
167 GdipCreateMatrix2(3.0, -2.0, 5.0, 2.0, 6.0, 3.0, &matrix
);
168 status
= GdipInvertMatrix(matrix
);
170 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
);
171 GdipIsMatrixEqual(matrix
, inverted
, &equal
);
174 GdipCreateMatrix2(0.0006, 0, 0, 0.0006, 400, 400, &matrix
);
175 status
= GdipInvertMatrix(matrix
);
177 status
= GdipGetMatrixElements(matrix
, elems
);
179 ok(compare_float(elems
[0], 1666.666504, 1), "elems[0] = %.10g\n", elems
[0]);
180 ok(compare_float(elems
[1], 0, 0), "elems[1] = %.10g\n", elems
[1]);
181 ok(compare_float(elems
[2], 0, 0), "elems[2] = %.10g\n", elems
[2]);
182 ok(compare_float(elems
[3], 1666.666504, 1), "elems[3] = %.10g\n", elems
[3]);
183 ok(compare_float(elems
[4], -666666.6875, 1), "elems[4] = %.10g\n", elems
[4]);
184 ok(compare_float(elems
[5], -666666.6875, 1), "elems[5] = %.10g\n", elems
[5]);
186 GdipDeleteMatrix(inverted
);
187 GdipDeleteMatrix(matrix
);
190 static void test_shear(void)
193 GpMatrix
*matrix
= NULL
;
194 GpMatrix
*sheared
= NULL
;
198 status
= GdipShearMatrix(NULL
, 0.0, 0.0, MatrixOrderPrepend
);
199 expect(InvalidParameter
, status
);
201 /* X only shearing, MatrixOrderPrepend */
202 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
203 status
= GdipShearMatrix(matrix
, 1.5, 0.0, MatrixOrderPrepend
);
205 GdipCreateMatrix2(1.0, 2.0, 5.5, 2.0, 6.0, 3.0, &sheared
);
206 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
208 GdipDeleteMatrix(sheared
);
209 GdipDeleteMatrix(matrix
);
211 /* X only shearing, MatrixOrderAppend */
212 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
213 status
= GdipShearMatrix(matrix
, 1.5, 0.0, MatrixOrderAppend
);
215 GdipCreateMatrix2(4.0, 2.0, 2.5, -1.0, 10.5, 3.0, &sheared
);
216 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
218 GdipDeleteMatrix(sheared
);
219 GdipDeleteMatrix(matrix
);
221 /* Y only shearing, MatrixOrderPrepend */
222 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
223 status
= GdipShearMatrix(matrix
, 0.0, 1.5, MatrixOrderPrepend
);
225 GdipCreateMatrix2(7.0, 0.5, 4.0, -1.0, 6.0, 3.0, &sheared
);
226 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
228 GdipDeleteMatrix(sheared
);
229 GdipDeleteMatrix(matrix
);
231 /* Y only shearing, MatrixOrderAppend */
232 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
233 status
= GdipShearMatrix(matrix
, 0.0, 1.5, MatrixOrderAppend
);
235 GdipCreateMatrix2(1.0, 3.5, 4.0, 5.0, 6.0, 12.0, &sheared
);
236 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
238 GdipDeleteMatrix(sheared
);
239 GdipDeleteMatrix(matrix
);
241 /* X,Y shearing, MatrixOrderPrepend */
242 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
243 status
= GdipShearMatrix(matrix
, 4.0, 1.5, MatrixOrderPrepend
);
245 GdipCreateMatrix2(7.0, 0.5, 8.0, 7.0, 6.0, 3.0, &sheared
);
246 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
248 GdipDeleteMatrix(sheared
);
249 GdipDeleteMatrix(matrix
);
251 /* X,Y shearing, MatrixOrderAppend */
252 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix
);
253 status
= GdipShearMatrix(matrix
, 4.0, 1.5, MatrixOrderAppend
);
255 GdipCreateMatrix2(9.0, 3.5, 0.0, 5.0, 18.0, 12.0, &sheared
);
256 GdipIsMatrixEqual(matrix
, sheared
, &equal
);
258 GdipDeleteMatrix(sheared
);
259 GdipDeleteMatrix(matrix
);
262 static void test_constructor3(void)
264 /* MSDN is on crack. GdipCreateMatrix3 makes a matrix that transforms the
265 * corners of the given rectangle to the three points given. */
284 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
287 stat
= GdipGetMatrixElements(matrix
, values
);
290 expectf(1.0, values
[0]);
291 expectf(0.0, values
[1]);
292 expectf(0.0, values
[2]);
293 expectf(1.0, values
[3]);
294 expectf(0.0, values
[4]);
295 expectf(0.0, values
[5]);
297 GdipDeleteMatrix(matrix
);
306 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
309 stat
= GdipGetMatrixElements(matrix
, values
);
312 expectf(2.0, values
[0]);
313 expectf(0.0, values
[1]);
314 expectf(0.0, values
[2]);
315 expectf(1.0, values
[3]);
316 expectf(0.0, values
[4]);
317 expectf(0.0, values
[5]);
319 GdipDeleteMatrix(matrix
);
328 stat
= GdipCreateMatrix3(&rc
, pt
, &matrix
);
331 stat
= GdipGetMatrixElements(matrix
, values
);
334 expectf(1.0, values
[0]);
335 expectf(1.0, values
[1]);
336 expectf(0.0, values
[2]);
337 expectf(1.0, values
[3]);
338 expectf(0.0, values
[4]);
339 expectf(0.0, values
[5]);
341 GdipDeleteMatrix(matrix
);
344 static void test_isidentity(void)
350 stat
= GdipIsMatrixIdentity(NULL
, NULL
);
351 expect(InvalidParameter
, stat
);
353 stat
= GdipIsMatrixIdentity(NULL
, &result
);
354 expect(InvalidParameter
, stat
);
356 stat
= GdipCreateMatrix2(1.0, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix
);
359 stat
= GdipIsMatrixIdentity(matrix
, NULL
);
360 expect(InvalidParameter
, stat
);
363 stat
= GdipIsMatrixIdentity(matrix
, &result
);
365 ok(!!result
, "got %d\n", result
);
367 stat
= GdipSetMatrixElements(matrix
, 1.0, 0.0, 0.0, 1.0, 0.1, 0.0);
371 stat
= GdipIsMatrixIdentity(matrix
, &result
);
373 ok(!result
, "got %d\n", result
);
375 GdipDeleteMatrix(matrix
);
380 struct GdiplusStartupInput gdiplusStartupInput
;
381 ULONG_PTR gdiplusToken
;
383 int (CDECL
* _controlfp_s
)(unsigned int *cur
, unsigned int newval
, unsigned int mask
);
385 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
386 hmsvcrt
= LoadLibraryA("msvcrt");
387 _controlfp_s
= (void*)GetProcAddress(hmsvcrt
, "_controlfp_s");
388 if (_controlfp_s
) _controlfp_s(0, 0, 0x0008001e);
390 gdiplusStartupInput
.GdiplusVersion
= 1;
391 gdiplusStartupInput
.DebugEventCallback
= NULL
;
392 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
393 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
395 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
397 test_constructor_destructor();
405 GdiplusShutdown(gdiplusToken
);