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