icm.c 9.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 * Tests for ICM functions
 *
 * Copyright (C) 2005, 2008 Hans Leidekker
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"

#include "wine/test.h"

static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};

static void test_GetICMProfileA( HDC dc )
{
    BOOL ret;
    DWORD size, error;
    char filename[MAX_PATH];

38
    SetLastError( 0xdeadbeef );
39
    ret = GetICMProfileA( NULL, NULL, NULL );
40 41
    if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
    {
42
        win_skip( "GetICMProfileA is not implemented\n" );
43 44
        return;
    }
45 46 47 48 49 50 51 52 53 54 55 56 57 58
    ok( !ret, "GetICMProfileA succeeded\n" );

    ret = GetICMProfileA( dc, NULL, NULL );
    ok( !ret, "GetICMProfileA succeeded\n" );

    size = MAX_PATH;
    ret = GetICMProfileA( dc, &size, NULL );
    ok( !ret, "GetICMProfileA succeeded\n" );

    size = MAX_PATH;
    ret = GetICMProfileA( NULL, &size, filename );
    ok( !ret, "GetICMProfileA succeeded\n" );

    size = 0;
59
    filename[0] = 0;
60 61 62 63 64
    SetLastError(0xdeadbeef);
    ret = GetICMProfileA( dc, &size, filename );
    error = GetLastError();
    ok( !ret, "GetICMProfileA succeeded\n" );
    ok( size, "expected size > 0\n" );
65
    ok( filename[0] == 0, "Expected filename to be empty\n" );
66
    ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
67

68 69
    ret = GetICMProfileA( dc, NULL, filename );
    ok( !ret, "GetICMProfileA succeeded\n" );
70 71 72 73 74 75 76 77 78 79 80 81 82 83

    size = MAX_PATH;
    ret = GetICMProfileA( dc, &size, filename );
    ok( ret, "GetICMProfileA failed %d\n", GetLastError() );

    trace( "%s\n", filename );
}

static void test_GetICMProfileW( HDC dc )
{
    BOOL ret;
    DWORD size, error;
    WCHAR filename[MAX_PATH];

84
    SetLastError( 0xdeadbeef );
85
    ret = GetICMProfileW( NULL, NULL, NULL );
86 87
    if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
    {
88
        win_skip( "GetICMProfileW is not implemented\n" );
89 90
        return;
    }
91 92 93 94 95
    ok( !ret, "GetICMProfileW succeeded\n" );

    ret = GetICMProfileW( dc, NULL, NULL );
    ok( !ret, "GetICMProfileW succeeded\n" );

96 97 98 99 100 101 102
    if (0)
    {
        /* Vista crashes */
        size = MAX_PATH;
        ret = GetICMProfileW( dc, &size, NULL );
        ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
    }
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

    ret = GetICMProfileW( dc, NULL, filename );
    ok( !ret, "GetICMProfileW succeeded\n" );

    size = MAX_PATH;
    ret = GetICMProfileW( NULL, &size, filename );
    ok( !ret, "GetICMProfileW succeeded\n" );

    size = 0;
    SetLastError(0xdeadbeef);
    ret = GetICMProfileW( dc, &size, filename );
    error = GetLastError();
    ok( !ret, "GetICMProfileW succeeded\n" );
    ok( size, "expected size > 0\n" );
    ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );

    size = MAX_PATH;
    ret = GetICMProfileW( dc, &size, filename );
    ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
}

static void test_SetICMMode( HDC dc )
{
    INT ret, knob, save;
127 128 129 130 131 132
    BOOL impl;

    SetLastError( 0xdeadbeef );
    impl = GetICMProfileA( NULL, NULL, NULL );
    if ( !impl && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
    {
133
        win_skip( "On NT4 where SetICMMode is not implemented but this is not advertised\n" );
134 135
        return;
    }
136

137
    SetLastError( 0xdeadbeef );
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    ret = SetICMMode( NULL, 0 );
    ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );

    ret = SetICMMode( dc, -1 );
    ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );

    save = SetICMMode( dc, ICM_QUERY );
    ok( save == ICM_ON || save == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );

    if (save == ICM_ON) knob = ICM_OFF; else knob = ICM_ON;

    ret = SetICMMode( dc, knob );
    todo_wine ok( ret, "SetICMMode failed (%d)\n", GetLastError() );

    ret = SetICMMode( dc, ICM_QUERY );
    todo_wine ok( ret == knob, "SetICMMode failed (%d)\n", GetLastError() );

    ret = SetICMMode( dc, save );
    ok( ret, "SetICMMode failed (%d)\n", GetLastError() );

158
    SetLastError( 0xdeadbeef );
159
    dc = CreateDCW( displayW, NULL, NULL, NULL );
