74d594556366a56f7da0be48b6cbaf1743588f85
[reactos.git] / rostests / apitests / gdi32 / DPtoLP.c
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 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 void Test_DPtoLP_Params()
13 {
14 HDC hdc;
15 POINT apt[2];
16
17 apt[0].x = 0;
18 apt[0].y = 0;
19 apt[1].x = -1000;
20 apt[1].y = 1000;
21
22 SetLastError(ERROR_SUCCESS);
23 ok_int(DPtoLP(NULL, NULL, 0), 1);
24 ok_err(ERROR_SUCCESS);
25
26 ok_int(DPtoLP(NULL, NULL, -1), 1);
27 ok_err(ERROR_SUCCESS);
28
29 ok_int(DPtoLP(NULL, (PVOID)0x80000000, -1), 1);
30 ok_err(ERROR_SUCCESS);
31
32 ok_int(DPtoLP(NULL, NULL, 2), 0);
33 ok_err(ERROR_INVALID_PARAMETER);
34
35 SetLastError(ERROR_SUCCESS);
36 ok_int(DPtoLP(NULL, apt, 2), 0);
37 ok_err(ERROR_INVALID_PARAMETER);
38
39 SetLastError(ERROR_SUCCESS);
40 ok_int(DPtoLP(NULL, apt, 0), 1);
41 ok(GetLastError() == ERROR_SUCCESS, "Exected ERROR_SUCCESS, got %ld\n", GetLastError());
42
43 SetLastError(ERROR_SUCCESS);
44 ok_int(DPtoLP(NULL, apt, -2), 1);
45 ok_err(ERROR_SUCCESS);
46
47 SetLastError(ERROR_SUCCESS);
48 ok_int(DPtoLP((HDC)-4, apt, -2), 1);
49 ok_err(ERROR_SUCCESS);
50
51 hdc = GetDC(0);
52 SetLastError(ERROR_SUCCESS);
53 ok_int(DPtoLP(hdc, NULL, 2), 1);
54 ok_err(ERROR_SUCCESS);
55
56 hdc = GetDC(0);
57 SetLastError(ERROR_SUCCESS);
58 ok_int(DPtoLP(hdc, (PVOID)0x80000000, 2), 1);
59 ok_err(ERROR_SUCCESS);
60
61
62 ReleaseDC(0, hdc);
63 }
64
65 void Test_DPtoLP()
66 {
67 HDC hdc;
68 POINT apt[2];
69 XFORM xform;
70 LONG lLogPixelsX, lLogPixelsY;
71
72 apt[0].x = 1;
73 apt[0].y = 1;
74 apt[1].x = -1000;
75 apt[1].y = 1000;
76
77 hdc = GetDC(0);
78 lLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
79 lLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
80
81 SetMapMode(hdc, MM_TEXT);
82 ok_int(DPtoLP(hdc, apt, 2), 1);
83 ok_int(apt[0].x, 1);
84 ok_int(apt[0].y, 1);
85 ok_int(apt[1].x, -1000);
86 ok_int(apt[1].y, 1000);
87
88 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
89 SetMapMode(hdc, MM_LOMETRIC);
90 ok_int(DPtoLP(hdc, apt, 2), 1);
91 ok_int(apt[0].x * lLogPixelsX, 33888 );
92 ok_int(apt[0].y * lLogPixelsY, -86688 );
93 ok_int(apt[1].x * lLogPixelsX, -338688 );
94 ok_int(apt[1].y * lLogPixelsY, -338688 );
95 SetGraphicsMode(hdc, GM_ADVANCED);
96 SetMapMode(hdc, MM_ANISOTROPIC);
97
98 xform.eM11 = 1.;
99 xform.eM12 = 0.;
100 xform.eM21 = 0.;
101 xform.eM22 = 1.;
102 xform.eDx = (FLOAT)4294967167.999999761;
103 xform.eDy = 1.;
104 ok_int(SetWorldTransform(hdc, &xform), 1);
105
106 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
107 ok_int(DPtoLP(hdc, apt, 2), 1);
108 ok_int(apt[0].x * lLogPixelsX, 58464 );
109 ok_int(apt[0].y * lLogPixelsY, -86784 );
110 ok_int(apt[1].x * lLogPixelsX, -314112 );
111 ok_int(apt[1].y * lLogPixelsY, -338784 );
112
113 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
114 xform.eM11 = 10000000.;
115 ok_int(SetWorldTransform(hdc, &xform), 1);
116 ok_int(DPtoLP(hdc, apt, 2), 1);
117 ok_int(apt[0].x * lLogPixelsX, -41184 );
118 ok_int(apt[0].y * lLogPixelsY, -86784 );
119 ok_int(apt[1].x * lLogPixelsX, -41184 );
120 ok_int(apt[1].y * lLogPixelsY, -338784 );
121
122 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
123 xform.eM11 = 1.;
124 xform.eDx = (FLOAT)4294967167.999999762; // this is too big
125 ok_int(SetWorldTransform(hdc, &xform), 1);
126 ok_int(DPtoLP(hdc, apt, 2), 0);
127 ok_int(apt[0].x, 100 );
128 ok_int(apt[0].y, 256 );
129 ok_int(apt[1].x, -1000 );
130 ok_int(apt[1].y, 1000 );
131
132 xform.eM11 = 2.;
133 xform.eDx = (FLOAT)4294967167.999999762;
134 ok_int(SetWorldTransform(hdc, &xform), 1);
135 ok_int(DPtoLP(hdc, apt, 2), 1);
136 ok_int(apt[0].x * lLogPixelsX, 16896 );
137 ok_int(apt[0].y * lLogPixelsY, -86784 );
138 ok_int(apt[1].x * lLogPixelsX, -169344 );
139 ok_int(apt[1].y * lLogPixelsY, -338784 );
140
141 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
142 xform.eM11 = 10000000.;
143 ok_int(SetWorldTransform(hdc, &xform), 1);
144 ok_int(DPtoLP(hdc, apt, 2), 1);
145 ok_int(apt[0].x * lLogPixelsX, -41184 );
146 ok_int(apt[0].y * lLogPixelsY, -86784 );
147 ok_int(apt[1].x * lLogPixelsX, -41184 );
148 ok_int(apt[1].y * lLogPixelsY, -338784 );
149
150 xform.eM11 = 1000000.;
151 ok_int(SetWorldTransform(hdc, &xform), 1);
152 ok_int(DPtoLP(hdc, apt, 2), 1);
153 ok_int(apt[0].x * lLogPixelsX, -412320 );
154 ok_int(apt[0].y * lLogPixelsY, 306048 );
155 ok_int(apt[1].x * lLogPixelsX, -412320 );
156 ok_int(apt[1].y * lLogPixelsY, 1195104 );
157
158 ReleaseDC(0, hdc);
159 }
160
161 START_TEST(DPtoLP)
162 {
163 Test_DPtoLP_Params();
164 Test_DPtoLP();
165 }
166