gdi32: Prefer a Microsoft cmap table over other platform ones.
[wine] / dlls / gdi32 / tests / mapping.c
1 /*
2  * Unit tests for mapping functions
3  *
4  * Copyright (c) 2005 Huw Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <stdio.h>
23 #include <math.h>
24
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.h"
30
31
32 static void test_modify_world_transform(void)
33 {
34     HDC hdc = GetDC(0);
35     int ret;
36
37     ret = SetGraphicsMode(hdc, GM_ADVANCED);
38     if(!ret) /* running in win9x so quit */
39     {
40         ReleaseDC(0, hdc);
41         return;
42     }
43
44     ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
45     ok(ret, "ret = %d\n", ret);
46
47     ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
48     ok(!ret, "ret = %d\n", ret);
49
50     ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
51     ok(!ret, "ret = %d\n", ret);
52
53     ReleaseDC(0, hdc);
54 }
55
56 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
57 {
58     SIZE windowExt, viewportExt;
59     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
60
61     GetWindowOrgEx(hdc, &windowOrg);
62     GetViewportOrgEx(hdc, &viewportOrg);
63
64     SetWindowExtEx(hdc, cx, cy, NULL);
65     GetWindowExtEx(hdc, &windowExt);
66     ok(windowExt.cx == cx && windowExt.cy == cy,
67        "Window extension: Expected %dx%d, got %dx%d\n",
68        cx, cy, windowExt.cx, windowExt.cy);
69
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 %dx%d, got %dx%d\n",
73         expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
74
75     GetWindowOrgEx(hdc, &windowOrgAfter);
76     ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
77         "Window origin changed from (%d,%d) to (%d,%d)\n",
78         windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
79
80     GetViewportOrgEx(hdc, &viewportOrgAfter);
81     ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
82         "Viewport origin changed from (%d,%d) to (%d,%d)\n",
83         viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
84 }
85
86 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
87 {
88     SIZE windowExt, windowExtAfter, viewportExt;
89     POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
90
91     GetWindowOrgEx(hdc, &windowOrg);
92     GetViewportOrgEx(hdc, &viewportOrg);
93     GetWindowExtEx(hdc, &windowExt);
94
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 %dx%d, got %dx%d\n",
99         expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
100
101     GetWindowExtEx(hdc, &windowExtAfter);
102     ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
103        "Window extension changed from %dx%d to %dx%d\n",
104        windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
105
106     GetWindowOrgEx(hdc, &windowOrgAfter);
107     ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
108         "Window origin changed from (%d,%d) to (%d,%d)\n",
109         windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
110
111     GetViewportOrgEx(hdc, &viewportOrgAfter);
112     ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
113         "Viewport origin changed from (%d,%d) to (%d,%d)\n",
114         viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
115 }
116
117 static void test_isotropic_mapping(void)
118 {
119     SIZE win, vp;
120     HDC hdc = GetDC(0);
121     
122     SetMapMode(hdc, MM_ISOTROPIC);
123     
124     /* MM_ISOTROPIC is set up like MM_LOMETRIC.
125        Initial values after SetMapMode():
126        (1 inch = 25.4 mm)
127        
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
131        
132        To test without rounding errors, we have to use multiples of
133        these values!
134      */
135     
136     GetWindowExtEx(hdc, &win);
137     GetViewportExtEx(hdc, &vp);
138     
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);
152     
153     ReleaseDC(0, hdc);
154 }
155
156 START_TEST(mapping)
157 {
158     test_modify_world_transform();
159     test_isotropic_mapping();
160 }