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