gdi32/tests: Prevent a crash on win95.
[wine.git] / dlls / gdi32 / tests / icm.c
blobb36165cbf16e9d163300a34ce60d6dd5f3bc4d29
1 /*
2 * Tests for ICM functions
4 * Copyright (C) 2005, 2008 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
28 #include "wine/test.h"
30 static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
32 static void test_GetICMProfileA( HDC dc )
34 BOOL ret;
35 DWORD size, error;
36 char filename[MAX_PATH];
38 SetLastError( 0xdeadbeef );
39 ret = GetICMProfileA( NULL, NULL, NULL );
40 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
42 skip( "GetICMProfileA is not implemented\n" );
43 return;
45 ok( !ret, "GetICMProfileA succeeded\n" );
47 ret = GetICMProfileA( dc, NULL, NULL );
48 ok( !ret, "GetICMProfileA succeeded\n" );
50 size = MAX_PATH;
51 ret = GetICMProfileA( dc, &size, NULL );
52 ok( !ret, "GetICMProfileA succeeded\n" );
54 size = MAX_PATH;
55 ret = GetICMProfileA( NULL, &size, filename );
56 ok( !ret, "GetICMProfileA succeeded\n" );
58 size = 0;
59 filename[0] = 0;
60 SetLastError(0xdeadbeef);
61 ret = GetICMProfileA( dc, &size, filename );
62 error = GetLastError();
63 ok( !ret, "GetICMProfileA succeeded\n" );
64 ok( size, "expected size > 0\n" );
65 ok( filename[0] == 0, "Expected filename to be empty\n" );
66 ok( error == ERROR_INSUFFICIENT_BUFFER ||
67 error == ERROR_SUCCESS, /* Win95 */
68 "got %d, expected ERROR_INSUFFICIENT_BUFFER or ERROR_SUCCESS(Win95)\n", error );
70 /* Next test will crash on Win95 */
71 if ( error == ERROR_INSUFFICIENT_BUFFER )
73 ret = GetICMProfileA( dc, NULL, filename );
74 ok( !ret, "GetICMProfileA succeeded\n" );
77 size = MAX_PATH;
78 ret = GetICMProfileA( dc, &size, filename );
79 ok( ret, "GetICMProfileA failed %d\n", GetLastError() );
81 trace( "%s\n", filename );
84 static void test_GetICMProfileW( HDC dc )
86 BOOL ret;
87 DWORD size, error;
88 WCHAR filename[MAX_PATH];
90 SetLastError( 0xdeadbeef );
91 ret = GetICMProfileW( NULL, NULL, NULL );
92 if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
94 skip( "GetICMProfileW is not implemented\n" );
95 return;
97 ok( !ret, "GetICMProfileW succeeded\n" );
99 ret = GetICMProfileW( dc, NULL, NULL );
100 ok( !ret, "GetICMProfileW succeeded\n" );
102 if (0)
104 /* Vista crashes */
105 size = MAX_PATH;
106 ret = GetICMProfileW( dc, &size, NULL );
107 ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
110 ret = GetICMProfileW( dc, NULL, filename );
111 ok( !ret, "GetICMProfileW succeeded\n" );
113 size = MAX_PATH;
114 ret = GetICMProfileW( NULL, &size, filename );
115 ok( !ret, "GetICMProfileW succeeded\n" );
117 size = 0;
118 SetLastError(0xdeadbeef);
119 ret = GetICMProfileW( dc, &size, filename );
120 error = GetLastError();
121 ok( !ret, "GetICMProfileW succeeded\n" );
122 ok( size, "expected size > 0\n" );
123 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
125 size = MAX_PATH;
126 ret = GetICMProfileW( dc, &size, filename );
127 ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
130 static void test_SetICMMode( HDC dc )
132 INT ret, knob, save;
134 SetLastError( 0xdeadbeef );
135 ret = SetICMMode( NULL, 0 );
136 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
138 ret = SetICMMode( dc, -1 );
139 ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
141 save = SetICMMode( dc, ICM_QUERY );
142 ok( save == ICM_ON || save == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
144 if (save == ICM_ON) knob = ICM_OFF; else knob = ICM_ON;
146 ret = SetICMMode( dc, knob );
147 todo_wine ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
149 ret = SetICMMode( dc, ICM_QUERY );
150 todo_wine ok( ret == knob, "SetICMMode failed (%d)\n", GetLastError() );
152 ret = SetICMMode( dc, save );
153 ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
155 SetLastError( 0xdeadbeef );
156 dc = CreateDCW( displayW, NULL, NULL, NULL );
157 if ( !dc && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
159 skip( "CreateDCW is not implemented\n" );
160 return;
162 ok( dc != NULL, "CreateDCW failed (%d)\n", GetLastError() );
164 ret = SetICMMode( dc, ICM_QUERY );
165 ok( ret == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
167 DeleteDC( dc );
170 START_TEST(icm)
172 HDC dc = GetDC( NULL );
174 test_GetICMProfileA( dc );
175 test_GetICMProfileW( dc );
176 test_SetICMMode( dc );
178 ReleaseDC( NULL, dc );