urlmon: Don't create stgmed_obj for binding to object.
[wine] / dlls / gdiplus / tests / matrix.c
1 /*
2  * Unit test suite for matrices
3  *
4  * Copyright (C) 2007 Google (Evan Stade)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <math.h>
22
23 #include "windows.h"
24 #include "gdiplus.h"
25 #include "wine/test.h"
26
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28
29 static void test_constructor_destructor(void)
30 {
31     GpStatus status;
32     GpMatrix *matrix = NULL;
33
34     status = GdipCreateMatrix2(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &matrix);
35     expect(Ok, status);
36     ok(matrix != NULL, "Expected matrix to be initialized\n");
37
38     status = GdipDeleteMatrix(NULL);
39     expect(InvalidParameter, status);
40
41     status = GdipDeleteMatrix(matrix);
42     expect(Ok, status);
43 }
44
45 typedef struct{
46     REAL X;
47     REAL Y;
48 } real_point;
49
50 static real_point transform_points[] = {
51     {1000.00, 2600.00}, /*0*/
52     {855.00, 2390.00}, /*1*/
53     {700.00, 2200.00}, /*2*/
54     {565.00, 1970.00}, /*3*/
55     {400.00, 1800.00}, /*4*/
56     {275.00, 1550.00}, /*5*/
57     {100.00, 1400.00}, /*6*/
58     {-15.00, 1130.00}, /*7*/
59     {-200.00, 1000.00}, /*8*/
60     {-305.00, 710.00} /*9*/
61     };
62
63 static void test_transform(void)
64 {
65     GpStatus status;
66     GpMatrix *matrix = NULL;
67     GpPointF pts[10];
68     INT i;
69     BOOL match;
70
71     for(i = 0; i < 10; i ++){
72         pts[i].X = i * 5.0 * (REAL)(i % 2);
73         pts[i].Y = 50.0 - i * 5.0;
74     }
75
76     GdipCreateMatrix2(1.0, -2.0, 30.0, 40.0, -500.0, 600.0, &matrix);
77
78     status = GdipTransformMatrixPoints(matrix, pts, 10);
79     expect(Ok, status);
80
81     for(i = 0; i < 10; i ++){
82         match = fabs(transform_points[i].X - pts[i].X) < 2.0
83             && fabs(transform_points[i].Y -  pts[i].Y) < 2.0;
84
85         ok(match, "Expected #%d to be (%.2f, %.2f) but got (%.2f, %.2f)\n", i,
86            transform_points[i].X, transform_points[i].Y, pts[i].X, pts[i].Y);
87     }
88
89     GdipDeleteMatrix(matrix);
90 }
91
92 START_TEST(matrix)
93 {
94     struct GdiplusStartupInput gdiplusStartupInput;
95     ULONG_PTR gdiplusToken;
96
97     gdiplusStartupInput.GdiplusVersion              = 1;
98     gdiplusStartupInput.DebugEventCallback          = NULL;
99     gdiplusStartupInput.SuppressBackgroundThread    = 0;
100     gdiplusStartupInput.SuppressExternalCodecs      = 0;
101
102     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
103
104     test_constructor_destructor();
105     test_transform();
106
107     GdiplusShutdown(gdiplusToken);
108 }