riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / mscms / tests / profile.c
blob012a7dcccd973e9e6955574e2a3151c06b48a7a3
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 BOOL have_color_profile;
127 static const unsigned char rgbheader[] =
128 { 0x48, 0x0c, 0x00, 0x00, 0x6f, 0x6e, 0x69, 0x4c, 0x00, 0x00, 0x10, 0x02,
129 0x72, 0x74, 0x6e, 0x6d, 0x20, 0x42, 0x47, 0x52, 0x20, 0x5a, 0x59, 0x58,
130 0x02, 0x00, 0xce, 0x07, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x31, 0x00,
131 0x70, 0x73, 0x63, 0x61, 0x54, 0x46, 0x53, 0x4d, 0x00, 0x00, 0x00, 0x00,
132 0x20, 0x43, 0x45, 0x49, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xf6, 0x00, 0x00,
134 0x00, 0x00, 0x01, 0x00, 0x2d, 0xd3, 0x00, 0x00, 0x20, 0x20, 0x50, 0x48 };
136 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
138 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
140 INT i = strlen( path );
142 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
143 strcpy( name, &path[i] );
146 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
148 INT i = lstrlenW( path );
150 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
151 lstrcpyW( name, &path[i] );
154 static void test_GetColorDirectoryA(void)
156 BOOL ret;
157 DWORD size;
158 char buffer[MAX_PATH];
160 /* Parameter checks */
162 ret = pGetColorDirectoryA( NULL, NULL, NULL );
163 ok( !ret, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
165 size = 0;
167 ret = pGetColorDirectoryA( NULL, NULL, &size );
168 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
170 size = 0;
172 ret = pGetColorDirectoryA( NULL, buffer, &size );
173 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
175 size = 1;
177 ret = pGetColorDirectoryA( NULL, buffer, &size );
178 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%d)\n", GetLastError() );
180 /* Functional checks */
182 size = sizeof(buffer);
184 ret = pGetColorDirectoryA( NULL, buffer, &size );
185 ok( ret && size > 0, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
188 static void test_GetColorDirectoryW(void)
190 BOOL ret;
191 DWORD size;
192 WCHAR buffer[MAX_PATH];
194 /* Parameter checks */
196 /* This one crashes win2k
198 ret = pGetColorDirectoryW( NULL, NULL, NULL );
199 ok( !ret, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
203 size = 0;
205 ret = pGetColorDirectoryW( NULL, NULL, &size );
206 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
208 size = 0;
210 ret = pGetColorDirectoryW( NULL, buffer, &size );
211 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
213 size = 1;
215 ret = pGetColorDirectoryW( NULL, buffer, &size );
216 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%d)\n", GetLastError() );
218 /* Functional checks */
220 size = sizeof(buffer);
222 ret = pGetColorDirectoryW( NULL, buffer, &size );
223 ok( ret && size > 0, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
226 static void test_GetColorProfileElement( char *standardprofile )
228 if (standardprofile)
230 PROFILE profile;
231 HPROFILE handle;
232 BOOL ret, ref;
233 DWORD size;
234 TAGTYPE tag = 0x63707274; /* 'cprt' */
235 static char buffer[51];
236 static const char expect[] =
237 { 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70,
238 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20,
239 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65, 0x74,
240 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x72, 0x64, 0x20, 0x43,
241 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x00 };
243 profile.dwType = PROFILE_FILENAME;
244 profile.pProfileData = standardprofile;
245 profile.cbDataSize = strlen(standardprofile);
247 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
248 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
250 /* Parameter checks */
252 ret = pGetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
253 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
255 ret = pGetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
256 ok( !ret, "GetColorProfileElement() succeeded (%d)\n", GetLastError() );
258 size = 0;
259 ret = pGetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
260 ok( !ret, "GetColorProfileElement() succeeded\n" );
261 ok( size > 0, "wrong size\n" );
263 /* Functional checks */
265 size = sizeof(buffer);
266 ret = pGetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
267 ok( ret, "GetColorProfileElement() failed %u\n", GetLastError() );
268 ok( size > 0, "wrong size\n" );
269 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
271 pCloseColorProfile( handle );
275 static void test_GetColorProfileElementTag( char *standardprofile )
277 if (standardprofile)
279 PROFILE profile;
280 HPROFILE handle;
281 BOOL ret;
282 DWORD index = 1;
283 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
285 profile.dwType = PROFILE_FILENAME;
286 profile.pProfileData = standardprofile;
287 profile.cbDataSize = strlen(standardprofile);
289 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
290 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
292 /* Parameter checks */
294 ret = pGetColorProfileElementTag( NULL, index, &tag );
295 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
297 ret = pGetColorProfileElementTag( handle, 0, &tag );
298 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
300 ret = pGetColorProfileElementTag( handle, index, NULL );
301 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
303 ret = pGetColorProfileElementTag( handle, 18, NULL );
304 ok( !ret, "GetColorProfileElementTag() succeeded (%d)\n", GetLastError() );
306 /* Functional checks */
308 ret = pGetColorProfileElementTag( handle, index, &tag );
309 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%d)\n",
310 GetLastError() );
312 pCloseColorProfile( handle );
316 static void test_GetColorProfileFromHandle( char *testprofile )
318 if (testprofile)
320 PROFILE profile;
321 HPROFILE handle;
322 DWORD size;
323 BOOL ret;
324 static const unsigned char expect[] =
325 { 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f, 0x02, 0x10, 0x00,
326 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59,
327 0x5a, 0x20, 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06, 0x00,
328 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54,
329 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47,
330 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00,
332 0x00, 0xd3, 0x2d, 0x48, 0x50, 0x20, 0x20 };
334 unsigned char *buffer;
336 profile.dwType = PROFILE_FILENAME;
337 profile.pProfileData = testprofile;
338 profile.cbDataSize = strlen(testprofile);
340 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
341 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
343 /* Parameter checks */
345 size = 0;
347 ret = pGetColorProfileFromHandle( handle, NULL, &size );
348 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
350 buffer = HeapAlloc( GetProcessHeap(), 0, size );
352 if (buffer)
354 ret = pGetColorProfileFromHandle( NULL, buffer, &size );
355 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
357 ret = pGetColorProfileFromHandle( handle, buffer, NULL );
358 ok( !ret, "GetColorProfileFromHandle() succeeded (%d)\n", GetLastError() );
360 /* Functional checks */
362 ret = pGetColorProfileFromHandle( handle, buffer, &size );
363 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%d)\n", GetLastError() );
365 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
367 HeapFree( GetProcessHeap(), 0, buffer );
370 pCloseColorProfile( handle );
374 static void test_GetColorProfileHeader( char *testprofile )
376 if (testprofile)
378 PROFILE profile;
379 HPROFILE handle;
380 BOOL ret;
381 PROFILEHEADER header;
383 profile.dwType = PROFILE_FILENAME;
384 profile.pProfileData = testprofile;
385 profile.cbDataSize = strlen(testprofile);
387 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
388 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
390 /* Parameter checks */
392 ret = pGetColorProfileHeader( NULL, NULL );
393 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
395 ret = pGetColorProfileHeader( NULL, &header );
396 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
398 if (0) /* Crashes on Vista */
400 ret = pGetColorProfileHeader( handle, NULL );
401 ok( !ret, "GetColorProfileHeader() succeeded (%d)\n", GetLastError() );
404 /* Functional checks */
406 ret = pGetColorProfileHeader( handle, &header );
407 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
409 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
411 pCloseColorProfile( handle );
415 static void test_GetCountColorProfileElements( char *standardprofile )
417 if (standardprofile)
419 PROFILE profile;
420 HPROFILE handle;
421 BOOL ret;
422 DWORD count, expect = 17;
424 profile.dwType = PROFILE_FILENAME;
425 profile.pProfileData = standardprofile;
426 profile.cbDataSize = strlen(standardprofile);
428 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
429 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
431 /* Parameter checks */
433 ret = pGetCountColorProfileElements( NULL, &count );
434 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
435 GetLastError() );
437 ret = pGetCountColorProfileElements( handle, NULL );
438 ok( !ret, "GetCountColorProfileElements() succeeded (%d)\n",
439 GetLastError() );
441 /* Functional checks */
443 ret = pGetCountColorProfileElements( handle, &count );
444 ok( ret && count == expect,
445 "GetCountColorProfileElements() failed (%d)\n", GetLastError() );
447 pCloseColorProfile( handle );
451 static void test_GetStandardColorSpaceProfileA( char *standardprofile )
453 BOOL ret;
454 DWORD size;
455 CHAR oldprofile[MAX_PATH];
456 CHAR newprofile[MAX_PATH];
458 /* Parameter checks */
460 /* Single invalid parameter checks: */
462 size = sizeof(newprofile);
463 SetLastError(0xfaceabee); /* 1st param, */
464 ret = pGetStandardColorSpaceProfileA(machine, LCS_sRGB, newprofile, &size);
465 ok( !ret && GetLastError() == ERROR_NOT_SUPPORTED, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
467 size = sizeof(newprofile);
468 SetLastError(0xfaceabee); /* 2nd param, */
469 ret = pGetStandardColorSpaceProfileA(NULL, (DWORD)-1, newprofile, &size);
470 ok( !ret && GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
472 size = sizeof(newprofile);
473 SetLastError(0xfaceabee); /* 4th param, */
474 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, newprofile, NULL);
475 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
477 size = sizeof(newprofile);
478 SetLastError(0xfaceabee); /* 3rd param, */
479 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, NULL, &size);
480 ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
482 size = 0;
483 SetLastError(0xfaceabee); /* dereferenced 4th param, */
484 ret = pGetStandardColorSpaceProfileA(NULL, LCS_sRGB, newprofile, &size);
485 ok( !ret && (GetLastError() == ERROR_MORE_DATA || GetLastError() == ERROR_INSUFFICIENT_BUFFER),
486 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
488 /* Several invalid parameter checks: */
490 size = 0;
491 SetLastError(0xfaceabee); /* 1st, maybe 2nd and then dereferenced 4th param, */
492 ret = pGetStandardColorSpaceProfileA(machine, 0, newprofile, &size);
493 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_NOT_SUPPORTED),
494 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
496 SetLastError(0xfaceabee); /* maybe 2nd and then 4th param, */
497 ret = pGetStandardColorSpaceProfileA(NULL, 0, newprofile, NULL);
498 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
500 size = 0;
501 SetLastError(0xfaceabee); /* maybe 2nd, then 3rd and dereferenced 4th param, */
502 ret = pGetStandardColorSpaceProfileA(NULL, 0, NULL, &size);
503 ok( !ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER || GetLastError() == ERROR_FILE_NOT_FOUND),
504 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
506 size = sizeof(newprofile);
507 SetLastError(0xfaceabee); /* maybe 2nd param. */
508 ret = pGetStandardColorSpaceProfileA(NULL, 0, newprofile, &size);
509 if (!ret) ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
510 else ok( !lstrcmpiA( newprofile, "" ) && GetLastError() == 0xfaceabee,
511 "GetStandardColorSpaceProfileA() returns %d (GLE=%d)\n", ret, GetLastError() );
513 /* Functional checks */
515 size = sizeof(oldprofile);
516 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile, &size );
517 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
519 SetLastError(0xdeadbeef);
520 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, standardprofile );
521 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
523 skip("Not enough rights for SetStandardColorSpaceProfileA\n");
524 return;
526 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
528 size = sizeof(newprofile);
529 ret = pGetStandardColorSpaceProfileA( NULL, LCS_sRGB, newprofile, &size );
530 ok( ret, "GetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
532 ret = pSetStandardColorSpaceProfileA( NULL, LCS_sRGB, oldprofile );
533 ok( ret, "SetStandardColorSpaceProfileA() failed (%d)\n", GetLastError() );
536 static void test_GetStandardColorSpaceProfileW( WCHAR *standardprofileW )
538 BOOL ret;
539 DWORD size;
540 WCHAR oldprofile[MAX_PATH];
541 WCHAR newprofile[MAX_PATH];
542 CHAR newprofileA[MAX_PATH];
544 /* Parameter checks */
546 /* Single invalid parameter checks: */
548 size = sizeof(newprofile);
549 SetLastError(0xfaceabee); /* 1st param, */
550 ret = pGetStandardColorSpaceProfileW(machineW, LCS_sRGB, newprofile, &size);
551 ok( !ret && GetLastError() == ERROR_NOT_SUPPORTED, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
553 size = sizeof(newprofile);
554 SetLastError(0xfaceabee); /* 2nd param, */
555 ret = pGetStandardColorSpaceProfileW(NULL, (DWORD)-1, newprofile, &size);
556 ok( !ret && GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
558 size = sizeof(newprofile);
559 SetLastError(0xfaceabee); /* 2nd param, */
560 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, &size);
561 ok( (!ret && GetLastError() == ERROR_FILE_NOT_FOUND) ||
562 broken(ret), /* Win98 and WinME */
563 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
565 size = sizeof(newprofile);
566 SetLastError(0xfaceabee); /* 3rd param, */
567 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, NULL, &size);
568 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
569 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
570 broken(GetLastError() == 0xfaceabee) /* win98 */,
571 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
573 size = sizeof(newprofile);
574 SetLastError(0xfaceabee); /* 4th param, */
575 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, newprofile, NULL);
576 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
578 size = 0;
579 SetLastError(0xfaceabee); /* dereferenced 4th param. */
580 ret = pGetStandardColorSpaceProfileW(NULL, LCS_sRGB, newprofile, &size);
581 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
582 ok( GetLastError() == ERROR_MORE_DATA ||
583 GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
584 broken(GetLastError() == 0xfaceabee) /* win98 */,
585 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
587 /* Several invalid parameter checks: */
589 size = 0;
590 SetLastError(0xfaceabee); /* 1st, maybe 2nd and then dereferenced 4th param, */
591 ret = pGetStandardColorSpaceProfileW(machineW, 0, newprofile, &size);
592 ok( !ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_NOT_SUPPORTED),
593 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
595 SetLastError(0xfaceabee); /* maybe 2nd and then 4th param, */
596 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, NULL);
597 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
599 size = 0;
600 SetLastError(0xfaceabee); /* maybe 2nd, then 3rd and dereferenced 4th param, */
601 ret = pGetStandardColorSpaceProfileW(NULL, 0, NULL, &size);
602 ok( !ret || broken(ret) /* win98 */, "GetStandardColorSpaceProfileW succeeded\n" );
603 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
604 GetLastError() == ERROR_FILE_NOT_FOUND ||
605 broken(GetLastError() == 0xfaceabee) /* win98 */,
606 "GetStandardColorSpaceProfileW() returns GLE=%u\n", GetLastError() );
608 size = sizeof(newprofile);
609 SetLastError(0xfaceabee); /* maybe 2nd param. */
610 ret = pGetStandardColorSpaceProfileW(NULL, 0, newprofile, &size);
611 if (!ret) ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
612 else
614 WideCharToMultiByte(CP_ACP, 0, newprofile, -1, newprofileA, sizeof(newprofileA), NULL, NULL);
615 ok( !lstrcmpiA( newprofileA, "" ) && GetLastError() == 0xfaceabee,
616 "GetStandardColorSpaceProfileW() returns %d (GLE=%d)\n", ret, GetLastError() );
619 /* Functional checks */
621 size = sizeof(oldprofile);
622 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile, &size );
623 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
625 SetLastError(0xdeadbeef);
626 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, standardprofileW );
627 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
629 skip("Not enough rights for SetStandardColorSpaceProfileW\n");
630 return;
632 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
634 size = sizeof(newprofile);
635 ret = pGetStandardColorSpaceProfileW( NULL, LCS_sRGB, newprofile, &size );
636 ok( ret, "GetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
638 ret = pSetStandardColorSpaceProfileW( NULL, LCS_sRGB, oldprofile );
639 ok( ret, "SetStandardColorSpaceProfileW() failed (%d)\n", GetLastError() );
642 static void test_EnumColorProfilesA( char *standardprofile )
644 BOOL ret;
645 DWORD total, size, number;
646 ENUMTYPEA record;
647 BYTE *buffer;
649 /* Parameter checks */
651 memset( &record, 0, sizeof(ENUMTYPEA) );
653 record.dwSize = sizeof(ENUMTYPEA);
654 record.dwVersion = ENUM_TYPE_VERSION;
655 record.dwFields |= ET_DATACOLORSPACE;
656 record.dwDataColorSpace = SPACE_RGB;
658 total = 0;
659 ret = pEnumColorProfilesA( NULL, &record, NULL, &total, &number );
660 ok( !ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
661 buffer = HeapAlloc( GetProcessHeap(), 0, total );
663 size = total;
664 ret = pEnumColorProfilesA( machine, &record, buffer, &size, &number );
665 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
667 ret = pEnumColorProfilesA( NULL, NULL, buffer, &size, &number );
668 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
670 ret = pEnumColorProfilesA( NULL, &record, buffer, NULL, &number );
671 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
673 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
674 if (have_color_profile)
675 ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
676 else
677 todo_wine ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
679 size = 0;
681 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
682 ok( !ret, "EnumColorProfilesA() succeeded (%d)\n", GetLastError() );
684 /* Functional checks */
686 size = total;
687 ret = pEnumColorProfilesA( NULL, &record, buffer, &size, &number );
688 if (have_color_profile)
689 ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
690 else
691 todo_wine ok( ret, "EnumColorProfilesA() failed (%d)\n", GetLastError() );
693 HeapFree( GetProcessHeap(), 0, buffer );
696 static void test_EnumColorProfilesW( WCHAR *standardprofileW )
698 BOOL ret;
699 DWORD total, size, number;
700 ENUMTYPEW record;
701 BYTE *buffer;
703 /* Parameter checks */
705 memset( &record, 0, sizeof(ENUMTYPEW) );
707 record.dwSize = sizeof(ENUMTYPEW);
708 record.dwVersion = ENUM_TYPE_VERSION;
709 record.dwFields |= ET_DATACOLORSPACE;
710 record.dwDataColorSpace = SPACE_RGB;
712 total = 0;
713 ret = pEnumColorProfilesW( NULL, &record, NULL, &total, &number );
714 ok( !ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
715 buffer = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
717 size = total;
718 ret = pEnumColorProfilesW( machineW, &record, buffer, &size, &number );
719 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
721 ret = pEnumColorProfilesW( NULL, NULL, buffer, &size, &number );
722 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
724 ret = pEnumColorProfilesW( NULL, &record, buffer, NULL, &number );
725 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
727 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
728 if (have_color_profile)
729 ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
730 else
731 todo_wine ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
733 size = 0;
734 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
735 ok( !ret, "EnumColorProfilesW() succeeded (%d)\n", GetLastError() );
737 /* Functional checks */
739 size = total;
740 ret = pEnumColorProfilesW( NULL, &record, buffer, &size, &number );
741 if (have_color_profile)
742 ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
743 else
744 todo_wine ok( ret, "EnumColorProfilesW() failed (%d)\n", GetLastError() );
746 HeapFree( GetProcessHeap(), 0, buffer );
749 static void test_InstallColorProfileA( char *standardprofile, char *testprofile )
751 BOOL ret;
753 /* Parameter checks */
755 ret = pInstallColorProfileA( NULL, NULL );
756 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
758 ret = pInstallColorProfileA( machine, NULL );
759 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
761 ret = pInstallColorProfileA( NULL, machine );
762 ok( !ret, "InstallColorProfileA() succeeded (%d)\n", GetLastError() );
764 if (standardprofile)
766 ret = pInstallColorProfileA( NULL, standardprofile );
767 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
770 /* Functional checks */
772 if (testprofile)
774 CHAR dest[MAX_PATH], base[MAX_PATH];
775 DWORD size = sizeof(dest);
776 CHAR slash[] = "\\";
777 HANDLE handle;
779 SetLastError(0xdeadbeef);
780 ret = pInstallColorProfileA( NULL, testprofile );
781 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
783 skip("Not enough rights for InstallColorProfileA\n");
784 return;
786 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
788 ret = pGetColorDirectoryA( NULL, dest, &size );
789 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
791 MSCMS_basenameA( testprofile, base );
793 lstrcatA( dest, slash );
794 lstrcatA( dest, base );
796 /* Check if the profile is really there */
797 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
798 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%d)\n", GetLastError() );
799 CloseHandle( handle );
801 ret = pUninstallColorProfileA( NULL, dest, TRUE );
802 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
806 static void test_InstallColorProfileW( WCHAR *standardprofileW, WCHAR *testprofileW )
808 BOOL ret;
810 /* Parameter checks */
812 ret = pInstallColorProfileW( NULL, NULL );
813 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
815 ret = pInstallColorProfileW( machineW, NULL );
816 ok( !ret, "InstallColorProfileW() succeeded (%d)\n", GetLastError() );
818 ret = pInstallColorProfileW( NULL, machineW );
819 ok( !ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
821 if (standardprofileW)
823 ret = pInstallColorProfileW( NULL, standardprofileW );
824 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
827 /* Functional checks */
829 if (testprofileW)
831 WCHAR dest[MAX_PATH], base[MAX_PATH];
832 DWORD size = sizeof(dest);
833 WCHAR slash[] = { '\\', 0 };
834 HANDLE handle;
836 SetLastError(0xdeadbeef);
837 ret = pInstallColorProfileW( NULL, testprofileW );
838 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
840 skip("Not enough rights for InstallColorProfileW\n");
841 return;
843 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
845 ret = pGetColorDirectoryW( NULL, dest, &size );
846 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
848 MSCMS_basenameW( testprofileW, base );
850 lstrcatW( dest, slash );
851 lstrcatW( dest, base );
853 /* Check if the profile is really there */
854 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
855 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%d)\n", GetLastError() );
856 CloseHandle( handle );
858 ret = pUninstallColorProfileW( NULL, dest, TRUE );
859 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
863 static void test_IsColorProfileTagPresent( char *standardprofile )
865 if (standardprofile)
867 PROFILE profile;
868 HPROFILE handle;
869 BOOL ret, present;
870 TAGTYPE tag;
872 profile.dwType = PROFILE_FILENAME;
873 profile.pProfileData = standardprofile;
874 profile.cbDataSize = strlen(standardprofile);
876 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
877 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
879 /* Parameter checks */
881 tag = 0;
883 ret = pIsColorProfileTagPresent( handle, tag, &present );
884 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
886 tag = 0x63707274; /* 'cprt' */
888 ret = pIsColorProfileTagPresent( NULL, tag, &present );
889 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
891 ret = pIsColorProfileTagPresent( handle, tag, NULL );
892 ok( !ret, "IsColorProfileTagPresent() succeeded (%d)\n", GetLastError() );
894 /* Functional checks */
896 ret = pIsColorProfileTagPresent( handle, tag, &present );
897 ok( ret && present, "IsColorProfileTagPresent() failed (%d)\n", GetLastError() );
899 pCloseColorProfile( handle );
903 static void test_OpenColorProfileA( char *standardprofile )
905 PROFILE profile;
906 HPROFILE handle;
907 BOOL ret;
909 profile.dwType = PROFILE_FILENAME;
910 profile.pProfileData = NULL;
911 profile.cbDataSize = 0;
913 /* Parameter checks */
915 handle = pOpenColorProfileA( NULL, 0, 0, 0 );
916 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
918 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
919 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
921 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
922 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
924 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
925 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
927 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
929 if (standardprofile)
931 profile.pProfileData = standardprofile;
932 profile.cbDataSize = strlen(standardprofile);
934 handle = pOpenColorProfileA( &profile, 0, 0, 0 );
935 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
937 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
938 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
940 handle = pOpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
941 ok( handle == NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
943 /* Functional checks */
945 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
946 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
948 ret = pCloseColorProfile( handle );
949 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
951 profile.dwType = PROFILE_FILENAME;
952 profile.pProfileData = (void *)"sRGB Color Space Profile.icm";
953 profile.cbDataSize = sizeof("sRGB Color Space Profile.icm");
955 handle = pOpenColorProfileA( &profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
956 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
958 ret = pCloseColorProfile( handle );
959 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
963 static void test_OpenColorProfileW( WCHAR *standardprofileW )
965 PROFILE profile;
966 HPROFILE handle;
967 BOOL ret;
969 profile.dwType = PROFILE_FILENAME;
970 profile.pProfileData = NULL;
971 profile.cbDataSize = 0;
973 /* Parameter checks */
975 handle = pOpenColorProfileW( NULL, 0, 0, 0 );
976 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
978 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
979 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
981 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
982 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
984 handle = pOpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
985 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
987 ok ( !pCloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
989 if (standardprofileW)
991 profile.pProfileData = standardprofileW;
992 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
994 handle = pOpenColorProfileW( &profile, 0, 0, 0 );
995 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
997 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
998 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1000 handle = pOpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
1001 ok( handle == NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1003 /* Functional checks */
1005 handle = pOpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1006 ok( handle != NULL, "OpenColorProfileW() failed (%d)\n", GetLastError() );
1008 ret = pCloseColorProfile( handle );
1009 ok( ret, "CloseColorProfile() failed (%d)\n", GetLastError() );
1013 static void test_SetColorProfileElement( char *testprofile )
1015 if (testprofile)
1017 PROFILE profile;
1018 HPROFILE handle;
1019 DWORD size;
1020 BOOL ret, ref;
1022 TAGTYPE tag = 0x63707274; /* 'cprt' */
1023 static char data[] = "(c) The Wine Project";
1024 static char buffer[51];
1026 profile.dwType = PROFILE_FILENAME;
1027 profile.pProfileData = testprofile;
1028 profile.cbDataSize = strlen(testprofile);
1030 /* Parameter checks */
1032 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1033 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1035 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1036 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1038 pCloseColorProfile( handle );
1040 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1041 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1043 ret = pSetColorProfileElement( NULL, 0, 0, NULL, NULL );
1044 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1046 ret = pSetColorProfileElement( handle, 0, 0, NULL, NULL );
1047 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1049 ret = pSetColorProfileElement( handle, tag, 0, NULL, NULL );
1050 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1052 ret = pSetColorProfileElement( handle, tag, 0, &size, NULL );
1053 ok( !ret, "SetColorProfileElement() succeeded (%d)\n", GetLastError() );
1055 /* Functional checks */
1057 size = sizeof(data);
1058 ret = pSetColorProfileElement( handle, tag, 0, &size, data );
1059 ok( ret, "SetColorProfileElement() failed %u\n", GetLastError() );
1061 size = sizeof(buffer);
1062 ret = pGetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
1063 ok( ret, "GetColorProfileElement() failed %u\n", GetLastError() );
1064 ok( size > 0, "wrong size\n" );
1066 ok( !memcmp( data, buffer, sizeof(data) ),
1067 "Unexpected tag data, expected %s, got %s (%u)\n", data, buffer, GetLastError() );
1069 pCloseColorProfile( handle );
1073 static void test_SetColorProfileHeader( char *testprofile )
1075 if (testprofile)
1077 PROFILE profile;
1078 HPROFILE handle;
1079 BOOL ret;
1080 PROFILEHEADER header;
1082 profile.dwType = PROFILE_FILENAME;
1083 profile.pProfileData = testprofile;
1084 profile.cbDataSize = strlen(testprofile);
1086 header.phSize = 0x00000c48;
1087 header.phCMMType = 0x4c696e6f;
1088 header.phVersion = 0x02100000;
1089 header.phClass = 0x6d6e7472;
1090 header.phDataColorSpace = 0x52474220;
1091 header.phConnectionSpace = 0x58595a20;
1092 header.phDateTime[0] = 0x07ce0002;
1093 header.phDateTime[1] = 0x00090006;
1094 header.phDateTime[2] = 0x00310000;
1095 header.phSignature = 0x61637370;
1096 header.phPlatform = 0x4d534654;
1097 header.phProfileFlags = 0x00000000;
1098 header.phManufacturer = 0x49454320;
1099 header.phModel = 0x73524742;
1100 header.phAttributes[0] = 0x00000000;
1101 header.phAttributes[1] = 0x00000000;
1102 header.phRenderingIntent = 0x00000000;
1103 header.phIlluminant.ciexyzX = 0x0000f6d6;
1104 header.phIlluminant.ciexyzY = 0x00010000;
1105 header.phIlluminant.ciexyzZ = 0x0000d32d;
1106 header.phCreator = 0x48502020;
1108 /* Parameter checks */
1110 handle = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
1111 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1113 ret = pSetColorProfileHeader( handle, &header );
1114 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1116 pCloseColorProfile( handle );
1118 handle = pOpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
1119 ok( handle != NULL, "OpenColorProfileA() failed (%d)\n", GetLastError() );
1121 ret = pSetColorProfileHeader( NULL, NULL );
1122 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1124 ret = pSetColorProfileHeader( handle, NULL );
1125 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1127 ret = pSetColorProfileHeader( NULL, &header );
1128 ok( !ret, "SetColorProfileHeader() succeeded (%d)\n", GetLastError() );
1130 /* Functional checks */
1132 ret = pSetColorProfileHeader( handle, &header );
1133 ok( ret, "SetColorProfileHeader() failed (%d)\n", GetLastError() );
1135 ret = pGetColorProfileHeader( handle, &header );
1136 ok( ret, "GetColorProfileHeader() failed (%d)\n", GetLastError() );
1138 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
1140 pCloseColorProfile( handle );
1144 static void test_UninstallColorProfileA( char *testprofile )
1146 BOOL ret;
1148 /* Parameter checks */
1150 ret = pUninstallColorProfileA( NULL, NULL, FALSE );
1151 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1153 ret = pUninstallColorProfileA( machine, NULL, FALSE );
1154 ok( !ret, "UninstallColorProfileA() succeeded (%d)\n", GetLastError() );
1156 /* Functional checks */
1158 if (testprofile)
1160 CHAR dest[MAX_PATH], base[MAX_PATH];
1161 DWORD size = sizeof(dest);
1162 CHAR slash[] = "\\";
1163 HANDLE handle;
1165 SetLastError(0xdeadbeef);
1166 ret = pInstallColorProfileA( NULL, testprofile );
1167 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1169 skip("Not enough rights for InstallColorProfileA\n");
1170 return;
1172 ok( ret, "InstallColorProfileA() failed (%d)\n", GetLastError() );
1174 ret = pGetColorDirectoryA( NULL, dest, &size );
1175 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1177 MSCMS_basenameA( testprofile, base );
1179 lstrcatA( dest, slash );
1180 lstrcatA( dest, base );
1182 ret = pUninstallColorProfileA( NULL, dest, TRUE );
1183 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
1185 /* Check if the profile is really gone */
1186 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1187 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%d)\n", GetLastError() );
1188 CloseHandle( handle );
1192 static void test_UninstallColorProfileW( WCHAR *testprofileW )
1194 BOOL ret;
1196 /* Parameter checks */
1198 ret = pUninstallColorProfileW( NULL, NULL, FALSE );
1199 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1201 ret = pUninstallColorProfileW( machineW, NULL, FALSE );
1202 ok( !ret, "UninstallColorProfileW() succeeded (%d)\n", GetLastError() );
1204 /* Functional checks */
1206 if (testprofileW)
1208 WCHAR dest[MAX_PATH], base[MAX_PATH];
1209 char destA[MAX_PATH];
1210 DWORD size = sizeof(dest);
1211 WCHAR slash[] = { '\\', 0 };
1212 HANDLE handle;
1213 int bytes_copied;
1215 SetLastError(0xdeadbeef);
1216 ret = pInstallColorProfileW( NULL, testprofileW );
1217 if (!ret && (GetLastError() == ERROR_ACCESS_DENIED))
1219 skip("Not enough rights for InstallColorProfileW\n");
1220 return;
1222 ok( ret, "InstallColorProfileW() failed (%d)\n", GetLastError() );
1224 ret = pGetColorDirectoryW( NULL, dest, &size );
1225 ok( ret, "GetColorDirectoryW() failed (%d)\n", GetLastError() );
1227 MSCMS_basenameW( testprofileW, base );
1229 lstrcatW( dest, slash );
1230 lstrcatW( dest, base );
1232 ret = pUninstallColorProfileW( NULL, dest, TRUE );
1233 ok( ret, "UninstallColorProfileW() failed (%d)\n", GetLastError() );
1235 bytes_copied = WideCharToMultiByte(CP_ACP, 0, dest, -1, destA, MAX_PATH, NULL, NULL);
1236 ok( bytes_copied > 0 , "WideCharToMultiByte() returns %d\n", bytes_copied);
1237 /* Check if the profile is really gone */
1238 handle = CreateFileA( destA, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1239 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%d)\n", GetLastError() );
1240 CloseHandle( handle );
1244 static void test_AssociateColorProfileWithDeviceA( char *testprofile )
1246 BOOL ret;
1247 char profile[MAX_PATH], basename[MAX_PATH];
1248 DWORD error, size = sizeof(profile);
1249 DISPLAY_DEVICEA display, monitor;
1250 BOOL res;
1252 if (testprofile && pEnumDisplayDevicesA)
1254 display.cb = sizeof( DISPLAY_DEVICEA );
1255 res = pEnumDisplayDevicesA( NULL, 0, &display, 0 );
1256 ok( res, "Can't get display info\n" );
1258 monitor.cb = sizeof( DISPLAY_DEVICEA );
1259 res = pEnumDisplayDevicesA( display.DeviceName, 0, &monitor, 0 );
1260 if (res)
1262 SetLastError(0xdeadbeef);
1263 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, NULL );
1264 error = GetLastError();
1265 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1266 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1268 SetLastError(0xdeadbeef);
1269 ret = pAssociateColorProfileWithDeviceA( "machine", NULL, monitor.DeviceID );
1270 error = GetLastError();
1271 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1272 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1274 SetLastError(0xdeadbeef);
1275 ret = pAssociateColorProfileWithDeviceA( "machine", testprofile, monitor.DeviceID );
1276 error = GetLastError();
1277 ok( !ret, "AssociateColorProfileWithDevice() succeeded\n" );
1278 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1280 ret = pInstallColorProfileA( NULL, testprofile );
1281 ok( ret, "InstallColorProfileA() failed (%u)\n", GetLastError() );
1283 ret = pGetColorDirectoryA( NULL, profile, &size );
1284 ok( ret, "GetColorDirectoryA() failed (%d)\n", GetLastError() );
1286 MSCMS_basenameA( testprofile, basename );
1287 lstrcatA( profile, "\\" );
1288 lstrcatA( profile, basename );
1290 ret = pAssociateColorProfileWithDeviceA( NULL, profile, monitor.DeviceID );
1291 ok( ret, "AssociateColorProfileWithDevice() failed (%u)\n", GetLastError() );
1293 SetLastError(0xdeadbeef);
1294 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, NULL );
1295 error = GetLastError();
1296 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1297 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1299 SetLastError(0xdeadbeef);
1300 ret = pDisassociateColorProfileFromDeviceA( "machine", NULL, monitor.DeviceID );
1301 error = GetLastError();
1302 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1303 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error );
1305 SetLastError(0xdeadbeef);
1306 ret = pDisassociateColorProfileFromDeviceA( "machine", profile, monitor.DeviceID );
1307 error = GetLastError();
1308 ok( !ret, "DisassociateColorProfileFromDeviceA() succeeded\n" );
1309 ok( error == ERROR_NOT_SUPPORTED, "expected ERROR_NOT_SUPPORTED, got %u\n", error );
1311 ret = pDisassociateColorProfileFromDeviceA( NULL, profile, monitor.DeviceID );
1312 ok( ret, "DisassociateColorProfileFromDeviceA() failed (%u)\n", GetLastError() );
1314 ret = pUninstallColorProfileA( NULL, profile, TRUE );
1315 ok( ret, "UninstallColorProfileA() failed (%d)\n", GetLastError() );
1317 else
1318 skip("Unable to obtain monitor name\n");
1322 static BOOL have_profile(void)
1324 char glob[MAX_PATH + sizeof("\\*.icm")];
1325 DWORD size = MAX_PATH;
1326 HANDLE handle;
1327 WIN32_FIND_DATAA data;
1329 if (!pGetColorDirectoryA( NULL, glob, &size )) return FALSE;
1330 lstrcatA( glob, "\\*.icm" );
1331 handle = FindFirstFileA( glob, &data );
1332 if (handle == INVALID_HANDLE_VALUE) return FALSE;
1333 FindClose( handle );
1334 return TRUE;
1337 START_TEST(profile)
1339 UINT len;
1340 HANDLE handle;
1341 char path[MAX_PATH], file[MAX_PATH], profilefile1[MAX_PATH], profilefile2[MAX_PATH];
1342 WCHAR profilefile1W[MAX_PATH], profilefile2W[MAX_PATH], fileW[MAX_PATH];
1343 char *standardprofile = NULL, *testprofile = NULL;
1344 WCHAR *standardprofileW = NULL, *testprofileW = NULL;
1345 UINT ret;
1347 hmscms = LoadLibraryA( "mscms.dll" );
1348 if (!hmscms) return;
1350 huser32 = LoadLibraryA( "user32.dll" );
1351 if (!huser32)
1353 FreeLibrary( hmscms );
1354 return;
1357 if (!init_function_ptrs())
1359 FreeLibrary( huser32 );
1360 FreeLibrary( hmscms );
1361 return;
1364 /* See if we can find the standard color profile */
1365 ret = GetSystemDirectoryA( profilefile1, sizeof(profilefile1) );
1366 ok( ret > 0, "GetSystemDirectoryA() returns %d, LastError = %d\n", ret, GetLastError());
1367 ok(profilefile1[0] && lstrlenA(profilefile1) < MAX_PATH,
1368 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenA(profilefile1));
1369 MultiByteToWideChar(CP_ACP, 0, profilefile1, -1, profilefile1W, MAX_PATH);
1370 ok(profilefile1W[0] && lstrlenW(profilefile1W) < MAX_PATH,
1371 "Expected length between 0 and MAX_PATH, got %d\n", lstrlenW(profilefile1W));
1372 lstrcpyA(profilefile2, profilefile1);
1373 lstrcpyW(profilefile2W, profilefile1W);
1375 lstrcatA( profilefile1, profile1 );
1376 lstrcatW( profilefile1W, profile1W );
1377 handle = CreateFileA( profilefile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1379 if (handle != INVALID_HANDLE_VALUE)
1381 standardprofile = profilefile1;
1382 standardprofileW = profilefile1W;
1383 CloseHandle( handle );
1386 lstrcatA( profilefile2, profile2 );
1387 lstrcatW( profilefile2W, profile2W );
1388 handle = CreateFileA( profilefile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
1390 if (handle != INVALID_HANDLE_VALUE)
1392 standardprofile = profilefile2;
1393 standardprofileW = profilefile2W;
1394 CloseHandle( handle );
1397 /* If found, create a temporary copy for testing purposes */
1398 if (standardprofile && GetTempPathA( sizeof(path), path ))
1400 if (GetTempFileNameA( path, "rgb", 0, file ))
1402 if (CopyFileA( standardprofile, file, FALSE ))
1404 testprofile = (LPSTR)&file;
1405 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
1406 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
1407 testprofileW = (LPWSTR)&fileW;
1412 have_color_profile = have_profile();
1414 test_GetColorDirectoryA();
1415 test_GetColorDirectoryW();
1417 test_GetColorProfileElement( standardprofile );
1418 test_GetColorProfileElementTag( standardprofile );
1420 test_GetColorProfileFromHandle( testprofile );
1421 test_GetColorProfileHeader( testprofile );
1423 test_GetCountColorProfileElements( standardprofile );
1425 test_GetStandardColorSpaceProfileA( standardprofile );
1426 test_GetStandardColorSpaceProfileW( standardprofileW );
1428 test_EnumColorProfilesA( standardprofile );
1429 test_EnumColorProfilesW( standardprofileW );
1431 test_InstallColorProfileA( standardprofile, testprofile );
1432 test_InstallColorProfileW( standardprofileW, testprofileW );
1434 test_IsColorProfileTagPresent( standardprofile );
1436 test_OpenColorProfileA( standardprofile );
1437 test_OpenColorProfileW( standardprofileW );
1439 test_SetColorProfileElement( testprofile );
1440 test_SetColorProfileHeader( testprofile );
1442 test_UninstallColorProfileA( testprofile );
1443 test_UninstallColorProfileW( testprofileW );
1445 test_AssociateColorProfileWithDeviceA( testprofile );
1447 if (testprofile) DeleteFileA( testprofile );
1448 FreeLibrary( huser32 );
1449 FreeLibrary( hmscms );