include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / gdi32 / tests / mapping.c
blob78c83907a7eb5f201dc718cfc984ad51ae2fa24a
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 <stdio.h>
23 #include <math.h>
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.h"
31 static DWORD (WINAPI *pGetLayout)(HDC hdc);
32 static INT (WINAPI *pGetRandomRgn)(HDC hDC, HRGN hRgn, INT iCode);
33 static BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
34 static BOOL (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD);
36 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
38 #define expect_LPtoDP(_hdc, _x, _y) \
39 { \
40 POINT _pt = { 1000, 1000 }; \
41 LPtoDP(_hdc, &_pt, 1); \
42 ok(rough_match(_pt.x, _x), "expected x %d, got %ld\n", (_x), _pt.x); \
43 ok(rough_match(_pt.y, _y), "expected y %d, got %ld\n", (_y), _pt.y); \
46 #define expect_world_transform(_hdc, _em11, _em22) \
47 { \
48 BOOL _ret; \
49 XFORM _xform; \
50 SetLastError(0xdeadbeef); \
51 _ret = GetWorldTransform(_hdc, &_xform); \
52 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
53 { \
54 ok(_ret, "GetWorldTransform error %lu\n", GetLastError()); \
55 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
56 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
57 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
58 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
59 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
60 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
61 } \
64 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
65 { \
66 BOOL _ret; \
67 SIZE _size; \
68 SetLastError(0xdeadbeef); \
69 _ret = _func(_hdc, &_size); \
70 ok(_ret, #_func " error %lu\n", GetLastError()); \
71 ok(_size.cx == (_cx), "expected cx %ld, got %ld\n", (_cx), _size.cx); \
72 ok(_size.cy == (_cy), "expected cy %ld, got %ld\n", (_cy), _size.cy); \
75 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
76 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
78 static void test_world_transform(void)
80 HDC hdc;
81 int ret;
82 LONG size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
83 XFORM xform;
84 SIZE size;
86 hdc = CreateCompatibleDC(0);
88 xform.eM11 = 1.0f;
89 xform.eM12 = 0.0f;
90 xform.eM21 = 0.0f;
91 xform.eM22 = 1.0f;
92 xform.eDx = 0.0f;
93 xform.eDy = 0.0f;
94 ret = SetWorldTransform(hdc, &xform);
95 ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
97 size_cx = GetDeviceCaps(hdc, HORZSIZE);
98 size_cy = GetDeviceCaps(hdc, VERTSIZE);
99 res_x = GetDeviceCaps(hdc, HORZRES);
100 res_y = GetDeviceCaps(hdc, VERTRES);
101 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
102 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
103 trace("dc size %ld x %ld, resolution %ld x %ld dpi %ld x %ld\n",
104 size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );
106 expect_viewport_ext(hdc, 1l, 1l);
107 expect_window_ext(hdc, 1l, 1l);
108 expect_world_transform(hdc, 1.0, 1.0);
109 expect_LPtoDP(hdc, 1000, 1000);
111 SetLastError(0xdeadbeef);
112 ret = SetMapMode(hdc, MM_LOMETRIC);
113 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
115 expect_viewport_ext(hdc, res_x, -res_y);
116 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
117 ok( rough_match( size.cx, size_cx * 10 ) ||
118 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
119 "expected cx %ld or %d, got %ld\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
120 ok( rough_match( size.cy, size_cy * 10 ) ||
121 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
122 "expected cy %ld or %d, got %ld\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
123 expect_world_transform(hdc, 1.0, 1.0);
124 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
126 SetLastError(0xdeadbeef);
127 ret = SetMapMode(hdc, MM_TEXT);
128 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
130 expect_viewport_ext(hdc, 1l, 1l);
131 expect_window_ext(hdc, 1l, 1l);
132 expect_world_transform(hdc, 1.0, 1.0);
133 expect_LPtoDP(hdc, 1000, 1000);
135 ret = SetGraphicsMode(hdc, GM_ADVANCED);
136 if (!ret)
138 DeleteDC(hdc);
139 skip("GM_ADVANCED is not supported on this platform\n");
140 return;
143 expect_viewport_ext(hdc, 1l, 1l);
144 expect_window_ext(hdc, 1l, 1l);
145 expect_world_transform(hdc, 1.0, 1.0);
146 expect_LPtoDP(hdc, 1000, 1000);
148 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
149 xform.eM11 = 1.0f;
150 xform.eM12 = 2.0f;
151 xform.eM21 = 1.0f;
152 xform.eM22 = 2.0f;
153 xform.eDx = 0.0f;
154 xform.eDy = 0.0f;
155 ret = SetWorldTransform(hdc, &xform);
156 ok(!ret ||
157 broken(ret), /* NT4 */
158 "SetWorldTransform should fail with an invalid xform\n");
160 xform.eM11 = 20.0f;
161 xform.eM12 = 0.0f;
162 xform.eM21 = 0.0f;
163 xform.eM22 = 20.0f;
164 xform.eDx = 0.0f;
165 xform.eDy = 0.0f;
166 SetLastError(0xdeadbeef);
167 ret = SetWorldTransform(hdc, &xform);
168 ok(ret, "SetWorldTransform error %lu\n", GetLastError());
170 expect_viewport_ext(hdc, 1l, 1l);
171 expect_window_ext(hdc, 1l, 1l);
172 expect_world_transform(hdc, 20.0, 20.0);
173 expect_LPtoDP(hdc, 20000, 20000);
175 SetLastError(0xdeadbeef);
176 ret = SetMapMode(hdc, MM_LOMETRIC);
177 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
179 expect_viewport_ext(hdc, res_x, -res_y);
180 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
181 ok( rough_match( size.cx, size_cx * 10 ) ||
182 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
183 "expected cx %ld or %d, got %ld\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
184 ok( rough_match( size.cy, size_cy * 10 ) ||
185 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
186 "expected cy %ld or %d, got %ld\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
187 expect_world_transform(hdc, 20.0, 20.0);
188 expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
190 SetLastError(0xdeadbeef);
191 ret = SetMapMode(hdc, MM_TEXT);
192 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
194 expect_viewport_ext(hdc, 1l, 1l);
195 expect_window_ext(hdc, 1l, 1l);
196 expect_world_transform(hdc, 20.0, 20.0);
197 expect_LPtoDP(hdc, 20000, 20000);
199 size.cx = 0xdeadbeef;
200 size.cy = 0xdeadbeef;
201 ret = SetViewportExtEx(hdc, -1, -1, &size);
202 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
203 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %ld,%ld\n", size.cx, size.cy);
204 expect_viewport_ext(hdc, 1l, 1l);
205 expect_window_ext(hdc, 1l, 1l);
206 expect_world_transform(hdc, 20.0, 20.0);
207 expect_LPtoDP(hdc, 20000, 20000);
209 ret = SetMapMode(hdc, MM_ANISOTROPIC);
210 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
212 expect_viewport_ext(hdc, 1l, 1l);
213 expect_window_ext(hdc, 1l, 1l);
214 expect_world_transform(hdc, 20.0, 20.0);
215 expect_LPtoDP(hdc, 20000, 20000);
217 size.cx = 0xdeadbeef;
218 size.cy = 0xdeadbeef;
219 ret = SetViewportExtEx(hdc, -1, -1, &size);
220 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
221 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %ld,%ld\n", size.cx, size.cy);
222 expect_viewport_ext(hdc, -1l, -1l);
223 expect_window_ext(hdc, 1l, 1l);
224 expect_world_transform(hdc, 20.0, 20.0);
225 expect_LPtoDP(hdc, -20000, -20000);
227 ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
228 ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
229 ret = GetGraphicsMode(hdc);
230 ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);
232 expect_viewport_ext(hdc, -1l, -1l);
233 expect_window_ext(hdc, 1l, 1l);
234 expect_world_transform(hdc, 20.0, 20.0);
235 expect_LPtoDP(hdc, -20000, -20000);
237 DeleteDC(hdc);
240 static void test_dc_layout(void)
242 INT ret;
243 LONG size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
244 SIZE size;
245 POINT pt;
246 HBITMAP bitmap;
247 RECT rc, ret_rc;
248 HDC hdc;
249 HRGN hrgn;
251 if (!pGetLayout)
253 win_skip( "Don't have GetLayout\n" );
254 return;
257 hdc = CreateCompatibleDC(0);
258 bitmap = CreateCompatibleBitmap( hdc, 100, 100 );
259 SelectObject( hdc, bitmap );
261 size_cx = GetDeviceCaps(hdc, HORZSIZE);
262 size_cy = GetDeviceCaps(hdc, VERTSIZE);
263 res_x = GetDeviceCaps(hdc, HORZRES);
264 res_y = GetDeviceCaps(hdc, VERTRES);
265 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
266 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
268 ret = GetMapMode( hdc );
269 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
270 expect_viewport_ext(hdc, 1l, 1l);
271 expect_window_ext(hdc, 1l, 1l);
272 expect_world_transform(hdc, 1.0, 1.0);
273 expect_LPtoDP(hdc, 1000, 1000);
275 SetLayout( hdc, LAYOUT_RTL );
276 if (!pGetLayout( hdc ))
278 win_skip( "SetLayout not supported\n" );
279 DeleteDC(hdc);
280 return;
283 ret = GetMapMode( hdc );
284 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
285 ret = pGetLayout( hdc );
286 ok(ret == LAYOUT_RTL, "got %x\n", ret);
287 expect_viewport_ext(hdc, 1l, 1l);
288 expect_window_ext(hdc, 1l, 1l);
289 expect_world_transform(hdc, 1.0, 1.0);
290 expect_LPtoDP(hdc, -1000 + 99, 1000);
291 GetViewportOrgEx( hdc, &pt );
292 ok( pt.x == 0 && pt.y == 0, "wrong origin %ld,%ld\n", pt.x, pt.y );
293 GetWindowOrgEx( hdc, &pt );
294 ok( pt.x == 0 && pt.y == 0, "wrong origin %ld,%ld\n", pt.x, pt.y );
295 GetDCOrgEx( hdc, &pt );
296 ok( pt.x == 0 && pt.y == 0, "wrong origin %ld,%ld\n", pt.x, pt.y );
297 if (pGetTransform)
299 XFORM xform;
300 BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */
301 ok( ret, "got %d\n", ret );
302 ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 );
303 ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 );
304 ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 );
305 ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 );
306 ok( xform.eDx == 99.0, "got %f\n", xform.eDx );
307 ok( xform.eDy == 0.0, "got %f\n", xform.eDy );
310 SetRect( &rc, 10, 10, 20, 20 );
311 IntersectClipRect( hdc, 10, 10, 20, 20 );
312 hrgn = CreateRectRgn( 0, 0, 0, 0 );
313 GetClipRgn( hdc, hrgn );
314 GetRgnBox( hrgn, &ret_rc );
315 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
316 SetLayout( hdc, LAYOUT_LTR );
317 SetRect( &rc, 80, 10, 90, 20 );
318 GetClipRgn( hdc, hrgn );
319 GetRgnBox( hrgn, &ret_rc );
320 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
321 GetClipBox( hdc, &ret_rc );
322 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
323 IntersectClipRect( hdc, 80, 10, 85, 20 );
324 SetLayout( hdc, LAYOUT_RTL );
325 SetRect( &rc, 15, 10, 20, 20 );
326 GetClipRgn( hdc, hrgn );
327 GetRgnBox( hrgn, &ret_rc );
328 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
329 GetClipBox( hdc, &ret_rc );
330 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
331 SetRectRgn( hrgn, 60, 10, 80, 20 );
332 SetLayout( hdc, LAYOUT_LTR );
333 ExtSelectClipRgn( hdc, hrgn, RGN_OR );
334 SetLayout( hdc, LAYOUT_RTL );
335 SetRect( &rc, 15, 10, 40, 20 );
336 GetClipRgn( hdc, hrgn );
337 GetRgnBox( hrgn, &ret_rc );
338 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
339 GetClipBox( hdc, &ret_rc );
340 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
342 /* OffsetClipRgn mirrors too */
343 OffsetClipRgn( hdc, 5, 5 );
344 OffsetRect( &rc, 5, 5 );
345 GetClipRgn( hdc, hrgn );
346 GetRgnBox( hrgn, &ret_rc );
347 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
349 /* GetRandomRgn returns the raw region */
350 if (pGetRandomRgn)
352 SetRect( &rc, 55, 15, 80, 25 );
353 pGetRandomRgn( hdc, hrgn, 1 );
354 GetRgnBox( hrgn, &ret_rc );
355 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
358 SetMapMode(hdc, MM_LOMETRIC);
359 ret = GetMapMode( hdc );
360 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
362 expect_viewport_ext(hdc, res_x, -res_y);
363 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
364 ok( rough_match( size.cx, size_cx * 10 ) ||
365 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
366 "expected cx %ld or %d, got %ld\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
367 ok( rough_match( size.cy, size_cy * 10 ) ||
368 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
369 "expected cy %lxd or %d, got %ld\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
370 expect_world_transform(hdc, 1.0, 1.0);
371 expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));
373 SetMapMode(hdc, MM_TEXT);
374 ret = GetMapMode( hdc );
375 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
376 SetLayout( hdc, LAYOUT_LTR );
377 ret = GetMapMode( hdc );
378 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
379 SetMapMode(hdc, MM_TEXT);
380 ret = GetMapMode( hdc );
381 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
383 DeleteDC(hdc);
384 DeleteObject( bitmap );
387 static void test_modify_world_transform(void)
389 HDC hdc = GetDC(0);
390 XFORM xform, xform2;
391 int ret;
393 ret = SetGraphicsMode(hdc, GM_ADVANCED);
394 ok(ret, "ret = %d\n", ret);
396 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
397 ok(ret, "ret = %d\n", ret);
399 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
400 ok(!ret, "ret = %d\n", ret);
402 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
403 ok(!ret, "ret = %d\n", ret);
405 xform.eM11 = 2;
406 xform.eM12 = 0;
407 xform.eM21 = 0;
408 xform.eM22 = 1;
409 xform.eDx = xform.eDy = 0;
410 ret = ModifyWorldTransform(hdc, &xform, 4);
411 ok(ret, "ModifyWorldTransform failed\n");
413 memset(&xform2, 0xcc, sizeof(xform2));
414 ret = GetWorldTransform(hdc, &xform2);
415 ok(ret, "GetWorldTransform failed\n");
416 ok(!memcmp(&xform, &xform2, sizeof(xform)), "unexpected xform\n");
418 xform.eM11 = 1;
419 xform.eM12 = 1;
420 xform.eM21 = 1;
421 xform.eM22 = 1;
422 xform.eDx = xform.eDy = 0;
423 ret = ModifyWorldTransform(hdc, &xform, 4);
424 ok(!ret, "ModifyWorldTransform succeeded\n");
426 ReleaseDC(0, hdc);
429 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
431 SIZE windowExt, viewportExt;
432 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
434 GetWindowOrgEx(hdc, &windowOrg);
435 GetViewportOrgEx(hdc, &viewportOrg);
437 SetWindowExtEx(hdc, cx, cy, NULL);
438 GetWindowExtEx(hdc, &windowExt);
439 ok(windowExt.cx == cx && windowExt.cy == cy,
440 "Window extension: Expected %ldx%ld, got %ldx%ld\n",
441 cx, cy, windowExt.cx, windowExt.cy);
443 GetViewportExtEx(hdc, &viewportExt);
444 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
445 "Viewport extents have not been properly adjusted: Expected %ldx%ld, got %ldx%ld\n",
446 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
448 GetWindowOrgEx(hdc, &windowOrgAfter);
449 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
450 "Window origin changed from (%ld,%ld) to (%ld,%ld)\n",
451 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
453 GetViewportOrgEx(hdc, &viewportOrgAfter);
454 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
455 "Viewport origin changed from (%ld,%ld) to (%ld,%ld)\n",
456 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
459 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
461 SIZE windowExt, windowExtAfter, viewportExt;
462 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
464 GetWindowOrgEx(hdc, &windowOrg);
465 GetViewportOrgEx(hdc, &viewportOrg);
466 GetWindowExtEx(hdc, &windowExt);
468 SetViewportExtEx(hdc, cx, cy, NULL);
469 GetViewportExtEx(hdc, &viewportExt);
470 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
471 "Viewport extents have not been properly adjusted: Expected %ldx%ld, got %ldx%ld\n",
472 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
474 GetWindowExtEx(hdc, &windowExtAfter);
475 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
476 "Window extension changed from %ldx%ld to %ldx%ld\n",
477 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
479 GetWindowOrgEx(hdc, &windowOrgAfter);
480 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
481 "Window origin changed from (%ld,%ld) to (%ld,%ld)\n",
482 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
484 GetViewportOrgEx(hdc, &viewportOrgAfter);
485 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
486 "Viewport origin changed from (%ld,%ld) to (%ld,%ld)\n",
487 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
490 static void test_isotropic_mapping(void)
492 SIZE win, vp;
493 HDC hdc = GetDC(0);
495 SetMapMode(hdc, MM_ISOTROPIC);
497 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
498 Initial values after SetMapMode():
499 (1 inch = 25.4 mm)
501 Windows 9x: Windows NT:
502 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
503 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
505 To test without rounding errors, we have to use multiples of
506 these values!
509 GetWindowExtEx(hdc, &win);
510 GetViewportExtEx(hdc, &vp);
512 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
513 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
514 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
515 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
516 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
517 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
518 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
519 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
520 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
521 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
522 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
523 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
524 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
526 ReleaseDC(0, hdc);
529 static void test_setvirtualresolution(void)
531 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
532 BOOL r;
533 INT horz_res = GetDeviceCaps(hdc, HORZRES);
534 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
535 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
536 SIZE orig_lometric_vp, orig_lometric_wnd;
538 if(!pSetVirtualResolution)
540 win_skip("Don't have SetVirtualResolution\n");
541 return;
544 /* Get the true resolution limits */
545 SetMapMode(hdc, MM_LOMETRIC);
546 GetViewportExtEx(hdc, &orig_lometric_vp);
547 GetWindowExtEx(hdc, &orig_lometric_wnd);
548 SetMapMode(hdc, MM_TEXT);
550 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
551 ok(r == TRUE, "got %d\n", r);
552 expect_LPtoDP(hdc, 1000, 1000);
553 expect_viewport_ext(hdc, 1l, 1l);
554 expect_window_ext(hdc, 1l, 1l);
556 SetMapMode(hdc, MM_LOMETRIC);
557 expect_LPtoDP(hdc, 1000, -500);
558 expect_viewport_ext(hdc, 4000l, -1000l);
559 expect_window_ext(hdc, 4000l, 2000l);
561 /* Doesn't change the device caps */
562 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
563 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
564 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
566 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
567 ok(r == TRUE, "got %d\n", r);
568 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
569 SetMapMode(hdc, MM_TEXT);
570 SetMapMode(hdc, MM_LOMETRIC);
571 expect_LPtoDP(hdc, 2000, -500);
572 expect_viewport_ext(hdc, 8000l, -1000l);
573 expect_window_ext(hdc, 4000l, 2000l);
575 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
576 ok(r == TRUE, "got %d\n", r);
577 SetMapMode(hdc, MM_TEXT);
578 SetMapMode(hdc, MM_LOMETRIC);
579 expect_LPtoDP(hdc, 4000, -500);
580 expect_viewport_ext(hdc, 8000l, -1000l);
581 expect_window_ext(hdc, 2000l, 2000l);
583 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
584 ok(r == TRUE, "got %d\n", r);
585 SetMapMode(hdc, MM_TEXT);
586 SetMapMode(hdc, MM_LOMETRIC);
587 expect_LPtoDP(hdc, 4000, -500);
588 expect_viewport_ext(hdc, 8000l, -1000l);
589 expect_window_ext(hdc, 2000l, 2000l);
591 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
592 ok(r == TRUE, "got %d\n", r);
593 SetMapMode(hdc, MM_TEXT);
594 SetMapMode(hdc, MM_LOMETRIC);
595 expect_LPtoDP(hdc, 4000, -1000);
596 expect_viewport_ext(hdc, 8000l, -2000l);
597 expect_window_ext(hdc, 2000l, 2000l);
599 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
600 ok(r == FALSE, "got %d\n", r);
601 SetMapMode(hdc, MM_TEXT);
602 SetMapMode(hdc, MM_LOMETRIC);
603 expect_LPtoDP(hdc, 4000, -1000);
604 expect_viewport_ext(hdc, 8000l, -2000l);
605 expect_window_ext(hdc, 2000l, 2000l);
607 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
608 ok(r == TRUE, "got %d\n", r);
609 SetMapMode(hdc, MM_TEXT);
610 SetMapMode(hdc, MM_LOMETRIC);
611 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
612 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
614 DeleteDC(hdc);
618 static inline void expect_identity(int line, XFORM *xf)
620 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
621 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
622 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
623 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
624 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
625 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
628 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
630 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
631 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
632 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
633 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
634 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
635 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
639 static void test_gettransform(void)
641 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
642 XFORM xform, expect;
643 BOOL r;
644 SIZE lometric_vp, lometric_wnd;
646 if(!pGetTransform)
648 win_skip("Don't have GetTransform\n");
649 return;
652 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
653 ok(r == TRUE, "got %d\n", r);
654 expect_identity(__LINE__, &xform);
655 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
656 ok(r == TRUE, "got %d\n", r);
657 expect_identity(__LINE__, &xform);
658 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
659 ok(r == TRUE, "got %d\n", r);
660 expect_identity(__LINE__, &xform);
661 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
662 ok(r == TRUE, "got %d\n", r);
663 expect_identity(__LINE__, &xform);
665 SetMapMode(hdc, MM_LOMETRIC);
666 GetViewportExtEx(hdc, &lometric_vp);
667 GetWindowExtEx(hdc, &lometric_wnd);
669 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
670 ok(r == TRUE, "got %d\n", r);
671 expect_identity(__LINE__, &xform);
673 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
674 ok(r == TRUE, "got %d\n", r);
675 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
676 expect.eM12 = expect.eM21 = 0.0;
677 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
678 expect.eDx = expect.eDy = 0.0;
679 xform_near_match(__LINE__, &xform, &expect);
681 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
682 ok(r == TRUE, "got %d\n", r);
683 xform_near_match(__LINE__, &xform, &expect);
685 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
686 ok(r == TRUE, "got %d\n", r);
687 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
688 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
689 xform_near_match(__LINE__, &xform, &expect);
692 SetGraphicsMode(hdc, GM_ADVANCED);
694 expect.eM11 = 10.0;
695 expect.eM22 = 20.0;
696 SetWorldTransform(hdc, &expect);
697 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
698 ok(r == TRUE, "got %d\n", r);
699 xform_near_match(__LINE__, &xform, &expect);
701 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
702 ok(r == TRUE, "got %d\n", r);
703 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
704 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
705 xform_near_match(__LINE__, &xform, &expect);
707 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
708 ok(r == TRUE, "got %d\n", r);
709 expect.eM11 *= 10.0;
710 expect.eM22 *= 20.0;
711 xform_near_match(__LINE__, &xform, &expect);
713 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
714 ok(r == TRUE, "got %d\n", r);
715 expect.eM11 = 1 / expect.eM11;
716 expect.eM22 = 1 / expect.eM22;
717 xform_near_match(__LINE__, &xform, &expect);
719 r = pGetTransform(hdc, 0x102, &xform);
720 ok(r == FALSE, "got %d\n", r);
721 r = pGetTransform(hdc, 0x103, &xform);
722 ok(r == FALSE, "got %d\n", r);
723 r = pGetTransform(hdc, 0x104, &xform);
724 ok(r == FALSE, "got %d\n", r);
725 r = pGetTransform(hdc, 0x202, &xform);
726 ok(r == FALSE, "got %d\n", r);
727 r = pGetTransform(hdc, 0x302, &xform);
728 ok(r == FALSE, "got %d\n", r);
729 r = pGetTransform(hdc, 0x303, &xform);
730 ok(r == FALSE, "got %d\n", r);
731 r = pGetTransform(hdc, 0x403, &xform);
732 ok(r == FALSE, "got %d\n", r);
733 r = pGetTransform(hdc, 0x404, &xform);
734 ok(r == FALSE, "got %d\n", r);
735 r = pGetTransform(hdc, 0xffff, &xform);
736 ok(r == FALSE, "got %d\n", r);
739 START_TEST(mapping)
741 HMODULE mod = GetModuleHandleA("gdi32.dll");
742 pGetLayout = (void *)GetProcAddress( mod, "GetLayout" );
743 pGetRandomRgn = (void *)GetProcAddress( mod, "GetRandomRgn" );
744 pGetTransform = (void *)GetProcAddress( mod, "GetTransform" );
745 pSetVirtualResolution = (void *)GetProcAddress( mod, "SetVirtualResolution" );
747 test_modify_world_transform();
748 test_world_transform();
749 test_dc_layout();
750 test_isotropic_mapping();
751 test_setvirtualresolution();
752 test_gettransform();