Convert gdi32api into wine style test
[reactos.git] / rostests / apitests / gdi32 / SetWindowExtEx.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetWindowExtEx
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 #define TEST(x) ok(x, #x)
13 #define RTEST(x) ok(x, #x)
14
15 void Test_SetWindowExtEx()
16 {
17 HDC hDC;
18 BOOL ret;
19 SIZE WindowExt, ViewportExt;
20 //PGDI_TABLE_ENTRY pEntry;
21 //DC_ATTR* pDC_Attr;
22
23 hDC = CreateCompatibleDC(0);
24 ok(hDC != NULL, "CreateCompatibleDC failed. Skipping tests.\n");
25 if (hDC == NULL) return;
26
27 SetLastError(0);
28 ret = SetWindowExtEx(0, 0, 0, NULL);
29 TEST(GetLastError() == ERROR_INVALID_HANDLE);
30 TEST(ret == 0);
31
32 SetLastError(0);
33 ret = SetWindowExtEx((HDC)0x1234, 0, 0, NULL);
34 TEST(GetLastError() == ERROR_INVALID_HANDLE);
35 TEST(ret == 0);
36
37 SetLastError(0);
38 ret = SetWindowExtEx(hDC, 0, 0, NULL);
39 TEST(GetLastError() == 0);
40 TEST(ret == 1);
41
42 WindowExt.cx = 1234;
43 WindowExt.cy = 6789;
44 SetLastError(0);
45 ret = SetWindowExtEx(0, 0, 0, &WindowExt);
46 TEST(GetLastError() == ERROR_INVALID_HANDLE);
47 TEST(ret == 0);
48 TEST(WindowExt.cx == 1234);
49 TEST(WindowExt.cy == 6789);
50
51 DeleteDC(hDC);
52
53 /* Test with a deleted DC */
54 SetLastError(0);
55 ret = SetWindowExtEx(hDC, 0, 0, NULL);
56 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
57 TEST(ret == 0);
58
59 hDC = CreateCompatibleDC(0);
60 ok(hDC != NULL, "CreateCompatibleDC failed. Skipping tests.\n");
61 if (hDC == NULL) return;
62
63 //pEntry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hDC);
64 //pDC_Attr = pEntry->UserData;
65 //ASSERT(pDC_Attr);
66
67 /* Test setting it without changing the map mode (MM_TEXT) */
68 ret = SetWindowExtEx(hDC, 10, 20, &WindowExt);
69 TEST(ret == 1);
70 TEST(WindowExt.cx == 1);
71 TEST(WindowExt.cy == 1);
72
73 /* Values should not be changed */
74 WindowExt.cx = WindowExt.cy = 0;
75 ret = SetWindowExtEx(hDC, 40, 30, &WindowExt);
76 TEST(ret == 1);
77 TEST(WindowExt.cx == 1);
78 TEST(WindowExt.cy == 1);
79
80 /* Check the viewport */
81 GetViewportExtEx(hDC, &ViewportExt);
82 TEST(ViewportExt.cx == 1);
83 TEST(ViewportExt.cy == 1);
84
85 /* Test setting in isotropic mode with 0 extents */
86 SetMapMode(hDC, MM_ISOTROPIC);
87 WindowExt.cx = WindowExt.cy = 0;
88 ret = SetWindowExtEx(hDC, 0, 0, &WindowExt);
89 TEST(ret == 0);
90 //TEST(WindowExt.cx == 3600);
91 //TEST(WindowExt.cy == 2700);
92 ret = SetWindowExtEx(hDC, 100, 0, &WindowExt);
93 TEST(ret == 0);
94 ret = SetWindowExtEx(hDC, 0, 100, &WindowExt);
95 TEST(ret == 0);
96
97 /* Test setting in isotropic mode */
98 ret = SetWindowExtEx(hDC, 21224, 35114, &WindowExt);
99 TEST(ret == 1);
100 //TEST(WindowExt.cx == 3600);
101 //TEST(WindowExt.cy == 2700);
102
103 /* Values should be changed */
104 ret = SetWindowExtEx(hDC,
105 4 * GetDeviceCaps(GetDC(0), HORZRES),
106 -4 * GetDeviceCaps(GetDC(0), VERTRES),
107 &WindowExt);
108 TEST(ret == 1);
109 TEST(WindowExt.cx == 21224);
110 TEST(WindowExt.cy == 35114);
111
112 /* Check the viewport, should be the same */
113 GetViewportExtEx(hDC, &ViewportExt);
114 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
115 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
116
117 /* again isotropic mode with 1:1 res */
118 ret = SetWindowExtEx(hDC, 123, 123, &WindowExt);
119 TEST(ret == 1);
120 TEST(WindowExt.cx == 4 * GetDeviceCaps(GetDC(0), HORZRES));
121 TEST(WindowExt.cy == -4 * GetDeviceCaps(GetDC(0), VERTRES));
122
123 /* Test flXform */
124 //TEST(pDC_Attr->flXform & PAGE_EXTENTS_CHANGED);
125
126 /* Check the viewport from the dcattr, without going through gdi */
127 //TEST(pDC_Attr->szlViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
128 //TEST(pDC_Attr->szlViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
129
130 /* Check the viewport with gdi, should not be the same */
131 GetViewportExtEx(hDC, &ViewportExt);
132 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), VERTRES));
133 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
134
135 /* Test flXform */
136 //TEST(pDC_Attr->flXform & PAGE_EXTENTS_CHANGED);
137
138 /* again isotropic mode with 3:1 res */
139 ret = SetWindowExtEx(hDC, 300, 100, &WindowExt);
140 TEST(ret == 1);
141 TEST(WindowExt.cx == 123);
142 TEST(WindowExt.cy == 123);
143
144 /* Check the viewport now, should not be the same */
145 GetViewportExtEx(hDC, &ViewportExt);
146 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), VERTRES));
147 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES) / 3);
148
149 /* again isotropic mode with 1:3 res */
150 SetViewportExtEx(hDC, 6000, 3000, 0);
151 ret = SetWindowExtEx(hDC, 200, 600, &WindowExt);
152 TEST(ret == 1);
153 TEST(WindowExt.cx == 300);
154 TEST(WindowExt.cy == 100);
155
156 /* Check the viewport now, should not be the same */
157 GetViewportExtEx(hDC, &ViewportExt);
158 TEST(ViewportExt.cx == 1000);
159 TEST(ViewportExt.cy == 3000);
160
161 /* Test setting in anisotropic mode */
162 SetMapMode(hDC, MM_ANISOTROPIC);
163 ret = SetWindowExtEx(hDC, 80, 60, &WindowExt);
164 TEST(ret == 1);
165 TEST(WindowExt.cx == 200);
166 TEST(WindowExt.cy == 600);
167
168 /* Values should be changed */
169 ret = SetWindowExtEx(hDC, 500, 500, &WindowExt);
170 TEST(ret == 1);
171 TEST(WindowExt.cx == 80);
172 TEST(WindowExt.cy == 60);
173
174 /* Check the viewport */
175 GetViewportExtEx(hDC, &ViewportExt);
176 TEST(ViewportExt.cx == 1000);
177 TEST(ViewportExt.cy == 3000);
178
179 /* Test setting in low metric mode */
180 SetMapMode(hDC, MM_LOMETRIC);
181 ret = SetWindowExtEx(hDC, 120, 90, &WindowExt);
182 TEST(ret == 1);
183 //TEST(WindowExt.cx == 3600);
184 //TEST(WindowExt.cy == 2700);
185
186 /* Values should not be changed */
187 WindowExt.cx = WindowExt.cy = 0;
188 ret = SetWindowExtEx(hDC, 900, 700, &WindowExt);
189 TEST(ret == 1);
190 //TEST(WindowExt.cx == 3600);
191 //TEST(WindowExt.cy == 2700);
192
193 /* Check the viewport */
194 GetViewportExtEx(hDC, &ViewportExt);
195 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
196 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
197
198 /* Test setting in high metric mode */
199 SetMapMode(hDC, MM_HIMETRIC);
200 ret = SetWindowExtEx(hDC, 120, 90, &WindowExt);
201 TEST(ret == 1);
202 //TEST(WindowExt.cx == 36000);
203 //TEST(WindowExt.cy == 27000);
204
205 /* Values should not be changed */
206 WindowExt.cx = WindowExt.cy = 0;
207 ret = SetWindowExtEx(hDC, 500, 300, &WindowExt);
208 TEST(ret == 1);
209 //TEST(WindowExt.cx == 36000);
210 //TEST(WindowExt.cy == 27000);
211
212 /* Check the viewport */
213 GetViewportExtEx(hDC, &ViewportExt);
214 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
215 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
216
217 /* Test setting in low english mode */
218 SetMapMode(hDC, MM_LOENGLISH);
219 ret = SetWindowExtEx(hDC, 320, 290, &WindowExt);
220 TEST(ret == 1);
221 //TEST(WindowExt.cx == 1417);
222 //TEST(WindowExt.cy == 1063);
223
224 /* Values should not be changed */
225 WindowExt.cx = WindowExt.cy = 0;
226 ret = SetWindowExtEx(hDC, 560, 140, &WindowExt);
227 TEST(ret == 1);
228 //TEST(WindowExt.cx == 1417);
229 //TEST(WindowExt.cy == 1063);
230
231 /* Check the viewport */
232 GetViewportExtEx(hDC, &ViewportExt);
233 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
234 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
235
236 /* Test setting in high english mode */
237 SetMapMode(hDC, MM_HIENGLISH);
238 ret = SetWindowExtEx(hDC, 320, 290, &WindowExt);
239 TEST(ret == 1);
240 //TEST(WindowExt.cx == 14173);
241 //TEST(WindowExt.cy == 10630);
242
243 /* Values should not be changed */
244 WindowExt.cx = WindowExt.cy = 0;
245 ret = SetWindowExtEx(hDC, 1560, 1140, &WindowExt);
246 TEST(ret == 1);
247 //TEST(WindowExt.cx == 14173);
248 //TEST(WindowExt.cy == 10630);
249
250 /* Check the viewport */
251 GetViewportExtEx(hDC, &ViewportExt);
252 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
253 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
254
255 /* Test setting in twips mode */
256 SetMapMode(hDC, MM_TWIPS);
257 ret = SetWindowExtEx(hDC, 3320, 3290, &WindowExt);
258 TEST(ret == 1);
259 //TEST(WindowExt.cx == 20409);
260 //TEST(WindowExt.cy == 15307);
261
262 /* Values should not be changed */
263 WindowExt.cx = WindowExt.cy = 0;
264 ret = SetWindowExtEx(hDC, 4560, 4140, &WindowExt);
265 TEST(ret == 1);
266 //TEST(WindowExt.cx == 20409);
267 //TEST(WindowExt.cy == 15307);
268
269 /* Check the viewport */
270 GetViewportExtEx(hDC, &ViewportExt);
271 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
272 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
273
274 /* test manually modifying the dcattr, should go to tests for GetViewportExtEx */
275 SetMapMode(hDC, MM_ISOTROPIC);
276 ret = SetWindowExtEx(hDC, 420, 4140, &WindowExt);
277 //pDC_Attr->szlWindowExt.cx = 0;
278 GetViewportExtEx(hDC, &ViewportExt);
279 //TEST(pDC_Attr->szlWindowExt.cx == 0);
280 //TEST(ViewportExt.cx == 0);
281
282 DeleteDC(hDC);
283 }
284
285 START_TEST(SetWindowExtEx)
286 {
287 Test_SetWindowExtEx();
288 }
289