[MSCMS]
[reactos.git] / rostests / winetests / mscms / profile.c
1 /*
2 * Tests for color profile functions
3 *
4 * Copyright 2004, 2005, 2006 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 "winreg.h"
26 #include "winnls.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "icm.h"
30
31 #include "wine/test.h"
32
33 static HMODULE hmscms;
34 static HMODULE huser32;
35
36 static BOOL (WINAPI *pAssociateColorProfileWithDeviceA)(PCSTR,PCSTR,PCSTR);
37 static BOOL (WINAPI *pCloseColorProfile)(HPROFILE);
38 static BOOL (WINAPI *pDisassociateColorProfileFromDeviceA)(PCSTR,PCSTR,PCSTR);
39 static BOOL (WINAPI *pGetColorDirectoryA)(PCHAR,PCHAR,PDWORD);
40 static BOOL (WINAPI *pGetColorDirectoryW)(PWCHAR,PWCHAR,PDWORD);
41 static BOOL (WINAPI *pGetColorProfileElement)(HPROFILE,TAGTYPE,DWORD,PDWORD,PVOID,PBOOL);
42 static BOOL (WINAPI *pGetColorProfileElementTag)(HPROFILE,DWORD,PTAGTYPE);
43 static BOOL (WINAPI *pGetColorProfileFromHandle)(HPROFILE,PBYTE,PDWORD);
44 static BOOL (WINAPI *pGetColorProfileHeader)(HPROFILE,PPROFILEHEADER);
45 static BOOL (WINAPI *pGetCountColorProfileElements)(HPROFILE,PDWORD);
46 static BOOL (WINAPI *pGetStandardColorSpaceProfileA)(PCSTR,DWORD,PSTR,PDWORD);
47 static BOOL (WINAPI *pGetStandardColorSpaceProfileW)(PCWSTR,DWORD,PWSTR,PDWORD);
48 static BOOL (WINAPI *pEnumColorProfilesA)(PCSTR,PENUMTYPEA,PBYTE,PDWORD,PDWORD);
49 static BOOL (WINAPI *pEnumColorProfilesW)(PCWSTR,PENUMTYPEW,PBYTE,PDWORD,PDWORD);
50 static BOOL (WINAPI *pInstallColorProfileA)(PCSTR,PCSTR);
51 static BOOL (WINAPI *pInstallColorProfileW)(PCWSTR,PCWSTR);
52 static BOOL (WINAPI *pIsColorProfileTagPresent)(HPROFILE,TAGTYPE,PBOOL);
53 static HPROFILE (WINAPI *pOpenColorProfileA)(PPROFILE,DWORD,DWORD,DWORD);
54 static HPROFILE (WINAPI *pOpenColorProfileW)(PPROFILE,DWORD,DWORD,DWORD);
55 static BOOL (WINAPI *pSetColorProfileElement)(HPROFILE,TAGTYPE,DWORD,PDWORD,PVOID);
56 static BOOL (WINAPI *pSetColorProfileHeader)(HPROFILE,PPROFILEHEADER);
57 static BOOL (WINAPI *pSetStandardColorSpaceProfileA)(PCSTR,DWORD,PSTR);
58 static BOOL (WINAPI *pSetStandardColorSpaceProfileW)(PCWSTR,DWORD,PWSTR);
59 static BOOL (WINAPI *pUninstallColorProfileA)(PCSTR,PCSTR,BOOL);
60 static BOOL (WINAPI *pUninstallColorProfileW)(PCWSTR,PCWSTR,BOOL);
61
62 static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,PDISPLAY_DEVICE,DWORD);
63
64 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( hmscms, #func ); \
65 if (!p##func) return FALSE;
66
67 static BOOL init_function_ptrs( void )
68 {
69 GETFUNCPTR( AssociateColorProfileWithDeviceA )
70 GETFUNCPTR( CloseColorProfile )
71 GETFUNCPTR( DisassociateColorProfileFromDeviceA )
72 GETFUNCPTR( GetColorDirectoryA )
73 GETFUNCPTR( GetColorDirectoryW )
74 GETFUNCPTR( GetColorProfileElement )
75 GETFUNCPTR( GetColorProfileElementTag )
76 GETFUNCPTR( GetColorProfileFromHandle )
77 GETFUNCPTR( GetColorProfileHeader )
78 GETFUNCPTR( GetCountColorProfileElements )
79 GETFUNCPTR( GetStandardColorSpaceProfileA )
80 GETFUNCPTR( GetStandardColorSpaceProfileW )
81 GETFUNCPTR( EnumColorProfilesA )
82 GETFUNCPTR( EnumColorProfilesW )
83 GETFUNCPTR( InstallColorProfileA )
84 GETFUNCPTR( InstallColorProfileW )
85 GETFUNCPTR( IsColorProfileTagPresent )
86 GETFUNCPTR( OpenColorProfileA )
87 GETFUNCPTR( OpenColorProfileW )
88 GETFUNCPTR( SetColorProfileElement )
89 GETFUNCPTR( SetColorProfileHeader )
90 GETFUNCPTR( SetStandardColorSpaceProfileA )
91 GETFUNCPTR( SetStandardColorSpaceProfileW )
92 GETFUNCPTR( UninstallColorProfileA )
93 GETFUNCPTR( UninstallColorProfileW )
94
95 pEnumDisplayDevicesA = (void *)GetProcAddress( huser32, "EnumDisplayDevicesA" );
96
97 return TRUE;
98 }
99
100 static const char machine[] = "dummy";
101 static const WCHAR machineW[] = { 'd','u','m','m','y',0 };
102
103 /* To do any real functionality testing with this suite you need a copy of
104 * the freely distributable standard RGB color space profile. It comes
105 * standard with Windows, but on Wine you probably need to install it yourself
106 * in one of the locations mentioned below.
107 */
108
109 /* Two common places to find the standard color space profile, relative
110 * to the system directory.
111 */
112 static const char profile1[] =
113 "\\color\\srgb color space profile.icm";
114 static const char profile2[] =
115 "\\spool\\drivers\\color\\srgb color space profile.icm";
116
117 static const WCHAR profile1W[] =
118 { '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
119 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
120 static const WCHAR profile2W[] =
121 { '\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\',
122 'c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
123 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
124
125 static const unsigned char rgbheader[] =
126 { 0x48, 0x0c, 0x00, 0x00, 0x6f, 0x6e, 0x69, 0x4c, 0x00, 0x00, 0x10, 0x02,
127 0x72, 0x74, 0x6e, 0x6d, 0x20, 0x42, 0x47, 0x52, 0x20, 0x5a, 0x59, 0x58,
128 0x02, 0x00, 0xce, 0x07, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x31, 0x00,
129 0x70, 0x73, 0x63, 0x61, 0x54, 0x46, 0x53, 0x4d, 0x00, 0x00, 0x00, 0x00,
130 0x20, 0x43, 0x45, 0x49, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xf6, 0x00, 0x00,
132 0x00, 0x00, 0x01, 0x00, 0x2d, 0xd3, 0x00, 0x00, 0x20, 0x20, 0x50, 0x48 };
133
134 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
135
136 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
137 {
138 INT i = strlen( path );
139
140 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
141 strcpy( name, &path[i] );
142 }
143
144 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
145 {
146 INT i = lstrlenW( path );
147
148 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
149 lstrcpyW( name, &path[i] );
150 }
151
152 static void test_GetColorDirectoryA(void)
153 {
154 BOOL ret;
155 DWORD size;
156 char buffer[MAX_PATH];
157
158 /* Parameter checks */
159
160 ret = pGetColorDirectoryA( NULL, NULL, NULL );
161 ok( !ret, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
162
163 size = 0;
164
165 ret = pGetColorDirectoryA( NULL, NULL, &size );
166 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
167
168 size = 0;
169
170 ret = pGetColorDirectoryA( NULL, buffer, &size );
171 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
172
173 size = 1;
174
175 ret = pGetColorDirectoryA( NULL, buffer, &size );
176 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
177
178 /* Functional checks */
179
180 size = sizeof(buffer);
181
182 ret = pGetColorDirectoryA( NULL, buffer, &size );
183 ok( ret && size > 0, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
184 }
185
186 static void test_GetColorDirectoryW(void)
187 {
188 BOOL ret;
189 DWORD size;
190 WCHAR buffer[MAX_PATH];
191
192 /* Parameter checks */
193
194 /* This one crashes win2k
195
196 ret = pGetColorDirectoryW( NULL, NULL, NULL );
197 ok( !ret, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
198
199 */
200
201 size = 0;
202
203 ret = pGetColorDirectoryW( NULL, NULL, &size );
204 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
205
206 size = 0;
207
208 ret = pGetColorDirectoryW( NULL, buffer, &size );
209 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
210
211 size = 1;
212
213 ret = pGetColorDirectoryW( NULL, buffer, &size );
214 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
215
216 /* Functional checks */
217
218 size = sizeof(buffer);
219
220 ret = pGetColorDirectoryW( NULL, buffer, &size );
221 ok( ret && size > 0, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
222 }
223
224 static void test_GetColorProfileElement( char *standardprofile )
225 {
226 if (standardprofile)
227 {
228 PROFILE profile;
229 HPROFILE handle;
230 BOOL ret, ref;
231 DWORD size;
232 TAGTYPE tag = 0x63707274; /* 'cprt' */
233 static char buffer[51];
234 static const char expect[] =
235 { 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70,
236 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20,
237 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65, 0x74,
238 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x72, 0x64, 0x20, 0x43,
239 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x00 };
240
241 profile.dwType = PROFILE_FILENAME;
242 profile.pProfileData = standardprofile;
243 profile.cbDataSize = strlen(standardprofile);
244
245 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
246 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
247
248 /* Parameter checks */
249
250 ret = pGetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
251 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
252
253 ret = pGetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
254 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
255
256 size = 0;
257 ret = pGetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
258 ok( !ret, "GetColorProfileElement() succeeded\n" );
259 ok( size > 0, "wrong size\n" );
260
261 /* Functional checks */
262
263 size = sizeof(buffer);
264 ret = pGetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
265 ok( ret, "GetColorProfileElement() failed %u\n", GetLastError() );
266 ok( size > 0, "wrong size\n" );
267 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
268
269 pCloseColorProfile( handle );
270 }
271 }
272
273 static void test_GetColorProfileElementTag( char *standardprofile )
274 {
275 if (standardprofile)
276 {
277 PROFILE profile;
278 HPROFILE handle;
279 BOOL ret;
280 DWORD index = 1;
281 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
282
283 profile.dwType = PROFILE_FILENAME;
284 profile.pProfileData = standardprofile;
285 profile.cbDataSize = strlen(standardprofile);
286
287 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
288 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
289
290 /* Parameter checks */
291
292 ret = pGetColorProfileElementTag( NULL, index, &tag );
293 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
294
295 ret = pGetColorProfileElementTag( handle, 0, &tag );
296 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
297
298 ret = pGetColorProfileElementTag( handle, index, NULL );
299 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
300
301 ret = pGetColorProfileElementTag( handle, 18, NULL );
302 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
303
304 /* Functional checks */
305
306 ret = pGetColorProfileElementTag( handle, index, &tag );
307 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%d)\n",
308 GetLastError() );
309
310 pCloseColorProfile( handle );
311 }
312 }
313
314 static void test_GetColorProfileFromHandle( char *testprofile )
315 {
316 if (testprofile)
317 {
318 PROFILE profile;
319 HPROFILE handle;
320 DWORD size;
321 BOOL ret;
322 static const unsigned char expect[] =
323 { 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f, 0x02, 0x10, 0x00,
324 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59,
325 0x5a, 0x20, 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06, 0x00,
326 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54,
327 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47,
328 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00,
330 0x00, 0xd3, 0x2d, 0x48, 0x50, 0x20, 0x20 };
331
332 unsigned char *buffer;
333
334 profile.dwType = PROFILE_FILENAME;
335 profile.pProfileData = testprofile;
336 profile.cbDataSize = strlen(testprofile);
337
338 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
339 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
340
341 /* Parameter checks */
342
343 size = 0;
344
345 ret = pGetColorProfileFromHandle( handle, NULL, &size );
346 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
347
348 buffer = HeapAlloc( GetProcessHeap(), 0, size );
349
350 if (buffer)
351 {
352 ret = pGetColorProfileFromHandle( NULL, buffer, &size );
353 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
354
355 ret = pGetColorProfileFromHandle( handle, buffer, NULL );
356 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
357
358 /* Functional checks */
359
360 ret = pGetColorProfileFromHandle( handle, buffer, &size );
361 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
362
363 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
364
365 HeapFree( GetProcessHeap(), 0, buffer );
366 }
367
368 pCloseColorProfile( handle );
369 }
370 }
371
372 static void test_GetColorProfileHeader( char *testprofile )
373 {
374 if (testprofile)
375 {
376 PROFILE profile;
377 HPROFILE handle;
378 BOOL ret;
379 PROFILEHEADER header;
380
381 profile.dwType = PROFILE_FILENAME;
382 profile.pProfileData = testprofile;
383 profile.cbDataSize = strlen(testprofile);
384
385 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
386 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
387
388 /* Parameter checks */
389
390 ret = pGetColorProfileHeader( NULL, NULL );
391 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
392
393 ret = pGetColorProfileHeader( NULL, &header );
394 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
395
396 if (0) /* Crashes on Vista */
397 {
398 ret = pGetColorProfileHeader( handle, NULL );
399 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
400 }
401
402 /* Functional checks */
403
404 ret = pGetColorProfileHeader( handle, &header );
405 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
406
407 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
408
409 pCloseColorProfile( handle );
410 }
411 }
412
413 static void test_GetCountColorProfileElements( char *standardprofile )
414 {
415 if (standardprofile)
416 {
417 PROFILE profile;
418 HPROFILE handle;
419 BOOL ret;
420 DWORD count, expect = 17;
421
422 profile.dwType = PROFILE_FILENAME;
423 profile.pProfileData = standardprofile;
424 profile.cbDataSize = strlen(standardprofile);
425
426 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
427 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
428
429 /* Parameter checks */
430
431 ret = pGetCountColorProfileElements( NULL, &count );
432 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
433 GetLastError() );
434
435 ret = pGetCountColorProfileElements( handle, NULL );
436 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
437 GetLastError() );
438
439 /* Functional checks */
440
441 ret = pGetCountColorProfileElements( handle, &count );
442 ok( ret && count == expect,
443 "GetCountColorProfileElements() failed (%d)\n", GetLastError() );
444
445 pCloseColorProfile( handle );
446 }
447 }
448
449 static void test_GetStandardColorSpaceProfileA( char *standardprofile )
450 {
451 BOOL ret;
452 DWORD size;
453 CHAR oldprofile[MAX_PATH];
454 CHAR newprofile[MAX_PATH];
455
456 /* Parameter checks */
457
458 /* Single invalid parameter checks: */
459
460 size = sizeof(newprofile);
461 SetLastError(0xfaceabee); /* 1st param, */
462 ret = pGetStandardColorSpaceProfileA(machine, LCS_sRGB, newprofile, &size);
463 ok( !ret && GetLastError() == ERROR_NOT_SUPPORTED, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
464
465 size = sizeof(newprofile);
466 SetLastError(0xfaceabee); /* 2nd param, */
467 ret = pGetStandardColorSpaceProfileA(NULL, (DWORD)-1, newprofile, &size);
468 ok( !ret && GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
469
470 size = sizeof(newprofile);
471 SetLastError(0xfaceabee); /* 4th param, */
472 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, newprofile, NULL);
473 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
474
475 size = sizeof(newprofile);
476 SetLastError(0xfaceabee); /* 3rd param, */
477 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, NULL, &size);
478 ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
479
480 size = 0;
481 SetLastError(0xfaceabee); /* dereferenced 4th param, */
482 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, newprofile, &size);
483 ok( !ret && (GetLastError() == ERROR_MORE_DATA || GetLastError() == ERROR_INSUFFICIENT_BUFFER),
484 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
485
486 /* Several invalid parameter checks: */
487
488 size = 0;
489 SetLastError(0xfaceabee); /* 1st, maybe 2nd and then dereferenced 4th param, */
490 ret = pGetStandardColorSpaceProfileA(machine, 0, newprofile, &size);
491 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_NOT_SUPPORTED),
492 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
493
494 SetLastError(0xfaceabee); /* maybe 2nd and then 4th param, */
495 ret = pGetStandardColorSpaceProfileA(NULL, 0, newprofile, NULL);
496 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
497
498 size = 0;
499 SetLastError(0xfaceabee); /* maybe 2nd, then 3rd and dereferenced 4th param, */
500 ret = pGetStandardColorSpaceProfileA(NULL, 0, NULL, &size);
501 ok( !ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER || GetLastError() == ERROR_FILE_NOT_FOUND),
502 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
503
504 size = sizeof(newprofile);
505 SetLastError(0xfaceabee); /* maybe 2nd param. */
506 ret = pGetStandardColorSpaceProfileA(NULL, 0, newprofile, &size);
507 if (!ret) ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
508 else ok( !lstrcmpiA( newprofile, "" ) && GetLastError() == 0xfaceabee,
509 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
510
511 /* Functional checks */
512
513 size = sizeof(oldprofile);
514 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile, &size );
515 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
516
517 SetLastError(0xdeadbeef);
518 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, standardprofile );
519 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
520 {
521 skip("Not enough rights for SetStandardColorSpaceProfileA\n");
522 return;
523 }
524 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
525
526 size = sizeof(newprofile);
527 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, newprofile, &size );
528 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
529
530 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile );
531 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
532 }
533
534 static void test_GetStandardColorSpaceProfileW( WCHAR *standardprofileW )
535 {
536 BOOL ret;
537 DWORD size;
538 WCHAR oldprofile[MAX_PATH];
539 WCHAR newprofile[MAX_PATH];
540 CHAR newprofileA[MAX_PATH];
541
542 /* Parameter checks */
543
544 /* Single invalid parameter checks: */
545
546 size = sizeof(newprofile);
547 SetLastError(0xfaceabee); /* 1st param, */
548 ret = pGetStandardColorSpaceProfileW(machineW, LCS_sRGB, newprofile, &size);
549 ok( !ret && GetLastError() == ERROR_NOT_SUPPORTED, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
550
551 size = sizeof(newprofile);
552 SetLastError(0xfaceabee); /* 2nd param, */
553 ret = pGetStandardColorSpaceProfileW(NULL, (DWORD)-1, newprofile, &size);
554 ok( !ret && GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
555
556 size = sizeof(newprofile);
557 SetLastError(0xfaceabee); /* 2nd param, */
558 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, &size);
559 ok( (!ret && GetLastError() == ERROR_FILE_NOT_FOUND) ||
560 broken(ret), /* Win98 and WinME */
561 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
562
563 size = sizeof(newprofile);
564 SetLastError(0xfaceabee); /* 3rd param, */
565 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, NULL, &size);
566 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
567 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
568 broken(GetLastError() == 0xfaceabee) /* win98 */,
569 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
570
571 size = sizeof(newprofile);
572 SetLastError(0xfaceabee); /* 4th param, */
573 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, newprofile, NULL);
574 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
575
576 size = 0;
577 SetLastError(0xfaceabee); /* dereferenced 4th param. */
578 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, newprofile, &size);
579 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
580 ok( GetLastError() == ERROR_MORE_DATA ||
581 GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
582 broken(GetLastError() == 0xfaceabee) /* win98 */,
583 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
584
585 /* Several invalid parameter checks: */
586
587 size = 0;
588 SetLastError(0xfaceabee); /* 1st, maybe 2nd and then dereferenced 4th param, */
589 ret = pGetStandardColorSpaceProfileW(machineW, 0, newprofile, &size);
590 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_NOT_SUPPORTED),
591 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
592
593 SetLastError(0xfaceabee); /* maybe 2nd and then 4th param, */
594 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, NULL);
595 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
596
597 size = 0;
598 SetLastError(0xfaceabee); /* maybe 2nd, then 3rd and dereferenced 4th param, */
599 ret = pGetStandardColorSpaceProfileW(NULL, 0, NULL, &size);
600 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
601 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
602 GetLastError() == ERROR_FILE_NOT_FOUND ||
603 broken(GetLastError() == 0xfaceabee) /* win98 */,
604 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
605
606 size = sizeof(newprofile);
607 SetLastError(0xfaceabee); /* maybe 2nd param. */
608 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, &size);
609 if (!ret) ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
610 else
611 {
612 WideCharToMultiByte(CP_ACP, 0, newprofile, -1, newprofileA, sizeof(newprofileA), NULL, NULL);
613 ok( !lstrcmpiA( newprofileA, "" ) && GetLastError() == 0xfaceabee,
614 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
615 }
616
617 /* Functional checks */
618
619 size = sizeof(oldprofile);
620 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile, &size );
621 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
622
623 SetLastError(0xdeadbeef);
624 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, standardprofileW );
625 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
626 {
627 skip("Not enough rights for SetStandardColorSpaceProfileW\n");
628 return;
629 }
630 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
631
632 size = sizeof(newprofile);
633 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, newprofile, &size );
634 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
635
636 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile );
637 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
638 }
639
640 static void test_EnumColorProfilesA( char *standardprofile )
641 {
642 BOOL ret;
643 DWORD total, size, number;
644 ENUMTYPEA record;
645 BYTE *buffer;
646
647 /* Parameter checks */
648
649 memset( &record, 0, sizeof(ENUMTYPEA) );
650
651 record.dwSize = sizeof(ENUMTYPEA);
652 record.dwVersion = ENUM_TYPE_VERSION;
653 record.dwFields |= ET_DATACOLORSPACE;
654 record.dwDataColorSpace = SPACE_RGB;
655
656 total = 0;
657 ret = pEnumColorProfilesA( NULL, &record, NULL, &total, &number );
658 ok( !ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
659 buffer = HeapAlloc( GetProcessHeap(), 0, total );
660
661 size = total;
662 ret = pEnumColorProfilesA( machine, &record, buffer, &size, &number );
663 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
664
665 ret = pEnumColorProfilesA( NULL, NULL, buffer, &size, &number );
666 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
667
668 ret = pEnumColorProfilesA( NULL, &record, buffer, NULL, &number );
669 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
670
671 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
672 if (standardprofile)
673 ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
674 else
675 todo_wine ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
676
677 size = 0;
678
679 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
680 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
681
682 /* Functional checks */
683
684 size = total;
685 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
686 if (standardprofile)
687 ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
688 else
689 todo_wine ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
690
691 HeapFree( GetProcessHeap(), 0, buffer );
692 }
693
694 static void test_EnumColorProfilesW( WCHAR *standardprofileW )
695 {
696 BOOL ret;
697 DWORD total, size, number;
698 ENUMTYPEW record;
699 BYTE *buffer;
700
701 /* Parameter checks */
702
703 memset( &record, 0, sizeof(ENUMTYPEW) );
704
705 record.dwSize = sizeof(ENUMTYPEW);
706 record.dwVersion = ENUM_TYPE_VERSION;
707 record.dwFields |= ET_DATACOLORSPACE;
708 record.dwDataColorSpace = SPACE_RGB;
709
710 total = 0;
711 ret = pEnumColorProfilesW( NULL, &record, NULL, &total, &number );
712 ok( !ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
713 buffer = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
714
715 size = total;
716 ret = pEnumColorProfilesW( machineW, &record, buffer, &size, &number );
717 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
718
719 ret = pEnumColorProfilesW( NULL, NULL, buffer, &size, &number );
720 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
721
722 ret = pEnumColorProfilesW( NULL, &record, buffer, NULL, &number );
723 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
724
725 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
726 if (standardprofileW)
727 ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
728 else
729 todo_wine ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
730
731 size = 0;
732 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
733 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
734
735 /* Functional checks */
736
737 size = total;
738 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
739 if (standardprofileW)
740 ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
741 else
742 todo_wine ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
743
744 HeapFree( GetProcessHeap(), 0, buffer );
745 }
746
747 static void test_InstallColorProfileA( char *standardprofile, char *testprofile )
748 {
749 BOOL ret;
750
751 /* Parameter checks */
752
753 ret = pInstallColorProfileA( NULL, NULL );
754 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
755
756 ret = pInstallColorProfileA( machine, NULL );
757 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
758
759 ret = pInstallColorProfileA( NULL, machine );
760 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
761
762 if (standardprofile)
763 {
764 ret = pInstallColorProfileA( NULL, standardprofile );
765 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
766 }
767
768 /* Functional checks */
769
770 if (testprofile)
771 {
772 CHAR dest[MAX_PATH], base[MAX_PATH];
773 DWORD size = sizeof(dest);
774 CHAR slash[] = "\\";
775 HANDLE handle;
776
777 SetLastError(0xdeadbeef);
778 ret = pInstallColorProfileA( NULL, testprofile );
779 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
780 {
781 skip("Not enough rights for InstallColorProfileA\n");
782 return;
783 }
784 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
785
786 ret = pGetColorDirectoryA( NULL, dest, &size );
787 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
788
789 MSCMS_basenameA( testprofile, base );
790
791 lstrcatA( dest, slash );
792 lstrcatA( dest, base );
793
794 /* Check if the profile is really there */
795 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
796 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%d)\n", GetLastError() );
797 CloseHandle( handle );
798
799 ret = pUninstallColorProfileA( NULL, dest, TRUE );
800 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
801 }
802 }
803
804 static void test_InstallColorProfileW( WCHAR *standardprofileW, WCHAR *testprofileW )
805 {
806 BOOL ret;
807
808 /* Parameter checks */
809
810 ret = pInstallColorProfileW( NULL, NULL );
811 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
812
813 ret = pInstallColorProfileW( machineW, NULL );
814 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
815
816 ret = pInstallColorProfileW( NULL, machineW );
817 ok( !ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
818
819 if (standardprofileW)
820 {
821 ret = pInstallColorProfileW( NULL, standardprofileW );
822 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
823 }
824
825 /* Functional checks */
826
827 if (testprofileW)
828 {
829 WCHAR dest[MAX_PATH], base[MAX_PATH];
830 DWORD size = sizeof(dest);
831 WCHAR slash[] = { '\\', 0 };
832 HANDLE handle;
833
834 SetLastError(0xdeadbeef);
835 ret = pInstallColorProfileW( NULL, testprofileW );
836 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
837 {
838 skip("Not enough rights for InstallColorProfileW\n");
839 return;
840 }
841 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
842
843 ret = pGetColorDirectoryW( NULL, dest, &size );
844 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
845
846 MSCMS_basenameW( testprofileW, base );
847
848 lstrcatW( dest, slash );
849 lstrcatW( dest, base );
850
851 /* Check if the profile is really there */
852 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
853 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%d)\n", GetLastError() );
854 CloseHandle( handle );
855
856 ret = pUninstallColorProfileW( NULL, dest, TRUE );
857 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
858 }
859 }
860
861 static void test_IsColorProfileTagPresent( char *standardprofile )
862 {
863 if (standardprofile)
864 {
865 PROFILE profile;
866 HPROFILE handle;
867 BOOL ret, present;
868 TAGTYPE tag;
869
870 profile.dwType = PROFILE_FILENAME;
871 profile.pProfileData = standardprofile;
872 profile.cbDataSize = strlen(standardprofile);
873
874 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
875 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
876
877 /* Parameter checks */
878
879 tag = 0;
880
881 ret = pIsColorProfileTagPresent( handle, tag, &present );
882 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
883
884 tag = 0x63707274; /* 'cprt' */
885
886 ret = pIsColorProfileTagPresent( NULL, tag, &present );
887 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
888
889 ret = pIsColorProfileTagPresent( handle, tag, NULL );
890 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
891
892 /* Functional checks */
893
894 ret = pIsColorProfileTagPresent( handle, tag, &present );
895 ok( ret && present, "IsColorProfileTagPresent() failed (%d)\n", GetLastError() );
896
897 pCloseColorProfile( handle );
898 }
899 }
900
901 static void test_OpenColorProfileA( char *standardprofile )
902 {
903 PROFILE profile;
904 HPROFILE handle;
905 BOOL ret;
906
907 profile.dwType = PROFILE_FILENAME;
908 profile.pProfileData = NULL;
909 profile.cbDataSize = 0;
910
911 /* Parameter checks */
912
913 handle = pOpenColorProfileA( NULL, 0, 0, 0 );
914 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
915
916 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
917 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
918
919 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
920 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
921
922 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
923 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
924
925 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
926
927 if (standardprofile)
928 {
929 profile.pProfileData = standardprofile;
930 profile.cbDataSize = strlen(standardprofile);
931
932 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
933 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
934
935 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
936 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
937
938 handle = pOpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
939 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
940
941 /* Functional checks */
942
943 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
944 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
945
946 ret = pCloseColorProfile( handle );
947 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
948
949 profile.dwType = PROFILE_FILENAME;
950 profile.pProfileData = (void *)"sRGB Color Space Profile.icm";
951 profile.cbDataSize = sizeof("sRGB Color Space Profile.icm");
952
953 handle = pOpenColorProfileA( &profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
954 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
955
956 ret = pCloseColorProfile( handle );
957 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
958 }
959 }
960
961 static void test_OpenColorProfileW( WCHAR *standardprofileW )
962 {
963 PROFILE profile;
964 HPROFILE handle;
965 BOOL ret;
966
967 profile.dwType = PROFILE_FILENAME;
968 profile.pProfileData = NULL;
969 profile.cbDataSize = 0;
970
971 /* Parameter checks */
972
973 handle = pOpenColorProfileW( NULL, 0, 0, 0 );
974 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
975
976 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
977 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
978
979 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
980 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
981
982 handle = pOpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
983 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
984
985 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
986
987 if (standardprofileW)
988 {
989 profile.pProfileData = standardprofileW;
990 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
991
992 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
993 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
994
995 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
996 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
997
998 handle = pOpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
999 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1000
1001 /* Functional checks */
1002
1003 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1004 ok( handle != NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1005
1006 ret = pCloseColorProfile( handle );
1007 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
1008 }
1009 }
1010
1011 static void test_SetColorProfileElement( char *testprofile )
1012 {
1013 if (testprofile)
1014 {
1015 PROFILE profile;
1016 HPROFILE handle;
1017 DWORD size;
1018 BOOL ret, ref;
1019
1020 TAGTYPE tag = 0x63707274; /* 'cprt' */
1021 static char data[] = "(c) The Wine Project";
1022 static char buffer[51];
1023
1024 profile.dwType = PROFILE_FILENAME;
1025 profile.pProfileData = testprofile;
1026 profile.cbDataSize = strlen(testprofile);
1027
1028 /* Parameter checks */
1029
1030 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1031 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1032
1033 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1034 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1035
1036 pCloseColorProfile( handle );
1037
1038 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1039 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1040
1041 ret = pSetColorProfileElement( NULL, 0, 0, NULL, NULL );
1042 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1043
1044 ret = pSetColorProfileElement( handle, 0, 0, NULL, NULL );
1045 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1046
1047 ret = pSetColorProfileElement( handle, tag, 0, NULL, NULL );
1048 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1049
1050 ret = pSetColorProfileElement( handle, tag, 0, &size, NULL );
1051 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1052
1053 /* Functional checks */
1054
1055 size = sizeof(data);
1056 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1057 ok( ret, "SetColorProfileElement() failed %u\n", GetLastError() );
1058
1059 size = sizeof(buffer);
1060 ret = pGetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
1061 ok( ret, "GetColorProfileElement() failed %u\n", GetLastError() );
1062 ok( size > 0, "wrong size\n" );
1063
1064 ok( !memcmp( data, buffer, sizeof(data) ),
1065 "Unexpected tag data, expected %s, got %s (%u)\n", data, buffer, GetLastError() );
1066
1067 pCloseColorProfile( handle );
1068 }
1069 }
1070
1071 static void test_SetColorProfileHeader( char *testprofile )
1072 {
1073 if (testprofile)
1074 {
1075 PROFILE profile;
1076 HPROFILE handle;
1077 BOOL ret;
1078 PROFILEHEADER header;
1079
1080 profile.dwType = PROFILE_FILENAME;
1081 profile.pProfileData = testprofile;
1082 profile.cbDataSize = strlen(testprofile);
1083
1084 header.phSize = 0x00000c48;
1085 header.phCMMType = 0x4c696e6f;
1086 header.phVersion = 0x02100000;
1087 header.phClass = 0x6d6e7472;
1088 header.phDataColorSpace = 0x52474220;
1089 header.phConnectionSpace = 0x58595a20;
1090 header.phDateTime[0] = 0x07ce0002;
1091 header.phDateTime[1] = 0x00090006;
1092 header.phDateTime[2] = 0x00310000;
1093 header.phSignature = 0x61637370;
1094 header.phPlatform = 0x4d534654;
1095 header.phProfileFlags = 0x00000000;
1096 header.phManufacturer = 0x49454320;
1097 header.phModel = 0x73524742;
1098 header.phAttributes[0] = 0x00000000;
1099 header.phAttributes[1] = 0x00000000;
1100 header.phRenderingIntent = 0x00000000;
1101 header.phIlluminant.ciexyzX = 0x0000f6d6;
1102 header.phIlluminant.ciexyzY = 0x00010000;
1103 header.phIlluminant.ciexyzZ = 0x0000d32d;
1104 header.phCreator = 0x48502020;
1105
1106 /* Parameter checks */
1107
1108 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1109 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1110
1111 ret = pSetColorProfileHeader( handle, &header );
1112 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1113
1114 pCloseColorProfile( handle );
1115
1116 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1117 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1118
1119 ret = pSetColorProfileHeader( NULL, NULL );
1120 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1121
1122 ret = pSetColorProfileHeader( handle, NULL );
1123 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1124
1125 ret = pSetColorProfileHeader( NULL, &header );
1126 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1127
1128 /* Functional checks */
1129
1130 ret = pSetColorProfileHeader( handle, &header );
1131 ok( ret, "SetColorProfileHeader() failed (%d)\n", GetLastError() );
1132
1133 ret = pGetColorProfileHeader( handle, &header );
1134 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
1135
1136 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
1137
1138 pCloseColorProfile( handle );
1139 }
1140 }
1141
1142 static void test_UninstallColorProfileA( char *testprofile )
1143 {
1144 BOOL ret;
1145
1146 /* Parameter checks */
1147
1148 ret = pUninstallColorProfileA( NULL, NULL, FALSE );
1149 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1150
1151 ret = pUninstallColorProfileA( machine, NULL, FALSE );
1152 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1153
1154 /* Functional checks */
1155
1156 if (testprofile)
1157 {
1158 CHAR dest[MAX_PATH], base[MAX_PATH];
1159 DWORD size = sizeof(dest);
1160 CHAR slash[] = "\\";
1161 HANDLE handle;
1162
1163 SetLastError(0xdeadbeef);
1164 ret = pInstallColorProfileA( NULL, testprofile );
1165 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1166 {
1167 skip("Not enough rights for InstallColorProfileA\n");
1168 return;
1169 }
1170 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
1171
1172 ret = pGetColorDirectoryA( NULL, dest, &size );
1173 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1174
1175 MSCMS_basenameA( testprofile, base );
1176
1177 lstrcatA( dest, slash );
1178 lstrcatA( dest, base );
1179
1180 ret = pUninstallColorProfileA( NULL, dest, TRUE );
1181 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
1182
1183 /* Check if the profile is really gone */
1184 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1185 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%d)\n", GetLastError() );
1186 CloseHandle( handle );
1187 }
1188 }
1189
1190 static void test_UninstallColorProfileW( WCHAR *testprofileW )
1191 {
1192 BOOL ret;
1193
1194 /* Parameter checks */
1195
1196 ret = pUninstallColorProfileW( NULL, NULL, FALSE );
1197 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1198
1199 ret = pUninstallColorProfileW( machineW, NULL, FALSE );
1200 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1201
1202 /* Functional checks */
1203
1204 if (testprofileW)
1205 {
1206 WCHAR dest[MAX_PATH], base[MAX_PATH];
1207 char destA[MAX_PATH];
1208 DWORD size = sizeof(dest);
1209 WCHAR slash[] = { '\\', 0 };
1210 HANDLE handle;
1211 int bytes_copied;
1212
1213 SetLastError(0xdeadbeef);
1214 ret = pInstallColorProfileW( NULL, testprofileW );
1215 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1216 {
1217 skip("Not enough rights for InstallColorProfileW\n");
1218 return;
1219 }
1220 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
1221
1222 ret = pGetColorDirectoryW( NULL, dest, &size );
1223 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
1224
1225 MSCMS_basenameW( testprofileW, base );
1226
1227 lstrcatW( dest, slash );
1228 lstrcatW( dest, base );
1229
1230 ret = pUninstallColorProfileW( NULL, dest, TRUE );
1231 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
1232
1233 bytes_copied = WideCharToMultiByte(CP_ACP, 0, dest, -1, destA, MAX_PATH, NULL, NULL);
1234 ok( bytes_copied > 0 , "WideCharToMultiByte() returns %d\n", bytes_copied);
1235 /* Check if the profile is really gone */
1236 handle = CreateFileA( destA, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1237 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%d)\n", GetLastError() );
1238 CloseHandle( handle );
1239 }
1240 }
1241
1242 static void test_AssociateColorProfileWithDeviceA( char *testprofile )
1243 {
1244 BOOL ret;
1245 char profile[MAX_PATH], basename[MAX_PATH];
1246 DWORD error, size = sizeof(profile);
1247 DISPLAY_DEVICE display;
1248 BOOL res;
1249 DISPLAY_DEVICE monitor;
1250
1251 if (testprofile && pEnumDisplayDevicesA)
1252 {
1253 display.cb = sizeof( DISPLAY_DEVICE );
1254 res = pEnumDisplayDevicesA( NULL, 0, &display, 0 );
1255 ok( res, "Can't get display info\n" );
1256
1257 monitor.cb = sizeof( DISPLAY_DEVICE );
1258 res = pEnumDisplayDevicesA( display.DeviceName, 0, &monitor, 0 );
1259 if (res)
1260 {
1261 SetLastError(0xdeadbeef);
1262 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, NULL );
1263 error = GetLastError();
1264 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1265 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1266
1267 SetLastError(0xdeadbeef);
1268 ret = pAssociateColorProfileWithDeviceA( "machine", NULL, monitor.DeviceID );
1269 error = GetLastError();
1270 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1271 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1272
1273 SetLastError(0xdeadbeef);
1274 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, monitor.DeviceID );
1275 error = GetLastError();
1276 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1277 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1278
1279 ret = pInstallColorProfileA( NULL, testprofile );
1280 ok( ret, "InstallColorProfileA() failed (%u)\n", GetLastError() );
1281
1282 ret = pGetColorDirectoryA( NULL, profile, &size );
1283 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1284
1285 MSCMS_basenameA( testprofile, basename );
1286 lstrcatA( profile, "\\" );
1287 lstrcatA( profile, basename );
1288
1289 ret = pAssociateColorProfileWithDeviceA( NULL, profile, monitor.DeviceID );
1290 ok( ret, "AssociateColorProfileWithDevice() failed (%u)\n", GetLastError() );
1291
1292 SetLastError(0xdeadbeef);
1293 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, NULL );
1294 error = GetLastError();
1295 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1296 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1297
1298 SetLastError(0xdeadbeef);
1299 ret = pDisassociateColorProfileFromDeviceA( "machine", NULL, monitor.DeviceID );
1300 error = GetLastError();
1301 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1302 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1303
1304 SetLastError(0xdeadbeef);
1305 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, monitor.DeviceID );
1306 error = GetLastError();
1307 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1308 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1309
1310 ret = pDisassociateColorProfileFromDeviceA( NULL, profile, monitor.DeviceID );
1311 ok( ret, "DisassociateColorProfileFromDeviceA() failed (%u)\n", GetLastError() );
1312
1313 ret = pUninstallColorProfileA( NULL, profile, TRUE );
1314 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
1315 }
1316 else
1317 skip("Unable to obtain monitor name\n");
1318 }
1319 }
1320
1321 START_TEST(profile)
1322 {
1323 UINT len;
1324 HANDLE handle;
1325 char path[MAX_PATH], file[MAX_PATH], profilefile1[MAX_PATH], profilefile2[MAX_PATH];
1326 WCHAR profilefile1W[MAX_PATH], profilefile2W[MAX_PATH], fileW[MAX_PATH];
1327 char *standardprofile = NULL, *testprofile = NULL;
1328 WCHAR *standardprofileW = NULL, *testprofileW = NULL;
1329 UINT ret;
1330
1331 hmscms = LoadLibraryA( "mscms.dll" );
1332 if (!hmscms) return;
1333
1334 huser32 = LoadLibraryA( "user32.dll" );
1335 if (!huser32)
1336 {
1337 FreeLibrary( hmscms );
1338 return;
1339 }
1340
1341 if (!init_function_ptrs())
1342 {
1343 FreeLibrary( huser32 );
1344 FreeLibrary( hmscms );
1345 return;
1346 }
1347
1348 /* See if we can find the standard color profile */
1349 ret = GetSystemDirectoryA( profilefile1, sizeof(profilefile1) );
1350 ok( ret > 0, "GetSystemDirectoryA() returns %d, LastError = %d\n", ret, GetLastError());
1351 ok( lstrlenA(profilefile1) > 0 && lstrlenA(profilefile1) < MAX_PATH,
1352 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenA(profilefile1));
1353 MultiByteToWideChar(CP_ACP, 0, profilefile1, -1, profilefile1W, MAX_PATH);
1354 ok( lstrlenW(profilefile1W) > 0 && lstrlenW(profilefile1W) < MAX_PATH,
1355 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenW(profilefile1W));
1356 lstrcpyA(profilefile2, profilefile1);
1357 lstrcpyW(profilefile2W, profilefile1W);
1358
1359 lstrcatA( profilefile1, profile1 );
1360 lstrcatW( profilefile1W, profile1W );
1361 handle = CreateFileA( profilefile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1362
1363 if (handle != INVALID_HANDLE_VALUE)
1364 {
1365 standardprofile = profilefile1;
1366 standardprofileW = profilefile1W;
1367 CloseHandle( handle );
1368 }
1369
1370 lstrcatA( profilefile2, profile2 );
1371 lstrcatW( profilefile2W, profile2W );
1372 handle = CreateFileA( profilefile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1373
1374 if (handle != INVALID_HANDLE_VALUE)
1375 {
1376 standardprofile = profilefile2;
1377 standardprofileW = profilefile2W;
1378 CloseHandle( handle );
1379 }
1380
1381 /* If found, create a temporary copy for testing purposes */
1382 if (standardprofile && GetTempPath( sizeof(path), path ))
1383 {
1384 if (GetTempFileName( path, "rgb", 0, file ))
1385 {
1386 if (CopyFileA( standardprofile, file, FALSE ))
1387 {
1388 testprofile = (LPSTR)&file;
1389 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
1390 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
1391 testprofileW = (LPWSTR)&fileW;
1392 }
1393 }
1394 }
1395
1396 test_GetColorDirectoryA();
1397 test_GetColorDirectoryW();
1398
1399 test_GetColorProfileElement( standardprofile );
1400 test_GetColorProfileElementTag( standardprofile );
1401
1402 test_GetColorProfileFromHandle( testprofile );
1403 test_GetColorProfileHeader( testprofile );
1404
1405 test_GetCountColorProfileElements( standardprofile );
1406
1407 test_GetStandardColorSpaceProfileA( standardprofile );
1408 test_GetStandardColorSpaceProfileW( standardprofileW );
1409
1410 test_EnumColorProfilesA( standardprofile );
1411 test_EnumColorProfilesW( standardprofileW );
1412
1413 test_InstallColorProfileA( standardprofile, testprofile );
1414 test_InstallColorProfileW( standardprofileW, testprofileW );
1415
1416 test_IsColorProfileTagPresent( standardprofile );
1417
1418 test_OpenColorProfileA( standardprofile );
1419 test_OpenColorProfileW( standardprofileW );
1420
1421 test_SetColorProfileElement( testprofile );
1422 test_SetColorProfileHeader( testprofile );
1423
1424 test_UninstallColorProfileA( testprofile );
1425 test_UninstallColorProfileW( testprofileW );
1426
1427 test_AssociateColorProfileWithDeviceA( testprofile );
1428
1429 if (testprofile) DeleteFileA( testprofile );
1430 FreeLibrary( huser32 );
1431 FreeLibrary( hmscms );
1432 }