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
30 #include "wine/test.h"
32 static const char machine[] = "dummy";
33 static const WCHAR machineW[] = { 'd','u','m','m','y',0 };
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";
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 };
51 static LPSTR standardprofile;
52 static LPWSTR standardprofileW;
54 static LPSTR testprofile;
55 static LPWSTR testprofileW;
57 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
59 static void MSCMS_basenameA( LPCSTR path, LPSTR name )
61 INT i = strlen( path );
63 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
64 strcpy( name, &path[i] );
67 static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
69 INT i = lstrlenW( path );
71 while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
72 lstrcpyW( name, &path[i] );
75 static void test_GetColorDirectoryA()
79 char buffer[MAX_PATH];
81 /* Parameter checks */
85 ret = GetColorDirectoryA( NULL, NULL, &size );
86 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
90 ret = GetColorDirectoryA( NULL, buffer, &size );
91 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
95 ret = GetColorDirectoryA( NULL, buffer, &size );
96 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
98 size = sizeof(buffer);
100 ret = GetColorDirectoryA( machine, buffer, &size );
101 ok( !ret, "GetColorDirectoryA() succeeded (%ld)\n", GetLastError() );
103 /* Functional checks */
105 size = sizeof(buffer);
107 ret = GetColorDirectoryA( NULL, buffer, &size );
108 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
111 static void test_GetColorDirectoryW()
115 WCHAR buffer[MAX_PATH];
117 /* Parameter checks */
121 ret = GetColorDirectoryW( NULL, NULL, &size );
122 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
126 ret = GetColorDirectoryW( NULL, buffer, &size );
127 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
131 ret = GetColorDirectoryW( NULL, buffer, &size );
132 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
134 size = sizeof(buffer);
136 ret = GetColorDirectoryW( machineW, buffer, &size );
137 ok( !ret, "GetColorDirectoryW() succeeded (%ld)\n", GetLastError() );
139 /* Functional checks */
141 size = sizeof(buffer);
143 ret = GetColorDirectoryW( NULL, buffer, &size );
144 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
147 static void test_InstallColorProfileA()
151 /* Parameter checks */
153 ret = InstallColorProfileA( NULL, NULL );
154 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
156 ret = InstallColorProfileA( machine, NULL );
157 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
159 ret = InstallColorProfileA( NULL, machine );
160 ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
164 ret = InstallColorProfileA( NULL, standardprofile );
165 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
168 /* Functional checks */
172 CHAR dest[MAX_PATH], base[MAX_PATH];
173 DWORD size = sizeof(dest);
177 ret = InstallColorProfileA( NULL, testprofile );
178 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
180 ret = GetColorDirectoryA( NULL, dest, &size );
181 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
183 MSCMS_basenameA( testprofile, base );
185 strcat( dest, slash );
186 strcat( dest, base );
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 );
193 ret = UninstallColorProfileA( NULL, dest, TRUE );
194 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
198 static void test_InstallColorProfileW()
202 /* Parameter checks */
204 ret = InstallColorProfileW( NULL, NULL );
205 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
207 ret = InstallColorProfileW( machineW, NULL );
208 ok( !ret, "InstallColorProfileW() succeeded (%ld)\n", GetLastError() );
210 ret = InstallColorProfileW( NULL, machineW );
211 ok( !ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
213 if (standardprofileW)
215 ret = InstallColorProfileW( NULL, standardprofileW );
216 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
219 /* Functional checks */
223 WCHAR dest[MAX_PATH], base[MAX_PATH];
224 DWORD size = sizeof(dest);
225 WCHAR slash[] = { '\\', 0 };
228 ret = InstallColorProfileW( NULL, testprofileW );
229 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
231 ret = GetColorDirectoryW( NULL, dest, &size );
232 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
234 MSCMS_basenameW( testprofileW, base );
236 lstrcatW( dest, slash );
237 lstrcatW( dest, base );
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 );
244 ret = UninstallColorProfileW( NULL, dest, TRUE );
245 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
249 static void test_OpenColorProfileA()
254 profile.dwType = PROFILE_FILENAME;
255 profile.pProfileData = NULL;
256 profile.cbDataSize = 0;
258 /* Parameter checks */
260 handle = OpenColorProfileA( NULL, 0, 0, 0 );
261 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
263 handle = OpenColorProfileA( &profile, 0, 0, 0 );
264 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
266 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
267 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
269 handle = OpenColorProfileA( &profile, PROFILE_READWRITE, 0, 0 );
270 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
272 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded" );
276 profile.pProfileData = standardprofile;
277 profile.cbDataSize = strlen(standardprofile);
279 handle = OpenColorProfileA( &profile, 0, 0, 0 );
280 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
282 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, 0 );
283 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
285 handle = OpenColorProfileA( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
286 ok( handle == NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
288 /* Functional checks */
290 handle = OpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
291 ok( handle != NULL, "OpenColorProfileA() failed (%ld)\n", GetLastError() );
293 ok( CloseColorProfile( handle ), "CloseColorProfile() failed (%ld)\n", GetLastError() );
297 static void test_OpenColorProfileW()
302 profile.dwType = PROFILE_FILENAME;
303 profile.pProfileData = NULL;
304 profile.cbDataSize = 0;
306 /* Parameter checks */
308 handle = OpenColorProfileW( NULL, 0, 0, 0 );
309 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
311 handle = OpenColorProfileW( &profile, 0, 0, 0 );
312 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
314 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
315 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
317 handle = OpenColorProfileW( &profile, PROFILE_READWRITE, 0, 0 );
318 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
320 ok ( !CloseColorProfile( NULL ), "CloseColorProfile() succeeded" );
322 if (standardprofileW)
324 profile.pProfileData = standardprofileW;
325 profile.cbDataSize = lstrlenW(standardprofileW) * sizeof(WCHAR);
327 handle = OpenColorProfileW( &profile, 0, 0, 0 );
328 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
330 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, 0 );
331 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
333 handle = OpenColorProfileW( &profile, PROFILE_READ|PROFILE_READWRITE, 0, 0 );
334 ok( handle == NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
336 /* Functional checks */
338 handle = OpenColorProfileW( &profile, PROFILE_READ, 0, OPEN_EXISTING );
339 ok( handle != NULL, "OpenColorProfileW() failed (%ld)\n", GetLastError() );
341 ok( CloseColorProfile( handle ), "CloseColorProfile() failed (%ld)\n", GetLastError() );
345 static void test_UninstallColorProfileA()
349 /* Parameter checks */
351 ret = UninstallColorProfileA( NULL, NULL, FALSE );
352 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
354 ret = UninstallColorProfileA( machine, NULL, FALSE );
355 ok( !ret, "UninstallColorProfileA() succeeded (%ld)\n", GetLastError() );
357 /* Functional checks */
361 CHAR dest[MAX_PATH], base[MAX_PATH];
362 DWORD size = sizeof(dest);
366 ret = InstallColorProfileA( NULL, testprofile );
367 ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
369 ret = GetColorDirectoryA( NULL, dest, &size );
370 ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
372 MSCMS_basenameA( testprofile, base );
374 strcat( dest, slash );
375 strcat( dest, base );
377 ret = UninstallColorProfileA( NULL, dest, TRUE );
378 ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
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 );
387 static void test_UninstallColorProfileW()
391 /* Parameter checks */
393 ret = UninstallColorProfileW( NULL, NULL, FALSE );
394 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
396 ret = UninstallColorProfileW( machineW, NULL, FALSE );
397 ok( !ret, "UninstallColorProfileW() succeeded (%ld)\n", GetLastError() );
399 /* Functional checks */
403 WCHAR dest[MAX_PATH], base[MAX_PATH];
404 DWORD size = sizeof(dest);
405 WCHAR slash[] = { '\\', 0 };
408 ret = InstallColorProfileW( NULL, testprofileW );
409 ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
411 ret = GetColorDirectoryW( NULL, dest, &size );
412 ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
414 MSCMS_basenameW( testprofileW, base );
416 lstrcatW( dest, slash );
417 lstrcatW( dest, base );
419 ret = UninstallColorProfileW( NULL, dest, TRUE );
420 ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
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 );
433 char path[MAX_PATH], file[MAX_PATH];
434 WCHAR fileW[MAX_PATH];
436 /* See if we can find the standard color profile */
437 handle = CreateFileA( (LPCSTR)&profile1, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
439 if (handle != INVALID_HANDLE_VALUE)
441 standardprofile = (LPSTR)&profile1;
442 standardprofileW = (LPWSTR)&profile1W;
443 CloseHandle( handle );
446 handle = CreateFileA( (LPCSTR)&profile2, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
448 if (handle != INVALID_HANDLE_VALUE)
450 standardprofile = (LPSTR)&profile2;
451 standardprofileW = (LPWSTR)&profile2W;
452 CloseHandle( handle );
455 /* If found, create a temporary copy for testing purposes */
456 if (standardprofile && GetTempPath( sizeof(path), path ))
458 if (GetTempFileName( path, "rgb", 0, file ))
460 if (CopyFileA( standardprofile, file, FALSE ))
463 testprofile = (LPSTR)&file;
465 len = MultiByteToWideChar( CP_ACP, 0, testprofile, -1, NULL, 0 );
466 MultiByteToWideChar( CP_ACP, 0, testprofile, -1, fileW, len );
468 testprofileW = (LPWSTR)&fileW;
473 test_GetColorDirectoryA();
474 test_GetColorDirectoryW();
476 test_InstallColorProfileA();
477 test_InstallColorProfileW();
479 test_OpenColorProfileA();
480 test_OpenColorProfileW();
482 test_UninstallColorProfileA();
483 test_UninstallColorProfileW();
487 DeleteFileA( testprofile );