2 * Unit tests for window stations and desktops
4 * Copyright 2002 Alexandre Julliard
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
21 #include "wine/test.h"
26 #define DESKTOP_ALL_ACCESS 0x01ff
28 static void print_object( HANDLE obj )
33 strcpy( buffer, "foobar" );
34 if (!GetUserObjectInformationA( obj, UOI_NAME, buffer, sizeof(buffer), &size ))
35 trace( "could not get info for %p\n", obj );
37 trace( "obj %p name '%s'\n", obj, buffer );
38 strcpy( buffer, "foobar" );
39 if (!GetUserObjectInformationA( obj, UOI_TYPE, buffer, sizeof(buffer), &size ))
40 trace( "could not get type for %p\n", obj );
42 trace( "obj %p type '%s'\n", obj, buffer );
45 static DWORD CALLBACK thread( LPVOID arg )
48 HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0);
49 ok( hwnd != 0, "CreateWindow failed\n" );
50 d1 = GetThreadDesktop(GetCurrentThreadId());
51 trace( "thread %p desktop: %p\n", arg, d1 );
53 if (0) /* FIXME: this should be todo_wine but it would break the rest of the test */
55 SetLastError( 0xdeadbeef );
56 ok( !CloseHandle( d1 ), "CloseHandle succeeded\n" );
57 ok( GetLastError() == ERROR_INVALID_HANDLE, "bad last error %ld\n", GetLastError() );
60 SetLastError( 0xdeadbeef );
61 ok( !CloseDesktop( d1 ), "CloseDesktop succeeded\n" );
62 ok( GetLastError() == ERROR_BUSY, "bad last error %ld\n", GetLastError() );
64 d2 = CreateDesktop( "foobar2", NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL );
65 trace( "created desktop %p\n", d2 );
66 ok( d2 != 0, "CreateDesktop failed\n" );
70 SetLastError( 0xdeadbeef );
71 ok( !SetThreadDesktop( d2 ), "set thread desktop succeeded with existing window\n" );
72 ok( GetLastError() == ERROR_BUSY, "bad last error %ld\n", GetLastError() );
75 DestroyWindow( hwnd );
76 ok( SetThreadDesktop( d2 ), "set thread desktop failed\n" );
77 d1 = GetThreadDesktop(GetCurrentThreadId());
78 ok( d1 == d2, "GetThreadDesktop did not return set desktop %p/%p\n", d1, d2 );
82 HANDLE hthread = CreateThread( NULL, 0, thread, (char *)arg + 1, 0, NULL );
84 WaitForSingleObject( hthread, INFINITE );
89 static void test_handles(void)
98 w1 = GetProcessWindowStation();
99 ok( GetProcessWindowStation() == w1, "GetProcessWindowStation returned different handles\n" );
100 ok( !CloseWindowStation(w1), "closing process win station succeeded\n" );
101 SetLastError( 0xdeadbeef );
102 ok( !CloseHandle(w1), "closing process win station handle succeeded\n" );
103 ok( GetLastError() == ERROR_INVALID_HANDLE, "bad last error %ld\n", GetLastError() );
107 ok( GetHandleInformation( w1, &flags ), "GetHandleInformation failed\n" );
108 todo_wine ok( !(flags & HANDLE_FLAG_PROTECT_FROM_CLOSE), "handle %p PROTECT_FROM_CLOSE set\n", w1 );
110 ok( DuplicateHandle( GetCurrentProcess(), w1, GetCurrentProcess(), (PHANDLE)&w2, 0,
111 TRUE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
112 ok( CloseWindowStation(w2), "closing dup win station failed\n" );
114 ok( DuplicateHandle( GetCurrentProcess(), w1, GetCurrentProcess(), (PHANDLE)&w2, 0,
115 TRUE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
116 ok( CloseHandle(w2), "closing dup win station handle failed\n" );
118 w2 = CreateWindowStation("WinSta0", 0, WINSTA_ALL_ACCESS, NULL );
119 ok( w2 != 0, "CreateWindowStation failed\n" );
120 ok( w2 != w1, "CreateWindowStation returned default handle\n" );
121 SetLastError( 0xdeadbeef );
122 ok( !CloseDesktop( (HDESK)w2 ), "CloseDesktop succeeded on win station\n" );
123 ok( GetLastError() == ERROR_INVALID_HANDLE, "bad last error %ld\n", GetLastError() );
124 ok( CloseWindowStation( w2 ), "CloseWindowStation failed\n" );
126 w2 = CreateWindowStation("WinSta0", 0, WINSTA_ALL_ACCESS, NULL );
127 ok( CloseHandle( w2 ), "CloseHandle failed\n" );
129 w2 = OpenWindowStation("winsta0", TRUE, WINSTA_ALL_ACCESS );
130 ok( w2 != 0, "OpenWindowStation failed\n" );
131 ok( w2 != w1, "OpenWindowStation returned default handle\n" );
132 ok( CloseWindowStation( w2 ), "CloseWindowStation failed\n" );
134 w2 = OpenWindowStation("dummy name", TRUE, WINSTA_ALL_ACCESS );
135 ok( !w2, "open dummy win station succeeded\n" );
137 CreateMutexA( NULL, 0, "foobar" );
138 w2 = CreateWindowStation("foobar", 0, WINSTA_ALL_ACCESS, NULL );
139 ok( w2 != 0, "create foobar station failed\n" );
141 w3 = OpenWindowStation("foobar", TRUE, WINSTA_ALL_ACCESS );
142 ok( w3 != 0, "open foobar station failed\n" );
143 ok( w3 != w2, "open foobar station returned same handle\n" );
144 ok( CloseWindowStation( w2 ), "CloseWindowStation failed\n" );
145 ok( CloseWindowStation( w3 ), "CloseWindowStation failed\n" );
147 w3 = OpenWindowStation("foobar", TRUE, WINSTA_ALL_ACCESS );
148 ok( !w3, "open foobar station succeeded\n" );
151 d1 = GetThreadDesktop(GetCurrentThreadId());
152 ok( GetThreadDesktop(GetCurrentThreadId()) == d1,
153 "GetThreadDesktop returned different handles\n" );
156 ok( GetHandleInformation( d1, &flags ), "GetHandleInformation failed\n" );
157 ok( !(flags & HANDLE_FLAG_PROTECT_FROM_CLOSE), "handle %p PROTECT_FROM_CLOSE set\n", d1 );
159 SetLastError( 0xdeadbeef );
160 ok( !CloseDesktop(d1), "closing thread desktop succeeded\n" );
161 ok( GetLastError() == ERROR_BUSY, "bad last error %ld\n", GetLastError() );
163 if (0) /* FIXME: this should be todo_wine but it would break the rest of the test */
165 SetLastError( 0xdeadbeef );
166 ok( !CloseHandle(d1), "closing thread desktop handle failed\n" );
167 ok( GetLastError() == ERROR_INVALID_HANDLE, "bad last error %ld\n", GetLastError() );
170 ok( DuplicateHandle( GetCurrentProcess(), d1, GetCurrentProcess(), (PHANDLE)&d2, 0,
171 TRUE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
172 ok( CloseDesktop(d2), "closing dup desktop failed\n" );
174 ok( DuplicateHandle( GetCurrentProcess(), d1, GetCurrentProcess(), (PHANDLE)&d2, 0,
175 TRUE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
176 ok( CloseHandle(d2), "closing dup desktop handle failed\n" );
178 d2 = OpenDesktop( "dummy name", 0, TRUE, DESKTOP_ALL_ACCESS );
179 ok( !d2, "open dummy desktop succeeded\n" );
181 d2 = CreateDesktop( "foobar", NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL );
182 ok( d2 != 0, "create foobar desktop failed\n" );
183 SetLastError( 0xdeadbeef );
184 ok( !CloseWindowStation( (HWINSTA)d2 ), "CloseWindowStation succeeded on desktop\n" );
185 ok( GetLastError() == ERROR_INVALID_HANDLE, "bad last error %ld\n", GetLastError() );
187 d3 = OpenDesktop( "foobar", 0, TRUE, DESKTOP_ALL_ACCESS );
188 ok( d3 != 0, "open foobar desktop failed\n" );
189 ok( d3 != d2, "open foobar desktop returned same handle\n" );
190 ok( CloseDesktop( d2 ), "CloseDesktop failed\n" );
191 ok( CloseDesktop( d3 ), "CloseDesktop failed\n" );
193 d3 = OpenDesktop( "foobar", 0, TRUE, DESKTOP_ALL_ACCESS );
194 ok( !d3, "open foobar desktop succeeded\n" );
196 if (0) /* FIXME: this should be todo_wine but it would break the rest of the test */
198 ok( !CloseHandle(d1), "closing thread desktop handle succeeded\n" );
199 d2 = GetThreadDesktop(GetCurrentThreadId());
200 ok( d1 == d2, "got different handles after close\n" );
203 trace( "thread 1 desktop: %p\n", d2 );
205 hthread = CreateThread( NULL, 0, thread, (LPVOID)2, 0, &id );
207 trace( "get other thread desktop: %p\n", GetThreadDesktop(id) );
208 WaitForSingleObject( hthread, INFINITE );
211 START_TEST(winstation)