1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for ...
5  * PROGRAMMERS:     Timo Kreuzer
6  *                  Katayama Hirofumi MZ
7  */
8 
9 #include "precomp.h"
10 
11 #define INVALID_POINTER ((PVOID)(ULONG_PTR)0xdeadbeefdeadbeefULL)
12 
13 void Test_DPtoLP_Params()
14 {
15     HDC hdc;
16     POINT apt[2];
17 
18     apt[0].x = 0;
19     apt[0].y = 0;
20     apt[1].x = -1000;
21     apt[1].y = 1000;
22 
23     SetLastError(ERROR_SUCCESS);
24     ok_int(DPtoLP(NULL, NULL, 0), 1);
25     ok_err(ERROR_SUCCESS);
26 
27     ok_int(DPtoLP(NULL, NULL, -1), 1);
28     ok_err(ERROR_SUCCESS);
29 
30     ok_int(DPtoLP(NULL, INVALID_POINTER, -1), 1);
31     ok_err(ERROR_SUCCESS);
32 
33     ok_int(DPtoLP(NULL, NULL, 2), 0);
34     ok_err(ERROR_INVALID_PARAMETER);
35 
36     SetLastError(ERROR_SUCCESS);
37     ok_int(DPtoLP(NULL, apt, 2), 0);
38     ok_err(ERROR_INVALID_PARAMETER);
39 
40     SetLastError(ERROR_SUCCESS);
41     ok_int(DPtoLP(NULL, apt, 0), 1);
42     ok_err(ERROR_SUCCESS);
43 
44     SetLastError(ERROR_SUCCESS);
45     ok_int(DPtoLP(NULL, apt, -2), 1);
46     ok_err(ERROR_SUCCESS);
47 
48     SetLastError(ERROR_SUCCESS);
49     ok_int(DPtoLP((HDC)-4, apt, -2), 1);
50     ok_err(ERROR_SUCCESS);
51 
52     hdc = GetDC(0);
53     SetLastError(ERROR_SUCCESS);
54     ok_int(DPtoLP(hdc, NULL, 2), 1);
55     ok_err(ERROR_SUCCESS);
56 
57     hdc = GetDC(0);
58     SetLastError(ERROR_SUCCESS);
59     ok_int(DPtoLP(hdc, INVALID_POINTER, 2), 1);
60     ok_err(ERROR_SUCCESS);
61 
62 
63     ReleaseDC(0, hdc);
64 }
65 
66 static void GetExtent(HDC hdc, SIZE *psizWnd, SIZE *psizView)
67 {
68     GetWindowExtEx(hdc, psizWnd);
69     //trace("*psizWnd: (%ld, %ld)\n", psizWnd->cx, psizWnd->cy);
70 
71     GetViewportExtEx(hdc, psizView);
72     //trace("*psizView: (%ld, %ld)\n", psizView->cx, psizView->cy);
73 }
74 
75 void Test_DPtoLP()
76 {
77     HDC hdc;
78     POINT apt[2];
79     XFORM xform;
80     LONG lLogPixelsX, lLogPixelsY;
81     SIZE sizWnd, sizView;
82     LONG xLow, yLow, xHigh, yHigh;
83 
84     hdc = CreateCompatibleDC(NULL);
85     lLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
86     lLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
87     trace("lLogPixelsX: %ld\n", lLogPixelsX);
88     trace("lLogPixelsY: %ld\n", lLogPixelsY);
89 
90 //#define MULDIV(a, b, c) (((a) * (b)) / (c))
91 #define MULDIV(a, b, c) MulDiv((a), (b), (c))
92 
93     // MM_TEXT
94     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
95     SetMapMode(hdc, MM_TEXT);
96     GetExtent(hdc, &sizWnd, &sizView);
97     ok_int(DPtoLP(hdc, apt, 2), 1);
98     ok_long(sizWnd.cx, 1);
99     ok_long(sizWnd.cy, 1);
100     ok_long(sizView.cx, 1);
101     ok_long(sizView.cy, 1);
102     ok_long(apt[0].x, 100);
103     ok_long(apt[0].y, 256);
104     ok_long(apt[1].x, -1000);
105     ok_long(apt[1].y, 1000);
106 
107     // MM_LOMETRIC
108     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
109     SetMapMode(hdc, MM_LOMETRIC);
110     GetExtent(hdc, &sizWnd, &sizView);
111     ok_int(DPtoLP(hdc, apt, 2), 1);
112     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx));
113     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
114     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx));
115     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
116     xLow = apt[0].x;
117     yLow = apt[0].y;
118 
119     // MM_HIMETRIC
120     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
121     SetMapMode(hdc, MM_HIMETRIC);
122     GetExtent(hdc, &sizWnd, &sizView);
123     ok_int(DPtoLP(hdc, apt, 2), 1);
124     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx));
125     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
126     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx));
127     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
128     xHigh = apt[0].x;
129     yHigh = apt[0].y;
130     ok(labs(xLow) * 9 < labs(xHigh) && labs(xHigh) < 11 * labs(xLow), "%ld, %ld\n", xLow, xHigh);
131     ok(labs(yLow) * 9 < labs(yHigh) && labs(yHigh) < 11 * labs(yLow), "%ld, %ld\n", yLow, yHigh);
132 
133     // MM_LOENGLISH
134     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
135     SetMapMode(hdc, MM_LOENGLISH);
136     GetExtent(hdc, &sizWnd, &sizView);
137     ok_int(DPtoLP(hdc, apt, 2), 1);
138     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx));
139     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
140     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx));
141     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
142     xLow = apt[0].x;
143     yLow = apt[0].y;
144 
145     // MM_HIENGLISH
146     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
147     SetMapMode(hdc, MM_HIENGLISH);
148     GetExtent(hdc, &sizWnd, &sizView);
149     ok_int(DPtoLP(hdc, apt, 2), 1);
150     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx));
151     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
152     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx));
153     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
154     xHigh = apt[0].x;
155     yHigh = apt[0].y;
156     ok(labs(xLow) * 9 < labs(xHigh) && labs(xHigh) < 11 * labs(xLow), "%ld, %ld\n", xLow, xHigh);
157     ok(labs(yLow) * 9 < labs(yHigh) && labs(yHigh) < 11 * labs(yLow), "%ld, %ld\n", yLow, yHigh);
158 
159     // MM_TWIPS
160     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
161     SetMapMode(hdc, MM_TWIPS);
162     GetExtent(hdc, &sizWnd, &sizView);
163     ok_int(DPtoLP(hdc, apt, 2), 1);
164     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx));
165     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
166     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx));
167     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
168 
169     SetGraphicsMode(hdc, GM_ADVANCED);
170     SetMapMode(hdc, MM_ANISOTROPIC);
171 
172     xform.eM11 = 1.;
173     xform.eM12 = 0.;
174     xform.eM21 = 0.;
175     xform.eM22 = 1.;
176     xform.eDx = 2.;
177     xform.eDy = 1.;
178     ok_int(SetWorldTransform(hdc, &xform), 1);
179 
180     // eDx == 2, eDy == 1
181     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
182     GetExtent(hdc, &sizWnd, &sizView);
183     ok_int(DPtoLP(hdc, apt, 2), 1);
184     ok_long(apt[0].x, MULDIV(100, sizWnd.cx, sizView.cx) - (LONG)xform.eDx);
185     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy) - (LONG)xform.eDy);
186     ok_long(apt[1].x, MULDIV(-1000, sizWnd.cx, sizView.cx) - (LONG)xform.eDx);
187     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy) - (LONG)xform.eDy);
188 
189     // eM11 == 10000000
190     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
191     xform.eM11 = 10000000.;
192     xform.eDx = 0.;
193     xform.eDy = 0.;
194     ok_int(SetWorldTransform(hdc, &xform), 1);
195     GetExtent(hdc, &sizWnd, &sizView);
196     ok_int(DPtoLP(hdc, apt, 2), 1);
197     ok_long(apt[0].x, 0);
198     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
199     ok_long(apt[1].x, 0);
200     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
201 
202     // eM11 == 2
203     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
204     xform.eM11 = 2.;
205     xform.eDx = 0.;
206     xform.eDy = 0.;
207     ok_int(SetWorldTransform(hdc, &xform), 1);
208     GetExtent(hdc, &sizWnd, &sizView);
209     ok_int(DPtoLP(hdc, apt, 2), 1);
210     ok_long(apt[0].x, MULDIV(100 / 2, sizWnd.cx, sizView.cx));
211     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
212     ok_long(apt[1].x, MULDIV(-1000 / 2, sizWnd.cx, sizView.cx));
213     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
214 
215     // eM11 == (FLOAT)0x1FFFFFFFF
216     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
217     xform.eM11 = (FLOAT)0x1FFFFFFFF;
218     xform.eDx = 0.;
219     xform.eDy = 0.;
220     ok_int(SetWorldTransform(hdc, &xform), 1);
221     GetExtent(hdc, &sizWnd, &sizView);
222     ok_int(DPtoLP(hdc, apt, 2), 1);
223     ok_long(apt[0].x, 0);
224     //ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
225     ok_long(apt[1].x, 0);
226     //ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
227 
228     // eM11 == (FLOAT)0xFFFFFFFFU
229     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
230     xform.eM11 = (FLOAT)0xFFFFFFFFU;
231     xform.eM22 = 1.;
232     xform.eDx = 0.;
233     xform.eDy = 0.;
234     ok_int(SetWorldTransform(hdc, &xform), 1);
235     GetExtent(hdc, &sizWnd, &sizView);
236     ok_int(DPtoLP(hdc, apt, 2), 1);
237     ok_long(apt[0].x, 0);
238     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
239     ok_long(apt[1].x, 0);
240     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
241 
242     // eM22 == (FLOAT)0xFFFFFFFFU
243     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
244     xform.eM11 = 1.;
245     xform.eM22 = (FLOAT)0xFFFFFFFFU;
246     xform.eDx = 0.;
247     xform.eDy = 0.;
248     ok_int(SetWorldTransform(hdc, &xform), 1);
249     GetExtent(hdc, &sizWnd, &sizView);
250     ok_int(DPtoLP(hdc, apt, 2), 1);
251     //ok_long(apt[0].x, MULDIV(100, sizWnd.cy, sizView.cy));
252     ok_long(apt[0].y, 0);
253     //ok_long(apt[1].x, MULDIV(-1000, sizWnd.cy, sizView.cy));
254     ok_long(apt[1].y, 0);
255 
256     // eM22 == (FLOAT)0x1FFFFFFFFU
257     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
258     xform.eM11 = 1.;
259     xform.eM22 = (FLOAT)0x1FFFFFFFFU;
260     xform.eDx = 0.;
261     xform.eDy = 0.;
262     ok_int(SetWorldTransform(hdc, &xform), 1);
263     GetExtent(hdc, &sizWnd, &sizView);
264     ok_int(DPtoLP(hdc, apt, 2), 1);
265     //ok_long(apt[0].x, MULDIV(100, sizWnd.cy, sizView.cy));
266     ok_long(apt[0].y, 0);
267     //ok_long(apt[1].x, MULDIV(-1000, sizWnd.cy, sizView.cy));
268     ok_long(apt[1].y, 0);
269 
270     // eM11 == (FLOAT)0xFFFFFFFFU, eM22 == (FLOAT)0xFFFFFFFFU
271     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
272     xform.eM11 = (FLOAT)0xFFFFFFFFU;
273     xform.eM22 = (FLOAT)0xFFFFFFFFU;
274     xform.eDx = 0.;
275     xform.eDy = 0.;
276     ok_int(SetWorldTransform(hdc, &xform), 1);
277     GetExtent(hdc, &sizWnd, &sizView);
278     ok_int(DPtoLP(hdc, apt, 2), 1);
279     ok_long(apt[0].x, 0);
280     ok_long(apt[0].y, 0);
281     ok_long(apt[1].x, 0);
282     ok_long(apt[1].y, 0);
283 
284     // eM11 == (FLOAT)0x1FFFFFFFFU, eM22 == (FLOAT)0x1FFFFFFFFU
285     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
286     xform.eM11 = (FLOAT)0x1FFFFFFFFU;
287     xform.eM22 = (FLOAT)0x1FFFFFFFFU;
288     xform.eDx = 0.;
289     xform.eDy = 0.;
290     ok_int(SetWorldTransform(hdc, &xform), 1);
291     GetExtent(hdc, &sizWnd, &sizView);
292     ok_int(DPtoLP(hdc, apt, 2), 1);
293     ok_long(apt[0].x, 0);
294     ok_long(apt[0].y, 0);
295     ok_long(apt[1].x, 0);
296     ok_long(apt[1].y, 0);
297 
298     // eM11 == 10000000
299     apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
300     xform.eM11 = 10000000.;
301     xform.eM22 = 1.0;
302     ok_int(SetWorldTransform(hdc, &xform), 1);
303     GetExtent(hdc, &sizWnd, &sizView);
304     ok_int(DPtoLP(hdc, apt, 2), 1);
305     ok_long(apt[0].x, 0);
306     ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
307     ok_long(apt[1].x, 0);
308     ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
309 
310     xform.eM11 = 1000000.;
311     ok_int(SetWorldTransform(hdc, &xform), 1);
312     GetExtent(hdc, &sizWnd, &sizView);
313     ok_int(DPtoLP(hdc, apt, 2), 1);
314     ok_long(apt[0].x, 0);
315     //ok_long(apt[0].y, MULDIV(256, sizWnd.cy, sizView.cy));
316     ok_long(apt[1].x, 0);
317     //ok_long(apt[1].y, MULDIV(1000, sizWnd.cy, sizView.cy));
318 
319     DeleteDC(hdc);
320 }
321 
322 START_TEST(DPtoLP)
323 {
324     Test_DPtoLP_Params();
325     Test_DPtoLP();
326 }
327 
328