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 * Katayama Hirofumi MZ 7 */ 8 9 #include "precomp.h" 10 11 void Test_SetMapMode() 12 { 13 HDC hDC; 14 SIZE WindowExt, ViewportExt; 15 ULONG ulMapMode; 16 POINT pt; 17 18 hDC = CreateCompatibleDC(NULL); 19 ok(hDC != 0, "CreateCompatibleDC failed, skipping tests.\n"); 20 if (!hDC) return; 21 22 GetWindowExtEx(hDC, &WindowExt); 23 GetViewportExtEx(hDC, &ViewportExt); 24 25 ulMapMode = SetMapMode(hDC, MM_ISOTROPIC); 26 ok_long(ulMapMode, MM_TEXT); 27 ok_long(WindowExt.cx, 1); 28 ok_long(WindowExt.cy, 1); 29 ok_long(ViewportExt.cx, 1); 30 ok_long(ViewportExt.cy, 1); 31 32 SetLastError(0); 33 ulMapMode = SetMapMode(hDC, 0); 34 ok_err(0); 35 ok_long(ulMapMode, 0); 36 37 /* Go through all valid values */ 38 ulMapMode = SetMapMode(hDC, 1); 39 ok_long(ulMapMode, MM_ISOTROPIC); 40 ulMapMode = SetMapMode(hDC, 2); 41 ok_long(ulMapMode, 1); 42 ulMapMode = SetMapMode(hDC, 3); 43 ok_long(ulMapMode, 2); 44 ulMapMode = SetMapMode(hDC, 4); 45 ok_long(ulMapMode, 3); 46 ulMapMode = SetMapMode(hDC, 5); 47 ok_long(ulMapMode, 4); 48 ulMapMode = SetMapMode(hDC, 6); 49 ok_long(ulMapMode, 5); 50 ulMapMode = SetMapMode(hDC, 7); 51 ok_long(ulMapMode, 6); 52 ulMapMode = SetMapMode(hDC, 8); 53 ok_long(ulMapMode, 7); 54 55 /* Test invalid value */ 56 ulMapMode = SetMapMode(hDC, 9); 57 ok_long(ulMapMode, 0); 58 ulMapMode = SetMapMode(hDC, 10); 59 ok_long(ulMapMode, 0); 60 61 ok_err(0); 62 63 /* Test NULL DC */ 64 ulMapMode = SetMapMode((HDC)0, 2); 65 ok_long(ulMapMode, 0); 66 ok_err(ERROR_INVALID_PARAMETER); 67 68 /* Test NULL DC and invalid mode */ 69 ulMapMode = SetMapMode((HDC)0, 10); 70 ok_long(ulMapMode, 0); 71 ok_err(ERROR_INVALID_PARAMETER); 72 73 /* Test invalid DC */ 74 ulMapMode = SetMapMode((HDC)0x12345, 2); 75 ok_long(ulMapMode, 0); 76 ok_err(ERROR_INVALID_PARAMETER); 77 78 /* Test invalid DC and invalid mode */ 79 ulMapMode = SetMapMode((HDC)0x12345, 10); 80 ok_long(ulMapMode, 0); 81 ok_err(ERROR_INVALID_PARAMETER); 82 83 DeleteDC(hDC); 84 85 /* Test a deleted DC */ 86 ulMapMode = SetMapMode(hDC, 2); 87 ok_long(ulMapMode, 0); 88 ok_err(ERROR_INVALID_PARAMETER); 89 90 /* Test MM_TEXT */ 91 hDC = CreateCompatibleDC(NULL); 92 SetMapMode(hDC, MM_TEXT); 93 GetWindowExtEx(hDC, &WindowExt); 94 GetViewportExtEx(hDC, &ViewportExt); 95 ok_long(WindowExt.cx, 1); 96 ok_long(WindowExt.cy, 1); 97 ok_long(ViewportExt.cx, 1); 98 ok_long(ViewportExt.cy, 1); 99 DeleteDC(hDC); 100 101 /* Test MM_ISOTROPIC */ 102 hDC = CreateCompatibleDC(NULL); 103 SetMapMode(hDC, MM_ISOTROPIC); 104 GetWindowExtEx(hDC, &WindowExt); 105 GetViewportExtEx(hDC, &ViewportExt); 106 //ok_long(WindowExt.cx, 3600); 107 //ok_long(WindowExt.cy, 2700); 108 //ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES) - 4); 109 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 110 DeleteDC(hDC); 111 112 /* Test MM_ANISOTROPIC */ 113 hDC = CreateCompatibleDC(NULL); 114 SetMapMode(hDC, MM_ANISOTROPIC); 115 GetWindowExtEx(hDC, &WindowExt); 116 GetViewportExtEx(hDC, &ViewportExt); 117 ok_long(WindowExt.cx, 1); 118 ok_long(WindowExt.cy, 1); 119 ok_long(ViewportExt.cx, 1); 120 ok_long(ViewportExt.cy, 1); 121 122 /* set MM_ISOTROPIC first, the values will be kept */ 123 SetMapMode(hDC, MM_ISOTROPIC); 124 SetMapMode(hDC, MM_ANISOTROPIC); 125 GetWindowExtEx(hDC, &WindowExt); 126 GetViewportExtEx(hDC, &ViewportExt); 127 //ok_long(WindowExt.cx, 3600); 128 //ok_long(WindowExt.cy, 2700); 129 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 130 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 131 DeleteDC(hDC); 132 133 /* Test MM_LOMETRIC */ 134 hDC = CreateCompatibleDC(NULL); 135 SetMapMode(hDC, MM_LOMETRIC); 136 GetWindowExtEx(hDC, &WindowExt); 137 GetViewportExtEx(hDC, &ViewportExt); 138 //ok_long(WindowExt.cx, 3600); 139 //ok_long(WindowExt.cy, 2700); 140 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 141 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 142 DeleteDC(hDC); 143 144 /* Test MM_HIMETRIC */ 145 hDC = CreateCompatibleDC(NULL); 146 SetMapMode(hDC, MM_HIMETRIC); 147 GetWindowExtEx(hDC, &WindowExt); 148 GetViewportExtEx(hDC, &ViewportExt); 149 //ok_long(WindowExt.cx, 36000); 150 //ok_long(WindowExt.cy, 27000); 151 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 152 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 153 DeleteDC(hDC); 154 155 /* Test MM_LOENGLISH */ 156 hDC = CreateCompatibleDC(NULL); 157 SetMapMode(hDC, MM_LOENGLISH); 158 GetWindowExtEx(hDC, &WindowExt); 159 GetViewportExtEx(hDC, &ViewportExt); 160 //ok_long(WindowExt.cx, 1417); 161 //ok_long(WindowExt.cy, 1063); 162 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 163 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 164 DeleteDC(hDC); 165 166 /* Test MM_HIENGLISH */ 167 hDC = CreateCompatibleDC(NULL); 168 SetMapMode(hDC, MM_HIENGLISH); 169 GetWindowExtEx(hDC, &WindowExt); 170 GetViewportExtEx(hDC, &ViewportExt); 171 //ok_long(WindowExt.cx, 14173); 172 //ok_long(WindowExt.cy, 10630); 173 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 174 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 175 DeleteDC(hDC); 176 177 /* Test MM_TWIPS */ 178 hDC = CreateCompatibleDC(NULL); 179 SetMapMode(hDC, MM_TWIPS); 180 GetWindowExtEx(hDC, &WindowExt); 181 GetViewportExtEx(hDC, &ViewportExt); 182 //ok_long(WindowExt.cx, 20409); 183 //ok_long(WindowExt.cy, 15307); 184 ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES)); 185 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 186 DeleteDC(hDC); 187 188 // 189 // Test mode and extents 190 // 191 hDC = CreateCompatibleDC(NULL); 192 GetViewportExtEx(hDC, &ViewportExt); 193 GetWindowExtEx(hDC, &WindowExt); 194 ok_long(ViewportExt.cx, 1); 195 ok_long(ViewportExt.cy, 1); 196 ok_long(WindowExt.cx, 1); 197 ok_long(WindowExt.cy, 1); 198 199 SetMapMode(hDC, MM_ANISOTROPIC); 200 GetViewportExtEx(hDC, &ViewportExt); 201 GetWindowExtEx(hDC, &WindowExt); 202 ok_long(ViewportExt.cx, 1); 203 ok_long(ViewportExt.cy, 1); 204 ok_long(WindowExt.cx, 1); 205 ok_long(WindowExt.cy, 1); 206 SetWindowExtEx(hDC, 200, 200, NULL); 207 SetViewportExtEx(hDC, 100, 100, NULL); 208 209 SetMapMode(hDC, MM_ANISOTROPIC); 210 GetViewportExtEx(hDC, &ViewportExt); 211 GetWindowExtEx(hDC, &WindowExt); 212 ok_long(ViewportExt.cx, 100); 213 ok_long(ViewportExt.cy, 100); 214 ok_long(WindowExt.cx, 200); 215 ok_long(WindowExt.cy, 200); 216 217 SetMapMode(hDC, MM_ANISOTROPIC); 218 GetViewportExtEx(hDC, &ViewportExt); 219 ok_long(ViewportExt.cx, 100); 220 ok_long(ViewportExt.cy, 100); 221 ok_long(WindowExt.cx, 200); 222 ok_long(WindowExt.cy, 200); 223 224 SetMapMode(hDC, MM_ISOTROPIC); 225 GetViewportExtEx(hDC, &ViewportExt); 226 //ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES) - 4); 227 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 228 SetWindowExtEx(hDC, 100, 100, NULL); 229 SetViewportExtEx(hDC, 100, 100, NULL); 230 231 SetMapMode(hDC, MM_ISOTROPIC); 232 GetViewportExtEx(hDC, &ViewportExt); 233 ok_long(ViewportExt.cx, 100); 234 ok_long(ViewportExt.cy, 100); 235 236 SetMapMode(hDC, MM_ANISOTROPIC); 237 GetViewportExtEx(hDC, &ViewportExt); 238 ok_long(ViewportExt.cx, 100); 239 ok_long(ViewportExt.cy, 100); 240 241 SetMapMode(hDC, MM_TEXT); 242 GetViewportExtEx(hDC, &ViewportExt); 243 ok_long(ViewportExt.cx, 1); 244 ok_long(ViewportExt.cy, 1); 245 246 SetMapMode(hDC, MM_ANISOTROPIC); 247 GetViewportExtEx(hDC, &ViewportExt); 248 ok_long(ViewportExt.cx, 1); 249 ok_long(ViewportExt.cy, 1); 250 251 SetMapMode(hDC, MM_ISOTROPIC); 252 GetViewportExtEx(hDC, &ViewportExt); 253 //ok_long(ViewportExt.cx, GetDeviceCaps(GetDC(0), HORZRES) - 4); 254 ok_long(ViewportExt.cy, -GetDeviceCaps(GetDC(0), VERTRES)); 255 256 SetMapMode(hDC, MM_TEXT); 257 GetViewportExtEx(hDC, &ViewportExt); 258 GetWindowExtEx(hDC, &WindowExt); 259 ok_long(ViewportExt.cx, 1); 260 ok_long(ViewportExt.cy, 1); 261 ok_long(WindowExt.cx, 1); 262 ok_long(WindowExt.cy, 1); 263 DeleteDC(hDC); 264 265 // 266 // Test mode and GetCurrentPositionEx 267 // 268 hDC = CreateCompatibleDC(NULL); 269 MoveToEx(hDC, 100, 100, NULL); 270 SetMapMode(hDC, MM_ANISOTROPIC); 271 GetCurrentPositionEx(hDC, &pt); 272 ok_long(pt.x, 100); 273 ok_long(pt.y, 100); 274 SetMapMode(hDC, MM_TEXT); 275 GetCurrentPositionEx(hDC, &pt); 276 ok_long(pt.x, 100); 277 ok_long(pt.y, 100); 278 SetMapMode(hDC, MM_ISOTROPIC); 279 GetCurrentPositionEx(hDC, &pt); 280 ok_long(pt.x, 100); 281 ok_long(pt.y, 100); 282 DeleteDC(hDC); 283 } 284 285 START_TEST(SetMapMode) 286 { 287 Test_SetMapMode(); 288 } 289