160 161
    if ( !dc && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
    {
162
        win_skip( "CreateDCW is not implemented\n" );
163 164
        return;
    }
165 166 167 168 169 170 171 172
    ok( dc != NULL, "CreateDCW failed (%d)\n", GetLastError() );

    ret = SetICMMode( dc, ICM_QUERY );
    ok( ret == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );

    DeleteDC( dc );
}

173
static INT CALLBACK enum_profiles_callbackA( LPSTR filename, LPARAM lparam )
174 175 176 177 178 179 180 181 182 183 184 185 186
{
    trace("%s\n", filename);
    return 1;
}

static void test_EnumICMProfilesA( HDC dc )
{
    INT ret;

    ret = EnumICMProfilesA( NULL, NULL, 0 );
    ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret);

    ret = EnumICMProfilesA( dc, enum_profiles_callbackA, 0 );
187 188
    ok(ret == -1 || ret == 1 || broken(ret == 0) /* nt4 */,
       "expected -1 or 1, got %d\n", ret);
189

190 191
    ret = EnumICMProfilesA( dc, NULL, 0 );
    ok(ret == -1 || broken(ret == 0) /* nt4 */, "expected -1, got %d\n", ret);
192 193
}

194
static INT CALLBACK enum_profiles_callbackW( LPWSTR filename, LPARAM lparam )
195 196 197 198 199 200 201 202 203
{
    return 1;
}

static void test_EnumICMProfilesW( HDC dc )
{
    INT ret;

    ret = EnumICMProfilesW( NULL, NULL, 0 );
204
    ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret);
205 206

    ret = EnumICMProfilesW( dc, NULL, 0 );
207
    ok(ret == -1 || broken(ret == 0) /* NT4 */, "expected -1, got %d\n", ret);
208 209

    ret = EnumICMProfilesW( dc, enum_profiles_callbackW, 0 );
210
    ok(ret == -1 || ret == 1 || broken(ret == 0) /* NT4 */, "expected -1 or 1, got %d\n", ret);
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
}

static void test_SetICMProfileA( HDC dc )
{
    BOOL ret;
    char profile[MAX_PATH];
    DWORD len, error;

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileA( NULL, NULL );
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("SetICMProfileA is not implemented\n");
        return;
    }

    len = sizeof(profile);
    ret = GetICMProfileA( dc, &len, profile );
    ok(ret, "GetICMProfileA failed %u\n", GetLastError());

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileA( NULL, NULL );
    error = GetLastError();
    ok(!ret, "SetICMProfileA succeeded\n");
235
    ok(error == ERROR_INVALID_PARAMETER,
236 237 238 239 240 241
       "expected ERROR_INVALID_PARAMETER, got %u\n", error);

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileA( NULL, profile );
    error = GetLastError();
    ok(!ret, "SetICMProfileA succeeded\n");
242
    ok(error == ERROR_INVALID_HANDLE,
243 244 245 246 247 248
       "expected ERROR_INVALID_HANDLE, got %u\n", error);

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileA( dc, NULL );
    error = GetLastError();
    ok(!ret, "SetICMProfileA succeeded\n");
249
    ok(error == ERROR_INVALID_PARAMETER,
250
       "expected ERROR_INVALID_PARAMETER, got %u\n", error);
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

    ret = SetICMProfileA( dc, profile );
    ok(ret, "SetICMProfileA failed %u\n", GetLastError());
}

static void test_SetICMProfileW( HDC dc )
{
    BOOL ret;
    WCHAR profile[MAX_PATH];
    DWORD len, error;

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileW( NULL, NULL );
    if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("SetICMProfileW is not implemented\n");
        return;
    }

    len = sizeof(profile)/sizeof(profile[0]);
    ret = GetICMProfileW( dc, &len, profile );
    ok(ret, "GetICMProfileW failed %u\n", GetLastError());

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileW( NULL, NULL );
    error = GetLastError();
    ok(!ret, "SetICMProfileW succeeded\n");
    ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileW( NULL, profile );
    error = GetLastError();
    ok(!ret, "SetICMProfileW succeeded\n");
    ok(error == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %u\n", error);

    SetLastError( 0xdeadbeef );
    ret = SetICMProfileW( dc, NULL );
    error = GetLastError();
    ok(!ret, "SetICMProfileW succeeded\n");
    ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);

    ret = SetICMProfileW( dc, profile );
    ok(ret, "SetICMProfileW failed %u\n", GetLastError());
}

296 297 298 299 300 301 302
START_TEST(icm)
{
    HDC dc = GetDC( NULL );

    test_GetICMProfileA( dc );
    test_GetICMProfileW( dc );
    test_SetICMMode( dc );
303 304 305 306
    test_EnumICMProfilesA( dc );
    test_EnumICMProfilesW( dc );
    test_SetICMProfileA( dc );
    test_SetICMProfileW( dc );
307 308 309

    ReleaseDC( NULL, dc );
}