Sync to trunk head(r38096)
[reactos.git] / rostests / winetests / gdi32 / mapping.c
1 /*
2 * Unit tests for mapping functions
3 *
4 * Copyright (c) 2005 Huw Davies
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 <assert.h>
22 #include <stdio.h>
23 #include <math.h>
24
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.h"
30
31
32 static void test_modify_world_transform(void)
33 {
34 HDC hdc = GetDC(0);
35 int ret;
36
37 ret = SetGraphicsMode(hdc, GM_ADVANCED);
38 if(!ret) /* running in win9x so quit */
39 {
40 ReleaseDC(0, hdc);
41 return;
42 }
43
44 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
45 ok(ret, "ret = %d\n", ret);
46
47 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
48 ok(!ret, "ret = %d\n", ret);
49
50 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
51 ok(!ret, "ret = %d\n", ret);
52
53 ReleaseDC(0, hdc);
54 }
55
56 #define rough_match(got, expected) ((got >= expected - 2) && (got <= expected + 2))
57
58 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
59 {
60 SIZE windowExt, viewportExt;
61 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
62
63 GetWindowOrgEx(hdc, &windowOrg);
64 GetViewportOrgEx(hdc, &viewportOrg);
65
66 SetWindowExtEx(hdc, cx, cy, NULL);
67 GetWindowExtEx(hdc, &windowExt);
68 ok(windowExt.cx == cx && windowExt.cy == cy,
69 "Window extension: Expected %dx%d, got %dx%d\n",
70 cx, cy, windowExt.cx, windowExt.cy);
71
72 GetViewportExtEx(hdc, &viewportExt);
73 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
74 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
75 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
76
77 GetWindowOrgEx(hdc, &windowOrgAfter);
78 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
79 "Window origin changed from (%d,%d) to (%d,%d)\n",
80 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
81
82 GetViewportOrgEx(hdc, &viewportOrgAfter);
83 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
84 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
85 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
86 }
87
88 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
89 {
90 SIZE windowExt, windowExtAfter, viewportExt;
91 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
92
93 GetWindowOrgEx(hdc, &windowOrg);
94 GetViewportOrgEx(hdc, &viewportOrg);
95 GetWindowExtEx(hdc, &windowExt);
96
97 SetViewportExtEx(hdc, cx, cy, NULL);
98 GetViewportExtEx(hdc, &viewportExt);
99 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
100 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
101 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
102
103 GetWindowExtEx(hdc, &windowExtAfter);
104 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
105 "Window extension changed from %dx%d to %dx%d\n",
106 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
107
108 GetWindowOrgEx(hdc, &windowOrgAfter);
109 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
110 "Window origin changed from (%d,%d) to (%d,%d)\n",
111 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
112
113 GetViewportOrgEx(hdc, &viewportOrgAfter);
114 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
115 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
116 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
117 }
118
119 static void test_isotropic_mapping(void)
120 {
121 SIZE win, vp;
122 HDC hdc = GetDC(0);
123
124 SetMapMode(hdc, MM_ISOTROPIC);
125
126 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
127 Initial values after SetMapMode():
128 (1 inch = 25.4 mm)
129
130 Windows 9x: Windows NT:
131 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
132 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
133
134 To test without rounding errors, we have to use multiples of
135 these values!
136 */
137
138 GetWindowExtEx(hdc, &win);
139 GetViewportExtEx(hdc, &vp);
140
141 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
142 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
143 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
144 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
145 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
146 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
147 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
148 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
149 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
150 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
151 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
152 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
153 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
154
155 ReleaseDC(0, hdc);
156 }
157
158 START_TEST(mapping)
159 {
160 test_modify_world_transform();
161 test_isotropic_mapping();
162 }