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, relative
45 * to the system directory.
47 static const char profile1[] =
48 "\\color\\srgb color space profile.icm";
49 static const char profile2[] =
50 "\\spool\\drivers\\color\\srgb color space profile.icm";
52 static const WCHAR profile1W[] =
53 { '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
54 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
55 static const WCHAR profile2W[] =
56 { '\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\',
57 'c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
58 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
60 static const unsigned char rgbheader[] =
61 { 0x48, 0x0c, 0x00, 0x00, 0x6f, 0x6e, 0x69, 0x4c, 0x00, 0x00, 0x10, 0x02,
62 0x72, 0x74, 0x6e, 0x6d, 0x20, 0x42, 0x47, 0x52, 0x20, 0x5a, 0x59, 0x58,
63 0x02, 0x00, 0xce, 0x07, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x31, 0x00,
64 0x70, 0x73, 0x63, 0x61, 0x54, 0x46, 0x53, 0x4d, 0x00, 0x00, 0x00, 0x00,
65 0x20, 0x43, 0x45, 0x49, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xf6, 0x00, 0x00,
67 0x00, 0x00, 0x01, 0x00, 0x2d, 0xd3, 0x00, 0x00, 0x20, 0x20, 0x50, 0x48 };
69 static LPSTR standardprofile;
70 static LPWSTR standardprofileW;
72 static LPSTR testprofile;
73 static LPWSTR testprofileW;
75 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
77 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
79 INT i = strlen( path );
81 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
82 strcpy( name, &path[i] );
85 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
87 INT i = lstrlenW( path );
89 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
90 lstrcpyW( name, &path[i] );
93 static void test_GetColorDirectoryA(void)
97 char buffer[MAX_PATH];
99 /* Parameter checks */
101 ret = GetColorDirectoryA( NULL, NULL, NULL );
102 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
106 ret = GetColorDirectoryA( NULL, NULL, &size );
107 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
111 ret = GetColorDirectoryA( NULL, buffer, &size );
112 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
116 ret = GetColorDirectoryA( NULL, buffer, &size );
117 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
119 /* Functional checks */
121 size = sizeof(buffer);
123 ret = GetColorDirectoryA( NULL, buffer, &size );
124 ok( ret && size > 0, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
127 static void test_GetColorDirectoryW(void)
131 WCHAR buffer[MAX_PATH];
133 /* Parameter checks */
135 /* This one crashes win2k
137 ret = GetColorDirectoryW( NULL, NULL, NULL );
138 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
144 ret = GetColorDirectoryW( NULL, NULL, &size );
145 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
149 ret = GetColorDirectoryW( NULL, buffer, &size );
150 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
154 ret = GetColorDirectoryW( NULL, buffer, &size );
155 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
157 /* Functional checks */
159 size = sizeof(buffer);
161 ret = GetColorDirectoryW( NULL, buffer, &size );
162 ok( ret && size > 0, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
165 static void test_GetColorProfileElement(void)
173 TAGTYPE tag = 0x63707274; /* 'cprt' */
174 static char buffer[51];
175 static const char expect[] =
176 { 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70,
177 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20,
178 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65, 0x74,
179 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x72, 0x64, 0x20, 0x43,
180 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x00 };
182 profile.dwType = PROFILE_FILENAME;
183 profile.pProfileData = standardprofile;
184 profile.cbDataSize = strlen(standardprofile);
186 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
187 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
189 /* Parameter checks */
191 ret = GetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
192 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
194 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
195 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
199 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
200 ok( !ret && size > 0, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
202 size = sizeof(buffer);
204 /* Functional checks */
206 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
207 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
209 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
211 CloseColorProfile( handle );
215 static void test_GetColorProfileElementTag(void)
223 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
225 profile.dwType = PROFILE_FILENAME;
226 profile.pProfileData = standardprofile;
227 profile.cbDataSize = strlen(standardprofile);
229 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
230 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
232 /* Parameter checks */
234 ret = GetColorProfileElementTag( NULL, index, &tag );
235 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
237 ret = GetColorProfileElementTag( handle, 0, &tag );
238 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
240 ret = GetColorProfileElementTag( handle, index, NULL );
241 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
243 ret = GetColorProfileElementTag( handle, 18, NULL );
244 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
246 /* Functional checks */
248 ret = GetColorProfileElementTag( handle, index, &tag );
249 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%ld)\n",
252 CloseColorProfile( handle );
256 static void test_GetColorProfileFromHandle(void)
264 static const unsigned char expect[] =
265 { 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f, 0x02, 0x10, 0x00,
266 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59,
267 0x5a, 0x20, 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06, 0x00,
268 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54,
269 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47,
270 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00,
272 0x00, 0xd3, 0x2d, 0x48, 0x50, 0x20, 0x20 };
274 unsigned char *buffer;
276 profile.dwType = PROFILE_FILENAME;
277 profile.pProfileData = testprofile;
278 profile.cbDataSize = strlen(testprofile);
280 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
281 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
283 /* Parameter checks */
287 ret = GetColorProfileFromHandle( handle, NULL, &size );
288 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
290 buffer = HeapAlloc( GetProcessHeap(), 0, size );
294 ret = GetColorProfileFromHandle( NULL, buffer, &size );
295 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
297 ret = GetColorProfileFromHandle( handle, buffer, NULL );
298 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
300 /* Functional checks */
302 ret = GetColorProfileFromHandle( handle, buffer, &size );
303 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
305 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
307 HeapFree( GetProcessHeap(), 0, buffer );
310 CloseColorProfile( handle );
314 static void test_GetColorProfileHeader(void)
321 PROFILEHEADER header;
323 profile.dwType = PROFILE_FILENAME;
324 profile.pProfileData = testprofile;
325 profile.cbDataSize = strlen(testprofile);
327 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
328 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
330 /* Parameter checks */
332 ret = GetColorProfileHeader( NULL, NULL );
333 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
335 ret = GetColorProfileHeader( NULL, &header );
336 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
338 ret = GetColorProfileHeader( handle, NULL );
339 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
341 /* Functional checks */
343 ret = GetColorProfileHeader( handle, &header );
344 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
346 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
348 CloseColorProfile( handle );
352 static void test_GetCountColorProfileElements(void)
359 DWORD count, expect = 17;
361 profile.dwType = PROFILE_FILENAME;
362 profile.pProfileData = standardprofile;
363 profile.cbDataSize = strlen(standardprofile);
365 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
366 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
368 /* Parameter checks */
370 ret = GetCountColorProfileElements( NULL, &count );
371 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
374 ret = GetCountColorProfileElements( handle, NULL );
375 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
378 /* Functional checks */
380 ret = GetCountColorProfileElements( handle, &count );
381 ok( ret && count == expect,
382 "GetCountColorProfileElements() failed (%ld)\n", GetLastError() );
384 CloseColorProfile( handle );
388 static void test_GetStandardColorSpaceProfileA(void)
392 CHAR oldprofile[MAX_PATH];
393 CHAR newprofile[MAX_PATH];
395 /* Parameter checks */
397 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, NULL );
398 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
400 ret = GetStandardColorSpaceProfileA( machine, 0, newprofile, &size );
401 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
405 ret = GetStandardColorSpaceProfileA( NULL, 0, NULL, &size );
406 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
408 size = sizeof(newprofile);
410 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, &size );
411 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
413 /* Functional checks */
417 size = sizeof(oldprofile);
419 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile, &size );
420 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
422 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, standardprofile );
423 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
425 size = sizeof(newprofile);
427 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, newprofile, &size );
428 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
430 ok( !lstrcmpiA( (LPSTR)&newprofile, standardprofile ), "Unexpected profile\n" );
432 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile );
433 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
437 static void test_GetStandardColorSpaceProfileW(void)
441 WCHAR oldprofile[MAX_PATH];
442 WCHAR newprofile[MAX_PATH];
444 /* Parameter checks */
446 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, NULL );
447 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
449 ret = GetStandardColorSpaceProfileW( machineW, 0, newprofile, &size );
450 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
454 ret = GetStandardColorSpaceProfileW( NULL, 0, NULL, &size );
455 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
457 size = sizeof(newprofile);
459 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, &size );
460 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
462 /* Functional checks */
464 if (standardprofileW)
466 size = sizeof(oldprofile);
468 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile, &size );
469 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
471 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, standardprofileW );
472 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
474 size = sizeof(newprofile);
476 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, newprofile, &size );
477 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
479 ok( !lstrcmpiW( (LPWSTR)&newprofile, standardprofileW ), "Unexpected profile\n" );
481 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile );
482 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
486 static void test_InstallColorProfileA(void)
490 /* Parameter checks */
492 ret = InstallColorProfileA( NULL, NULL );
493 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
495 ret = InstallColorProfileA( machine, NULL );
496 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
498 ret = InstallColorProfileA( NULL, machine );
499 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
503 ret = InstallColorProfileA( NULL, standardprofile );
504 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
507 /* Functional checks */
511 CHAR dest[MAX_PATH], base[MAX_PATH];
512 DWORD size = sizeof(dest);
516 ret = InstallColorProfileA( NULL, testprofile );
517 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
519 ret = GetColorDirectoryA( NULL, dest, &size );
520 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
522 MSCMS_basenameA( testprofile, base );
524 strcat( dest, slash );
525 strcat( dest, base );
527 /* Check if the profile is really there */
528 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
529 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
530 CloseHandle( handle );
532 ret = UninstallColorProfileA( NULL, dest, TRUE );
533 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
537 static void test_InstallColorProfileW(void)
541 /* Parameter checks */
543 ret = InstallColorProfileW( NULL, NULL );
544 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
546 ret = InstallColorProfileW( machineW, NULL );
547 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
549 ret = InstallColorProfileW( NULL, machineW );
550 ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
552 if (standardprofileW)
554 ret = InstallColorProfileW( NULL, standardprofileW );
555 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
558 /* Functional checks */
562 WCHAR dest[MAX_PATH], base[MAX_PATH];
563 DWORD size = sizeof(dest);
564 WCHAR slash[] = { '\\', 0 };
567 ret = InstallColorProfileW( NULL, testprofileW );
568 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
570 ret = GetColorDirectoryW( NULL, dest, &size );
571 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
573 MSCMS_basenameW( testprofileW, base );
575 lstrcatW( dest, slash );
576 lstrcatW( dest, base );
578 /* Check if the profile is really there */
579 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
580 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
581 CloseHandle( handle );
583 ret = UninstallColorProfileW( NULL, dest, TRUE );
584 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
588 static void test_IsColorProfileTagPresent(void)
597 profile.dwType = PROFILE_FILENAME;
598 profile.pProfileData = standardprofile;
599 profile.cbDataSize = strlen(standardprofile);
601 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
602 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
604 /* Parameter checks */
608 ret = IsColorProfileTagPresent( handle, tag, &present );
609 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
611 tag = 0x63707274; /* 'cprt' */
613 ret = IsColorProfileTagPresent( NULL, tag, &present );
614 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
616 ret = IsColorProfileTagPresent( handle, tag, NULL );
617 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
619 /* Functional checks */
621 ret = IsColorProfileTagPresent( handle, tag, &present );
622 ok( ret && present, "IsColorProfileTagPresent() failed (%ld)\n", GetLastError() );
624 CloseColorProfile( handle );
628 static void test_OpenColorProfileA(void)
634 profile.dwType = PROFILE_FILENAME;
635 profile.pProfileData = NULL;
636 profile.cbDataSize = 0;
638 /* Parameter checks */
640 handle = OpenColorProfileA( NULL, 0, 0, 0 );
641 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
643 handle = OpenColorProfileA( &profile, 0, 0, 0 );
644 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
646 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
647 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
649 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
650 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
652 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
656 profile.pProfileData = standardprofile;
657 profile.cbDataSize = strlen(standardprofile);
659 handle = OpenColorProfileA( &profile, 0, 0, 0 );
660 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
662 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
663 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
665 handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
666 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
668 /* Functional checks */
670 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
671 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
673 ret = CloseColorProfile( handle );
674 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
678 static void test_OpenColorProfileW(void)
684 profile.dwType = PROFILE_FILENAME;
685 profile.pProfileData = NULL;
686 profile.cbDataSize = 0;
688 /* Parameter checks */
690 handle = OpenColorProfileW( NULL, 0, 0, 0 );
691 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
693 handle = OpenColorProfileW( &profile, 0, 0, 0 );
694 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
696 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
697 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
699 handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
700 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
702 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
704 if (standardprofileW)
706 profile.pProfileData = standardprofileW;
707 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
709 handle = OpenColorProfileW( &profile, 0, 0, 0 );
710 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
712 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
713 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
715 handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
716 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
718 /* Functional checks */
720 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
721 ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
723 ret = CloseColorProfile( handle );
724 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
728 static void test_SetColorProfileElement(void)
737 TAGTYPE tag = 0x63707274; /* 'cprt' */
738 static char data[] = "(c) The Wine Project";
739 static char buffer[51];
741 profile.dwType = PROFILE_FILENAME;
742 profile.pProfileData = testprofile;
743 profile.cbDataSize = strlen(testprofile);
745 /* Parameter checks */
747 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
748 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
750 ret = SetColorProfileElement( handle, tag, 0, &size, data );
751 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
753 CloseColorProfile( handle );
755 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
756 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
758 ret = SetColorProfileElement( NULL, 0, 0, NULL, NULL );
759 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
761 ret = SetColorProfileElement( handle, 0, 0, NULL, NULL );
762 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
764 ret = SetColorProfileElement( handle, tag, 0, NULL, NULL );
765 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
767 ret = SetColorProfileElement( handle, tag, 0, &size, NULL );
768 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
770 /* Functional checks */
772 ret = SetColorProfileElement( handle, tag, 0, &size, data );
773 ok( ret, "SetColorProfileElement() failed (%ld)\n", GetLastError() );
775 size = sizeof(buffer);
777 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
778 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
780 ok( !memcmp( data, buffer, sizeof(data) ), "Unexpected tag data\n" );
782 CloseColorProfile( handle );
786 static void test_SetColorProfileHeader(void)
793 PROFILEHEADER header;
795 profile.dwType = PROFILE_FILENAME;
796 profile.pProfileData = testprofile;
797 profile.cbDataSize = strlen(testprofile);
799 header.phSize = 0x00000c48;
800 header.phCMMType = 0x4c696e6f;
801 header.phVersion = 0x02100000;
802 header.phClass = 0x6d6e7472;
803 header.phDataColorSpace = 0x52474220;
804 header.phConnectionSpace = 0x58595a20;
805 header.phDateTime[0] = 0x07ce0002;
806 header.phDateTime[1] = 0x00090006;
807 header.phDateTime[2] = 0x00310000;
808 header.phSignature = 0x61637370;
809 header.phPlatform = 0x4d534654;
810 header.phProfileFlags = 0x00000000;
811 header.phManufacturer = 0x49454320;
812 header.phModel = 0x73524742;
813 header.phAttributes[0] = 0x00000000;
814 header.phAttributes[1] = 0x00000000;
815 header.phRenderingIntent = 0x00000000;
816 header.phIlluminant.ciexyzX = 0x0000f6d6;
817 header.phIlluminant.ciexyzY = 0x00010000;
818 header.phIlluminant.ciexyzZ = 0x0000d32d;
819 header.phCreator = 0x48502020;
821 /* Parameter checks */
823 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
824 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
826 ret = SetColorProfileHeader( handle, &header );
827 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
829 CloseColorProfile( handle );
831 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
832 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
834 ret = SetColorProfileHeader( NULL, NULL );
835 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
837 ret = SetColorProfileHeader( handle, NULL );
838 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
840 ret = SetColorProfileHeader( NULL, &header );
841 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
843 /* Functional checks */
845 ret = SetColorProfileHeader( handle, &header );
846 ok( ret, "SetColorProfileHeader() failed (%ld)\n", GetLastError() );
848 ret = GetColorProfileHeader( handle, &header );
849 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
851 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
853 CloseColorProfile( handle );
857 static void test_UninstallColorProfileA(void)
861 /* Parameter checks */
863 ret = UninstallColorProfileA( NULL, NULL, FALSE );
864 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
866 ret = UninstallColorProfileA( machine, NULL, FALSE );
867 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
869 /* Functional checks */
873 CHAR dest[MAX_PATH], base[MAX_PATH];
874 DWORD size = sizeof(dest);
878 ret = InstallColorProfileA( NULL, testprofile );
879 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
881 ret = GetColorDirectoryA( NULL, dest, &size );
882 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
884 MSCMS_basenameA( testprofile, base );
886 strcat( dest, slash );
887 strcat( dest, base );
889 ret = UninstallColorProfileA( NULL, dest, TRUE );
890 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
892 /* Check if the profile is really gone */
893 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
894 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
895 CloseHandle( handle );
899 static void test_UninstallColorProfileW(void)
903 /* Parameter checks */
905 ret = UninstallColorProfileW( NULL, NULL, FALSE );
906 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
908 ret = UninstallColorProfileW( machineW, NULL, FALSE );
909 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
911 /* Functional checks */
915 WCHAR dest[MAX_PATH], base[MAX_PATH];
916 DWORD size = sizeof(dest);
917 WCHAR slash[] = { '\\', 0 };
920 ret = InstallColorProfileW( NULL, testprofileW );
921 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
923 ret = GetColorDirectoryW( NULL, dest, &size );
924 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
926 MSCMS_basenameW( testprofileW, base );
928 lstrcatW( dest, slash );
929 lstrcatW( dest, base );
931 ret = UninstallColorProfileW( NULL, dest, TRUE );
932 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
934 /* Check if the profile is really gone */
935 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
936 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
937 CloseHandle( handle );
945 char path[MAX_PATH], file[MAX_PATH];
946 char profilefile1[MAX_PATH], profilefile2[MAX_PATH];
947 WCHAR profilefile1W[MAX_PATH], profilefile2W[MAX_PATH];
948 WCHAR fileW[MAX_PATH];
950 /* See if we can find the standard color profile */
951 GetSystemDirectoryA( profilefile1, sizeof(profilefile1) );
952 GetSystemDirectoryW( profilefile1W, sizeof(profilefile1W) / sizeof(WCHAR) );
953 lstrcatA( profilefile1, profile1 );
954 lstrcatW( profilefile1W, profile1W );
955 handle = CreateFileA( profilefile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
957 if (handle != INVALID_HANDLE_VALUE)
959 standardprofile = profilefile1;
960 standardprofileW = profilefile1W;
961 CloseHandle( handle );
964 GetSystemDirectoryA( profilefile2, sizeof(profilefile2) );
965 GetSystemDirectoryW( profilefile2W, sizeof(profilefile2W) / sizeof(WCHAR) );
966 lstrcatA( profilefile2, profile2 );
967 lstrcatW( profilefile2W, profile2W );
968 handle = CreateFileA( profilefile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
970 if (handle != INVALID_HANDLE_VALUE)
972 standardprofile = profilefile2;
973 standardprofileW = profilefile2W;
974 CloseHandle( handle );
977 /* If found, create a temporary copy for testing purposes */
978 if (standardprofile && GetTempPath( sizeof(path), path ))
980 if (GetTempFileName( path, "rgb", 0, file ))
982 if (CopyFileA( standardprofile, file, FALSE ))
984 testprofile = (LPSTR)&file;
986 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
987 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
989 testprofileW = (LPWSTR)&fileW;
994 test_GetColorDirectoryA();
995 test_GetColorDirectoryW();
997 test_GetColorProfileElement();
998 test_GetColorProfileElementTag();
1000 test_GetColorProfileFromHandle();
1001 test_GetColorProfileHeader();
1003 test_GetCountColorProfileElements();
1005 test_GetStandardColorSpaceProfileA();
1006 test_GetStandardColorSpaceProfileW();
1008 test_InstallColorProfileA();
1009 test_InstallColorProfileW();
1011 test_IsColorProfileTagPresent();
1013 test_OpenColorProfileA();
1014 test_OpenColorProfileW();
1016 test_SetColorProfileElement();
1017 test_SetColorProfileHeader();
1019 test_UninstallColorProfileA();
1020 test_UninstallColorProfileW();
1024 DeleteFileA( testprofile );