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
26 #include "wine/test.h"
32 #define rough_match(got, expected) (abs((got) - (expected)) <= 5)
34 #define expect_LPtoDP(_hdc, _x, _y) \
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) \
46 SetLastError(0xdeadbeef); \
47 _ret = GetWorldTransform(_hdc, &_xform); \
48 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
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); \
60 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
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)
78 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
82 SetLastError(0xdeadbeef);
83 GetWorldTransform(0, NULL);
84 is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
86 hdc = CreateCompatibleDC(0);
88 size_cx = GetDeviceCaps(hdc, HORZSIZE);
89 size_cy = GetDeviceCaps(hdc, VERTSIZE);
90 res_x = GetDeviceCaps(hdc, HORZRES);
91 res_y = GetDeviceCaps(hdc, VERTRES);
92 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
93 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
94 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
95 size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );
97 expect_viewport_ext(hdc, 1, 1);
98 expect_window_ext(hdc, 1, 1);
99 expect_world_trasform(hdc, 1.0, 1.0);
100 expect_LPtoDP(hdc, 1000, 1000);
102 SetLastError(0xdeadbeef);
103 ret = SetMapMode(hdc, MM_LOMETRIC);
104 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
108 expect_viewport_ext(hdc, dpi_x, dpi_y);
109 expect_window_ext(hdc, 254, -254);
113 expect_viewport_ext(hdc, res_x, -res_y);
114 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
115 ok( size.cx == size_cx * 10 ||
116 size.cx == MulDiv( res_x, 254, dpi_x ), /* Vista uses a more precise method */
117 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
118 ok( size.cy == size_cy * 10 ||
119 size.cy == MulDiv( res_y, 254, dpi_y ), /* Vista uses a more precise method */
120 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
122 expect_world_trasform(hdc, 1.0, 1.0);
123 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
125 SetLastError(0xdeadbeef);
126 ret = SetMapMode(hdc, MM_TEXT);
127 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
129 expect_viewport_ext(hdc, 1, 1);
130 expect_window_ext(hdc, 1, 1);
131 expect_world_trasform(hdc, 1.0, 1.0);
132 expect_LPtoDP(hdc, 1000, 1000);
134 ret = SetGraphicsMode(hdc, GM_ADVANCED);
138 skip("GM_ADVANCED is not supported on this platform\n");
142 expect_viewport_ext(hdc, 1, 1);
143 expect_window_ext(hdc, 1, 1);
144 expect_world_trasform(hdc, 1.0, 1.0);
145 expect_LPtoDP(hdc, 1000, 1000);
153 SetLastError(0xdeadbeef);
154 ret = SetWorldTransform(hdc, &xform);
155 ok(ret, "SetWorldTransform error %u\n", GetLastError());
157 expect_viewport_ext(hdc, 1, 1);
158 expect_window_ext(hdc, 1, 1);
159 expect_world_trasform(hdc, 20.0, 20.0);
160 expect_LPtoDP(hdc, 20000, 20000);
162 SetLastError(0xdeadbeef);
163 ret = SetMapMode(hdc, MM_LOMETRIC);
164 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
166 expect_viewport_ext(hdc, res_x, -res_y);
167 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
168 ok( size.cx == size_cx * 10 ||
169 size.cx == MulDiv( res_x, 254, dpi_x ), /* Vista uses a more precise method */
170 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
171 ok( size.cy == size_cy * 10 ||
172 size.cy == MulDiv( res_y, 254, dpi_y ), /* Vista uses a more precise method */
173 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
174 expect_world_trasform(hdc, 20.0, 20.0);
175 expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
177 SetLastError(0xdeadbeef);
178 ret = SetMapMode(hdc, MM_TEXT);
179 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
181 expect_viewport_ext(hdc, 1, 1);
182 expect_window_ext(hdc, 1, 1);
183 expect_world_trasform(hdc, 20.0, 20.0);
184 expect_LPtoDP(hdc, 20000, 20000);
189 static void test_modify_world_transform(void)
194 ret = SetGraphicsMode(hdc, GM_ADVANCED);
195 if(!ret) /* running in win9x so quit */
198 skip("GM_ADVANCED is not supported on this platform\n");
202 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
203 ok(ret, "ret = %d\n", ret);
205 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
206 ok(!ret, "ret = %d\n", ret);
208 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
209 ok(!ret, "ret = %d\n", ret);
214 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
216 SIZE windowExt, viewportExt;
217 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
219 GetWindowOrgEx(hdc, &windowOrg);
220 GetViewportOrgEx(hdc, &viewportOrg);
222 SetWindowExtEx(hdc, cx, cy, NULL);
223 GetWindowExtEx(hdc, &windowExt);
224 ok(windowExt.cx == cx && windowExt.cy == cy,
225 "Window extension: Expected %dx%d, got %dx%d\n",
226 cx, cy, windowExt.cx, windowExt.cy);
228 GetViewportExtEx(hdc, &viewportExt);
229 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
230 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
231 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
233 GetWindowOrgEx(hdc, &windowOrgAfter);
234 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
235 "Window origin changed from (%d,%d) to (%d,%d)\n",
236 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
238 GetViewportOrgEx(hdc, &viewportOrgAfter);
239 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
240 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
241 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
244 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
246 SIZE windowExt, windowExtAfter, viewportExt;
247 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
249 GetWindowOrgEx(hdc, &windowOrg);
250 GetViewportOrgEx(hdc, &viewportOrg);
251 GetWindowExtEx(hdc, &windowExt);
253 SetViewportExtEx(hdc, cx, cy, NULL);
254 GetViewportExtEx(hdc, &viewportExt);
255 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
256 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
257 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
259 GetWindowExtEx(hdc, &windowExtAfter);
260 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
261 "Window extension changed from %dx%d to %dx%d\n",
262 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
264 GetWindowOrgEx(hdc, &windowOrgAfter);
265 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
266 "Window origin changed from (%d,%d) to (%d,%d)\n",
267 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
269 GetViewportOrgEx(hdc, &viewportOrgAfter);
270 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
271 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
272 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
275 static void test_isotropic_mapping(void)
280 SetMapMode(hdc, MM_ISOTROPIC);
282 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
283 Initial values after SetMapMode():
286 Windows 9x: Windows NT:
287 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
288 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
290 To test without rounding errors, we have to use multiples of
294 GetWindowExtEx(hdc, &win);
295 GetViewportExtEx(hdc, &vp);
297 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
298 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
299 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
300 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
301 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
302 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
303 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
304 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
305 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
306 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
307 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
308 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
309 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
316 test_modify_world_transform();
317 test_world_transform();
318 test_isotropic_mapping();