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