[NETAPI32]
[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 <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
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, (PVOID)0x80000000, -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(GetLastError() == ERROR_SUCCESS, "Exected ERROR_SUCCESS, got %ld\n", GetLastError());
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, (PVOID)0x80000000, 2), 1);
60 ok_err(ERROR_SUCCESS);
61
62
63 ReleaseDC(0, hdc);
64 }
65
66 void Test_DPtoLP()
67 {
68 HDC hdc;
69 POINT apt[2];
70 XFORM xform;
71 LONG lLogPixelsX, lLogPixelsY;
72
73 apt[0].x = 1;
74 apt[0].y = 1;
75 apt[1].x = -1000;
76 apt[1].y = 1000;
77
78 hdc = GetDC(0);
79 lLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
80 lLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
81
82 SetMapMode(hdc, MM_TEXT);
83 ok_int(DPtoLP(hdc, apt, 2), 1);
84 ok_int(apt[0].x, 1);
85 ok_int(apt[0].y, 1);
86 ok_int(apt[1].x, -1000);
87 ok_int(apt[1].y, 1000);
88
89 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
90 SetMapMode(hdc, MM_LOMETRIC);
91 ok_int(DPtoLP(hdc, apt, 2), 1);
92 ok_int(apt[0].x * lLogPixelsX, 33888 );
93 ok_int(apt[0].y * lLogPixelsY, -86688 );
94 ok_int(apt[1].x * lLogPixelsX, -338688 );
95 ok_int(apt[1].y * lLogPixelsY, -338688 );
96 SetGraphicsMode(hdc, GM_ADVANCED);
97 SetMapMode(hdc, MM_ANISOTROPIC);
98
99 xform.eM11 = 1.;
100 xform.eM12 = 0.;
101 xform.eM21 = 0.;
102 xform.eM22 = 1.;
103 xform.eDx = (FLOAT)4294967167.999999761;
104 xform.eDy = 1.;
105 ok_int(SetWorldTransform(hdc, &xform), 1);
106
107 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
108 ok_int(DPtoLP(hdc, apt, 2), 1);
109 ok_int(apt[0].x * lLogPixelsX, 58464 );
110 ok_int(apt[0].y * lLogPixelsY, -86784 );
111 ok_int(apt[1].x * lLogPixelsX, -314112 );
112 ok_int(apt[1].y * lLogPixelsY, -338784 );
113
114 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
115 xform.eM11 = 10000000.;
116 ok_int(SetWorldTransform(hdc, &xform), 1);
117 ok_int(DPtoLP(hdc, apt, 2), 1);
118 ok_int(apt[0].x * lLogPixelsX, -41184 );
119 ok_int(apt[0].y * lLogPixelsY, -86784 );
120 ok_int(apt[1].x * lLogPixelsX, -41184 );
121 ok_int(apt[1].y * lLogPixelsY, -338784 );
122
123 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
124 xform.eM11 = 1.;
125 xform.eDx = (FLOAT)4294967167.999999762; // this is too big
126 ok_int(SetWorldTransform(hdc, &xform), 1);
127 ok_int(DPtoLP(hdc, apt, 2), 0);
128 ok_int(apt[0].x, 100 );
129 ok_int(apt[0].y, 256 );
130 ok_int(apt[1].x, -1000 );
131 ok_int(apt[1].y, 1000 );
132
133 xform.eM11 = 2.;
134 xform.eDx = (FLOAT)4294967167.999999762;
135 ok_int(SetWorldTransform(hdc, &xform), 1);
136 ok_int(DPtoLP(hdc, apt, 2), 1);
137 ok_int(apt[0].x * lLogPixelsX, 16896 );
138 ok_int(apt[0].y * lLogPixelsY, -86784 );
139 ok_int(apt[1].x * lLogPixelsX, -169344 );
140 ok_int(apt[1].y * lLogPixelsY, -338784 );
141
142 apt[0].x = 100; apt[0].y = 256; apt[1].x = -1000; apt[1].y = 1000;
143 xform.eM11 = 10000000.;
144 ok_int(SetWorldTransform(hdc, &xform), 1);
145 ok_int(DPtoLP(hdc, apt, 2), 1);
146 ok_int(apt[0].x * lLogPixelsX, -41184 );
147 ok_int(apt[0].y * lLogPixelsY, -86784 );
148 ok_int(apt[1].x * lLogPixelsX, -41184 );
149 ok_int(apt[1].y * lLogPixelsY, -338784 );
150
151 xform.eM11 = 1000000.;
152 ok_int(SetWorldTransform(hdc, &xform), 1);
153 ok_int(DPtoLP(hdc, apt, 2), 1);
154 ok_int(apt[0].x * lLogPixelsX, -412320 );
155 ok_int(apt[0].y * lLogPixelsY, 306048 );
156 ok_int(apt[1].x * lLogPixelsX, -412320 );
157 ok_int(apt[1].y * lLogPixelsY, 1195104 );
158
159 ReleaseDC(0, hdc);
160 }
161
162 START_TEST(DPtoLP)
163 {
164 Test_DPtoLP_Params();
165 Test_DPtoLP();
166 }
167