Commit dca6bdf5 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

Improve {Uninstall,Install}ColorProfile{A,W}.

Better tests for these functions.
parent 53e57999
...@@ -34,6 +34,16 @@ ...@@ -34,6 +34,16 @@
#include "lcms_api.h" #include "lcms_api.h"
#undef LCMS_API_FUNCTION #undef LCMS_API_FUNCTION
#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
static void MSCMS_basename( LPCWSTR path, LPWSTR name )
{
INT i = lstrlenW( path );
while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
lstrcpyW( name, &path[i] );
}
WINE_DEFAULT_DEBUG_CHANNEL(mscms); WINE_DEFAULT_DEBUG_CHANNEL(mscms);
BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size ) BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
...@@ -62,7 +72,6 @@ BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size ) ...@@ -62,7 +72,6 @@ BOOL WINAPI GetColorDirectoryA( PCSTR machine, PSTR buffer, PDWORD size )
HeapFree( GetProcessHeap(), 0, bufferW ); HeapFree( GetProcessHeap(), 0, bufferW );
} }
return ret; return ret;
} }
...@@ -83,7 +92,7 @@ BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size ) ...@@ -83,7 +92,7 @@ BOOL WINAPI GetColorDirectoryW( PCWSTR machine, PWSTR buffer, PDWORD size )
if (len <= *size) if (len <= *size)
{ {
lstrcatW( buffer, colordir ); lstrcpyW( buffer, colordir );
return TRUE; return TRUE;
} }
...@@ -111,27 +120,54 @@ BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile ) ...@@ -111,27 +120,54 @@ BOOL WINAPI InstallColorProfileA( PCSTR machine, PCSTR profile )
ret = InstallColorProfileW( NULL, profileW ); ret = InstallColorProfileW( NULL, profileW );
HeapFree( GetProcessHeap(), 0, profileW ); HeapFree( GetProcessHeap(), 0, profileW );
} }
return ret; return ret;
} }
BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile ) BOOL WINAPI InstallColorProfileW( PCWSTR machine, PCWSTR profile )
{ {
FIXME( "( %s ) stub\n", debugstr_w(profile) ); WCHAR dest[MAX_PATH], base[MAX_PATH];
DWORD size = sizeof(dest);
static const WCHAR slash[] = { '\\', 0 };
TRACE( "( %s )\n", debugstr_w(profile) );
if (machine || !profile) return FALSE; if (machine || !profile) return FALSE;
return FALSE; if (!GetColorDirectoryW( machine, dest, &size )) return FALSE;
MSCMS_basename( profile, base );
lstrcatW( dest, slash );
lstrcatW( dest, base );
/* Is source equal to destination? */
if (!lstrcmpW( profile, dest )) return TRUE;
return CopyFileW( profile, dest, TRUE );
} }
BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete ) BOOL WINAPI UninstallColorProfileA( PCSTR machine, PCSTR profile, BOOL delete )
{ {
UINT len;
LPWSTR profileW;
BOOL ret = FALSE;
TRACE( "( %s )\n", debugstr_a(profile) );
if (machine || !profile) return FALSE; if (machine || !profile) return FALSE;
if (delete) len = MultiByteToWideChar( CP_ACP, 0, profile, -1, NULL, 0 );
return DeleteFileA( profile ); profileW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
return TRUE; if (profileW)
{
MultiByteToWideChar( CP_ACP, 0, profile, -1, profileW, len );
ret = UninstallColorProfileW( NULL, profileW , delete );
HeapFree( GetProcessHeap(), 0, profileW );
}
return ret;
} }
BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete ) BOOL WINAPI UninstallColorProfileW( PCWSTR machine, PCWSTR profile, BOOL delete )
...@@ -175,7 +211,6 @@ HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing ...@@ -175,7 +211,6 @@ HPROFILE WINAPI OpenColorProfileA( PPROFILE profile, DWORD access, DWORD sharing
HeapFree( GetProcessHeap(), 0, profileW.pProfileData ); HeapFree( GetProcessHeap(), 0, profileW.pProfileData );
} }
} }
return handle; return handle;
} }
......
...@@ -48,11 +48,29 @@ static const WCHAR profile2W[] = ...@@ -48,11 +48,29 @@ static const WCHAR profile2W[] =
'\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ', '\\','c','o','l','o','r','\\','s','r','g','b',' ','c','o','l','o','r',' ',
's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 }; 's','p','a','c','e',' ','p','r','o','f','i','l','e','.','i','c','m',0 };
static LPSTR standardprofile = NULL; static LPSTR standardprofile;
static LPWSTR standardprofileW = NULL; static LPWSTR standardprofileW;
static LPSTR testprofile = NULL; static LPSTR testprofile;
static LPWSTR testprofileW = NULL; static LPWSTR testprofileW;
#define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
static void MSCMS_basenameA( LPCSTR path, LPSTR name )
{
INT i = strlen( path );
while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
strcpy( name, &path[i] );
}
static void MSCMS_basenameW( LPCWSTR path, LPWSTR name )
{
INT i = lstrlenW( path );
while (i > 0 && !IS_SEPARATOR(path[i - 1])) i--;
lstrcpyW( name, &path[i] );
}
static void test_GetColorDirectoryA() static void test_GetColorDirectoryA()
{ {
...@@ -139,7 +157,7 @@ static void test_InstallColorProfileA() ...@@ -139,7 +157,7 @@ static void test_InstallColorProfileA()
ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() ); ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
ret = InstallColorProfileA( NULL, machine ); ret = InstallColorProfileA( NULL, machine );
ok( !ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() ); ok( !ret, "InstallColorProfileA() succeeded (%ld)\n", GetLastError() );
if (standardprofile) if (standardprofile)
{ {
...@@ -151,10 +169,28 @@ static void test_InstallColorProfileA() ...@@ -151,10 +169,28 @@ static void test_InstallColorProfileA()
if (testprofile) if (testprofile)
{ {
CHAR dest[MAX_PATH], base[MAX_PATH];
DWORD size = sizeof(dest);
CHAR slash[] = "\\";
HANDLE handle;
ret = InstallColorProfileA( NULL, testprofile ); ret = InstallColorProfileA( NULL, testprofile );
ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() ); ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
ret = UninstallColorProfileA( NULL, testprofile, TRUE ); ret = GetColorDirectoryA( NULL, dest, &size );
ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
MSCMS_basenameA( testprofile, base );
strcat( dest, slash );
strcat( dest, base );
/* Check if the profile is really there */
handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
CloseHandle( handle );
ret = UninstallColorProfileA( NULL, dest, TRUE );
ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() ); ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
} }
} }
...@@ -184,10 +220,28 @@ static void test_InstallColorProfileW() ...@@ -184,10 +220,28 @@ static void test_InstallColorProfileW()
if (testprofileW) if (testprofileW)
{ {
WCHAR dest[MAX_PATH], base[MAX_PATH];
DWORD size = sizeof(dest);
WCHAR slash[] = { '\\', 0 };
HANDLE handle;
ret = InstallColorProfileW( NULL, testprofileW ); ret = InstallColorProfileW( NULL, testprofileW );
ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() ); ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
ret = UninstallColorProfileW( NULL, testprofileW, TRUE ); ret = GetColorDirectoryW( NULL, dest, &size );
ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
MSCMS_basenameW( testprofileW, base );
lstrcatW( dest, slash );
lstrcatW( dest, base );
/* Check if the profile is really there */
handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
ok( handle != INVALID_HANDLE_VALUE, "Couldn't find the profile (%ld)\n", GetLastError() );
CloseHandle( handle );
ret = UninstallColorProfileW( NULL, dest, TRUE );
ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() ); ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
} }
} }
...@@ -304,11 +358,29 @@ static void test_UninstallColorProfileA() ...@@ -304,11 +358,29 @@ static void test_UninstallColorProfileA()
if (testprofile) if (testprofile)
{ {
CHAR dest[MAX_PATH], base[MAX_PATH];
DWORD size = sizeof(dest);
CHAR slash[] = "\\";
HANDLE handle;
ret = InstallColorProfileA( NULL, testprofile ); ret = InstallColorProfileA( NULL, testprofile );
ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() ); ok( ret, "InstallColorProfileA() failed (%ld)\n", GetLastError() );
ret = UninstallColorProfileA( NULL, testprofile, TRUE ); ret = GetColorDirectoryA( NULL, dest, &size );
ok( ret, "GetColorDirectoryA() failed (%ld)\n", GetLastError() );
MSCMS_basenameA( testprofile, base );
strcat( dest, slash );
strcat( dest, base );
ret = UninstallColorProfileA( NULL, dest, TRUE );
ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() ); ok( ret, "UninstallColorProfileA() failed (%ld)\n", GetLastError() );
/* Check if the profile is really gone */
handle = CreateFileA( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
CloseHandle( handle );
} }
} }
...@@ -328,11 +400,29 @@ static void test_UninstallColorProfileW() ...@@ -328,11 +400,29 @@ static void test_UninstallColorProfileW()
if (testprofileW) if (testprofileW)
{ {
WCHAR dest[MAX_PATH], base[MAX_PATH];
DWORD size = sizeof(dest);
WCHAR slash[] = { '\\', 0 };
HANDLE handle;
ret = InstallColorProfileW( NULL, testprofileW ); ret = InstallColorProfileW( NULL, testprofileW );
ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() ); ok( ret, "InstallColorProfileW() failed (%ld)\n", GetLastError() );
ret = UninstallColorProfileW( NULL, testprofileW, TRUE ); ret = GetColorDirectoryW( NULL, dest, &size );
ok( ret, "GetColorDirectoryW() failed (%ld)\n", GetLastError() );
MSCMS_basenameW( testprofileW, base );
lstrcatW( dest, slash );
lstrcatW( dest, base );
ret = UninstallColorProfileW( NULL, dest, TRUE );
ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() ); ok( ret, "UninstallColorProfileW() failed (%ld)\n", GetLastError() );
/* Check if the profile is really gone */
handle = CreateFileW( dest, 0 , 0, NULL, OPEN_EXISTING, 0, NULL );
ok( handle == INVALID_HANDLE_VALUE, "Found the profile (%ld)\n", GetLastError() );
CloseHandle( handle );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment