Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[wine] / dlls / mscms / tests / profile.c
1 /*
2  * Tests for color profile functions
3  *
4  * Copyright 2004, 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "icm.h"
29
30 #include "wine/test.h"
31
32 static const char machine[] = "dummy";
33 static const WCHAR machineW[] = { 'd','u','m','m','y',0 };
34
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:
40  *
41  *  http://download.microsoft.com/download/whistler/hwdev1/1.0/wxp/en-us/ColorProfile.exe
42  */
43
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";
49
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 };
56
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 };
65
66 static LPSTR standardprofile;
67 static LPWSTR standardprofileW;
68
69 static LPSTR testprofile;
70 static LPWSTR testprofileW;
71
72 #define IS_SEPARATOR(ch)  ((ch) == '\\' || (ch) == '/')
73
74 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
75 {
76     INT i = strlen( path );
77
78     while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
79     strcpy( name, &path[i] );
80 }
81
82 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
83 {
84     INT i = lstrlenW( path );
85
86     while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
87     lstrcpyW( name, &path[i] );
88 }
89
90 static void test_GetColorDirectoryA()
91 {
92     BOOL ret;
93     DWORD size;
94     char buffer[MAX_PATH];
95
96     /* Parameter checks */
97
98     ret = GetColorDirectoryA( NULL, NULL, NULL );
99     ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
100
101     size = 0;
102
103     ret = GetColorDirectoryA( NULL, NULL, &size );
104     ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
105
106     size = 0;
107
108     ret = GetColorDirectoryA( NULL, buffer, &size );
109     ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
110
111     size = 1;
112
113     ret = GetColorDirectoryA( NULL, buffer, &size );
114     ok( !ret && size > 0, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
115
116     /* Functional checks */
117
118     size = sizeof(buffer);
119
120     ret = GetColorDirectoryA( NULL, buffer, &size );
121     ok( ret && size > 0, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
122 }
123
124 static void test_GetColorDirectoryW()
125 {
126     BOOL ret;
127     DWORD size;
128     WCHAR buffer[MAX_PATH];
129
130     /* Parameter checks */
131
132     /* This one crashes win2k
133     
134     ret = GetColorDirectoryW( NULL, NULL, NULL );
135     ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
136
137      */
138
139     size = 0;
140
141     ret = GetColorDirectoryW( NULL, NULL, &size );
142     ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
143
144     size = 0;
145
146     ret = GetColorDirectoryW( NULL, buffer, &size );
147     ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
148
149     size = 1;
150
151     ret = GetColorDirectoryW( NULL, buffer, &size );
152     ok( !ret && size > 0, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
153
154     /* Functional checks */
155
156     size = sizeof(buffer);
157
158     ret = GetColorDirectoryW( NULL, buffer, &size );
159     ok( ret && size > 0, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
160 }
161
162 static void test_GetColorProfileElement()
163 {
164     if (standardprofile)
165     {
166         PROFILE profile;
167         HPROFILE handle;
168         BOOL ret, ref;
169         DWORD size;
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 };
178
179         profile.dwType = PROFILE_FILENAME;
180         profile.pProfileData = standardprofile;
181         profile.cbDataSize = strlen(standardprofile);
182
183         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
184         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
185
186         /* Parameter checks */
187
188         ret = GetColorProfileElement( handle, tag, 0, NULL, NULL, &ref );
189         ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
190
191         ret = GetColorProfileElement( handle, tag, 0, &size, NULL, NULL );
192         ok( !ret, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
193
194         size = 0;
195
196         ret = GetColorProfileElement( handle, tag, 0, &size, NULL, &ref );
197         ok( !ret && size > 0, "GetColorProfileElement() succeeded (%ld)\n", GetLastError() );
198
199         size = sizeof(buffer);
200
201         /* Functional checks */
202
203         ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
204         ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
205
206         ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected tag data\n" );
207
208         CloseColorProfile( handle );
209     }
210 }
211
212 static void test_GetColorProfileElementTag()
213 {
214     if (standardprofile)
215     {
216         PROFILE profile;
217         HPROFILE handle;
218         BOOL ret;
219         DWORD index = 1;
220         TAGTYPE tag, expect = 0x63707274;  /* 'cprt' */
221
222         profile.dwType = PROFILE_FILENAME;
223         profile.pProfileData = standardprofile;
224         profile.cbDataSize = strlen(standardprofile);
225
226         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
227         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
228
229         /* Parameter checks */
230
231         ret = GetColorProfileElementTag( NULL, index, &tag );
232         ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
233
234         ret = GetColorProfileElementTag( handle, 0, &tag );
235         ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
236
237         ret = GetColorProfileElementTag( handle, index, NULL );
238         ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
239
240         ret = GetColorProfileElementTag( handle, 18, NULL );
241         ok( !ret, "GetColorProfileElementTag() succeeded (%ld)\n", GetLastError() );
242
243         /* Functional checks */
244
245         ret = GetColorProfileElementTag( handle, index, &tag );
246         ok( ret && tag == expect, "GetColorProfileElementTag() failed (%ld)\n",
247             GetLastError() );
248
249         CloseColorProfile( handle );
250     }
251 }
252
253 static void test_GetColorProfileFromHandle()
254 {
255     if (testprofile)
256     {
257         PROFILE profile;
258         HPROFILE handle;
259         DWORD size;
260         BOOL ret;
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 };
270
271         unsigned char *buffer;
272
273         profile.dwType = PROFILE_FILENAME;
274         profile.pProfileData = testprofile;
275         profile.cbDataSize = strlen(testprofile);
276
277         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
278         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
279
280         /* Parameter checks */
281
282         size = 0;
283
284         ret = GetColorProfileFromHandle( handle, NULL, &size );
285         ok( !ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
286
287         buffer = HeapAlloc( GetProcessHeap(), 0, size );
288
289         if (buffer)
290         {
291             ret = GetColorProfileFromHandle( NULL, buffer, &size );
292             ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
293
294             ret = GetColorProfileFromHandle( handle, buffer, NULL );
295             ok( !ret, "GetColorProfileFromHandle() succeeded (%ld)\n", GetLastError() );
296
297             /* Functional checks */
298
299             ret = GetColorProfileFromHandle( handle, buffer, &size );
300             ok( ret && size > 0, "GetColorProfileFromHandle() failed (%ld)\n", GetLastError() );
301
302             ok( !memcmp( buffer, expect, sizeof(expect) ), "Unexpected header data\n" );
303
304             HeapFree( GetProcessHeap(), 0, buffer );
305         }
306
307         CloseColorProfile( handle );
308     }
309 }
310
311 static void test_GetColorProfileHeader()
312 {
313     if (testprofile)
314     {
315         PROFILE profile;
316         HPROFILE handle;
317         BOOL ret;
318         PROFILEHEADER header;
319
320         profile.dwType = PROFILE_FILENAME;
321         profile.pProfileData = testprofile;
322         profile.cbDataSize = strlen(testprofile);
323
324         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
325         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
326
327         /* Parameter checks */
328
329         ret = GetColorProfileHeader( NULL, NULL );
330         ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
331
332         ret = GetColorProfileHeader( NULL, &header );
333         ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
334
335         ret = GetColorProfileHeader( handle, NULL );
336         ok( !ret, "GetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
337
338         /* Functional checks */
339
340         ret = GetColorProfileHeader( handle, &header );
341         ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
342
343         ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
344
345         CloseColorProfile( handle );
346     }
347 }
348
349 static void test_GetCountColorProfileElements()
350 {
351     if (standardprofile)
352     {
353         PROFILE profile;
354         HPROFILE handle;
355         BOOL ret;
356         DWORD count, expect = 17;
357
358         profile.dwType = PROFILE_FILENAME;
359         profile.pProfileData = standardprofile;
360         profile.cbDataSize = strlen(standardprofile);
361
362         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
363         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
364
365         /* Parameter checks */
366
367         ret = GetCountColorProfileElements( NULL, &count );
368         ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
369             GetLastError() );
370
371         ret = GetCountColorProfileElements( handle, NULL );
372         ok( !ret, "GetCountColorProfileElements() succeeded (%ld)\n",
373             GetLastError() );
374
375         /* Functional checks */
376
377         ret = GetCountColorProfileElements( handle, &count );
378         ok( ret && count == expect,
379             "GetCountColorProfileElements() failed (%ld)\n", GetLastError() );
380
381         CloseColorProfile( handle );
382     }
383 }
384
385 static void test_GetStandardColorSpaceProfileA()
386 {
387     BOOL ret;
388     DWORD size;
389     CHAR oldprofile[MAX_PATH];
390     CHAR newprofile[MAX_PATH];
391
392     /* Parameter checks */
393
394     ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, NULL );
395     ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
396
397     ret = GetStandardColorSpaceProfileA( machine, 0, newprofile, &size );
398     ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
399
400     size = 0;
401
402     ret = GetStandardColorSpaceProfileA( NULL, 0, NULL, &size );
403     ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
404
405     size = sizeof(newprofile);
406
407     ret = GetStandardColorSpaceProfileA( NULL, 0, newprofile, &size );
408     ok( !ret, "GetStandardColorSpaceProfileA() succeeded (%ld)\n", GetLastError() );
409
410     /* Functional checks */
411
412     if (standardprofile)
413     {
414         size = sizeof(oldprofile);
415
416         ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile, &size );
417         ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
418
419         ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, standardprofile );
420         ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
421
422         size = sizeof(newprofile);
423
424         ret = GetStandardColorSpaceProfileA( NULL, SPACE_RGB, newprofile, &size );
425         ok( ret, "GetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
426
427         ok( !lstrcmpiA( (LPSTR)&newprofile, standardprofile ), "Unexpected profile\n" );
428
429         ret = SetStandardColorSpaceProfileA( NULL, SPACE_RGB, oldprofile );
430         ok( ret, "SetStandardColorSpaceProfileA() failed (%ld)\n", GetLastError() );
431     }
432 }
433
434 static void test_GetStandardColorSpaceProfileW()
435 {
436     BOOL ret;
437     DWORD size;
438     WCHAR oldprofile[MAX_PATH];
439     WCHAR newprofile[MAX_PATH];
440
441     /* Parameter checks */
442
443     ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, NULL );
444     ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
445
446     ret = GetStandardColorSpaceProfileW( machineW, 0, newprofile, &size );
447     ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
448
449     size = 0;
450
451     ret = GetStandardColorSpaceProfileW( NULL, 0, NULL, &size );
452     ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
453
454     size = sizeof(newprofile);
455
456     ret = GetStandardColorSpaceProfileW( NULL, 0, newprofile, &size );
457     ok( !ret, "GetStandardColorSpaceProfileW() succeeded (%ld)\n", GetLastError() );
458
459     /* Functional checks */
460
461     if (standardprofileW)
462     {
463         size = sizeof(oldprofile);
464
465         ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile, &size );
466         ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
467
468         ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, standardprofileW );
469         ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
470
471         size = sizeof(newprofile);
472
473         ret = GetStandardColorSpaceProfileW( NULL, SPACE_RGB, newprofile, &size );
474         ok( ret, "GetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
475
476         ok( !lstrcmpiW( (LPWSTR)&newprofile, standardprofileW ), "Unexpected profile\n" );
477
478         ret = SetStandardColorSpaceProfileW( NULL, SPACE_RGB, oldprofile );
479         ok( ret, "SetStandardColorSpaceProfileW() failed (%ld)\n", GetLastError() );
480     }
481 }
482
483 static void test_InstallColorProfileA()
484 {
485     BOOL ret;
486
487     /* Parameter checks */
488
489     ret = InstallColorProfileA( NULL, NULL );
490     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
491
492     ret = InstallColorProfileA( machine, NULL );
493     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
494
495     ret = InstallColorProfileA( NULL, machine );
496     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
497
498     if (standardprofile)
499     {
500         ret = InstallColorProfileA( NULL, standardprofile );
501         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
502     }
503
504     /* Functional checks */
505
506     if (testprofile)
507     {
508         CHAR dest[MAX_PATH], base[MAX_PATH];
509         DWORD size = sizeof(dest);
510         CHAR slash[] = "\\";
511         HANDLE handle;
512
513         ret = InstallColorProfileA( NULL, testprofile );
514         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
515
516         ret = GetColorDirectoryA( NULL, dest, &size );
517         ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
518
519         MSCMS_basenameA( testprofile, base );
520
521         strcat( dest, slash );
522         strcat( dest, base );
523
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 );
528         
529         ret = UninstallColorProfileA( NULL, dest, TRUE );
530         ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
531     }
532 }
533
534 static void test_InstallColorProfileW()
535 {
536     BOOL ret;
537
538     /* Parameter checks */
539
540     ret = InstallColorProfileW( NULL, NULL );
541     ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
542
543     ret = InstallColorProfileW( machineW, NULL );
544     ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
545
546     ret = InstallColorProfileW( NULL, machineW );
547     ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
548
549     if (standardprofileW)
550     {
551         ret = InstallColorProfileW( NULL, standardprofileW );
552         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
553     }
554
555     /* Functional checks */
556
557     if (testprofileW)
558     {
559         WCHAR dest[MAX_PATH], base[MAX_PATH];
560         DWORD size = sizeof(dest);
561         WCHAR slash[] = { '\\', 0 };
562         HANDLE handle;
563
564         ret = InstallColorProfileW( NULL, testprofileW );
565         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
566
567         ret = GetColorDirectoryW( NULL, dest, &size );
568         ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
569
570         MSCMS_basenameW( testprofileW, base );
571
572         lstrcatW( dest, slash );
573         lstrcatW( dest, base );
574
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 );
579
580         ret = UninstallColorProfileW( NULL, dest, TRUE );
581         ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
582     }
583 }
584
585 static void test_IsColorProfileTagPresent()
586 {
587     if (standardprofile)
588     {
589         PROFILE profile;
590         HPROFILE handle;
591         BOOL ret, present;
592         TAGTYPE tag;
593
594         profile.dwType = PROFILE_FILENAME;
595         profile.pProfileData = standardprofile;
596         profile.cbDataSize = strlen(standardprofile);
597
598         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
599         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
600
601         /* Parameter checks */
602
603         tag = 0;
604
605         ret = IsColorProfileTagPresent( handle, tag, &present );
606         ok( !(ret && present), "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
607
608         tag = 0x63707274;  /* 'cprt' */
609
610         ret = IsColorProfileTagPresent( NULL, tag, &present );
611         ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
612
613         ret = IsColorProfileTagPresent( handle, tag, NULL );
614         ok( !ret, "IsColorProfileTagPresent() succeeded (%ld)\n", GetLastError() );
615
616         /* Functional checks */
617
618         ret = IsColorProfileTagPresent( handle, tag, &present );
619         ok( ret && present, "IsColorProfileTagPresent() failed (%ld)\n", GetLastError() );
620
621         CloseColorProfile( handle );
622     }
623 }
624
625 static void test_OpenColorProfileA()
626 {
627     PROFILE profile;
628     HPROFILE handle;
629     BOOL ret;
630
631     profile.dwType = PROFILE_FILENAME;
632     profile.pProfileData = NULL;
633     profile.cbDataSize = 0;
634
635     /* Parameter checks */
636
637     handle = OpenColorProfileA( NULL, 0, 0, 0 );
638     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
639
640     handle = OpenColorProfileA( &profile, 0, 0, 0 );
641     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
642
643     handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
644     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
645
646     handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
647     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
648
649     ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
650
651     if (standardprofile)
652     {
653         profile.pProfileData = standardprofile;
654         profile.cbDataSize = strlen(standardprofile);
655
656         handle = OpenColorProfileA( &profile, 0, 0, 0 );
657         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
658
659         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
660         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
661
662         handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
663         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
664
665         /* Functional checks */
666
667         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
668         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
669
670         ret = CloseColorProfile( handle );
671         ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
672     }
673 }
674
675 static void test_OpenColorProfileW()
676 {
677     PROFILE profile;
678     HPROFILE handle;
679     BOOL ret;
680
681     profile.dwType = PROFILE_FILENAME;
682     profile.pProfileData = NULL;
683     profile.cbDataSize = 0;
684
685     /* Parameter checks */
686
687     handle = OpenColorProfileW( NULL, 0, 0, 0 );
688     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
689
690     handle = OpenColorProfileW( &profile, 0, 0, 0 );
691     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
692
693     handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
694     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
695
696     handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
697     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
698
699     ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded\n" );
700
701     if (standardprofileW)
702     {
703         profile.pProfileData = standardprofileW;
704         profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
705
706         handle = OpenColorProfileW( &profile, 0, 0, 0 );
707         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
708
709         handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
710         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
711
712         handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
713         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
714
715         /* Functional checks */
716
717         handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
718         ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
719
720         ret = CloseColorProfile( handle );
721         ok( ret, "CloseColorProfile() failed (%ld)\n", GetLastError() );
722     }
723 }
724
725 static void test_SetColorProfileElement()
726 {
727     if (testprofile)
728     {
729         PROFILE profile;
730         HPROFILE handle;
731         DWORD size;
732         BOOL ret, ref;
733
734         TAGTYPE tag = 0x63707274;  /* 'cprt' */
735         static char data[] = "(c) The Wine Project";
736         static char buffer[51];
737
738         profile.dwType = PROFILE_FILENAME;
739         profile.pProfileData = testprofile;
740         profile.cbDataSize = strlen(testprofile);
741
742         /* Parameter checks */
743
744         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
745         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
746
747         ret = SetColorProfileElement( handle, tag, 0, &size, data );
748         ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
749
750         CloseColorProfile( handle );
751
752         handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
753         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
754
755         ret = SetColorProfileElement( NULL, 0, 0, NULL, NULL );
756         ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
757
758         ret = SetColorProfileElement( handle, 0, 0, NULL, NULL );
759         ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
760
761         ret = SetColorProfileElement( handle, tag, 0, NULL, NULL );
762         ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
763
764         ret = SetColorProfileElement( handle, tag, 0, &size, NULL );
765         ok( !ret, "SetColorProfileElement() succeeded (%ld)\n", GetLastError() );
766
767         /* Functional checks */
768
769         ret = SetColorProfileElement( handle, tag, 0, &size, data );
770         ok( ret, "SetColorProfileElement() failed (%ld)\n", GetLastError() );
771
772         size = sizeof(buffer);
773
774         ret = GetColorProfileElement( handle, tag, 0, &size, buffer, &ref );
775         ok( ret && size > 0, "GetColorProfileElement() failed (%ld)\n", GetLastError() );
776
777         ok( !memcmp( data, buffer, sizeof(data) ), "Unexpected tag data\n" );
778
779         CloseColorProfile( handle );
780     }
781 }
782
783 static void test_SetColorProfileHeader()
784 {
785     if (testprofile)
786     {
787         PROFILE profile;
788         HPROFILE handle;
789         BOOL ret;
790         PROFILEHEADER header;
791
792         profile.dwType = PROFILE_FILENAME;
793         profile.pProfileData = testprofile;
794         profile.cbDataSize = strlen(testprofile);
795
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;
817
818         /* Parameter checks */
819
820         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
821         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
822
823         ret = SetColorProfileHeader( handle, &header );
824         ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
825
826         CloseColorProfile( handle );
827
828         handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, OPEN_EXISTING );
829         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
830
831         ret = SetColorProfileHeader( NULL, NULL );
832         ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
833
834         ret = SetColorProfileHeader( handle, NULL );
835         ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
836
837         ret = SetColorProfileHeader( NULL, &header );
838         ok( !ret, "SetColorProfileHeader() succeeded (%ld)\n", GetLastError() );
839
840         /* Functional checks */
841
842         ret = SetColorProfileHeader( handle, &header );
843         ok( ret, "SetColorProfileHeader() failed (%ld)\n", GetLastError() );
844
845         ret = GetColorProfileHeader( handle, &header );
846         ok( ret, "GetColorProfileHeader() failed (%ld)\n", GetLastError() );
847
848         ok( !memcmp( &header, rgbheader, sizeof(rgbheader) ), "Unexpected header data\n" );
849
850         CloseColorProfile( handle );
851     }
852 }
853
854 static void test_UninstallColorProfileA()
855 {
856     BOOL ret;
857
858     /* Parameter checks */
859
860     ret = UninstallColorProfileA( NULL, NULL, FALSE );
861     ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
862
863     ret = UninstallColorProfileA( machine, NULL, FALSE );
864     ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
865
866     /* Functional checks */
867
868     if (testprofile)
869     {
870         CHAR dest[MAX_PATH], base[MAX_PATH];
871         DWORD size = sizeof(dest);
872         CHAR slash[] = "\\";
873         HANDLE handle;
874
875         ret = InstallColorProfileA( NULL, testprofile );
876         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
877
878         ret = GetColorDirectoryA( NULL, dest, &size );
879         ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
880
881         MSCMS_basenameA( testprofile, base );
882
883         strcat( dest, slash );
884         strcat( dest, base );
885
886         ret = UninstallColorProfileA( NULL, dest, TRUE );
887         ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
888
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 );
893     }
894 }
895
896 static void test_UninstallColorProfileW()
897 {
898     BOOL ret;
899
900     /* Parameter checks */
901
902     ret = UninstallColorProfileW( NULL, NULL, FALSE );
903     ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
904
905     ret = UninstallColorProfileW( machineW, NULL, FALSE );
906     ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
907
908     /* Functional checks */
909
910     if (testprofileW)
911     {
912         WCHAR dest[MAX_PATH], base[MAX_PATH];
913         DWORD size = sizeof(dest);
914         WCHAR slash[] = { '\\', 0 };
915         HANDLE handle;
916
917         ret = InstallColorProfileW( NULL, testprofileW );
918         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
919
920         ret = GetColorDirectoryW( NULL, dest, &size );
921         ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
922
923         MSCMS_basenameW( testprofileW, base );
924
925         lstrcatW( dest, slash );
926         lstrcatW( dest, base );
927
928         ret = UninstallColorProfileW( NULL, dest, TRUE );
929         ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
930
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 );
935     }
936 }
937
938 START_TEST(profile)
939 {
940     UINT len;
941     HANDLE 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];
946
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 );
953
954     if (handle != INVALID_HANDLE_VALUE)
955     {
956         standardprofile = profile1;
957         standardprofileW = profile1W;
958         CloseHandle( handle );
959     }
960
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 );
968
969     if (handle != INVALID_HANDLE_VALUE)
970     {
971         standardprofile = profile2;
972         standardprofileW = profile2W;
973         CloseHandle( handle );
974     }
975
976     /* If found, create a temporary copy for testing purposes */
977     if (standardprofile && GetTempPath( sizeof(path), path ))
978     {
979         if (GetTempFileName( path, "rgb", 0, file ))
980         {
981             if (CopyFileA( standardprofile, file, FALSE ))
982             {
983                 testprofile = (LPSTR)&file;
984
985                 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
986                 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
987
988                 testprofileW = (LPWSTR)&fileW;
989             }
990         }
991     }
992
993     test_GetColorDirectoryA();
994     test_GetColorDirectoryW();
995
996     test_GetColorProfileElement();
997     test_GetColorProfileElementTag();
998
999     test_GetColorProfileFromHandle();
1000     test_GetColorProfileHeader();
1001
1002     test_GetCountColorProfileElements();
1003
1004     test_GetStandardColorSpaceProfileA();
1005     test_GetStandardColorSpaceProfileW();
1006
1007     test_InstallColorProfileA();
1008     test_InstallColorProfileW();
1009
1010     test_IsColorProfileTagPresent();
1011
1012     test_OpenColorProfileA();
1013     test_OpenColorProfileW();
1014
1015     test_SetColorProfileElement();
1016     test_SetColorProfileHeader();
1017
1018     test_UninstallColorProfileA();
1019     test_UninstallColorProfileW();
1020
1021     /* Clean up */
1022     if (testprofile)
1023         DeleteFileA( testprofile );
1024 }