Update the address of the Free Software Foundation.
[wine.git] / dlls / gdi / tests / mapping.c
blob2baeb2d8004922d33c6ba141981525949cadee8e
1 /*
2 * Unit tests for mapping functions
4 * Copyright (c) 2005 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
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"
32 void test_modify_world_transform(void)
34 HDC hdc = GetDC(0);
35 int ret;
37 ret = SetGraphicsMode(hdc, GM_ADVANCED);
38 if(!ret) /* running in win9x so quit */
40 ReleaseDC(0, hdc);
41 return;
44 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
45 ok(ret, "ret = %d\n", ret);
47 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
48 ok(!ret, "ret = %d\n", ret);
50 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
51 ok(!ret, "ret = %d\n", ret);
53 ReleaseDC(0, hdc);
56 void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
58 SIZE windowExt, viewportExt;
59 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
61 GetWindowOrgEx(hdc, &windowOrg);
62 GetViewportOrgEx(hdc, &viewportOrg);
64 SetWindowExtEx(hdc, cx, cy, NULL);
65 GetWindowExtEx(hdc, &windowExt);
66 ok(windowExt.cx == cx && windowExt.cy == cy,
67 "Window extension: Expected %ldx%ld, got %ldx%ld\n",
68 cx, cy, windowExt.cx, windowExt.cy);
70 GetViewportExtEx(hdc, &viewportExt);
71 ok(viewportExt.cx == expected_vp_cx && viewportExt.cy == expected_vp_cy,
72 "Viewport extents have not been properly adjusted: Expected %ldx%ld, got %ldx%ld\n",
73 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
75 GetWindowOrgEx(hdc, &windowOrgAfter);
76 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
77 "Window origin changed from (%ld,%ld) to (%ld,%ld)\n",
78 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
80 GetViewportOrgEx(hdc, &viewportOrgAfter);
81 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
82 "Viewport origin changed from (%ld,%ld) to (%ld,%ld)\n",
83 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
86 void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
88 SIZE windowExt, windowExtAfter, viewportExt;
89 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
91 GetWindowOrgEx(hdc, &windowOrg);
92 GetViewportOrgEx(hdc, &viewportOrg);
93 GetWindowExtEx(hdc, &windowExt);
95 SetViewportExtEx(hdc, cx, cy, NULL);
96 GetViewportExtEx(hdc, &viewportExt);
97 ok(viewportExt.cx == expected_vp_cx && viewportExt.cy == expected_vp_cy,
98 "Viewport extents have not been properly adjusted: Expected %ldx%ld, got %ldx%ld\n",
99 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
101 GetWindowExtEx(hdc, &windowExtAfter);
102 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
103 "Window extension changed from %ldx%ld to %ldx%ld\n",
104 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
106 GetWindowOrgEx(hdc, &windowOrgAfter);
107 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
108 "Window origin changed from (%ld,%ld) to (%ld,%ld)\n",
109 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
111 GetViewportOrgEx(hdc, &viewportOrgAfter);
112 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
113 "Viewport origin changed from (%ld,%ld) to (%ld,%ld)\n",
114 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
117 void test_isotropic_mapping(void)
119 SIZE win, vp;
120 HDC hdc = GetDC(0);
122 SetMapMode(hdc, MM_ISOTROPIC);
124 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
125 Initial values after SetMapMode():
126 (1 inch = 25.4 mm)
128 Windows 9x: Windows NT:
129 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
130 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
132 To test without rounding errors, we have to use multiples of
133 these values!
136 GetWindowExtEx(hdc, &win);
137 GetViewportExtEx(hdc, &vp);
139 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
140 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
141 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
142 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
143 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
144 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
145 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
146 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
147 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
148 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
149 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
150 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
151 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
153 ReleaseDC(0, hdc);
156 START_TEST(mapping)
158 test_modify_world_transform();
159 test_isotropic_mapping();