push 6ad4febc802779d39881ae7cccabf16fa19e6741
[wine/hacks.git] / dlls / gdi32 / tests / mapping.c
blob7e85ca9e05ab2ccc6436ec3a9599c76d0a900eb7
1 /*
2 * Unit tests for mapping functions
4 * Copyright (c) 2005 Huw Davies
5 * Copyright (c) 2008 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include <stdio.h>
24 #include <math.h>
26 #include "wine/test.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.h"
32 #define rough_match(got, expected) (abs((got) - (expected)) <= 5)
34 #define expect_LPtoDP(_hdc, _x, _y) \
35 { \
36 POINT _pt = { 1000, 1000 }; \
37 LPtoDP(_hdc, &_pt, 1); \
38 ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \
39 ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \
42 #define expect_world_trasform(_hdc, _em11, _em22) \
43 { \
44 BOOL _ret; \
45 XFORM _xform; \
46 SetLastError(0xdeadbeef); \
47 _ret = GetWorldTransform(_hdc, &_xform); \
48 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
49 { \
50 ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \
51 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
52 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
53 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
54 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
55 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
56 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
57 } \
60 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
61 { \
62 BOOL _ret; \
63 SIZE _size; \
64 SetLastError(0xdeadbeef); \
65 _ret = _func(_hdc, &_size); \
66 ok(_ret, #_func " error %u\n", GetLastError()); \
67 ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \
68 ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \
71 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
72 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
74 static void test_world_transform(void)
76 BOOL is_win9x;
77 HDC hdc;
78 INT ret, size_cx, size_cy, res_x, res_y;
79 XFORM xform;
81 SetLastError(0xdeadbeef);
82 GetWorldTransform(0, NULL);
83 is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
85 hdc = CreateCompatibleDC(0);
87 size_cx = GetDeviceCaps(hdc, HORZSIZE);
88 size_cy = GetDeviceCaps(hdc, VERTSIZE);
89 res_x = GetDeviceCaps(hdc, HORZRES);
90 res_y = GetDeviceCaps(hdc, VERTRES);
91 trace("dc size %d x %d, resolution %d x %d\n", size_cx, size_cy, res_x, res_y);
93 expect_viewport_ext(hdc, 1, 1);
94 expect_window_ext(hdc, 1, 1);
95 expect_world_trasform(hdc, 1.0, 1.0);
96 expect_LPtoDP(hdc, 1000, 1000);
98 SetLastError(0xdeadbeef);
99 ret = SetMapMode(hdc, MM_LOMETRIC);
100 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
102 if (is_win9x)
104 expect_viewport_ext(hdc, GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
105 expect_window_ext(hdc, 254, -254);
107 else
109 expect_viewport_ext(hdc, res_x, -res_y);
110 expect_window_ext(hdc, size_cx * 10, size_cy * 10);
112 expect_world_trasform(hdc, 1.0, 1.0);
113 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
115 SetLastError(0xdeadbeef);
116 ret = SetMapMode(hdc, MM_TEXT);
117 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
119 expect_viewport_ext(hdc, 1, 1);
120 expect_window_ext(hdc, 1, 1);
121 expect_world_trasform(hdc, 1.0, 1.0);
122 expect_LPtoDP(hdc, 1000, 1000);
124 ret = SetGraphicsMode(hdc, GM_ADVANCED);
125 if (!ret)
127 DeleteDC(hdc);
128 skip("GM_ADVANCED is not supported on this platform\n");
129 return;
132 expect_viewport_ext(hdc, 1, 1);
133 expect_window_ext(hdc, 1, 1);
134 expect_world_trasform(hdc, 1.0, 1.0);
135 expect_LPtoDP(hdc, 1000, 1000);
137 xform.eM11 = 20.0f;
138 xform.eM12 = 0.0f;
139 xform.eM21 = 0.0f;
140 xform.eM22 = 20.0f;
141 xform.eDx = 0.0f;
142 xform.eDy = 0.0f;
143 SetLastError(0xdeadbeef);
144 ret = SetWorldTransform(hdc, &xform);
145 ok(ret, "SetWorldTransform error %u\n", GetLastError());
147 expect_viewport_ext(hdc, 1, 1);
148 expect_window_ext(hdc, 1, 1);
149 expect_world_trasform(hdc, 20.0, 20.0);
150 expect_LPtoDP(hdc, 20000, 20000);
152 SetLastError(0xdeadbeef);
153 ret = SetMapMode(hdc, MM_LOMETRIC);
154 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
156 expect_viewport_ext(hdc, res_x, -res_y);
157 expect_window_ext(hdc, size_cx * 10, size_cy * 10);
158 expect_world_trasform(hdc, 20.0, 20.0);
159 expect_LPtoDP(hdc, MulDiv(1000 * 2, res_x, size_cx), -MulDiv(1000 * 2, res_y, size_cy));
161 SetLastError(0xdeadbeef);
162 ret = SetMapMode(hdc, MM_TEXT);
163 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
165 expect_viewport_ext(hdc, 1, 1);
166 expect_window_ext(hdc, 1, 1);
167 expect_world_trasform(hdc, 20.0, 20.0);
168 expect_LPtoDP(hdc, 20000, 20000);
170 DeleteDC(hdc);
173 static void test_modify_world_transform(void)
175 HDC hdc = GetDC(0);
176 int ret;
178 ret = SetGraphicsMode(hdc, GM_ADVANCED);
179 if(!ret) /* running in win9x so quit */
181 ReleaseDC(0, hdc);
182 skip("GM_ADVANCED is not supported on this platform\n");
183 return;
186 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
187 ok(ret, "ret = %d\n", ret);
189 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
190 ok(!ret, "ret = %d\n", ret);
192 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
193 ok(!ret, "ret = %d\n", ret);
195 ReleaseDC(0, hdc);
198 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
200 SIZE windowExt, viewportExt;
201 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
203 GetWindowOrgEx(hdc, &windowOrg);
204 GetViewportOrgEx(hdc, &viewportOrg);
206 SetWindowExtEx(hdc, cx, cy, NULL);
207 GetWindowExtEx(hdc, &windowExt);
208 ok(windowExt.cx == cx && windowExt.cy == cy,
209 "Window extension: Expected %dx%d, got %dx%d\n",
210 cx, cy, windowExt.cx, windowExt.cy);
212 GetViewportExtEx(hdc, &viewportExt);
213 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
214 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
215 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
217 GetWindowOrgEx(hdc, &windowOrgAfter);
218 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
219 "Window origin changed from (%d,%d) to (%d,%d)\n",
220 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
222 GetViewportOrgEx(hdc, &viewportOrgAfter);
223 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
224 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
225 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
228 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
230 SIZE windowExt, windowExtAfter, viewportExt;
231 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
233 GetWindowOrgEx(hdc, &windowOrg);
234 GetViewportOrgEx(hdc, &viewportOrg);
235 GetWindowExtEx(hdc, &windowExt);
237 SetViewportExtEx(hdc, cx, cy, NULL);
238 GetViewportExtEx(hdc, &viewportExt);
239 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
240 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
241 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
243 GetWindowExtEx(hdc, &windowExtAfter);
244 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
245 "Window extension changed from %dx%d to %dx%d\n",
246 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
248 GetWindowOrgEx(hdc, &windowOrgAfter);
249 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
250 "Window origin changed from (%d,%d) to (%d,%d)\n",
251 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
253 GetViewportOrgEx(hdc, &viewportOrgAfter);
254 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
255 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
256 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
259 static void test_isotropic_mapping(void)
261 SIZE win, vp;
262 HDC hdc = GetDC(0);
264 SetMapMode(hdc, MM_ISOTROPIC);
266 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
267 Initial values after SetMapMode():
268 (1 inch = 25.4 mm)
270 Windows 9x: Windows NT:
271 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
272 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
274 To test without rounding errors, we have to use multiples of
275 these values!
278 GetWindowExtEx(hdc, &win);
279 GetViewportExtEx(hdc, &vp);
281 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
282 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
283 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
284 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
285 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
286 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
287 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
288 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
289 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
290 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
291 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
292 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
293 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
295 ReleaseDC(0, hdc);
298 START_TEST(mapping)
300 test_modify_world_transform();
301 test_world_transform();
302 test_isotropic_mapping();