Correct cases where arguments of ok() calls depend on the order in
[wine/gsoc_dplay.git] / dlls / mscms / tests / profile.c
blobceeb8dca075978f2d01ab8e923bea8d030169e0c
1 /*
2 * Tests for color profile functions
4 * Copyright 2004 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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "icm.h"
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 profile1[] =
46 "c:\\windows\\system\\color\\srgb color space profile.icm";
47 static const char profile2[] =
48 "c:\\windows\\system32\\spool\\drivers\\color\\srgb color space profile.icm";
50 static const WCHAR profile1W[] =
51 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m',
52 '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
53 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
54 static const WCHAR profile2W[] =
55 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m','3','2',
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()
95 BOOL ret;
96 DWORD size;
97 char buffer[MAX_PATH];
99 /* Parameter checks */
101 ret = GetColorDirectoryA( NULL, NULL, NULL );
102 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
104 size = 0;
106 ret = GetColorDirectoryA( NULL, NULL, &size );
107 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
109 size = 0;
111 ret = GetColorDirectoryA( NULL, buffer, &size );
112 ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
114 size = 1;
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()
129 BOOL ret;
130 DWORD size;
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() );
142 size = 0;
144 ret = GetColorDirectoryW( NULL, NULL, &size );
145 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
147 size = 0;
149 ret = GetColorDirectoryW( NULL, buffer, &size );
150 ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
152 size = 1;
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() );
163 ret = GetColorDirectoryW( NULL, buffer, &size );
166 static void test_GetColorProfileElement()
168 if (standardprofile)
170 PROFILE profile;
171 HPROFILE handle;
172 BOOL ret, ref;
173 DWORD size;
174 TAGTYPE tag = 0x63707274; /* 'cprt' */
175 static char buffer[51];
176 static const char expect[] =
177 { 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70,
178 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20,
179 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65, 0x74,
180 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x72, 0x64, 0x20, 0x43,
181 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x00 };
183 profile.dwType = PROFILE_FILENAME;
184 profile.pProfileData = standardprofile;
185 profile.cbDataSize = strlen(standardprofile);
187 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
188 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
190 /* Parameter checks */
192 ret = GetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
193 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
195 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
196 ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
198 size = 0;
200 ret = GetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
201 ok( !ret && size > 0, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
203 size = sizeof(buffer);
205 /* Functional checks */
207 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
208 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
210 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
212 CloseColorProfile( handle );
216 static void test_GetColorProfileElementTag()
218 if (standardprofile)
220 PROFILE profile;
221 HPROFILE handle;
222 BOOL ret;
223 DWORD index = 1;
224 TAGTYPE tag, expect = 0x63707274; /* 'cprt' */
226 profile.dwType = PROFILE_FILENAME;
227 profile.pProfileData = standardprofile;
228 profile.cbDataSize = strlen(standardprofile);
230 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
231 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
233 /* Parameter checks */
235 ret = GetColorProfileElementTag( NULL, index, &tag );
236 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
238 ret = GetColorProfileElementTag( handle, 0, &tag );
239 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
241 ret = GetColorProfileElementTag( handle, index, NULL );
242 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
244 ret = GetColorProfileElementTag( handle, 18, NULL );
245 ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
247 /* Functional checks */
249 ret = GetColorProfileElementTag( handle, index, &tag );
250 ok( ret && tag == expect, "GetColorProfileElementTag() failed (%ld)\n",
251 GetLastError() );
253 CloseColorProfile( handle );
257 static void test_GetColorProfileFromHandle()
259 if (testprofile)
261 PROFILE profile;
262 HPROFILE handle;
263 DWORD size;
264 BOOL ret;
265 static const unsigned char expect[] =
266 { 0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f, 0x02, 0x10, 0x00,
267 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59,
268 0x5a, 0x20, 0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06, 0x00,
269 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54,
270 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47,
271 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00,
273 0x00, 0xd3, 0x2d, 0x48, 0x50, 0x20, 0x20 };
275 unsigned char *buffer;
277 profile.dwType = PROFILE_FILENAME;
278 profile.pProfileData = testprofile;
279 profile.cbDataSize = strlen(testprofile);
281 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
282 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
284 /* Parameter checks */
286 size = 0;
288 ret = GetColorProfileFromHandle( handle, NULL, &size );
289 ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
291 buffer = HeapAlloc( GetProcessHeap(), 0, size );
293 if (buffer)
295 ret = GetColorProfileFromHandle( NULL, buffer, &size );
296 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
298 ret = GetColorProfileFromHandle( handle, buffer, NULL );
299 ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
301 /* Functional checks */
303 ret = GetColorProfileFromHandle( handle, buffer, &size );
304 ok( ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
306 ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
308 HeapFree( GetProcessHeap(), 0, buffer );
311 CloseColorProfile( handle );
315 static void test_GetColorProfileHeader()
317 if (testprofile)
319 PROFILE profile;
320 HPROFILE handle;
321 BOOL ret;
322 PROFILEHEADER header;
324 profile.dwType = PROFILE_FILENAME;
325 profile.pProfileData = testprofile;
326 profile.cbDataSize = strlen(testprofile);
328 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
329 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
331 /* Parameter checks */
333 ret = GetColorProfileHeader( NULL, NULL );
334 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
336 ret = GetColorProfileHeader( NULL, &header );
337 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
339 ret = GetColorProfileHeader( handle, NULL );
340 ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
342 /* Functional checks */
344 ret = GetColorProfileHeader( handle, &header );
345 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
347 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
349 CloseColorProfile( handle );
353 static void test_GetCountColorProfileElements()
355 if (standardprofile)
357 PROFILE profile;
358 HPROFILE handle;
359 BOOL ret;
360 DWORD count, expect = 17;
362 profile.dwType = PROFILE_FILENAME;
363 profile.pProfileData = standardprofile;
364 profile.cbDataSize = strlen(standardprofile);
366 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
367 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
369 /* Parameter checks */
371 ret = GetCountColorProfileElements( NULL, &count );
372 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
373 GetLastError() );
375 ret = GetCountColorProfileElements( handle, NULL );
376 ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
377 GetLastError() );
379 /* Functional checks */
381 ret = GetCountColorProfileElements( handle, &count );
382 ok( ret && count == expect,
383 "GetCountColorProfileElements() failed (%ld)\n", GetLastError() );
385 CloseColorProfile( handle );
389 static void test_GetStandardColorSpaceProfileA()
391 BOOL ret;
392 DWORD size;
393 CHAR oldprofile[MAX_PATH];
394 CHAR newprofile[MAX_PATH];
396 /* Parameter checks */
398 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, NULL );
399 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
401 ret = GetStandardColorSpaceProfileA( machine, 0, newprofile, &size );
402 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
404 size = 0;
406 ret = GetStandardColorSpaceProfileA( NULL, 0, NULL, &size );
407 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
409 size = sizeof(newprofile);
411 ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, &size );
412 ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
414 /* Functional checks */
416 if (standardprofile)
418 size = sizeof(oldprofile);
420 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile, &size );
421 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
423 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, standardprofile );
424 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
426 size = sizeof(newprofile);
428 ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, newprofile, &size );
429 ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
431 ok( !lstrcmpiA( (LPSTR)&newprofile, standardprofile ), "Unexpected profile\n" );
433 ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile );
434 ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
438 static void test_GetStandardColorSpaceProfileW()
440 BOOL ret;
441 DWORD size;
442 WCHAR oldprofile[MAX_PATH];
443 WCHAR newprofile[MAX_PATH];
445 /* Parameter checks */
447 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, NULL );
448 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
450 ret = GetStandardColorSpaceProfileW( machineW, 0, newprofile, &size );
451 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
453 size = 0;
455 ret = GetStandardColorSpaceProfileW( NULL, 0, NULL, &size );
456 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
458 size = sizeof(newprofile);
460 ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, &size );
461 ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
463 /* Functional checks */
465 if (standardprofileW)
467 size = sizeof(oldprofile);
469 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile, &size );
470 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
472 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, standardprofileW );
473 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
475 size = sizeof(newprofile);
477 ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, newprofile, &size );
478 ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
480 ok( !lstrcmpiW( (LPWSTR)&newprofile, standardprofileW ), "Unexpected profile\n" );
482 ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile );
483 ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
487 static void test_InstallColorProfileA()
489 BOOL ret;
491 /* Parameter checks */
493 ret = InstallColorProfileA( NULL, NULL );
494 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
496 ret = InstallColorProfileA( machine, NULL );
497 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
499 ret = InstallColorProfileA( NULL, machine );
500 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
502 if (standardprofile)
504 ret = InstallColorProfileA( NULL, standardprofile );
505 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
508 /* Functional checks */
510 if (testprofile)
512 CHAR dest[MAX_PATH], base[MAX_PATH];
513 DWORD size = sizeof(dest);
514 CHAR slash[] = "\\";
515 HANDLE handle;
517 ret = InstallColorProfileA( NULL, testprofile );
518 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
520 ret = GetColorDirectoryA( NULL, dest, &size );
521 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
523 MSCMS_basenameA( testprofile, base );
525 strcat( dest, slash );
526 strcat( dest, base );
528 /* Check if the profile is really there */
529 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
530 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
531 CloseHandle( handle );
533 ret = UninstallColorProfileA( NULL, dest, TRUE );
534 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
538 static void test_InstallColorProfileW()
540 BOOL ret;
542 /* Parameter checks */
544 ret = InstallColorProfileW( NULL, NULL );
545 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
547 ret = InstallColorProfileW( machineW, NULL );
548 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
550 ret = InstallColorProfileW( NULL, machineW );
551 ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
553 if (standardprofileW)
555 ret = InstallColorProfileW( NULL, standardprofileW );
556 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
559 /* Functional checks */
561 if (testprofileW)
563 WCHAR dest[MAX_PATH], base[MAX_PATH];
564 DWORD size = sizeof(dest);
565 WCHAR slash[] = { '\\', 0 };
566 HANDLE handle;
568 ret = InstallColorProfileW( NULL, testprofileW );
569 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
571 ret = GetColorDirectoryW( NULL, dest, &size );
572 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
574 MSCMS_basenameW( testprofileW, base );
576 lstrcatW( dest, slash );
577 lstrcatW( dest, base );
579 /* Check if the profile is really there */
580 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
581 ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
582 CloseHandle( handle );
584 ret = UninstallColorProfileW( NULL, dest, TRUE );
585 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
589 static void test_IsColorProfileTagPresent()
591 if (standardprofile)
593 PROFILE profile;
594 HPROFILE handle;
595 BOOL ret, present;
596 TAGTYPE tag;
598 profile.dwType = PROFILE_FILENAME;
599 profile.pProfileData = standardprofile;
600 profile.cbDataSize = strlen(standardprofile);
602 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
603 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
605 /* Parameter checks */
607 tag = 0;
609 ret = IsColorProfileTagPresent( handle, tag, &present );
610 ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
612 tag = 0x63707274; /* 'cprt' */
614 ret = IsColorProfileTagPresent( NULL, tag, &present );
615 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
617 ret = IsColorProfileTagPresent( handle, tag, NULL );
618 ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
620 /* Functional checks */
622 ret = IsColorProfileTagPresent( handle, tag, &present );
623 ok( ret && present, "IsColorProfileTagPresent() failed (%ld)\n", GetLastError() );
625 CloseColorProfile( handle );
629 static void test_OpenColorProfileA()
631 PROFILE profile;
632 HPROFILE handle;
633 BOOL ret;
635 profile.dwType = PROFILE_FILENAME;
636 profile.pProfileData = NULL;
637 profile.cbDataSize = 0;
639 /* Parameter checks */
641 handle = OpenColorProfileA( NULL, 0, 0, 0 );
642 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
644 handle = OpenColorProfileA( &profile, 0, 0, 0 );
645 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
647 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
648 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
650 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
651 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
653 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
655 if (standardprofile)
657 profile.pProfileData = standardprofile;
658 profile.cbDataSize = strlen(standardprofile);
660 handle = OpenColorProfileA( &profile, 0, 0, 0 );
661 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
663 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
664 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
666 handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
667 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
669 /* Functional checks */
671 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
672 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
674 ret = CloseColorProfile( handle );
675 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
679 static void test_OpenColorProfileW()
681 PROFILE profile;
682 HPROFILE handle;
683 BOOL ret;
685 profile.dwType = PROFILE_FILENAME;
686 profile.pProfileData = NULL;
687 profile.cbDataSize = 0;
689 /* Parameter checks */
691 handle = OpenColorProfileW( NULL, 0, 0, 0 );
692 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
694 handle = OpenColorProfileW( &profile, 0, 0, 0 );
695 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
697 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
698 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
700 handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
701 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
703 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
705 if (standardprofileW)
707 profile.pProfileData = standardprofileW;
708 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
710 handle = OpenColorProfileW( &profile, 0, 0, 0 );
711 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
713 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
714 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
716 handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
717 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
719 /* Functional checks */
721 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
722 ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
724 ret = CloseColorProfile( handle );
725 ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
729 static void test_SetColorProfileElement()
731 if (testprofile)
733 PROFILE profile;
734 HPROFILE handle;
735 DWORD size;
736 BOOL ret, ref;
738 TAGTYPE tag = 0x63707274; /* 'cprt' */
739 static char data[] = "(c) The Wine Project";
740 static char buffer[51];
742 profile.dwType = PROFILE_FILENAME;
743 profile.pProfileData = testprofile;
744 profile.cbDataSize = strlen(testprofile);
746 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
747 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
749 todo_wine
751 ret = SetColorProfileElement( handle, tag, 0, &size, data );
752 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
755 CloseColorProfile( handle );
757 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
758 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
760 /* Parameter checks */
762 ret = SetColorProfileElement( NULL, 0, 0, NULL, NULL );
763 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
765 ret = SetColorProfileElement( handle, 0, 0, NULL, NULL );
766 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
768 ret = SetColorProfileElement( handle, tag, 0, NULL, NULL );
769 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
771 ret = SetColorProfileElement( handle, tag, 0, &size, NULL );
772 ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
774 /* Functional checks */
776 ret = SetColorProfileElement( handle, tag, 0, &size, data );
777 ok( ret, "SetColorProfileElement() failed (%ld)\n", GetLastError() );
779 size = sizeof(buffer);
781 ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
782 ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
784 ok( !memcmp( data, buffer, sizeof(data) ), "Unexpected tag data\n" );
786 CloseColorProfile( handle );
790 static void test_SetColorProfileHeader()
792 if (testprofile)
794 PROFILE profile;
795 HPROFILE handle;
796 BOOL ret;
797 PROFILEHEADER header;
799 profile.dwType = PROFILE_FILENAME;
800 profile.pProfileData = testprofile;
801 profile.cbDataSize = strlen(testprofile);
803 header.phSize = 0x00000c48;
804 header.phCMMType = 0x4c696e6f;
805 header.phVersion = 0x02100000;
806 header.phClass = 0x6d6e7472;
807 header.phDataColorSpace = 0x52474220;
808 header.phConnectionSpace = 0x58595a20;
809 header.phDateTime[0] = 0x07ce0002;
810 header.phDateTime[1] = 0x00090006;
811 header.phDateTime[2] = 0x00310000;
812 header.phSignature = 0x61637370;
813 header.phPlatform = 0x4d534654;
814 header.phProfileFlags = 0x00000000;
815 header.phManufacturer = 0x49454320;
816 header.phModel = 0x73524742;
817 header.phAttributes[0] = 0x00000000;
818 header.phAttributes[1] = 0x00000000;
819 header.phRenderingIntent = 0x00000000;
820 header.phIlluminant.ciexyzX = 0x0000f6d6;
821 header.phIlluminant.ciexyzY = 0x00010000;
822 header.phIlluminant.ciexyzZ = 0x0000d32d;
823 header.phCreator = 0x48502020;
825 /* Parameter checks */
827 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
828 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
830 todo_wine
832 ret = SetColorProfileHeader( handle, &header );
833 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
836 CloseColorProfile( handle );
838 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
839 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
841 ret = SetColorProfileHeader( NULL, NULL );
842 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
844 ret = SetColorProfileHeader( handle, NULL );
845 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
847 ret = SetColorProfileHeader( NULL, &header );
848 ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
850 /* Functional checks */
852 ret = SetColorProfileHeader( handle, &header );
853 ok( ret, "SetColorProfileHeader() failed (%ld)\n", GetLastError() );
855 ret = GetColorProfileHeader( handle, &header );
856 ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
858 ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
860 CloseColorProfile( handle );
864 static void test_UninstallColorProfileA()
866 BOOL ret;
868 /* Parameter checks */
870 ret = UninstallColorProfileA( NULL, NULL, FALSE );
871 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
873 ret = UninstallColorProfileA( machine, NULL, FALSE );
874 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
876 /* Functional checks */
878 if (testprofile)
880 CHAR dest[MAX_PATH], base[MAX_PATH];
881 DWORD size = sizeof(dest);
882 CHAR slash[] = "\\";
883 HANDLE handle;
885 ret = InstallColorProfileA( NULL, testprofile );
886 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
888 ret = GetColorDirectoryA( NULL, dest, &size );
889 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
891 MSCMS_basenameA( testprofile, base );
893 strcat( dest, slash );
894 strcat( dest, base );
896 ret = UninstallColorProfileA( NULL, dest, TRUE );
897 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
899 /* Check if the profile is really gone */
900 handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
901 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
902 CloseHandle( handle );
906 static void test_UninstallColorProfileW()
908 BOOL ret;
910 /* Parameter checks */
912 ret = UninstallColorProfileW( NULL, NULL, FALSE );
913 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
915 ret = UninstallColorProfileW( machineW, NULL, FALSE );
916 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
918 /* Functional checks */
920 if (testprofileW)
922 WCHAR dest[MAX_PATH], base[MAX_PATH];
923 DWORD size = sizeof(dest);
924 WCHAR slash[] = { '\\', 0 };
925 HANDLE handle;
927 ret = InstallColorProfileW( NULL, testprofileW );
928 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
930 ret = GetColorDirectoryW( NULL, dest, &size );
931 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
933 MSCMS_basenameW( testprofileW, base );
935 lstrcatW( dest, slash );
936 lstrcatW( dest, base );
938 ret = UninstallColorProfileW( NULL, dest, TRUE );
939 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
941 /* Check if the profile is really gone */
942 handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
943 ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
944 CloseHandle( handle );
948 START_TEST(profile)
950 UINT len;
951 HANDLE handle;
952 char path[MAX_PATH], file[MAX_PATH];
953 WCHAR fileW[MAX_PATH];
955 /* See if we can find the standard color profile */
956 handle = CreateFileA( profile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
958 if (handle != INVALID_HANDLE_VALUE)
960 standardprofile = (LPSTR)&profile1;
961 standardprofileW = (LPWSTR)&profile1W;
962 CloseHandle( handle );
965 handle = CreateFileA( profile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
967 if (handle != INVALID_HANDLE_VALUE)
969 standardprofile = (LPSTR)&profile2;
970 standardprofileW = (LPWSTR)&profile2W;
971 CloseHandle( handle );
974 /* If found, create a temporary copy for testing purposes */
975 if (standardprofile && GetTempPath( sizeof(path), path ))
977 if (GetTempFileName( path, "rgb", 0, file ))
979 if (CopyFileA( standardprofile, file, FALSE ))
981 testprofile = (LPSTR)&file;
983 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
984 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
986 testprofileW = (LPWSTR)&fileW;
991 test_GetColorDirectoryA();
992 test_GetColorDirectoryW();
994 test_GetColorProfileElement();
995 test_GetColorProfileElementTag();
997 test_GetColorProfileFromHandle();
998 test_GetColorProfileHeader();
1000 test_GetCountColorProfileElements();
1002 test_GetStandardColorSpaceProfileA();
1003 test_GetStandardColorSpaceProfileW();
1005 test_InstallColorProfileA();
1006 test_InstallColorProfileW();
1008 test_IsColorProfileTagPresent();
1010 test_OpenColorProfileA();
1011 test_OpenColorProfileW();
1013 test_SetColorProfileElement();
1014 test_SetColorProfileHeader();
1016 test_UninstallColorProfileA();
1017 test_UninstallColorProfileW();
1019 /* Clean up */
1020 if (testprofile)
1021 DeleteFileA( testprofile );