gdi32: Fix CreateCompatibleDC to reject invalid DCs.
[wine] / dlls / gdi32 / tests / icm.c
1 /*
2  * Tests for ICM functions
3  *
4  * Copyright (C) 2005, 2008 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27
28 #include "wine/test.h"
29
30 static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
31
32 static void test_GetICMProfileA( HDC dc )
33 {
34     BOOL ret;
35     DWORD size, error;
36     char filename[MAX_PATH];
37
38     SetLastError( 0xdeadbeef );
39     ret = GetICMProfileA( NULL, NULL, NULL );
40     if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
41     {
42         skip( "GetICMProfileA is not implemented\n" );
43         return;
44     }
45     ok( !ret, "GetICMProfileA succeeded\n" );
46
47     ret = GetICMProfileA( dc, NULL, NULL );
48     ok( !ret, "GetICMProfileA succeeded\n" );
49
50     size = MAX_PATH;
51     ret = GetICMProfileA( dc, &size, NULL );
52     ok( !ret, "GetICMProfileA succeeded\n" );
53
54     ret = GetICMProfileA( dc, NULL, filename );
55     ok( !ret, "GetICMProfileA succeeded\n" );
56
57     size = MAX_PATH;
58     ret = GetICMProfileA( NULL, &size, filename );
59     ok( !ret, "GetICMProfileA succeeded\n" );
60
61     size = 0;
62     SetLastError(0xdeadbeef);
63     ret = GetICMProfileA( dc, &size, filename );
64     error = GetLastError();
65     ok( !ret, "GetICMProfileA succeeded\n" );
66     ok( size, "expected size > 0\n" );
67     ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
68
69     size = MAX_PATH;
70     ret = GetICMProfileA( dc, &size, filename );
71     ok( ret, "GetICMProfileA failed %d\n", GetLastError() );
72
73     trace( "%s\n", filename );
74 }
75
76 static void test_GetICMProfileW( HDC dc )
77 {
78     BOOL ret;
79     DWORD size, error;
80     WCHAR filename[MAX_PATH];
81
82     SetLastError( 0xdeadbeef );
83     ret = GetICMProfileW( NULL, NULL, NULL );
84     if ( !ret && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
85     {
86         skip( "GetICMProfileW is not implemented\n" );
87         return;
88     }
89     ok( !ret, "GetICMProfileW succeeded\n" );
90
91     ret = GetICMProfileW( dc, NULL, NULL );
92     ok( !ret, "GetICMProfileW succeeded\n" );
93
94     if (0)
95     {
96         /* Vista crashes */
97         size = MAX_PATH;
98         ret = GetICMProfileW( dc, &size, NULL );
99         ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
100     }
101
102     ret = GetICMProfileW( dc, NULL, filename );
103     ok( !ret, "GetICMProfileW succeeded\n" );
104
105     size = MAX_PATH;
106     ret = GetICMProfileW( NULL, &size, filename );
107     ok( !ret, "GetICMProfileW succeeded\n" );
108
109     size = 0;
110     SetLastError(0xdeadbeef);
111     ret = GetICMProfileW( dc, &size, filename );
112     error = GetLastError();
113     ok( !ret, "GetICMProfileW succeeded\n" );
114     ok( size, "expected size > 0\n" );
115     ok( error == ERROR_INSUFFICIENT_BUFFER, "got %d, expected ERROR_INSUFFICIENT_BUFFER\n", error );
116
117     size = MAX_PATH;
118     ret = GetICMProfileW( dc, &size, filename );
119     ok( ret, "GetICMProfileW failed %d\n", GetLastError() );
120 }
121
122 static void test_SetICMMode( HDC dc )
123 {
124     INT ret, knob, save;
125
126     SetLastError( 0xdeadbeef );
127     ret = SetICMMode( NULL, 0 );
128     ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
129
130     ret = SetICMMode( dc, -1 );
131     ok( !ret, "SetICMMode succeeded (%d)\n", GetLastError() );
132
133     save = SetICMMode( dc, ICM_QUERY );
134     ok( save == ICM_ON || save == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
135
136     if (save == ICM_ON) knob = ICM_OFF; else knob = ICM_ON;
137
138     ret = SetICMMode( dc, knob );
139     todo_wine ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
140
141     ret = SetICMMode( dc, ICM_QUERY );
142     todo_wine ok( ret == knob, "SetICMMode failed (%d)\n", GetLastError() );
143
144     ret = SetICMMode( dc, save );
145     ok( ret, "SetICMMode failed (%d)\n", GetLastError() );
146
147     SetLastError( 0xdeadbeef );
148     dc = CreateDCW( displayW, NULL, NULL, NULL );
149     if ( !dc && ( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) )
150     {
151         skip( "CreateDCW is not implemented\n" );
152         return;
153     }
154     ok( dc != NULL, "CreateDCW failed (%d)\n", GetLastError() );
155
156     ret = SetICMMode( dc, ICM_QUERY );
157     ok( ret == ICM_OFF, "SetICMMode failed (%d)\n", GetLastError() );
158
159     DeleteDC( dc );
160 }
161
162 START_TEST(icm)
163 {
164     HDC dc = GetDC( NULL );
165
166     test_GetICMProfileA( dc );
167     test_GetICMProfileW( dc );
168     test_SetICMMode( dc );
169
170     ReleaseDC( NULL, dc );
171 }