Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / mscms / tests / profile.c
1 /*
2  * Tests for color profile functions
3  *
4  * Copyright 2004 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 /* Two common places to find the standard color space profile */
36 static const char profile1[] =
37 "c:\\windows\\system\\color\\srgb color space profile.icm";
38 static const char profile2[] =
39 "c:\\windows\\system32\\spool\\drivers\\color\\srgb color space profile.icm";
40
41 static const WCHAR profile1W[] =
42 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m',
43   '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
44   's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
45 static const WCHAR profile2W[] =
46 { 'c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m','3','2',
47   '\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
48   '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
49   's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
50
51 static LPSTR standardprofile;
52 static LPWSTR standardprofileW;
53
54 static LPSTR testprofile;
55 static LPWSTR testprofileW;
56
57 #define IS_SEPARATOR(ch)  ((ch) == '\\' || (ch) == '/')
58
59 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
60 {
61     INT i = strlen( path );
62
63     while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
64     strcpy( name, &path[i] );
65 }
66
67 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
68 {
69     INT i = lstrlenW( path );
70
71     while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
72     lstrcpyW( name, &path[i] );
73 }
74
75 static void test_GetColorDirectoryA()
76 {
77     BOOL ret;
78     DWORD size;
79     char buffer[MAX_PATH];
80
81     /* Parameter checks */
82
83     size = 0;
84
85     ret = GetColorDirectoryA( NULL, NULL, &size );
86     ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
87
88     size = 0;
89
90     ret = GetColorDirectoryA( NULL, buffer, &size );
91     ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
92
93     size = 1;
94
95     ret = GetColorDirectoryA( NULL, buffer, &size );
96     ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
97
98     size = sizeof(buffer);
99
100     ret = GetColorDirectoryA( machine, buffer, &size );
101     ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
102
103     /* Functional checks */
104
105     size = sizeof(buffer);
106
107     ret = GetColorDirectoryA( NULL, buffer, &size );
108     ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
109 }
110
111 static void test_GetColorDirectoryW()
112 {
113     BOOL ret;
114     DWORD size;
115     WCHAR buffer[MAX_PATH];
116
117     /* Parameter checks */
118
119     size = 0;
120
121     ret = GetColorDirectoryW( NULL, NULL, &size );
122     ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
123
124     size = 0;
125
126     ret = GetColorDirectoryW( NULL, buffer, &size );
127     ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
128
129     size = 1;
130
131     ret = GetColorDirectoryW( NULL, buffer, &size );
132     ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
133
134     size = sizeof(buffer);
135
136     ret = GetColorDirectoryW( machineW, buffer, &size );
137     ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
138
139     /* Functional checks */
140
141     size = sizeof(buffer);
142
143     ret = GetColorDirectoryW( NULL, buffer, &size );
144     ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
145 }
146
147 static void test_InstallColorProfileA()
148 {
149     BOOL ret;
150
151     /* Parameter checks */
152
153     ret = InstallColorProfileA( NULL, NULL );
154     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
155
156     ret = InstallColorProfileA( machine, NULL );
157     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
158
159     ret = InstallColorProfileA( NULL, machine );
160     ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
161
162     if (standardprofile)
163     {
164         ret = InstallColorProfileA( NULL, standardprofile );
165         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
166     }
167
168     /* Functional checks */
169
170     if (testprofile)
171     {
172         CHAR dest[MAX_PATH], base[MAX_PATH];
173         DWORD size = sizeof(dest);
174         CHAR slash[] = "\\";
175         HANDLE handle;
176
177         ret = InstallColorProfileA( NULL, testprofile );
178         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
179
180         ret = GetColorDirectoryA( NULL, dest, &size );
181         ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
182
183         MSCMS_basenameA( testprofile, base );
184
185         strcat( dest, slash );
186         strcat( dest, base );
187
188         /* Check if the profile is really there */ 
189         handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
190         ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
191         CloseHandle( handle );
192         
193         ret = UninstallColorProfileA( NULL, dest, TRUE );
194         ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
195     }
196 }
197
198 static void test_InstallColorProfileW()
199 {
200     BOOL ret;
201
202     /* Parameter checks */
203
204     ret = InstallColorProfileW( NULL, NULL );
205     ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
206
207     ret = InstallColorProfileW( machineW, NULL );
208     ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
209
210     ret = InstallColorProfileW( NULL, machineW );
211     ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
212
213     if (standardprofileW)
214     {
215         ret = InstallColorProfileW( NULL, standardprofileW );
216         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
217     }
218
219     /* Functional checks */
220
221     if (testprofileW)
222     {
223         WCHAR dest[MAX_PATH], base[MAX_PATH];
224         DWORD size = sizeof(dest);
225         WCHAR slash[] = { '\\', 0 };
226         HANDLE handle;
227
228         ret = InstallColorProfileW( NULL, testprofileW );
229         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
230
231         ret = GetColorDirectoryW( NULL, dest, &size );
232         ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
233
234         MSCMS_basenameW( testprofileW, base );
235
236         lstrcatW( dest, slash );
237         lstrcatW( dest, base );
238
239         /* Check if the profile is really there */
240         handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
241         ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
242         CloseHandle( handle );
243
244         ret = UninstallColorProfileW( NULL, dest, TRUE );
245         ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
246     }
247 }
248
249 static void test_OpenColorProfileA()
250 {
251     PROFILE profile;
252     HPROFILE handle;
253
254     profile.dwType = PROFILE_FILENAME;
255     profile.pProfileData = NULL;
256     profile.cbDataSize = 0;
257
258     /* Parameter checks */
259
260     handle = OpenColorProfileA( NULL, 0, 0, 0 );
261     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
262
263     handle = OpenColorProfileA( &profile, 0, 0, 0 );
264     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
265
266     handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
267     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
268
269     handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
270     ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
271
272     ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded" );
273
274     if (standardprofile)
275     {
276         profile.pProfileData = standardprofile;
277         profile.cbDataSize = strlen(standardprofile);
278
279         handle = OpenColorProfileA( &profile, 0, 0, 0 );
280         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
281
282         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
283         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
284
285         handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
286         ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
287
288         /* Functional checks */
289
290         handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
291         ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
292
293         ok( CloseColorProfile( handle ), "CloseColorProfile() failed (%ld)\n", GetLastError() );
294     }
295 }
296
297 static void test_OpenColorProfileW()
298 {
299     PROFILE profile;
300     HPROFILE handle;
301
302     profile.dwType = PROFILE_FILENAME;
303     profile.pProfileData = NULL;
304     profile.cbDataSize = 0;
305
306     /* Parameter checks */
307
308     handle = OpenColorProfileW( NULL, 0, 0, 0 );
309     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
310
311     handle = OpenColorProfileW( &profile, 0, 0, 0 );
312     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
313
314     handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
315     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
316
317     handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
318     ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
319
320     ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded" );
321
322     if (standardprofileW)
323     {
324         profile.pProfileData = standardprofileW;
325         profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
326
327         handle = OpenColorProfileW( &profile, 0, 0, 0 );
328         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
329
330         handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
331         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
332
333         handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
334         ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
335
336         /* Functional checks */
337
338         handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
339         ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
340
341         ok( CloseColorProfile( handle ), "CloseColorProfile() failed (%ld)\n", GetLastError() );
342     }
343 }
344
345 static void test_UninstallColorProfileA()
346 {
347     BOOL ret;
348
349     /* Parameter checks */
350
351     ret = UninstallColorProfileA( NULL, NULL, FALSE );
352     ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
353
354     ret = UninstallColorProfileA( machine, NULL, FALSE );
355     ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
356
357     /* Functional checks */
358
359     if (testprofile)
360     {
361         CHAR dest[MAX_PATH], base[MAX_PATH];
362         DWORD size = sizeof(dest);
363         CHAR slash[] = "\\";
364         HANDLE handle;
365
366         ret = InstallColorProfileA( NULL, testprofile );
367         ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
368
369         ret = GetColorDirectoryA( NULL, dest, &size );
370         ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
371
372         MSCMS_basenameA( testprofile, base );
373
374         strcat( dest, slash );
375         strcat( dest, base );
376
377         ret = UninstallColorProfileA( NULL, dest, TRUE );
378         ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
379
380         /* Check if the profile is really gone */
381         handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
382         ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
383         CloseHandle( handle );
384     }
385 }
386
387 static void test_UninstallColorProfileW()
388 {
389     BOOL ret;
390
391     /* Parameter checks */
392
393     ret = UninstallColorProfileW( NULL, NULL, FALSE );
394     ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
395
396     ret = UninstallColorProfileW( machineW, NULL, FALSE );
397     ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
398
399     /* Functional checks */
400
401     if (testprofileW)
402     {
403         WCHAR dest[MAX_PATH], base[MAX_PATH];
404         DWORD size = sizeof(dest);
405         WCHAR slash[] = { '\\', 0 };
406         HANDLE handle;
407
408         ret = InstallColorProfileW( NULL, testprofileW );
409         ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
410
411         ret = GetColorDirectoryW( NULL, dest, &size );
412         ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
413
414         MSCMS_basenameW( testprofileW, base );
415
416         lstrcatW( dest, slash );
417         lstrcatW( dest, base );
418
419         ret = UninstallColorProfileW( NULL, dest, TRUE );
420         ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
421
422         /* Check if the profile is really gone */
423         handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
424         ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
425         CloseHandle( handle );
426     }
427 }
428
429 START_TEST(profile)
430 {
431     UINT len;
432     HANDLE handle;
433     char path[MAX_PATH], file[MAX_PATH];
434     WCHAR fileW[MAX_PATH];
435
436     /* See if we can find the standard color profile */
437     handle = CreateFileA( (LPCSTR)&profile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
438
439     if (handle != INVALID_HANDLE_VALUE)
440     {
441         standardprofile = (LPSTR)&profile1;
442         standardprofileW = (LPWSTR)&profile1W;
443         CloseHandle( handle );
444     }
445
446     handle = CreateFileA( (LPCSTR)&profile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
447
448     if (handle != INVALID_HANDLE_VALUE)
449     {
450         standardprofile = (LPSTR)&profile2;
451         standardprofileW = (LPWSTR)&profile2W;
452         CloseHandle( handle );
453     }
454
455     /* If found, create a temporary copy for testing purposes */
456     if (standardprofile && GetTempPath( sizeof(path), path ))
457     {
458         if (GetTempFileName( path, "rgb", 0, file ))
459         {
460             if (CopyFileA( standardprofile, file, FALSE ))
461             {
462
463                 testprofile = (LPSTR)&file;
464
465                 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
466                 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
467
468                 testprofileW = (LPWSTR)&fileW;
469             }
470         }
471     }
472
473     test_GetColorDirectoryA();
474     test_GetColorDirectoryW();
475
476     test_InstallColorProfileA();
477     test_InstallColorProfileW();
478
479     test_OpenColorProfileA();
480     test_OpenColorProfileW();
481
482     test_UninstallColorProfileA();
483     test_UninstallColorProfileW();
484
485     /* Clean up */
486     if (testprofile)
487         DeleteFileA( testprofile );
488 }