mscms/tests: Compile with -D__WINESRC__.
[wine.git] / dlls / mscms / tests / profile.c
blobcfaf2ba822bce2251b4b9d1d9e777c14786ea90f
1 /*
2 * Tests for color profile functions
4 * Copyright 2004, 2005, 2006 Hans Leidekker
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.
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.
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
21 #include <stdarg.h>
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"
31 #include "wine/test.h"
33 static HMODULE hmscms;
34 static HMODULE huser32;
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);
62 static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,PDISPLAY_DEVICEA,DWORD);
64 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( hmscms, #func ); \
65 if (!p##func) return FALSE;
67 static BOOL init_function_ptrs( void )
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 )
95 pEnumDisplayDevicesA = (void *)GetProcAddress( huser32, "EnumDisplayDevicesA" );
97 return TRUE;
100 static const char machine[] = "dummy";
101 static const WCHAR machineW[] = { 'd','u','m','m','y',0 };
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.
109 /* Two common places to find the standard color space profile, relative
110 * to the system directory.
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";
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 };
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 };
134 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
136 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
138 INT i = strlen( path );
140 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
141 strcpy( name, &path[i] );
144 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
146 INT i = lstrlenW( path );
148 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
149 lstrcpyW( name, &path[i] );
152 static void test_GetColorDirectoryA(void)
154 BOOL ret;
155 DWORD size;
156 char buffer[MAX_PATH];
158 /* Parameter checks */
160 ret = pGetColorDirectoryA( NULL, NULL, NULL );
161 ok( !ret, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
163 size = 0;
165 ret = pGetColorDirectoryA( NULL, NULL, &size );
166 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
168 size = 0;
170 ret = pGetColorDirectoryA( NULL, buffer, &size );
171 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
173 size = 1;
175 ret = pGetColorDirectoryA( NULL, buffer, &size );
176 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
178 /* Functional checks */
180 size = sizeof(buffer);
182 ret = pGetColorDirectoryA( NULL, buffer, &size );
183 ok( ret && size > 0, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
186 static void test_GetColorDirectoryW(void)
188 BOOL ret;
189 DWORD size;
190 WCHAR buffer[MAX_PATH];
192 /* Parameter checks */
194 /* This one crashes win2k
196 ret = pGetColorDirectoryW( NULL, NULL, NULL );
197 ok( !ret, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
201 size = 0;
203 ret = pGetColorDirectoryW( NULL, NULL, &size );
204 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
206 size = 0;
208 ret = pGetColorDirectoryW( NULL, buffer, &size );
209 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
211 size = 1;
213 ret = pGetColorDirectoryW( NULL, buffer, &size );
214 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
216 /* Functional checks */
218 size = sizeof(buffer);
220 ret = pGetColorDirectoryW( NULL, buffer, &size );
221 ok( ret && size > 0, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
224 static void test_GetColorProfileElement( char *standardprofile )
226 if (standardprofile)
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 };
241 profile.dwType = PROFILE_FILENAME;
242 profile.pProfileData = standardprofile;
243 profile.cbDataSize = strlen(standardprofile);
245 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
246 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
248 /* Parameter checks */
250 ret = pGetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
251 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
253 ret = pGetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
254 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
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" );
261 /* Functional checks */
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" );
269 pCloseColorProfile( handle );
273 static void test_GetColorProfileElementTag( char *standardprofile )
275 if (standardprofile)
277 PROFILE profile;
278 HPROFILE handle;
279 BOOL ret;
280 DWORD index = 1;
281 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
283 profile.dwType = PROFILE_FILENAME;
284 profile.pProfileData = standardprofile;
285 profile.cbDataSize = strlen(standardprofile);
287 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
288 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
290 /* Parameter checks */
292 ret = pGetColorProfileElementTag( NULL, index, &tag );
293 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
295 ret = pGetColorProfileElementTag( handle, 0, &tag );
296 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
298 ret = pGetColorProfileElementTag( handle, index, NULL );
299 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
301 ret = pGetColorProfileElementTag( handle, 18, NULL );
302 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
304 /* Functional checks */
306 ret = pGetColorProfileElementTag( handle, index, &tag );
307 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%d)\n",
308 GetLastError() );
310 pCloseColorProfile( handle );
314 static void test_GetColorProfileFromHandle( char *testprofile )
316 if (testprofile)
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 };
332 unsigned char *buffer;
334 profile.dwType = PROFILE_FILENAME;
335 profile.pProfileData = testprofile;
336 profile.cbDataSize = strlen(testprofile);
338 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
339 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
341 /* Parameter checks */
343 size = 0;
345 ret = pGetColorProfileFromHandle( handle, NULL, &size );
346 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
348 buffer = HeapAlloc( GetProcessHeap(), 0, size );
350 if (buffer)
352 ret = pGetColorProfileFromHandle( NULL, buffer, &size );
353 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
355 ret = pGetColorProfileFromHandle( handle, buffer, NULL );
356 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
358 /* Functional checks */
360 ret = pGetColorProfileFromHandle( handle, buffer, &size );
361 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
363 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
365 HeapFree( GetProcessHeap(), 0, buffer );
368 pCloseColorProfile( handle );
372 static void test_GetColorProfileHeader( char *testprofile )
374 if (testprofile)
376 PROFILE profile;
377 HPROFILE handle;
378 BOOL ret;
379 PROFILEHEADER header;
381 profile.dwType = PROFILE_FILENAME;
382 profile.pProfileData = testprofile;
383 profile.cbDataSize = strlen(testprofile);
385 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
386 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
388 /* Parameter checks */
390 ret = pGetColorProfileHeader( NULL, NULL );
391 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
393 ret = pGetColorProfileHeader( NULL, &header );
394 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
396 if (0) /* Crashes on Vista */
398 ret = pGetColorProfileHeader( handle, NULL );
399 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
402 /* Functional checks */
404 ret = pGetColorProfileHeader( handle, &header );
405 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
407 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
409 pCloseColorProfile( handle );
413 static void test_GetCountColorProfileElements( char *standardprofile )
415 if (standardprofile)
417 PROFILE profile;
418 HPROFILE handle;
419 BOOL ret;
420 DWORD count, expect = 17;
422 profile.dwType = PROFILE_FILENAME;
423 profile.pProfileData = standardprofile;
424 profile.cbDataSize = strlen(standardprofile);
426 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
427 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
429 /* Parameter checks */
431 ret = pGetCountColorProfileElements( NULL, &count );
432 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
433 GetLastError() );
435 ret = pGetCountColorProfileElements( handle, NULL );
436 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
437 GetLastError() );
439 /* Functional checks */
441 ret = pGetCountColorProfileElements( handle, &count );
442 ok( ret && count == expect,
443 "GetCountColorProfileElements() failed (%d)\n", GetLastError() );
445 pCloseColorProfile( handle );
449 static void test_GetStandardColorSpaceProfileA( char *standardprofile )
451 BOOL ret;
452 DWORD size;
453 CHAR oldprofile[MAX_PATH];
454 CHAR newprofile[MAX_PATH];
456 /* Parameter checks */
458 /* Single invalid parameter checks: */
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() );
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() );
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() );
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() );
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() );
486 /* Several invalid parameter checks: */
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() );
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() );
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() );
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() );
511 /* Functional checks */
513 size = sizeof(oldprofile);
514 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile, &size );
515 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
517 SetLastError(0xdeadbeef);
518 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, standardprofile );
519 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
521 skip("Not enough rights for SetStandardColorSpaceProfileA\n");
522 return;
524 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
526 size = sizeof(newprofile);
527 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, newprofile, &size );
528 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
530 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile );
531 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
534 static void test_GetStandardColorSpaceProfileW( WCHAR *standardprofileW )
536 BOOL ret;
537 DWORD size;
538 WCHAR oldprofile[MAX_PATH];
539 WCHAR newprofile[MAX_PATH];
540 CHAR newprofileA[MAX_PATH];
542 /* Parameter checks */
544 /* Single invalid parameter checks: */
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() );
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() );
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() );
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() );
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() );
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() );
585 /* Several invalid parameter checks: */
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() );
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() );
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() );
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
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() );
617 /* Functional checks */
619 size = sizeof(oldprofile);
620 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile, &size );
621 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
623 SetLastError(0xdeadbeef);
624 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, standardprofileW );
625 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
627 skip("Not enough rights for SetStandardColorSpaceProfileW\n");
628 return;
630 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
632 size = sizeof(newprofile);
633 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, newprofile, &size );
634 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
636 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile );
637 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
640 static void test_EnumColorProfilesA( char *standardprofile )
642 BOOL ret;
643 DWORD total, size, number;
644 ENUMTYPEA record;
645 BYTE *buffer;
647 /* Parameter checks */
649 memset( &record, 0, sizeof(ENUMTYPEA) );
651 record.dwSize = sizeof(ENUMTYPEA);
652 record.dwVersion = ENUM_TYPE_VERSION;
653 record.dwFields |= ET_DATACOLORSPACE;
654 record.dwDataColorSpace = SPACE_RGB;
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 );
661 size = total;
662 ret = pEnumColorProfilesA( machine, &record, buffer, &size, &number );
663 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
665 ret = pEnumColorProfilesA( NULL, NULL, buffer, &size, &number );
666 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
668 ret = pEnumColorProfilesA( NULL, &record, buffer, NULL, &number );
669 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
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() );
677 size = 0;
679 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
680 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
682 /* Functional checks */
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() );
691 HeapFree( GetProcessHeap(), 0, buffer );
694 static void test_EnumColorProfilesW( WCHAR *standardprofileW )
696 BOOL ret;
697 DWORD total, size, number;
698 ENUMTYPEW record;
699 BYTE *buffer;
701 /* Parameter checks */
703 memset( &record, 0, sizeof(ENUMTYPEW) );
705 record.dwSize = sizeof(ENUMTYPEW);
706 record.dwVersion = ENUM_TYPE_VERSION;
707 record.dwFields |= ET_DATACOLORSPACE;
708 record.dwDataColorSpace = SPACE_RGB;
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) );
715 size = total;
716 ret = pEnumColorProfilesW( machineW, &record, buffer, &size, &number );
717 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
719 ret = pEnumColorProfilesW( NULL, NULL, buffer, &size, &number );
720 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
722 ret = pEnumColorProfilesW( NULL, &record, buffer, NULL, &number );
723 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
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() );
731 size = 0;
732 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
733 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
735 /* Functional checks */
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() );
744 HeapFree( GetProcessHeap(), 0, buffer );
747 static void test_InstallColorProfileA( char *standardprofile, char *testprofile )
749 BOOL ret;
751 /* Parameter checks */
753 ret = pInstallColorProfileA( NULL, NULL );
754 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
756 ret = pInstallColorProfileA( machine, NULL );
757 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
759 ret = pInstallColorProfileA( NULL, machine );
760 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
762 if (standardprofile)
764 ret = pInstallColorProfileA( NULL, standardprofile );
765 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
768 /* Functional checks */
770 if (testprofile)
772 CHAR dest[MAX_PATH], base[MAX_PATH];
773 DWORD size = sizeof(dest);
774 CHAR slash[] = "\\";
775 HANDLE handle;
777 SetLastError(0xdeadbeef);
778 ret = pInstallColorProfileA( NULL, testprofile );
779 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
781 skip("Not enough rights for InstallColorProfileA\n");
782 return;
784 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
786 ret = pGetColorDirectoryA( NULL, dest, &size );
787 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
789 MSCMS_basenameA( testprofile, base );
791 lstrcatA( dest, slash );
792 lstrcatA( dest, base );
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 );
799 ret = pUninstallColorProfileA( NULL, dest, TRUE );
800 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
804 static void test_InstallColorProfileW( WCHAR *standardprofileW, WCHAR *testprofileW )
806 BOOL ret;
808 /* Parameter checks */
810 ret = pInstallColorProfileW( NULL, NULL );
811 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
813 ret = pInstallColorProfileW( machineW, NULL );
814 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
816 ret = pInstallColorProfileW( NULL, machineW );
817 ok( !ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
819 if (standardprofileW)
821 ret = pInstallColorProfileW( NULL, standardprofileW );
822 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
825 /* Functional checks */
827 if (testprofileW)
829 WCHAR dest[MAX_PATH], base[MAX_PATH];
830 DWORD size = sizeof(dest);
831 WCHAR slash[] = { '\\', 0 };
832 HANDLE handle;
834 SetLastError(0xdeadbeef);
835 ret = pInstallColorProfileW( NULL, testprofileW );
836 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
838 skip("Not enough rights for InstallColorProfileW\n");
839 return;
841 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
843 ret = pGetColorDirectoryW( NULL, dest, &size );
844 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
846 MSCMS_basenameW( testprofileW, base );
848 lstrcatW( dest, slash );
849 lstrcatW( dest, base );
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 );
856 ret = pUninstallColorProfileW( NULL, dest, TRUE );
857 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
861 static void test_IsColorProfileTagPresent( char *standardprofile )
863 if (standardprofile)
865 PROFILE profile;
866 HPROFILE handle;
867 BOOL ret, present;
868 TAGTYPE tag;
870 profile.dwType = PROFILE_FILENAME;
871 profile.pProfileData = standardprofile;
872 profile.cbDataSize = strlen(standardprofile);
874 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
875 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
877 /* Parameter checks */
879 tag = 0;
881 ret = pIsColorProfileTagPresent( handle, tag, &present );
882 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
884 tag = 0x63707274; /* 'cprt' */
886 ret = pIsColorProfileTagPresent( NULL, tag, &present );
887 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
889 ret = pIsColorProfileTagPresent( handle, tag, NULL );
890 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
892 /* Functional checks */
894 ret = pIsColorProfileTagPresent( handle, tag, &present );
895 ok( ret && present, "IsColorProfileTagPresent() failed (%d)\n", GetLastError() );
897 pCloseColorProfile( handle );
901 static void test_OpenColorProfileA( char *standardprofile )
903 PROFILE profile;
904 HPROFILE handle;
905 BOOL ret;
907 profile.dwType = PROFILE_FILENAME;
908 profile.pProfileData = NULL;
909 profile.cbDataSize = 0;
911 /* Parameter checks */
913 handle = pOpenColorProfileA( NULL, 0, 0, 0 );
914 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
916 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
917 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
919 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
920 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
922 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
923 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
925 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
927 if (standardprofile)
929 profile.pProfileData = standardprofile;
930 profile.cbDataSize = strlen(standardprofile);
932 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
933 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
935 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
936 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
938 handle = pOpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
939 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
941 /* Functional checks */
943 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
944 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
946 ret = pCloseColorProfile( handle );
947 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
949 profile.dwType = PROFILE_FILENAME;
950 profile.pProfileData = (void *)"sRGB Color Space Profile.icm";
951 profile.cbDataSize = sizeof("sRGB Color Space Profile.icm");
953 handle = pOpenColorProfileA( &profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
954 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
956 ret = pCloseColorProfile( handle );
957 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
961 static void test_OpenColorProfileW( WCHAR *standardprofileW )
963 PROFILE profile;
964 HPROFILE handle;
965 BOOL ret;
967 profile.dwType = PROFILE_FILENAME;
968 profile.pProfileData = NULL;
969 profile.cbDataSize = 0;
971 /* Parameter checks */
973 handle = pOpenColorProfileW( NULL, 0, 0, 0 );
974 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
976 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
977 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
979 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
980 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
982 handle = pOpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
983 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
985 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
987 if (standardprofileW)
989 profile.pProfileData = standardprofileW;
990 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
992 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
993 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
995 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
996 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
998 handle = pOpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
999 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1001 /* Functional checks */
1003 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1004 ok( handle != NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1006 ret = pCloseColorProfile( handle );
1007 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
1011 static void test_SetColorProfileElement( char *testprofile )
1013 if (testprofile)
1015 PROFILE profile;
1016 HPROFILE handle;
1017 DWORD size;
1018 BOOL ret, ref;
1020 TAGTYPE tag = 0x63707274; /* 'cprt' */
1021 static char data[] = "(c) The Wine Project";
1022 static char buffer[51];
1024 profile.dwType = PROFILE_FILENAME;
1025 profile.pProfileData = testprofile;
1026 profile.cbDataSize = strlen(testprofile);
1028 /* Parameter checks */
1030 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1031 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1033 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1034 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1036 pCloseColorProfile( handle );
1038 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1039 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1041 ret = pSetColorProfileElement( NULL, 0, 0, NULL, NULL );
1042 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1044 ret = pSetColorProfileElement( handle, 0, 0, NULL, NULL );
1045 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1047 ret = pSetColorProfileElement( handle, tag, 0, NULL, NULL );
1048 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1050 ret = pSetColorProfileElement( handle, tag, 0, &size, NULL );
1051 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1053 /* Functional checks */
1055 size = sizeof(data);
1056 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1057 ok( ret, "SetColorProfileElement() failed %u\n", GetLastError() );
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" );
1064 ok( !memcmp( data, buffer, sizeof(data) ),
1065 "Unexpected tag data, expected %s, got %s (%u)\n", data, buffer, GetLastError() );
1067 pCloseColorProfile( handle );
1071 static void test_SetColorProfileHeader( char *testprofile )
1073 if (testprofile)
1075 PROFILE profile;
1076 HPROFILE handle;
1077 BOOL ret;
1078 PROFILEHEADER header;
1080 profile.dwType = PROFILE_FILENAME;
1081 profile.pProfileData = testprofile;
1082 profile.cbDataSize = strlen(testprofile);
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;
1106 /* Parameter checks */
1108 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1109 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1111 ret = pSetColorProfileHeader( handle, &header );
1112 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1114 pCloseColorProfile( handle );
1116 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1117 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1119 ret = pSetColorProfileHeader( NULL, NULL );
1120 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1122 ret = pSetColorProfileHeader( handle, NULL );
1123 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1125 ret = pSetColorProfileHeader( NULL, &header );
1126 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1128 /* Functional checks */
1130 ret = pSetColorProfileHeader( handle, &header );
1131 ok( ret, "SetColorProfileHeader() failed (%d)\n", GetLastError() );
1133 ret = pGetColorProfileHeader( handle, &header );
1134 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
1136 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
1138 pCloseColorProfile( handle );
1142 static void test_UninstallColorProfileA( char *testprofile )
1144 BOOL ret;
1146 /* Parameter checks */
1148 ret = pUninstallColorProfileA( NULL, NULL, FALSE );
1149 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1151 ret = pUninstallColorProfileA( machine, NULL, FALSE );
1152 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1154 /* Functional checks */
1156 if (testprofile)
1158 CHAR dest[MAX_PATH], base[MAX_PATH];
1159 DWORD size = sizeof(dest);
1160 CHAR slash[] = "\\";
1161 HANDLE handle;
1163 SetLastError(0xdeadbeef);
1164 ret = pInstallColorProfileA( NULL, testprofile );
1165 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1167 skip("Not enough rights for InstallColorProfileA\n");
1168 return;
1170 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
1172 ret = pGetColorDirectoryA( NULL, dest, &size );
1173 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1175 MSCMS_basenameA( testprofile, base );
1177 lstrcatA( dest, slash );
1178 lstrcatA( dest, base );
1180 ret = pUninstallColorProfileA( NULL, dest, TRUE );
1181 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
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 );
1190 static void test_UninstallColorProfileW( WCHAR *testprofileW )
1192 BOOL ret;
1194 /* Parameter checks */
1196 ret = pUninstallColorProfileW( NULL, NULL, FALSE );
1197 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1199 ret = pUninstallColorProfileW( machineW, NULL, FALSE );
1200 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1202 /* Functional checks */
1204 if (testprofileW)
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;
1213 SetLastError(0xdeadbeef);
1214 ret = pInstallColorProfileW( NULL, testprofileW );
1215 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1217 skip("Not enough rights for InstallColorProfileW\n");
1218 return;
1220 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
1222 ret = pGetColorDirectoryW( NULL, dest, &size );
1223 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
1225 MSCMS_basenameW( testprofileW, base );
1227 lstrcatW( dest, slash );
1228 lstrcatW( dest, base );
1230 ret = pUninstallColorProfileW( NULL, dest, TRUE );
1231 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
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 );
1242 static void test_AssociateColorProfileWithDeviceA( char *testprofile )
1244 BOOL ret;
1245 char profile[MAX_PATH], basename[MAX_PATH];
1246 DWORD error, size = sizeof(profile);
1247 DISPLAY_DEVICEA display, monitor;
1248 BOOL res;
1250 if (testprofile && pEnumDisplayDevicesA)
1252 display.cb = sizeof( DISPLAY_DEVICEA );
1253 res = pEnumDisplayDevicesA( NULL, 0, &display, 0 );
1254 ok( res, "Can't get display info\n" );
1256 monitor.cb = sizeof( DISPLAY_DEVICEA );
1257 res = pEnumDisplayDevicesA( display.DeviceName, 0, &monitor, 0 );
1258 if (res)
1260 SetLastError(0xdeadbeef);
1261 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, NULL );
1262 error = GetLastError();
1263 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1264 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1266 SetLastError(0xdeadbeef);
1267 ret = pAssociateColorProfileWithDeviceA( "machine", NULL, monitor.DeviceID );
1268 error = GetLastError();
1269 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1270 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1272 SetLastError(0xdeadbeef);
1273 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, monitor.DeviceID );
1274 error = GetLastError();
1275 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1276 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1278 ret = pInstallColorProfileA( NULL, testprofile );
1279 ok( ret, "InstallColorProfileA() failed (%u)\n", GetLastError() );
1281 ret = pGetColorDirectoryA( NULL, profile, &size );
1282 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1284 MSCMS_basenameA( testprofile, basename );
1285 lstrcatA( profile, "\\" );
1286 lstrcatA( profile, basename );
1288 ret = pAssociateColorProfileWithDeviceA( NULL, profile, monitor.DeviceID );
1289 ok( ret, "AssociateColorProfileWithDevice() failed (%u)\n", GetLastError() );
1291 SetLastError(0xdeadbeef);
1292 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, NULL );
1293 error = GetLastError();
1294 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1295 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1297 SetLastError(0xdeadbeef);
1298 ret = pDisassociateColorProfileFromDeviceA( "machine", NULL, monitor.DeviceID );
1299 error = GetLastError();
1300 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1301 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1303 SetLastError(0xdeadbeef);
1304 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, monitor.DeviceID );
1305 error = GetLastError();
1306 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1307 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1309 ret = pDisassociateColorProfileFromDeviceA( NULL, profile, monitor.DeviceID );
1310 ok( ret, "DisassociateColorProfileFromDeviceA() failed (%u)\n", GetLastError() );
1312 ret = pUninstallColorProfileA( NULL, profile, TRUE );
1313 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
1315 else
1316 skip("Unable to obtain monitor name\n");
1320 START_TEST(profile)
1322 UINT len;
1323 HANDLE handle;
1324 char path[MAX_PATH], file[MAX_PATH], profilefile1[MAX_PATH], profilefile2[MAX_PATH];
1325 WCHAR profilefile1W[MAX_PATH], profilefile2W[MAX_PATH], fileW[MAX_PATH];
1326 char *standardprofile = NULL, *testprofile = NULL;
1327 WCHAR *standardprofileW = NULL, *testprofileW = NULL;
1328 UINT ret;
1330 hmscms = LoadLibraryA( "mscms.dll" );
1331 if (!hmscms) return;
1333 huser32 = LoadLibraryA( "user32.dll" );
1334 if (!huser32)
1336 FreeLibrary( hmscms );
1337 return;
1340 if (!init_function_ptrs())
1342 FreeLibrary( huser32 );
1343 FreeLibrary( hmscms );
1344 return;
1347 /* See if we can find the standard color profile */
1348 ret = GetSystemDirectoryA( profilefile1, sizeof(profilefile1) );
1349 ok( ret > 0, "GetSystemDirectoryA() returns %d, LastError = %d\n", ret, GetLastError());
1350 ok( lstrlenA(profilefile1) > 0 && lstrlenA(profilefile1) < MAX_PATH,
1351 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenA(profilefile1));
1352 MultiByteToWideChar(CP_ACP, 0, profilefile1, -1, profilefile1W, MAX_PATH);
1353 ok( lstrlenW(profilefile1W) > 0 && lstrlenW(profilefile1W) < MAX_PATH,
1354 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenW(profilefile1W));
1355 lstrcpyA(profilefile2, profilefile1);
1356 lstrcpyW(profilefile2W, profilefile1W);
1358 lstrcatA( profilefile1, profile1 );
1359 lstrcatW( profilefile1W, profile1W );
1360 handle = CreateFileA( profilefile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1362 if (handle != INVALID_HANDLE_VALUE)
1364 standardprofile = profilefile1;
1365 standardprofileW = profilefile1W;
1366 CloseHandle( handle );
1369 lstrcatA( profilefile2, profile2 );
1370 lstrcatW( profilefile2W, profile2W );
1371 handle = CreateFileA( profilefile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1373 if (handle != INVALID_HANDLE_VALUE)
1375 standardprofile = profilefile2;
1376 standardprofileW = profilefile2W;
1377 CloseHandle( handle );
1380 /* If found, create a temporary copy for testing purposes */
1381 if (standardprofile && GetTempPathA( sizeof(path), path ))
1383 if (GetTempFileNameA( path, "rgb", 0, file ))
1385 if (CopyFileA( standardprofile, file, FALSE ))
1387 testprofile = (LPSTR)&file;
1388 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
1389 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
1390 testprofileW = (LPWSTR)&fileW;
1395 test_GetColorDirectoryA();
1396 test_GetColorDirectoryW();
1398 test_GetColorProfileElement( standardprofile );
1399 test_GetColorProfileElementTag( standardprofile );
1401 test_GetColorProfileFromHandle( testprofile );
1402 test_GetColorProfileHeader( testprofile );
1404 test_GetCountColorProfileElements( standardprofile );
1406 test_GetStandardColorSpaceProfileA( standardprofile );
1407 test_GetStandardColorSpaceProfileW( standardprofileW );
1409 test_EnumColorProfilesA( standardprofile );
1410 test_EnumColorProfilesW( standardprofileW );
1412 test_InstallColorProfileA( standardprofile, testprofile );
1413 test_InstallColorProfileW( standardprofileW, testprofileW );
1415 test_IsColorProfileTagPresent( standardprofile );
1417 test_OpenColorProfileA( standardprofile );
1418 test_OpenColorProfileW( standardprofileW );
1420 test_SetColorProfileElement( testprofile );
1421 test_SetColorProfileHeader( testprofile );
1423 test_UninstallColorProfileA( testprofile );
1424 test_UninstallColorProfileW( testprofileW );
1426 test_AssociateColorProfileWithDeviceA( testprofile );
1428 if (testprofile) DeleteFileA( testprofile );
1429 FreeLibrary( huser32 );
1430 FreeLibrary( hmscms );