gdiplus: GdipInvertMatrix implementation with tests.
[wine.git] / dlls / gdiplus / tests / matrix.c
blob3d3c4842eaa8c596f78f195a4fdb8dcf73f2f4ba
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 "windows.h"
24 #include <stdio.h>
25 #include "gdiplus.h"
26 #include "wine/test.h"
28 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\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, 10);
80 expect(Ok, status);
82 for(i = 0; i < 10; i ++){
83 match = fabs(transform_points[i].X - pts[i].X) < 2.0
84 && fabs(transform_points[i].Y - pts[i].Y) < 2.0;
86 ok(match, "Expected #%d to be (%.2f, %.2f) but got (%.2f, %.2f)\n", i,
87 transform_points[i].X, transform_points[i].Y, pts[i].X, pts[i].Y);
90 GdipDeleteMatrix(matrix);
93 static void test_isinvertible(void)
95 GpStatus status;
96 GpMatrix *matrix = NULL;
97 BOOL result;
99 /* NULL arguments */
100 status = GdipIsMatrixInvertible(NULL, &result);
101 expect(InvalidParameter, status);
102 status = GdipIsMatrixInvertible((GpMatrix*)0xdeadbeef, NULL);
103 expect(InvalidParameter, status);
104 status = GdipIsMatrixInvertible(NULL, NULL);
105 expect(InvalidParameter, status);
107 /* invertible */
108 GdipCreateMatrix2(1.0, 1.2, 2.3, -1.0, 2.0, 3.0, &matrix);
109 status = GdipIsMatrixInvertible(matrix, &result);
110 expect(Ok, status);
111 expect(TRUE, result);
112 GdipDeleteMatrix(matrix);
114 /* noninvertible */
115 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix);
116 status = GdipIsMatrixInvertible(matrix, &result);
117 expect(Ok, status);
118 expect(FALSE, result);
119 GdipDeleteMatrix(matrix);
122 static void test_invert(void)
124 GpStatus status;
125 GpMatrix *matrix = NULL;
126 GpMatrix *inverted = NULL;
127 BOOL equal;
129 /* NULL */
130 status = GdipInvertMatrix(NULL);
131 expect(InvalidParameter, status);
133 /* noninvertible */
134 GdipCreateMatrix2(2.0, -1.0, 6.0, -3.0, 2.2, 3.0, &matrix);
135 status = GdipInvertMatrix(matrix);
136 expect(InvalidParameter, status);
137 GdipDeleteMatrix(matrix);
139 /* invertible */
140 GdipCreateMatrix2(1.0, 2.0, 4.0, -1.0, 6.0, 3.0, &matrix);
141 status = GdipInvertMatrix(matrix);
142 expect(Ok, status);
144 GdipCreateMatrix2(1.0/9.0, 2.0/9.0, 4.0/9.0, -1.0/9.0, -2.0, -1.0, &inverted);
145 GdipIsMatrixEqual(matrix, inverted, &equal);
146 expect(TRUE, equal);
148 GdipDeleteMatrix(inverted);
149 GdipDeleteMatrix(matrix);
152 START_TEST(matrix)
154 struct GdiplusStartupInput gdiplusStartupInput;
155 ULONG_PTR gdiplusToken;
157 gdiplusStartupInput.GdiplusVersion = 1;
158 gdiplusStartupInput.DebugEventCallback = NULL;
159 gdiplusStartupInput.SuppressBackgroundThread = 0;
160 gdiplusStartupInput.SuppressExternalCodecs = 0;
162 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
164 test_constructor_destructor();
165 test_transform();
166 test_isinvertible();
167 test_invert();
169 GdiplusShutdown(gdiplusToken);