Time to commit some Work-In-Progress stuff before my diff gets too large..
[reactos.git] / rostests / apitests / gdi32 / SetMapMode.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetMapMode
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 #define TEST(x) ok(x, #x"\n")
14 #define RTEST(x) ok(x, #x"\n")
15
16 void Test_SetMapMode()
17 {
18 HDC hDC;
19 SIZE WindowExt, ViewportExt;
20 ULONG ulMapMode;
21
22 hDC = CreateCompatibleDC(NULL);
23 ok(hDC != 0, "CreateCompatibleDC failed, skipping tests.\n");
24 if (!hDC) return;
25
26 GetWindowExtEx(hDC, &WindowExt);
27 GetViewportExtEx(hDC, &ViewportExt);
28
29 ulMapMode = SetMapMode(hDC, MM_ISOTROPIC);
30 TEST(ulMapMode == MM_TEXT);
31 TEST(WindowExt.cx == 1);
32 TEST(WindowExt.cy == 1);
33 TEST(ViewportExt.cx == 1);
34 TEST(ViewportExt.cy == 1);
35
36 SetLastError(0);
37 ulMapMode = SetMapMode(hDC, 0);
38 TEST(GetLastError() == 0);
39 TEST(ulMapMode == 0);
40
41 /* Go through all valid values */
42 ulMapMode = SetMapMode(hDC, 1);
43 TEST(ulMapMode == MM_ISOTROPIC);
44 ulMapMode = SetMapMode(hDC, 2);
45 TEST(ulMapMode == 1);
46 ulMapMode = SetMapMode(hDC, 3);
47 TEST(ulMapMode == 2);
48 ulMapMode = SetMapMode(hDC, 4);
49 TEST(ulMapMode == 3);
50 ulMapMode = SetMapMode(hDC, 5);
51 TEST(ulMapMode == 4);
52 ulMapMode = SetMapMode(hDC, 6);
53 TEST(ulMapMode == 5);
54 ulMapMode = SetMapMode(hDC, 7);
55 TEST(ulMapMode == 6);
56 ulMapMode = SetMapMode(hDC, 8);
57 TEST(ulMapMode == 7);
58
59 /* Test invalid value */
60 ulMapMode = SetMapMode(hDC, 9);
61 TEST(ulMapMode == 0);
62 ulMapMode = SetMapMode(hDC, 10);
63 TEST(ulMapMode == 0);
64
65 TEST(GetLastError() == 0);
66
67 /* Test NULL DC */
68 ulMapMode = SetMapMode((HDC)0, 2);
69 TEST(ulMapMode == 0);
70 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
71
72 /* Test NULL DC and invalid mode */
73 ulMapMode = SetMapMode((HDC)0, 10);
74 TEST(ulMapMode == 0);
75 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
76
77 /* Test invalid DC */
78 ulMapMode = SetMapMode((HDC)0x12345, 2);
79 TEST(ulMapMode == 0);
80 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
81
82 /* Test invalid DC and invalid mode */
83 ulMapMode = SetMapMode((HDC)0x12345, 10);
84 TEST(ulMapMode == 0);
85 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
86
87 DeleteDC(hDC);
88
89 /* Test a deleted DC */
90 ulMapMode = SetMapMode(hDC, 2);
91 TEST(ulMapMode == 0);
92 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
93
94 /* Test MM_TEXT */
95 hDC = CreateCompatibleDC(NULL);
96 SetMapMode(hDC, MM_TEXT);
97 GetWindowExtEx(hDC, &WindowExt);
98 GetViewportExtEx(hDC, &ViewportExt);
99 TEST(WindowExt.cx == 1);
100 TEST(WindowExt.cy == 1);
101 TEST(ViewportExt.cx == 1);
102 TEST(ViewportExt.cy == 1);
103 DeleteDC(hDC);
104
105 /* Test MM_ISOTROPIC */
106 hDC = CreateCompatibleDC(NULL);
107 SetMapMode(hDC, MM_ISOTROPIC);
108 GetWindowExtEx(hDC, &WindowExt);
109 GetViewportExtEx(hDC, &ViewportExt);
110 //TEST(WindowExt.cx == 3600);
111 //TEST(WindowExt.cy == 2700);
112 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
113 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
114 DeleteDC(hDC);
115
116 /* Test MM_ANISOTROPIC */
117 hDC = CreateCompatibleDC(NULL);
118 SetMapMode(hDC, MM_ANISOTROPIC);
119 GetWindowExtEx(hDC, &WindowExt);
120 GetViewportExtEx(hDC, &ViewportExt);
121 TEST(WindowExt.cx == 1);
122 TEST(WindowExt.cy == 1);
123 TEST(ViewportExt.cx == 1);
124 TEST(ViewportExt.cy == 1);
125
126 /* set MM_ISOTROPIC first, the values will be kept */
127 SetMapMode(hDC, MM_ISOTROPIC);
128 SetMapMode(hDC, MM_ANISOTROPIC);
129 GetWindowExtEx(hDC, &WindowExt);
130 GetViewportExtEx(hDC, &ViewportExt);
131 //TEST(WindowExt.cx == 3600);
132 //TEST(WindowExt.cy == 2700);
133 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
134 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
135 DeleteDC(hDC);
136
137 /* Test MM_LOMETRIC */
138 hDC = CreateCompatibleDC(NULL);
139 SetMapMode(hDC, MM_LOMETRIC);
140 GetWindowExtEx(hDC, &WindowExt);
141 GetViewportExtEx(hDC, &ViewportExt);
142 //TEST(WindowExt.cx == 3600);
143 //TEST(WindowExt.cy == 2700);
144 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
145 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
146 DeleteDC(hDC);
147
148 /* Test MM_HIMETRIC */
149 hDC = CreateCompatibleDC(NULL);
150 SetMapMode(hDC, MM_HIMETRIC);
151 GetWindowExtEx(hDC, &WindowExt);
152 GetViewportExtEx(hDC, &ViewportExt);
153 //TEST(WindowExt.cx == 36000);
154 //TEST(WindowExt.cy == 27000);
155 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
156 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
157 DeleteDC(hDC);
158
159 /* Test MM_LOENGLISH */
160 hDC = CreateCompatibleDC(NULL);
161 SetMapMode(hDC, MM_LOENGLISH);
162 GetWindowExtEx(hDC, &WindowExt);
163 GetViewportExtEx(hDC, &ViewportExt);
164 //TEST(WindowExt.cx == 1417);
165 //TEST(WindowExt.cy == 1063);
166 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
167 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
168 DeleteDC(hDC);
169
170 /* Test MM_HIENGLISH */
171 hDC = CreateCompatibleDC(NULL);
172 SetMapMode(hDC, MM_HIENGLISH);
173 GetWindowExtEx(hDC, &WindowExt);
174 GetViewportExtEx(hDC, &ViewportExt);
175 //TEST(WindowExt.cx == 14173);
176 //TEST(WindowExt.cy == 10630);
177 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
178 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
179 DeleteDC(hDC);
180
181 /* Test MM_TWIPS */
182 hDC = CreateCompatibleDC(NULL);
183 SetMapMode(hDC, MM_TWIPS);
184 GetWindowExtEx(hDC, &WindowExt);
185 GetViewportExtEx(hDC, &ViewportExt);
186 //TEST(WindowExt.cx == 20409);
187 //TEST(WindowExt.cy == 15307);
188 TEST(ViewportExt.cx == GetDeviceCaps(GetDC(0), HORZRES));
189 TEST(ViewportExt.cy == -GetDeviceCaps(GetDC(0), VERTRES));
190 DeleteDC(hDC);
191 }
192
193 START_TEST(SetMapMode)
194 {
195 Test_SetMapMode();
196 }
197