~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/tests/mapping.c

Version: ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  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;
 79     XFORM xform;
 80 
 81     SetLastError(0xdeadbeef);
 82     GetWorldTransform(0, NULL);
 83     is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
 84 
 85     hdc = CreateCompatibleDC(0);
 86 
 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);
 92 
 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);
 97 
 98     SetLastError(0xdeadbeef);
 99     ret = SetMapMode(hdc, MM_LOMETRIC);
100     ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
101 
102     if (is_win9x)
103     {
104         expect_viewport_ext(hdc, 96, 96);
105         expect_window_ext(hdc, 254, -254);
106     }
107     else
108     {
109         expect_viewport_ext(hdc, res_x, -res_y);
110         expect_window_ext(hdc, size_cx * 10, size_cy * 10);
111     }
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));
114 
115     SetLastError(0xdeadbeef);
116     ret = SetMapMode(hdc, MM_TEXT);
117     ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
118 
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);
123 
124     ret = SetGraphicsMode(hdc, GM_ADVANCED);
125     if (!ret)
126     {
127         DeleteDC(hdc);
128         skip("GM_ADVANCED is not supported on this platform\n");
129         return;
130     }
131 
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);
136 
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());
146 
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);
151 
152     SetLastError(0xdeadbeef);
153     ret = SetMapMode(hdc, MM_LOMETRIC);
154     ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
155 
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));
160 
161     SetLastError(0xdeadbeef);
162     ret = SetMapMode(hdc, MM_TEXT);
163     ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
164 
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);
169 
170     DeleteDC(hdc);
171 }
172 
173 static void test_modify_world_transform(void)
174 {
175     HDC hdc = GetDC(0);
176     int ret;
177 
178     ret = SetGraphicsMode(hdc, GM_ADVANCED);
179     if(!ret) /* running in win9x so quit */
180     {
181         ReleaseDC(0, hdc);
182         skip("GM_ADVANCED is not supported on this platform\n");
183         return;
184     }
185 
186     ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
187     ok(ret, "ret = %d\n", ret);
188 
189     ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
190     ok(!ret, "ret = %d\n", ret);
191 
192     ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
193     ok(!ret, "ret = %d\n", ret);
194 
195     ReleaseDC(0, hdc);
196 }
197 
198 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
199 {
200     SIZE windowExt, viewportExt;
201     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
202 
203     GetWindowOrgEx(hdc, &windowOrg);
204     GetViewportOrgEx(hdc, &viewportOrg);
205 
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);
211 
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);
216 
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);
221 
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);
226 }
227 
228 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
229 {
230     SIZE windowExt, windowExtAfter, viewportExt;
231     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
232 
233     GetWindowOrgEx(hdc, &windowOrg);
234     GetViewportOrgEx(hdc, &viewportOrg);
235     GetWindowExtEx(hdc, &windowExt);
236 
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);
242 
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);
247 
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);
252 
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);
257 }
258 
259 static void test_isotropic_mapping(void)
260 {
261     SIZE win, vp;
262     HDC hdc = GetDC(0);
263     
264     SetMapMode(hdc, MM_ISOTROPIC);
265     
266     /* MM_ISOTROPIC is set up like MM_LOMETRIC.
267        Initial values after SetMapMode():
268        (1 inch = 25.4 mm)
269        
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
273        
274        To test without rounding errors, we have to use multiples of
275        these values!
276      */
277     
278     GetWindowExtEx(hdc, &win);
279     GetViewportExtEx(hdc, &vp);
280     
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);
294     
295     ReleaseDC(0, hdc);
296 }
297 
298 START_TEST(mapping)
299 {
300     test_modify_world_transform();
301     test_world_transform();
302     test_isotropic_mapping();
303 }
304 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.