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 "precomp.h" 22 23 static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0}; 24 25 static void test_GetICMProfileA( HDC dc ) 26 { 27 BOOL ret; 28 DWORD size, error; 29 char filename[MAX_PATH]; 30 31 SetLastError( 0xdeadbeef ); 32 ret = GetICMProfileA( NULL, NULL, NULL ); 33 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) ) 34 { 35 win_skip( "GetICMProfileA is not implemented\n" ); 36 return; 37 } 38 ok( !ret, "GetICMProfileA succeeded\n" ); 39 40 ret = GetICMProfileA( dc, NULL, NULL ); 41 ok( !ret, "GetICMProfileA succeeded\n" ); 42 43 size = MAX_PATH; 44 ret = GetICMProfileA( dc, &size, NULL ); 45 ok( !ret, "GetICMProfileA succeeded\n" ); 46 ok( size > 0, "got %u\n", size ); 47 48 size = 0; 49 ret = GetICMProfileA( dc, &size, NULL ); 50 ok( !ret, "GetICMProfileA succeeded\n" ); 51 ok( size > 0, "got %u\n", size ); 52 53 size = MAX_PATH; 54 ret = GetICMProfileA( NULL, &size, filename ); 55 ok( !ret, "GetICMProfileA succeeded\n" ); 56 57 size = 0; 58 filename[0] = 0; 59 SetLastError(0xdeadbeef); 60 ret = GetICMProfileA( dc, &size, filename ); 61 error = GetLastError(); 62 ok( !ret, "GetICMProfileA succeeded\n" ); 63 ok( size, "expected size > 0\n" ); 64 ok( filename[0] == 0, "Expected filename to be empty\n" ); 65 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error ); 66 67 ret = GetICMProfileA( dc, NULL, filename ); 68 ok( !ret, "GetICMProfileA succeeded\n" ); 69 70 size = MAX_PATH; 71 ret = GetICMProfileA( dc, &size, filename ); 72 ok( ret, "GetICMProfileA failed %d\n", GetLastError() ); 73 74 trace( "%s\n", filename ); 75 } 76 77 static void test_GetICMProfileW( HDC dc ) 78 { 79 BOOL ret; 80 DWORD size, error; 81 WCHAR filename[MAX_PATH]; 82 83 SetLastError( 0xdeadbeef ); 84 ret = GetICMProfileW( NULL, NULL, NULL ); 85 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) ) 86 { 87 win_skip( "GetICMProfileW is not implemented\n" ); 88 return; 89 } 90 ok( !ret, "GetICMProfileW succeeded\n" ); 91 92 ret = GetICMProfileW( dc, NULL, NULL ); 93 ok( !ret, "GetICMProfileW succeeded\n" ); 94 95 if (0) 96 { 97 /* Vista crashes */ 98 size = MAX_PATH; 99 ret = GetICMProfileW( dc, &size, NULL ); 100 ok( ret, "GetICMProfileW failed %d\n", GetLastError() ); 101 } 102 103 ret = GetICMProfileW( dc, NULL, filename ); 104 ok( !ret, "GetICMProfileW succeeded\n" ); 105 106 size = MAX_PATH; 107 ret = GetICMProfileW( NULL, &size, filename ); 108 ok( !ret, "GetICMProfileW succeeded\n" ); 109 110 size = 0; 111 ret = GetICMProfileW( dc, &size, NULL ); 112 ok( !ret, "GetICMProfileW succeeded\n" ); 113 ok( size > 0, "got %u\n", size ); 114 115 size = 0; 116 SetLastError(0xdeadbeef); 117 ret = GetICMProfileW( dc, &size, filename ); 118 error = GetLastError(); 119 ok( !ret, "GetICMProfileW succeeded\n" ); 120 ok( size, "expected size > 0\n" ); 121 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error ); 122 123 size = MAX_PATH; 124 ret = GetICMProfileW( dc, &size, filename ); 125 ok( ret, "GetICMProfileW failed %d\n", GetLastError() ); 126 } 127 128 static void test_SetICMMode( HDC dc ) 129 { 130 INT ret, knob, save; 131 BOOL impl; 132 133 SetLastError( 0xdeadbeef ); 134 impl = GetICMProfileA( NULL, NULL, NULL ); 135 if ( !impl && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) ) 136 { 137 win_skip( "On NT4 where SetICMMode is not implemented but this is not advertised\n" ); 138 return; 139 } 140 141 SetLastError( 0xdeadbeef ); 142 ret = SetICMMode( NULL, 0 ); 143 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() ); 144 145 ret = SetICMMode( dc, -1 ); 146 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() ); 147 148 save = SetICMMode( dc, ICM_QUERY ); 149 ok( save == ICM_ON || save == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() ); 150 151 if (save == ICM_ON) knob = ICM_OFF; else knob = ICM_ON; 152 153 ret = SetICMMode( dc, knob ); 154 todo_wine ok( ret, "SetICMMode failed (%d)\n", GetLastError() ); 155 156 ret = SetICMMode( dc, ICM_QUERY ); 157 todo_wine ok( ret == knob, "SetICMMode failed (%d)\n", GetLastError() ); 158 159 ret = SetICMMode( dc, save ); 160 ok( ret, "SetICMMode failed (%d)\n", GetLastError() ); 161 162 SetLastError( 0xdeadbeef ); 163 dc = CreateDCW( displayW, NULL, NULL, NULL ); 164 if ( !dc && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) ) 165 { 166 win_skip( "CreateDCW is not implemented\n" ); 167 return; 168 } 169 ok( dc != NULL, "CreateDCW failed (%d)\n", GetLastError() ); 170 171 ret = SetICMMode( dc, ICM_QUERY ); 172 ok( ret == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() ); 173 174 DeleteDC( dc ); 175 } 176 177 static INT CALLBACK enum_profiles_callbackA( LPSTR filename, LPARAM lparam ) 178 { 179 trace("%s\n", filename); 180 return 1; 181 } 182 183 static void test_EnumICMProfilesA( HDC dc ) 184 { 185 INT ret; 186 187 ret = EnumICMProfilesA( NULL, NULL, 0 ); 188 ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret); 189 190 ret = EnumICMProfilesA( dc, enum_profiles_callbackA, 0 ); 191 ok(ret == -1 || ret == 1 || broken(ret == 0) /* nt4 */, 192 "expected -1 or 1, got %d\n", ret); 193 194 ret = EnumICMProfilesA( dc, NULL, 0 ); 195 ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret); 196 } 197 198 static INT CALLBACK enum_profiles_callbackW( LPWSTR filename, LPARAM lparam ) 199 { 200 return 1; 201 } 202 203 static void test_EnumICMProfilesW( HDC dc ) 204 { 205 INT ret; 206 207 ret = EnumICMProfilesW( NULL, NULL, 0 ); 208 ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret); 209 210 ret = EnumICMProfilesW( dc, NULL, 0 ); 211 ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret); 212 213 ret = EnumICMProfilesW( dc, enum_profiles_callbackW, 0 ); 214 ok(ret == -1 || ret == 1 || broken(ret == 0) /* NT4 */, "expected -1 or 1, got %d\n", ret); 215 } 216 217 static void test_SetICMProfileA( HDC dc ) 218 { 219 BOOL ret; 220 char profile[MAX_PATH]; 221 DWORD len, error; 222 223 SetLastError( 0xdeadbeef ); 224 ret = SetICMProfileA( NULL, NULL ); 225 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) 226 { 227 win_skip("SetICMProfileA is not implemented\n"); 228 return; 229 } 230 231 len = sizeof(profile); 232 ret = GetICMProfileA( dc, &len, profile ); 233 ok(ret, "GetICMProfileA failed %u\n", GetLastError()); 234 235 SetLastError( 0xdeadbeef ); 236 ret = SetICMProfileA( NULL, NULL ); 237 error = GetLastError(); 238 ok(!ret, "SetICMProfileA succeeded\n"); 239 ok(error == ERROR_INVALID_PARAMETER, 240 "expected ERROR_INVALID_PARAMETER, got %u\n", error); 241 242 SetLastError( 0xdeadbeef ); 243 ret = SetICMProfileA( NULL, profile ); 244 error = GetLastError(); 245 ok(!ret, "SetICMProfileA succeeded\n"); 246 ok(error == ERROR_INVALID_HANDLE, 247 "expected ERROR_INVALID_HANDLE, got %u\n", error); 248 249 SetLastError( 0xdeadbeef ); 250 ret = SetICMProfileA( dc, NULL ); 251 error = GetLastError(); 252 ok(!ret, "SetICMProfileA succeeded\n"); 253 ok(error == ERROR_INVALID_PARAMETER, 254 "expected ERROR_INVALID_PARAMETER, got %u\n", error); 255 256 ret = SetICMProfileA( dc, profile ); 257 ok(ret, "SetICMProfileA failed %u\n", GetLastError()); 258 } 259 260 static void test_SetICMProfileW( HDC dc ) 261 { 262 BOOL ret; 263 WCHAR profile[MAX_PATH]; 264 DWORD len, error; 265 266 SetLastError( 0xdeadbeef ); 267 ret = SetICMProfileW( NULL, NULL ); 268 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) 269 { 270 win_skip("SetICMProfileW is not implemented\n"); 271 return; 272 } 273 274 len = sizeof(profile)/sizeof(profile[0]); 275 ret = GetICMProfileW( dc, &len, profile ); 276 ok(ret, "GetICMProfileW failed %u\n", GetLastError()); 277 278 SetLastError( 0xdeadbeef ); 279 ret = SetICMProfileW( NULL, NULL ); 280 error = GetLastError(); 281 ok(!ret, "SetICMProfileW succeeded\n"); 282 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error); 283 284 SetLastError( 0xdeadbeef ); 285 ret = SetICMProfileW( NULL, profile ); 286 error = GetLastError(); 287 ok(!ret, "SetICMProfileW succeeded\n"); 288 ok(error == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %u\n", error); 289 290 SetLastError( 0xdeadbeef ); 291 ret = SetICMProfileW( dc, NULL ); 292 error = GetLastError(); 293 ok(!ret, "SetICMProfileW succeeded\n"); 294 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error); 295 296 ret = SetICMProfileW( dc, profile ); 297 ok(ret, "SetICMProfileW failed %u\n", GetLastError()); 298 } 299 300 START_TEST(icm) 301 { 302 HDC dc = GetDC( NULL ); 303 304 test_GetICMProfileA( dc ); 305 test_GetICMProfileW( dc ); 306 test_SetICMMode( dc ); 307 test_EnumICMProfilesA( dc ); 308 test_EnumICMProfilesW( dc ); 309 test_SetICMProfileA( dc ); 310 test_SetICMProfileW( dc ); 311 312 ReleaseDC( NULL, dc ); 313 } 314