gdi32: Make wing.dll into a stand-alone 16-bit module.
[wine] / dlls / gdi32 / tests / mapping.c
1 /*
2  * Unit tests for mapping functions
3  *
4  * Copyright (c) 2005 Huw Davies
5  * Copyright (c) 2008 Dmitry  Timoshkov
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <assert.h>
23 #include <stdio.h>
24 #include <math.h>
25
26 #include "wine/test.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.h"
31
32 #define rough_match(got, expected) (abs((got) - (expected)) <= 5)
33
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); \
40 }
41
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     } \
58 }
59
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); \
69 }
70
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)
73
74 static void test_world_transform(void)
75 {
76     BOOL is_win9x;
77     HDC hdc;
78     INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
79     XFORM xform;
80     SIZE size;
81
82     SetLastError(0xdeadbeef);
83     GetWorldTransform(0, NULL);
84     is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
85
86     hdc = CreateCompatibleDC(0);
87
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");
96
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 %d x %d, resolution %d x %d dpi %d x %d\n",
104           size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );
105
106     expect_viewport_ext(hdc, 1, 1);
107     expect_window_ext(hdc, 1, 1);
108     expect_world_trasform(hdc, 1.0, 1.0);
109     expect_LPtoDP(hdc, 1000, 1000);
110
111     SetLastError(0xdeadbeef);
112     ret = SetMapMode(hdc, MM_LOMETRIC);
113     ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
114
115     if (is_win9x)
116     {
117         expect_viewport_ext(hdc, dpi_x, dpi_y);
118         expect_window_ext(hdc, 254, -254);
119     }
120     else
121     {
122         expect_viewport_ext(hdc, res_x, -res_y);
123         ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
124         ok( size.cx == size_cx * 10 ||
125             size.cx == MulDiv( res_x, 254, dpi_x ),  /* Vista uses a more precise method */
126             "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
127         ok( size.cy == size_cy * 10 ||
128             size.cy == MulDiv( res_y, 254, dpi_y ),  /* Vista uses a more precise method */
129             "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
130     }
131     expect_world_trasform(hdc, 1.0, 1.0);
132     expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
133
134     SetLastError(0xdeadbeef);
135     ret = SetMapMode(hdc, MM_TEXT);
136     ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
137
138     expect_viewport_ext(hdc, 1, 1);
139     expect_window_ext(hdc, 1, 1);
140     expect_world_trasform(hdc, 1.0, 1.0);
141     expect_LPtoDP(hdc, 1000, 1000);
142
143     ret = SetGraphicsMode(hdc, GM_ADVANCED);
144     if (!ret)
145     {
146         DeleteDC(hdc);
147         skip("GM_ADVANCED is not supported on this platform\n");
148         return;
149     }
150
151     expect_viewport_ext(hdc, 1, 1);
152     expect_window_ext(hdc, 1, 1);
153     expect_world_trasform(hdc, 1.0, 1.0);
154     expect_LPtoDP(hdc, 1000, 1000);
155
156     /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
157     xform.eM11 = 1.0f;
158     xform.eM12 = 2.0f;
159     xform.eM21 = 1.0f;
160     xform.eM22 = 2.0f;
161     xform.eDx = 0.0f;
162     xform.eDy = 0.0f;
163     ret = SetWorldTransform(hdc, &xform);
164     ok(!ret ||
165        broken(ret), /* NT4 */
166        "SetWorldTransform should fail with an invalid xform\n");
167
168     xform.eM11 = 20.0f;
169     xform.eM12 = 0.0f;
170     xform.eM21 = 0.0f;
171     xform.eM22 = 20.0f;
172     xform.eDx = 0.0f;
173     xform.eDy = 0.0f;
174     SetLastError(0xdeadbeef);
175     ret = SetWorldTransform(hdc, &xform);
176     ok(ret, "SetWorldTransform error %u\n", GetLastError());
177
178     expect_viewport_ext(hdc, 1, 1);
179     expect_window_ext(hdc, 1, 1);
180     expect_world_trasform(hdc, 20.0, 20.0);
181     expect_LPtoDP(hdc, 20000, 20000);
182
183     SetLastError(0xdeadbeef);
184     ret = SetMapMode(hdc, MM_LOMETRIC);
185     ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
186
187     expect_viewport_ext(hdc, res_x, -res_y);
188     ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
189     ok( size.cx == size_cx * 10 ||
190         size.cx == MulDiv( res_x, 254, dpi_x ),  /* Vista uses a more precise method */
191         "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
192     ok( size.cy == size_cy * 10 ||
193         size.cy == MulDiv( res_y, 254, dpi_y ),  /* Vista uses a more precise method */
194         "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
195     expect_world_trasform(hdc, 20.0, 20.0);
196     expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
197
198     SetLastError(0xdeadbeef);
199     ret = SetMapMode(hdc, MM_TEXT);
200     ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
201
202     expect_viewport_ext(hdc, 1, 1);
203     expect_window_ext(hdc, 1, 1);
204     expect_world_trasform(hdc, 20.0, 20.0);
205     expect_LPtoDP(hdc, 20000, 20000);
206
207     ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
208     ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
209     ret = GetGraphicsMode(hdc);
210     ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);
211
212     expect_viewport_ext(hdc, 1, 1);
213     expect_window_ext(hdc, 1, 1);
214     expect_world_trasform(hdc, 20.0, 20.0);
215     expect_LPtoDP(hdc, 20000, 20000);
216
217     DeleteDC(hdc);
218 }
219
220 static void test_modify_world_transform(void)
221 {
222     HDC hdc = GetDC(0);
223     int ret;
224
225     ret = SetGraphicsMode(hdc, GM_ADVANCED);
226     if(!ret) /* running in win9x so quit */
227     {
228         ReleaseDC(0, hdc);
229         skip("GM_ADVANCED is not supported on this platform\n");
230         return;
231     }
232
233     ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
234     ok(ret, "ret = %d\n", ret);
235
236     ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
237     ok(!ret, "ret = %d\n", ret);
238
239     ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
240     ok(!ret, "ret = %d\n", ret);
241
242     ReleaseDC(0, hdc);
243 }
244
245 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
246 {
247     SIZE windowExt, viewportExt;
248     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
249
250     GetWindowOrgEx(hdc, &windowOrg);
251     GetViewportOrgEx(hdc, &viewportOrg);
252
253     SetWindowExtEx(hdc, cx, cy, NULL);
254     GetWindowExtEx(hdc, &windowExt);
255     ok(windowExt.cx == cx && windowExt.cy == cy,
256        "Window extension: Expected %dx%d, got %dx%d\n",
257        cx, cy, windowExt.cx, windowExt.cy);
258
259     GetViewportExtEx(hdc, &viewportExt);
260     ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
261         "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
262         expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
263
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);
268
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);
273 }
274
275 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
276 {
277     SIZE windowExt, windowExtAfter, viewportExt;
278     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
279
280     GetWindowOrgEx(hdc, &windowOrg);
281     GetViewportOrgEx(hdc, &viewportOrg);
282     GetWindowExtEx(hdc, &windowExt);
283
284     SetViewportExtEx(hdc, cx, cy, NULL);
285     GetViewportExtEx(hdc, &viewportExt);
286     ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
287         "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
288         expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
289
290     GetWindowExtEx(hdc, &windowExtAfter);
291     ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
292        "Window extension changed from %dx%d to %dx%d\n",
293        windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
294
295     GetWindowOrgEx(hdc, &windowOrgAfter);
296     ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
297         "Window origin changed from (%d,%d) to (%d,%d)\n",
298         windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
299
300     GetViewportOrgEx(hdc, &viewportOrgAfter);
301     ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
302         "Viewport origin changed from (%d,%d) to (%d,%d)\n",
303         viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
304 }
305
306 static void test_isotropic_mapping(void)
307 {
308     SIZE win, vp;
309     HDC hdc = GetDC(0);
310     
311     SetMapMode(hdc, MM_ISOTROPIC);
312     
313     /* MM_ISOTROPIC is set up like MM_LOMETRIC.
314        Initial values after SetMapMode():
315        (1 inch = 25.4 mm)
316        
317                        Windows 9x:               Windows NT:
318        Window Ext:     254 x -254                HORZSIZE*10 x VERTSIZE*10
319        Viewport Ext:   LOGPIXELSX x LOGPIXELSY   HORZRES x -VERTRES
320        
321        To test without rounding errors, we have to use multiples of
322        these values!
323      */
324     
325     GetWindowExtEx(hdc, &win);
326     GetViewportExtEx(hdc, &vp);
327     
328     test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
329     test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
330     test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
331     test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
332     test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
333     test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
334     test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
335     test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
336     test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
337     test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
338     test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);    
339     test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
340     test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
341     
342     ReleaseDC(0, hdc);
343 }
344
345 static void test_setvirtualresolution(void)
346 {
347     HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
348     DWORD r;
349     DWORD (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD);
350     INT horz_res = GetDeviceCaps(hdc, HORZRES);
351     INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
352     INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
353     SIZE orig_lometric_vp, orig_lometric_wnd;
354
355     pSetVirtualResolution = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "SetVirtualResolution");
356
357     if(!pSetVirtualResolution)
358     {
359         win_skip("Don't have SetVirtualResolution\n");
360         return;
361     }
362
363     /* Get the true resolution limits */
364     SetMapMode(hdc, MM_LOMETRIC);
365     GetViewportExtEx(hdc, &orig_lometric_vp);
366     GetWindowExtEx(hdc, &orig_lometric_wnd);
367     SetMapMode(hdc, MM_TEXT);
368
369     r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
370     ok(r == TRUE, "got %d\n", r);
371     expect_LPtoDP(hdc, 1000, 1000);
372     expect_viewport_ext(hdc, 1, 1);
373     expect_window_ext(hdc, 1, 1);
374
375     SetMapMode(hdc, MM_LOMETRIC);
376     expect_LPtoDP(hdc, 1000, -500);
377     expect_viewport_ext(hdc, 4000, -1000);
378     expect_window_ext(hdc, 4000, 2000);
379
380     /* Doesn't change the device caps */
381     ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
382     ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
383     ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
384
385     r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
386     ok(r == TRUE, "got %d\n", r);
387     expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
388     SetMapMode(hdc, MM_TEXT);
389     SetMapMode(hdc, MM_LOMETRIC);
390     expect_LPtoDP(hdc, 2000, -500);
391     expect_viewport_ext(hdc, 8000, -1000);
392     expect_window_ext(hdc, 4000, 2000);
393
394     r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
395     ok(r == TRUE, "got %d\n", r);
396     SetMapMode(hdc, MM_TEXT);
397     SetMapMode(hdc, MM_LOMETRIC);
398     expect_LPtoDP(hdc, 4000, -500);
399     expect_viewport_ext(hdc, 8000, -1000);
400     expect_window_ext(hdc, 2000, 2000);
401
402     r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
403     ok(r == TRUE, "got %d\n", r);
404     SetMapMode(hdc, MM_TEXT);
405     SetMapMode(hdc, MM_LOMETRIC);
406     expect_LPtoDP(hdc, 4000, -500);
407     expect_viewport_ext(hdc, 8000, -1000);
408     expect_window_ext(hdc, 2000, 2000);
409
410     r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
411     ok(r == TRUE, "got %d\n", r);
412     SetMapMode(hdc, MM_TEXT);
413     SetMapMode(hdc, MM_LOMETRIC);
414     expect_LPtoDP(hdc, 4000, -1000);
415     expect_viewport_ext(hdc, 8000, -2000);
416     expect_window_ext(hdc, 2000, 2000);
417
418     r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
419     ok(r == FALSE, "got %d\n", r);
420     SetMapMode(hdc, MM_TEXT);
421     SetMapMode(hdc, MM_LOMETRIC);
422     expect_LPtoDP(hdc, 4000, -1000);
423     expect_viewport_ext(hdc, 8000, -2000);
424     expect_window_ext(hdc, 2000, 2000);
425
426     r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
427     ok(r == TRUE, "got %d\n", r);
428     SetMapMode(hdc, MM_TEXT);
429     SetMapMode(hdc, MM_LOMETRIC);
430     expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
431     expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
432
433     DeleteDC(hdc);
434 }
435
436
437 static inline void expect_identity(int line, XFORM *xf)
438 {
439     ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
440     ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
441     ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
442     ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
443     ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
444     ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
445 }
446
447 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
448 {
449     ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
450     ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
451     ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
452     ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
453     ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
454     ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
455 }
456
457
458 static void test_gettransform(void)
459 {
460     HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
461     BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
462     XFORM xform, expect;
463     BOOL r;
464     SIZE lometric_vp, lometric_wnd;
465
466     pGetTransform = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetTransform");
467
468     if(!pGetTransform)
469     {
470         win_skip("Don't have GetTransform\n");
471         return;
472     }
473
474     r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
475     ok(r == TRUE, "got %d\n", r);
476     expect_identity(__LINE__, &xform);
477     r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
478     ok(r == TRUE, "got %d\n", r);
479     expect_identity(__LINE__, &xform);
480     r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
481     ok(r == TRUE, "got %d\n", r);
482     expect_identity(__LINE__, &xform);
483     r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
484     ok(r == TRUE, "got %d\n", r);
485     expect_identity(__LINE__, &xform);
486
487     SetMapMode(hdc, MM_LOMETRIC);
488     GetViewportExtEx(hdc, &lometric_vp);
489     GetWindowExtEx(hdc, &lometric_wnd);
490
491     r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
492     ok(r == TRUE, "got %d\n", r);
493     expect_identity(__LINE__, &xform);
494
495     r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
496     ok(r == TRUE, "got %d\n", r);
497     expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
498     expect.eM12 = expect.eM21 = 0.0;
499     expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
500     expect.eDx = expect.eDy = 0.0;
501     xform_near_match(__LINE__, &xform, &expect);
502
503     r = pGetTransform(hdc, 0x204, &xform);  /* World -> Device */
504     ok(r == TRUE, "got %d\n", r);
505     xform_near_match(__LINE__, &xform, &expect);
506
507     r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
508     ok(r == TRUE, "got %d\n", r);
509     expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
510     expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
511     xform_near_match(__LINE__, &xform, &expect);
512
513
514     SetGraphicsMode(hdc, GM_ADVANCED);
515
516     expect.eM11 = 10.0;
517     expect.eM22 = 20.0;
518     SetWorldTransform(hdc, &expect);
519     r = pGetTransform(hdc, 0x203, &xform);  /* World -> Page */
520     ok(r == TRUE, "got %d\n", r);
521     xform_near_match(__LINE__, &xform, &expect);
522
523     r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
524     ok(r == TRUE, "got %d\n", r);
525     expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
526     expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
527     xform_near_match(__LINE__, &xform, &expect);
528
529     r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
530     ok(r == TRUE, "got %d\n", r);
531     expect.eM11 *= 10.0;
532     expect.eM22 *= 20.0;
533     xform_near_match(__LINE__, &xform, &expect);
534
535     r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
536     ok(r == TRUE, "got %d\n", r);
537     expect.eM11 = 1 / expect.eM11;
538     expect.eM22 = 1 / expect.eM22;
539     xform_near_match(__LINE__, &xform, &expect);
540
541     r = pGetTransform(hdc, 0x102, &xform);
542     ok(r == FALSE, "got %d\n", r);
543     r = pGetTransform(hdc, 0x103, &xform);
544     ok(r == FALSE, "got %d\n", r);
545     r = pGetTransform(hdc, 0x104, &xform);
546     ok(r == FALSE, "got %d\n", r);
547     r = pGetTransform(hdc, 0x202, &xform);
548     ok(r == FALSE, "got %d\n", r);
549     r = pGetTransform(hdc, 0x302, &xform);
550     ok(r == FALSE, "got %d\n", r);
551     r = pGetTransform(hdc, 0x303, &xform);
552     ok(r == FALSE, "got %d\n", r);
553     r = pGetTransform(hdc, 0x403, &xform);
554     ok(r == FALSE, "got %d\n", r);
555     r = pGetTransform(hdc, 0x404, &xform);
556     ok(r == FALSE, "got %d\n", r);
557     r = pGetTransform(hdc, 0xffff, &xform);
558     ok(r == FALSE, "got %d\n", r);
559 }
560
561 START_TEST(mapping)
562 {
563     test_modify_world_transform();
564     test_world_transform();
565     test_isotropic_mapping();
566     test_setvirtualresolution();
567     test_gettransform();
568 }