4afae6beb30c94c15966d24d499bf2c754bd2d43
[reactos.git] / rostests / winetests / gdi32 / icm.c
1 /*
2 * Tests for ICM functions
3 *
4 * Copyright (C) 2005, 2008 Hans Leidekker
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27
28 #include "wine/test.h"
29
30 static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
31
32 static void test_GetICMProfileA( HDC dc )
33 {
34 BOOL ret;
35 DWORD size, error;
36 char filename[MAX_PATH];
37
38 SetLastError( 0xdeadbeef );
39 ret = GetICMProfileA( NULL, NULL, NULL );
40 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
41 {
42 win_skip( "GetICMProfileA is not implemented\n" );
43 return;
44 }
45 ok( !ret, "GetICMProfileA succeeded\n" );
46
47 ret = GetICMProfileA( dc, NULL, NULL );
48 ok( !ret, "GetICMProfileA succeeded\n" );
49
50 size = MAX_PATH;
51 ret = GetICMProfileA( dc, &size, NULL );
52 ok( !ret, "GetICMProfileA succeeded\n" );
53
54 size = MAX_PATH;
55 ret = GetICMProfileA( NULL, &size, filename );
56 ok( !ret, "GetICMProfileA succeeded\n" );
57
58 size = 0;
59 filename[0] = 0;
60 SetLastError(0xdeadbeef);
61 ret = GetICMProfileA( dc, &size, filename );
62 error = GetLastError();
63 ok( !ret, "GetICMProfileA succeeded\n" );
64 ok( size, "expected size > 0\n" );
65 ok( filename[0] == 0, "Expected filename to be empty\n" );
66 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
67
68 ret = GetICMProfileA( dc, NULL, filename );
69 ok( !ret, "GetICMProfileA succeeded\n" );
70
71 size = MAX_PATH;
72 ret = GetICMProfileA( dc, &size, filename );
73 ok( ret, "GetICMProfileA failed %d\n", GetLastError() );
74
75 trace( "%s\n", filename );
76 }
77
78 static void test_GetICMProfileW( HDC dc )
79 {
80 BOOL ret;
81 DWORD size, error;
82 WCHAR filename[MAX_PATH];
83
84 SetLastError( 0xdeadbeef );
85 ret = GetICMProfileW( NULL, NULL, NULL );
86 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
87 {
88 win_skip( "GetICMProfileW is not implemented\n" );
89 return;
90 }
91 ok( !ret, "GetICMProfileW succeeded\n" );
92
93 ret = GetICMProfileW( dc, NULL, NULL );
94 ok( !ret, "GetICMProfileW succeeded\n" );
95
96 if (0)
97 {
98 /* Vista crashes */
99 size = MAX_PATH;
100 ret = GetICMProfileW( dc, &size, NULL );
101 ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
102 }
103
104 ret = GetICMProfileW( dc, NULL, filename );
105 ok( !ret, "GetICMProfileW succeeded\n" );
106
107 size = MAX_PATH;
108 ret = GetICMProfileW( NULL, &size, filename );
109 ok( !ret, "GetICMProfileW succeeded\n" );
110
111 size = 0;
112 SetLastError(0xdeadbeef);
113 ret = GetICMProfileW( dc, &size, filename );
114 error = GetLastError();
115 ok( !ret, "GetICMProfileW succeeded\n" );
116 ok( size, "expected size > 0\n" );
117 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
118
119 size = MAX_PATH;
120 ret = GetICMProfileW( dc, &size, filename );
121 ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
122 }
123
124 static void test_SetICMMode( HDC dc )
125 {
126 INT ret, knob, save;
127 BOOL impl;
128
129 SetLastError( 0xdeadbeef );
130 impl = GetICMProfileA( NULL, NULL, NULL );
131 if ( !impl && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
132 {
133 win_skip( "On NT4 where SetICMMode is not implemented but this is not advertised\n" );
134 return;
135 }
136
137 SetLastError( 0xdeadbeef );
138 ret = SetICMMode( NULL, 0 );
139 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
140
141 ret = SetICMMode( dc, -1 );
142 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
143
144 save = SetICMMode( dc, ICM_QUERY );
145 ok( save == ICM_ON || save == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
146
147 if (save == ICM_ON) knob = ICM_OFF; else knob = ICM_ON;
148
149 ret = SetICMMode( dc, knob );
150 todo_wine ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
151
152 ret = SetICMMode( dc, ICM_QUERY );
153 todo_wine ok( ret == knob, "SetICMMode failed (%d)\n", GetLastError() );
154
155 ret = SetICMMode( dc, save );
156 ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
157
158 SetLastError( 0xdeadbeef );
159 dc = CreateDCW( displayW, NULL, NULL, NULL );
160 if ( !dc && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
161 {
162 win_skip( "CreateDCW is not implemented\n" );
163 return;
164 }
165 ok( dc != NULL, "CreateDCW failed (%d)\n", GetLastError() );
166
167 ret = SetICMMode( dc, ICM_QUERY );
168 ok( ret == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
169
170 DeleteDC( dc );
171 }
172
173 static INT CALLBACK enum_profiles_callbackA( LPSTR filename, LPARAM lparam )
174 {
175 trace("%s\n", filename);
176 return 1;
177 }
178
179 static void test_EnumICMProfilesA( HDC dc )
180 {
181 INT ret;
182
183 ret = EnumICMProfilesA( NULL, NULL, 0 );
184 ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret);
185
186 ret = EnumICMProfilesA( dc, enum_profiles_callbackA, 0 );
187 ok(ret == -1 || ret == 1 || broken(ret == 0) /* nt4 */,
188 "expected -1 or 1, got %d\n", ret);
189
190 ret = EnumICMProfilesA( dc, NULL, 0 );
191 ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret);
192 }
193
194 static INT CALLBACK enum_profiles_callbackW( LPWSTR filename, LPARAM lparam )
195 {
196 return 1;
197 }
198
199 static void test_EnumICMProfilesW( HDC dc )
200 {
201 INT ret;
202
203 ret = EnumICMProfilesW( NULL, NULL, 0 );
204 ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret);
205
206 ret = EnumICMProfilesW( dc, NULL, 0 );
207 ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret);
208
209 ret = EnumICMProfilesW( dc, enum_profiles_callbackW, 0 );
210 ok(ret == -1 || ret == 1 || broken(ret == 0) /* NT4 */, "expected -1 or 1, got %d\n", ret);
211 }
212
213 static void test_SetICMProfileA( HDC dc )
214 {
215 BOOL ret;
216 char profile[MAX_PATH];
217 DWORD len, error;
218
219 SetLastError( 0xdeadbeef );
220 ret = SetICMProfileA( NULL, NULL );
221 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
222 {
223 win_skip("SetICMProfileA is not implemented\n");
224 return;
225 }
226
227 len = sizeof(profile);
228 ret = GetICMProfileA( dc, &len, profile );
229 ok(ret, "GetICMProfileA failed %u\n", GetLastError());
230
231 SetLastError( 0xdeadbeef );
232 ret = SetICMProfileA( NULL, NULL );
233 error = GetLastError();
234 ok(!ret, "SetICMProfileA succeeded\n");
235 ok(error == ERROR_INVALID_PARAMETER,
236 "expected ERROR_INVALID_PARAMETER, got %u\n", error);
237
238 SetLastError( 0xdeadbeef );
239 ret = SetICMProfileA( NULL, profile );
240 error = GetLastError();
241 ok(!ret, "SetICMProfileA succeeded\n");
242 ok(error == ERROR_INVALID_HANDLE,
243 "expected ERROR_INVALID_HANDLE, got %u\n", error);
244
245 SetLastError( 0xdeadbeef );
246 ret = SetICMProfileA( dc, NULL );
247 error = GetLastError();
248 ok(!ret, "SetICMProfileA succeeded\n");
249 ok(error == ERROR_INVALID_PARAMETER,
250 "expected ERROR_INVALID_PARAMETER, got %u\n", error);
251
252 ret = SetICMProfileA( dc, profile );
253 ok(ret, "SetICMProfileA failed %u\n", GetLastError());
254 }
255
256 static void test_SetICMProfileW( HDC dc )
257 {
258 BOOL ret;
259 WCHAR profile[MAX_PATH];
260 DWORD len, error;
261
262 SetLastError( 0xdeadbeef );
263 ret = SetICMProfileW( NULL, NULL );
264 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
265 {
266 win_skip("SetICMProfileW is not implemented\n");
267 return;
268 }
269
270 len = sizeof(profile)/sizeof(profile[0]);
271 ret = GetICMProfileW( dc, &len, profile );
272 ok(ret, "GetICMProfileW failed %u\n", GetLastError());
273
274 SetLastError( 0xdeadbeef );
275 ret = SetICMProfileW( NULL, NULL );
276 error = GetLastError();
277 ok(!ret, "SetICMProfileW succeeded\n");
278 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
279
280 SetLastError( 0xdeadbeef );
281 ret = SetICMProfileW( NULL, profile );
282 error = GetLastError();
283 ok(!ret, "SetICMProfileW succeeded\n");
284 ok(error == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %u\n", error);
285
286 SetLastError( 0xdeadbeef );
287 ret = SetICMProfileW( dc, NULL );
288 error = GetLastError();
289 ok(!ret, "SetICMProfileW succeeded\n");
290 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
291
292 ret = SetICMProfileW( dc, profile );
293 ok(ret, "SetICMProfileW failed %u\n", GetLastError());
294 }
295
296 START_TEST(icm)
297 {
298 HDC dc = GetDC( NULL );
299
300 test_GetICMProfileA( dc );
301 test_GetICMProfileW( dc );
302 test_SetICMMode( dc );
303 test_EnumICMProfilesA( dc );
304 test_EnumICMProfilesW( dc );
305 test_SetICMProfileA( dc );
306 test_SetICMProfileW( dc );
307
308 ReleaseDC( NULL, dc );
309 }