2 * Tests for color profile functions
4 * Copyright 2004, 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/test.h"
32 static const char machine[] = "dummy";
33 static const WCHAR machineW[] = { 'd','u','m','m','y',0 };
35 /* To do any real functionality testing with this suite you need a copy of
36 * the freely distributable standard RGB color space profile. It comes
37 * standard with Windows, but on Wine you probably need to install it yourself
38 * in one of the locations mentioned below. Here's a link to the profile in
39 * a self extracting zip file:
41 * http://download.microsoft.com/download/whistler/hwdev1/1.0/wxp/en-us/ColorProfile.exe
44 /* Two common places to find the standard color space profile */
45 static const char profilefile[] =
46 "\\color\\srgb color space profile.icm";
47 static const char profilesubdir[] =
48 "\\system32\\spool\\drivers";
50 static const WCHAR profilefileW[] =
51 { '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
52 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
53 static const WCHAR profilesubdirW[] =
54 { '\\', 's','y','s','t','e','m','3','2','\\','s','p','o','o','l',
55 '\\','d','r','i','v','e','r','s',0 };
57 static const unsigned char rgbheader[] =
58 { 0x48, 0x0c, 0x00, 0x00, 0x6f, 0x6e, 0x69, 0x4c, 0x00, 0x00, 0x10, 0x02,
59 0x72, 0x74, 0x6e, 0x6d, 0x20, 0x42, 0x47, 0x52, 0x20, 0x5a, 0x59, 0x58,
60 0x02, 0x00, 0xce, 0x07, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x31, 0x00,
61 0x70, 0x73, 0x63, 0x61, 0x54, 0x46, 0x53, 0x4d, 0x00, 0x00, 0x00, 0x00,
62 0x20, 0x43, 0x45, 0x49, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xf6, 0x00, 0x00,
64 0x00, 0x00, 0x01, 0x00, 0x2d, 0xd3, 0x00, 0x00, 0x20, 0x20, 0x50, 0x48 };
66 static LPSTR standardprofile;
67 static LPWSTR standardprofileW;
69 static LPSTR testprofile;
70 static LPWSTR testprofileW;
72 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
74 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
76 INT i = strlen( path );
78 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
79 strcpy( name, &path[i] );
82 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
84 INT i = lstrlenW( path );
86 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
87 lstrcpyW( name, &path[i] );
90 static void test_GetColorDirectoryA()
94 char buffer[MAX_PATH];
96 /* Parameter checks */
98 ret = GetColorDirectoryA( NULL, NULL, NULL );
99 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
103 ret = GetColorDirectoryA( NULL, NULL, &size );
104 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
108 ret = GetColorDirectoryA( NULL, buffer, &size );
109 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
113 ret = GetColorDirectoryA( NULL, buffer, &size );
114 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
116 /* Functional checks */
118 size = sizeof(buffer);
120 ret = GetColorDirectoryA( NULL, buffer, &size );
121 ok( ret && size > 0, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
124 static void test_GetColorDirectoryW()
128 WCHAR buffer[MAX_PATH];
130 /* Parameter checks */
132 /* This one crashes win2k
134 ret = GetColorDirectoryW( NULL, NULL, NULL );
135 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
141 ret = GetColorDirectoryW( NULL, NULL, &size );
142 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
146 ret = GetColorDirectoryW( NULL, buffer, &size );
147 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
151 ret = GetColorDirectoryW( NULL, buffer, &size );
152 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
154 /* Functional checks */
156 size = sizeof(buffer);
158 ret = GetColorDirectoryW( NULL, buffer, &size );
159 ok( ret && size > 0, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
162 static void test_GetColorProfileElement()
170 TAGTYPE tag = 0x63707274; /* 'cprt' */
171 static char buffer[51];
172 static const char expect[] =
173 { 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70,
174 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20,
175 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65, 0x74,
176 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x72, 0x64, 0x20, 0x43,
177 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x00 };
179 profile.dwType = PROFILE_FILENAME;
180 profile.pProfileData = standardprofile;
181 profile.cbDataSize = strlen(standardprofile);
183 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
184 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
186 /* Parameter checks */
188 ret = GetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
189 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
191 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
192 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
196 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
197 ok( !ret && size > 0, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
199 size = sizeof(buffer);
201 /* Functional checks */
203 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
204 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
206 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
208 CloseColorProfile( handle );
212 static void test_GetColorProfileElementTag()
220 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
222 profile.dwType = PROFILE_FILENAME;
223 profile.pProfileData = standardprofile;
224 profile.cbDataSize = strlen(standardprofile);
226 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
227 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
229 /* Parameter checks */
231 ret = GetColorProfileElementTag( NULL, index, &tag );
232 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
234 ret = GetColorProfileElementTag( handle, 0, &tag );
235 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
237 ret = GetColorProfileElementTag( handle, index, NULL );
238 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
240 ret = GetColorProfileElementTag( handle, 18, NULL );
241 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
243 /* Functional checks */
245 ret = GetColorProfileElementTag( handle, index, &tag );
246 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%ld)\n",
249 CloseColorProfile( handle );
253 static void test_GetColorProfileFromHandle()
261 static const unsigned char expect[] =
262 { 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f, 0x02, 0x10, 0x00,
263 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59,
264 0x5a, 0x20, 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06, 0x00,
265 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54,
266 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47,
267 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00,
269 0x00, 0xd3, 0x2d, 0x48, 0x50, 0x20, 0x20 };
271 unsigned char *buffer;
273 profile.dwType = PROFILE_FILENAME;
274 profile.pProfileData = testprofile;
275 profile.cbDataSize = strlen(testprofile);
277 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
278 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
280 /* Parameter checks */
284 ret = GetColorProfileFromHandle( handle, NULL, &size );
285 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
287 buffer = HeapAlloc( GetProcessHeap(), 0, size );
291 ret = GetColorProfileFromHandle( NULL, buffer, &size );
292 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
294 ret = GetColorProfileFromHandle( handle, buffer, NULL );
295 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
297 /* Functional checks */
299 ret = GetColorProfileFromHandle( handle, buffer, &size );
300 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
302 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
304 HeapFree( GetProcessHeap(), 0, buffer );
307 CloseColorProfile( handle );
311 static void test_GetColorProfileHeader()
318 PROFILEHEADER header;
320 profile.dwType = PROFILE_FILENAME;
321 profile.pProfileData = testprofile;
322 profile.cbDataSize = strlen(testprofile);
324 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
325 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
327 /* Parameter checks */
329 ret = GetColorProfileHeader( NULL, NULL );
330 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
332 ret = GetColorProfileHeader( NULL, &header );
333 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
335 ret = GetColorProfileHeader( handle, NULL );
336 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
338 /* Functional checks */
340 ret = GetColorProfileHeader( handle, &header );
341 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
343 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
345 CloseColorProfile( handle );
349 static void test_GetCountColorProfileElements()
356 DWORD count, expect = 17;
358 profile.dwType = PROFILE_FILENAME;
359 profile.pProfileData = standardprofile;
360 profile.cbDataSize = strlen(standardprofile);
362 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
363 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
365 /* Parameter checks */
367 ret = GetCountColorProfileElements( NULL, &count );
368 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
371 ret = GetCountColorProfileElements( handle, NULL );
372 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
375 /* Functional checks */
377 ret = GetCountColorProfileElements( handle, &count );
378 ok( ret && count == expect,
379 "GetCountColorProfileElements() failed (%ld)\n", GetLastError() );
381 CloseColorProfile( handle );
385 static void test_GetStandardColorSpaceProfileA()
389 CHAR oldprofile[MAX_PATH];
390 CHAR newprofile[MAX_PATH];
392 /* Parameter checks */
394 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, NULL );
395 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
397 ret = GetStandardColorSpaceProfileA( machine, 0, newprofile, &size );
398 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
402 ret = GetStandardColorSpaceProfileA( NULL, 0, NULL, &size );
403 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
405 size = sizeof(newprofile);
407 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, &size );
408 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
410 /* Functional checks */
414 size = sizeof(oldprofile);
416 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile, &size );
417 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
419 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, standardprofile );
420 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
422 size = sizeof(newprofile);
424 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, newprofile, &size );
425 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
427 ok( !lstrcmpiA( (LPSTR)&newprofile, standardprofile ), "Unexpected profile\n" );
429 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile );
430 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
434 static void test_GetStandardColorSpaceProfileW()
438 WCHAR oldprofile[MAX_PATH];
439 WCHAR newprofile[MAX_PATH];
441 /* Parameter checks */
443 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, NULL );
444 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
446 ret = GetStandardColorSpaceProfileW( machineW, 0, newprofile, &size );
447 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
451 ret = GetStandardColorSpaceProfileW( NULL, 0, NULL, &size );
452 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
454 size = sizeof(newprofile);
456 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, &size );
457 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
459 /* Functional checks */
461 if (standardprofileW)
463 size = sizeof(oldprofile);
465 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile, &size );
466 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
468 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, standardprofileW );
469 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
471 size = sizeof(newprofile);
473 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, newprofile, &size );
474 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
476 ok( !lstrcmpiW( (LPWSTR)&newprofile, standardprofileW ), "Unexpected profile\n" );
478 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile );
479 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
483 static void test_InstallColorProfileA()
487 /* Parameter checks */
489 ret = InstallColorProfileA( NULL, NULL );
490 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
492 ret = InstallColorProfileA( machine, NULL );
493 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
495 ret = InstallColorProfileA( NULL, machine );
496 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
500 ret = InstallColorProfileA( NULL, standardprofile );
501 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
504 /* Functional checks */
508 CHAR dest[MAX_PATH], base[MAX_PATH];
509 DWORD size = sizeof(dest);
513 ret = InstallColorProfileA( NULL, testprofile );
514 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
516 ret = GetColorDirectoryA( NULL, dest, &size );
517 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
519 MSCMS_basenameA( testprofile, base );
521 strcat( dest, slash );
522 strcat( dest, base );
524 /* Check if the profile is really there */
525 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
526 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
527 CloseHandle( handle );
529 ret = UninstallColorProfileA( NULL, dest, TRUE );
530 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
534 static void test_InstallColorProfileW()
538 /* Parameter checks */
540 ret = InstallColorProfileW( NULL, NULL );
541 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
543 ret = InstallColorProfileW( machineW, NULL );
544 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
546 ret = InstallColorProfileW( NULL, machineW );
547 ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
549 if (standardprofileW)
551 ret = InstallColorProfileW( NULL, standardprofileW );
552 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
555 /* Functional checks */
559 WCHAR dest[MAX_PATH], base[MAX_PATH];
560 DWORD size = sizeof(dest);
561 WCHAR slash[] = { '\\', 0 };
564 ret = InstallColorProfileW( NULL, testprofileW );
565 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
567 ret = GetColorDirectoryW( NULL, dest, &size );
568 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
570 MSCMS_basenameW( testprofileW, base );
572 lstrcatW( dest, slash );
573 lstrcatW( dest, base );
575 /* Check if the profile is really there */
576 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
577 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
578 CloseHandle( handle );
580 ret = UninstallColorProfileW( NULL, dest, TRUE );
581 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
585 static void test_IsColorProfileTagPresent()
594 profile.dwType = PROFILE_FILENAME;
595 profile.pProfileData = standardprofile;
596 profile.cbDataSize = strlen(standardprofile);
598 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
599 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
601 /* Parameter checks */
605 ret = IsColorProfileTagPresent( handle, tag, &present );
606 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
608 tag = 0x63707274; /* 'cprt' */
610 ret = IsColorProfileTagPresent( NULL, tag, &present );
611 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
613 ret = IsColorProfileTagPresent( handle, tag, NULL );
614 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
616 /* Functional checks */
618 ret = IsColorProfileTagPresent( handle, tag, &present );
619 ok( ret && present, "IsColorProfileTagPresent() failed (%ld)\n", GetLastError() );
621 CloseColorProfile( handle );
625 static void test_OpenColorProfileA()
631 profile.dwType = PROFILE_FILENAME;
632 profile.pProfileData = NULL;
633 profile.cbDataSize = 0;
635 /* Parameter checks */
637 handle = OpenColorProfileA( NULL, 0, 0, 0 );
638 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
640 handle = OpenColorProfileA( &profile, 0, 0, 0 );
641 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
643 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
644 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
646 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
647 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
649 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
653 profile.pProfileData = standardprofile;
654 profile.cbDataSize = strlen(standardprofile);
656 handle = OpenColorProfileA( &profile, 0, 0, 0 );
657 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
659 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
660 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
662 handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
663 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
665 /* Functional checks */
667 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
668 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
670 ret = CloseColorProfile( handle );
671 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
675 static void test_OpenColorProfileW()
681 profile.dwType = PROFILE_FILENAME;
682 profile.pProfileData = NULL;
683 profile.cbDataSize = 0;
685 /* Parameter checks */
687 handle = OpenColorProfileW( NULL, 0, 0, 0 );
688 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
690 handle = OpenColorProfileW( &profile, 0, 0, 0 );
691 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
693 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
694 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
696 handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
697 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
699 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
701 if (standardprofileW)
703 profile.pProfileData = standardprofileW;
704 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
706 handle = OpenColorProfileW( &profile, 0, 0, 0 );
707 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
709 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
710 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
712 handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
713 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
715 /* Functional checks */
717 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
718 ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
720 ret = CloseColorProfile( handle );
721 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
725 static void test_SetColorProfileElement()
734 TAGTYPE tag = 0x63707274; /* 'cprt' */
735 static char data[] = "(c) The Wine Project";
736 static char buffer[51];
738 profile.dwType = PROFILE_FILENAME;
739 profile.pProfileData = testprofile;
740 profile.cbDataSize = strlen(testprofile);
742 /* Parameter checks */
744 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
745 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
747 ret = SetColorProfileElement( handle, tag, 0, &size, data );
748 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
750 CloseColorProfile( handle );
752 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
753 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
755 ret = SetColorProfileElement( NULL, 0, 0, NULL, NULL );
756 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
758 ret = SetColorProfileElement( handle, 0, 0, NULL, NULL );
759 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
761 ret = SetColorProfileElement( handle, tag, 0, NULL, NULL );
762 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
764 ret = SetColorProfileElement( handle, tag, 0, &size, NULL );
765 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
767 /* Functional checks */
769 ret = SetColorProfileElement( handle, tag, 0, &size, data );
770 ok( ret, "SetColorProfileElement() failed (%ld)\n", GetLastError() );
772 size = sizeof(buffer);
774 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
775 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
777 ok( !memcmp( data, buffer, sizeof(data) ), "Unexpected tag data\n" );
779 CloseColorProfile( handle );
783 static void test_SetColorProfileHeader()
790 PROFILEHEADER header;
792 profile.dwType = PROFILE_FILENAME;
793 profile.pProfileData = testprofile;
794 profile.cbDataSize = strlen(testprofile);
796 header.phSize = 0x00000c48;
797 header.phCMMType = 0x4c696e6f;
798 header.phVersion = 0x02100000;
799 header.phClass = 0x6d6e7472;
800 header.phDataColorSpace = 0x52474220;
801 header.phConnectionSpace = 0x58595a20;
802 header.phDateTime[0] = 0x07ce0002;
803 header.phDateTime[1] = 0x00090006;
804 header.phDateTime[2] = 0x00310000;
805 header.phSignature = 0x61637370;
806 header.phPlatform = 0x4d534654;
807 header.phProfileFlags = 0x00000000;
808 header.phManufacturer = 0x49454320;
809 header.phModel = 0x73524742;
810 header.phAttributes[0] = 0x00000000;
811 header.phAttributes[1] = 0x00000000;
812 header.phRenderingIntent = 0x00000000;
813 header.phIlluminant.ciexyzX = 0x0000f6d6;
814 header.phIlluminant.ciexyzY = 0x00010000;
815 header.phIlluminant.ciexyzZ = 0x0000d32d;
816 header.phCreator = 0x48502020;
818 /* Parameter checks */
820 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
821 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
823 ret = SetColorProfileHeader( handle, &header );
824 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
826 CloseColorProfile( handle );
828 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
829 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
831 ret = SetColorProfileHeader( NULL, NULL );
832 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
834 ret = SetColorProfileHeader( handle, NULL );
835 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
837 ret = SetColorProfileHeader( NULL, &header );
838 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
840 /* Functional checks */
842 ret = SetColorProfileHeader( handle, &header );
843 ok( ret, "SetColorProfileHeader() failed (%ld)\n", GetLastError() );
845 ret = GetColorProfileHeader( handle, &header );
846 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
848 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
850 CloseColorProfile( handle );
854 static void test_UninstallColorProfileA()
858 /* Parameter checks */
860 ret = UninstallColorProfileA( NULL, NULL, FALSE );
861 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
863 ret = UninstallColorProfileA( machine, NULL, FALSE );
864 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
866 /* Functional checks */
870 CHAR dest[MAX_PATH], base[MAX_PATH];
871 DWORD size = sizeof(dest);
875 ret = InstallColorProfileA( NULL, testprofile );
876 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
878 ret = GetColorDirectoryA( NULL, dest, &size );
879 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
881 MSCMS_basenameA( testprofile, base );
883 strcat( dest, slash );
884 strcat( dest, base );
886 ret = UninstallColorProfileA( NULL, dest, TRUE );
887 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
889 /* Check if the profile is really gone */
890 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
891 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
892 CloseHandle( handle );
896 static void test_UninstallColorProfileW()
900 /* Parameter checks */
902 ret = UninstallColorProfileW( NULL, NULL, FALSE );
903 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
905 ret = UninstallColorProfileW( machineW, NULL, FALSE );
906 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
908 /* Functional checks */
912 WCHAR dest[MAX_PATH], base[MAX_PATH];
913 DWORD size = sizeof(dest);
914 WCHAR slash[] = { '\\', 0 };
917 ret = InstallColorProfileW( NULL, testprofileW );
918 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
920 ret = GetColorDirectoryW( NULL, dest, &size );
921 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
923 MSCMS_basenameW( testprofileW, base );
925 lstrcatW( dest, slash );
926 lstrcatW( dest, base );
928 ret = UninstallColorProfileW( NULL, dest, TRUE );
929 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
931 /* Check if the profile is really gone */
932 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
933 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
934 CloseHandle( handle );
942 char path[MAX_PATH], file[MAX_PATH];
943 char profile1[MAX_PATH], profile2[MAX_PATH];
944 WCHAR profile1W[MAX_PATH], profile2W[MAX_PATH];
945 WCHAR fileW[MAX_PATH];
947 /* See if we can find the standard color profile */
948 GetSystemDirectoryA( profile1, sizeof(profile1) );
949 GetSystemDirectoryW( profile1W, sizeof(profile1W) / sizeof(WCHAR) );
950 strcat( profile1, profilefile );
951 lstrcatW( profile1W, profilefileW );
952 handle = CreateFileA( profile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
954 if (handle != INVALID_HANDLE_VALUE)
956 standardprofile = profile1;
957 standardprofileW = profile1W;
958 CloseHandle( handle );
961 GetWindowsDirectoryA( profile2, sizeof(profile2) );
962 GetWindowsDirectoryW( profile2W, sizeof(profile2W) / sizeof(WCHAR) );
963 strcat( profile2, profilesubdir );
964 lstrcatW( profile2W, profilesubdirW );
965 strcat( profile2, profilefile );
966 lstrcatW( profile2W, profilefileW );
967 handle = CreateFileA( profile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
969 if (handle != INVALID_HANDLE_VALUE)
971 standardprofile = profile2;
972 standardprofileW = profile2W;
973 CloseHandle( handle );
976 /* If found, create a temporary copy for testing purposes */
977 if (standardprofile && GetTempPath( sizeof(path), path ))
979 if (GetTempFileName( path, "rgb", 0, file ))
981 if (CopyFileA( standardprofile, file, FALSE ))
983 testprofile = (LPSTR)&file;
985 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
986 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
988 testprofileW = (LPWSTR)&fileW;
993 test_GetColorDirectoryA();
994 test_GetColorDirectoryW();
996 test_GetColorProfileElement();
997 test_GetColorProfileElementTag();
999 test_GetColorProfileFromHandle();
1000 test_GetColorProfileHeader();
1002 test_GetCountColorProfileElements();
1004 test_GetStandardColorSpaceProfileA();
1005 test_GetStandardColorSpaceProfileW();
1007 test_InstallColorProfileA();
1008 test_InstallColorProfileW();
1010 test_IsColorProfileTagPresent();
1012 test_OpenColorProfileA();
1013 test_OpenColorProfileW();
1015 test_SetColorProfileElement();
1016 test_SetColorProfileHeader();
1018 test_UninstallColorProfileA();
1019 test_UninstallColorProfileW();
1023 DeleteFileA( testprofile );