2 * Unit test suite for clipboard functions.
4 * Copyright 2002 Dmitry Timoshkov
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
22 #include "wine/test.h"
29 static BOOL (WINAPI
*pAddClipboardFormatListener
)(HWND hwnd
);
30 static BOOL (WINAPI
*pRemoveClipboardFormatListener
)(HWND hwnd
);
31 static BOOL (WINAPI
*pGetUpdatedClipboardFormats
)( UINT
*formats
, UINT count
, UINT
*out_count
);
33 static int thread_from_line
;
36 static DWORD WINAPI
open_clipboard_thread(LPVOID arg
)
39 ok(OpenClipboard(hWnd
), "%u: OpenClipboard failed\n", thread_from_line
);
43 static DWORD WINAPI
empty_clipboard_thread(LPVOID arg
)
45 SetLastError( 0xdeadbeef );
46 ok(!EmptyClipboard(), "%u: EmptyClipboard succeeded\n", thread_from_line
);
47 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "%u: wrong error %u\n",
48 thread_from_line
, GetLastError());
52 static DWORD WINAPI
open_and_empty_clipboard_thread(LPVOID arg
)
55 ok(OpenClipboard(hWnd
), "%u: OpenClipboard failed\n", thread_from_line
);
56 ok(EmptyClipboard(), "%u: EmptyClipboard failed\n", thread_from_line
);
60 static DWORD WINAPI
open_and_empty_clipboard_win_thread(LPVOID arg
)
62 HWND hwnd
= CreateWindowA( "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
63 ok(OpenClipboard(hwnd
), "%u: OpenClipboard failed\n", thread_from_line
);
64 ok(EmptyClipboard(), "%u: EmptyClipboard failed\n", thread_from_line
);
68 static DWORD WINAPI
set_clipboard_data_thread(LPVOID arg
)
73 SetLastError( 0xdeadbeef );
74 if (GetClipboardOwner() == hwnd
)
76 SetClipboardData( CF_WAVE
, 0 );
77 ok( IsClipboardFormatAvailable( CF_WAVE
), "%u: SetClipboardData failed\n", thread_from_line
);
78 ret
= SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 ));
79 ok( ret
!= 0, "%u: SetClipboardData failed err %u\n", thread_from_line
, GetLastError() );
80 SetLastError( 0xdeadbeef );
81 ret
= GetClipboardData( CF_WAVE
);
82 ok( !ret
, "%u: GetClipboardData succeeded\n", thread_from_line
);
83 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "%u: wrong error %u\n",
84 thread_from_line
, GetLastError());
88 SetClipboardData( CF_WAVE
, 0 );
89 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "%u: wrong error %u\n",
90 thread_from_line
, GetLastError());
91 ok( !IsClipboardFormatAvailable( CF_WAVE
), "%u: SetClipboardData succeeded\n", thread_from_line
);
92 ret
= SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 ));
93 ok( !ret
, "%u: SetClipboardData succeeded\n", thread_from_line
);
94 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "%u: wrong error %u\n",
95 thread_from_line
, GetLastError());
100 static void set_clipboard_data_process( int arg
)
104 SetLastError( 0xdeadbeef );
107 ok( IsClipboardFormatAvailable( CF_WAVE
), "process %u: CF_WAVE not available\n", arg
);
108 ret
= SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 ));
109 ok( ret
!= 0, "process %u: SetClipboardData failed err %u\n", arg
, GetLastError() );
113 SetClipboardData( CF_WAVE
, 0 );
114 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "process %u: wrong error %u\n",
115 arg
, GetLastError());
116 ok( !IsClipboardFormatAvailable( CF_WAVE
), "process %u: SetClipboardData succeeded\n", arg
);
117 ret
= SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 ));
118 ok( !ret
, "process %u: SetClipboardData succeeded\n", arg
);
119 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "process %u: wrong error %u\n",
120 arg
, GetLastError());
124 static void grab_clipboard_process( int arg
)
128 SetLastError( 0xdeadbeef );
129 ret
= OpenClipboard( 0 );
130 ok( ret
, "OpenClipboard failed\n" );
131 ret
= EmptyClipboard();
132 ok( ret
, "EmptyClipboard failed\n" );
135 HANDLE ret
= SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 ));
136 ok( ret
!= 0, "process %u: SetClipboardData failed err %u\n", arg
, GetLastError() );
140 static void run_thread( LPTHREAD_START_ROUTINE func
, void *arg
, int line
)
145 thread_from_line
= line
;
146 thread
= CreateThread(NULL
, 0, func
, arg
, 0, NULL
);
147 ok(thread
!= NULL
, "%u: CreateThread failed with error %d\n", line
, GetLastError());
150 ret
= MsgWaitForMultipleObjectsEx( 1, &thread
, 1000, QS_ALLINPUT
, 0 );
151 if (ret
== WAIT_OBJECT_0
+ 1)
154 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
158 ok(ret
== WAIT_OBJECT_0
, "%u: expected WAIT_OBJECT_0, got %u\n", line
, ret
);
162 static void run_process( const char *args
)
165 PROCESS_INFORMATION info
;
166 STARTUPINFOA startup
;
168 sprintf( cmd
, "%s clipboard %s", argv0
, args
);
169 memset( &startup
, 0, sizeof(startup
) );
170 startup
.cb
= sizeof(startup
);
171 ok( CreateProcessA( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
),
172 "CreateProcess %s failed\n", cmd
);
174 winetest_wait_child_process( info
.hProcess
);
175 CloseHandle( info
.hProcess
);
176 CloseHandle( info
.hThread
);
179 static WNDPROC old_proc
;
180 static LRESULT CALLBACK
winproc_wrapper( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
182 static int wm_renderallformats
;
183 static int wm_drawclipboard
;
185 DWORD msg_flags
= InSendMessageEx( NULL
);
187 if (!seqno
) seqno
= GetClipboardSequenceNumber();
189 trace( "%p msg %04x\n", hwnd
, msg
);
190 if (!wm_renderallformats
)
192 ok( GetClipboardOwner() == hwnd
, "%04x: wrong owner %p/%p\n", msg
, GetClipboardOwner(), hwnd
);
193 ok( seqno
== GetClipboardSequenceNumber(), "%04x: seqno changed\n", msg
);
197 ok( !GetClipboardOwner(), "%04x: wrong owner %p\n", msg
, GetClipboardOwner() );
198 ok( seqno
+ 1 == GetClipboardSequenceNumber(), "%04x: seqno unchanged\n", msg
);
200 ok( GetClipboardViewer() == hwnd
, "%04x: wrong viewer %p/%p\n", msg
, GetClipboardViewer(), hwnd
);
201 ok( GetOpenClipboardWindow() == hwnd
, "%04x: wrong open win %p/%p\n",
202 msg
, GetOpenClipboardWindow(), hwnd
);
207 ok( wm_renderallformats
, "didn't receive WM_RENDERALLFORMATS before WM_DESTROY\n" );
208 ok( wm_drawclipboard
, "didn't receive WM_DRAWCLIPBOARD before WM_DESTROY\n" );
210 case WM_DRAWCLIPBOARD
:
211 ok( msg_flags
== ISMEX_NOSEND
, "WM_DRAWCLIPBOARD wrong flags %x\n", msg_flags
);
214 case WM_RENDERALLFORMATS
:
215 ok( msg_flags
== ISMEX_NOSEND
, "WM_RENDERALLFORMATS wrong flags %x\n", msg_flags
);
216 wm_renderallformats
++;
219 return old_proc( hwnd
, msg
, wp
, lp
);
222 static void test_ClipboardOwner(void)
227 SetLastError(0xdeadbeef);
228 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef,
229 "could not perform clipboard test: clipboard already owned\n");
231 hWnd1
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
232 0, 0, 10, 10, 0, 0, 0, NULL
);
233 ok(hWnd1
!= 0, "CreateWindowExA error %d\n", GetLastError());
234 trace("hWnd1 = %p\n", hWnd1
);
236 hWnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
237 0, 0, 10, 10, 0, 0, 0, NULL
);
238 ok(hWnd2
!= 0, "CreateWindowExA error %d\n", GetLastError());
239 trace("hWnd2 = %p\n", hWnd2
);
241 SetLastError(0xdeadbeef);
242 ok(!CloseClipboard(), "CloseClipboard should fail if clipboard wasn't open\n");
243 ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
|| broken(GetLastError() == 0xdeadbeef), /* wow64 */
244 "wrong error %u\n", GetLastError());
246 ok(OpenClipboard(0), "OpenClipboard failed\n");
247 ok(!GetClipboardOwner(), "clipboard should still be not owned\n");
248 ok(!OpenClipboard(hWnd1
), "OpenClipboard should fail since clipboard already opened\n");
249 ok(OpenClipboard(0), "OpenClipboard again failed\n");
250 ret
= CloseClipboard();
251 ok( ret
, "CloseClipboard error %d\n", GetLastError());
253 ok(OpenClipboard(hWnd1
), "OpenClipboard failed\n");
254 run_thread( open_clipboard_thread
, hWnd1
, __LINE__
);
255 run_thread( empty_clipboard_thread
, 0, __LINE__
);
256 run_thread( set_clipboard_data_thread
, hWnd1
, __LINE__
);
257 ok( !IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE available\n" );
258 ok( !GetClipboardData( CF_WAVE
), "CF_WAVE data available\n" );
259 run_process( "set_clipboard_data 0" );
260 ok(!CloseClipboard(), "CloseClipboard should fail if clipboard wasn't open\n");
261 ok(OpenClipboard(hWnd1
), "OpenClipboard failed\n");
263 SetLastError(0xdeadbeef);
264 ret
= OpenClipboard(hWnd2
);
265 ok(!ret
&& (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED
),
266 "OpenClipboard should fail without setting last error value, or with ERROR_ACCESS_DENIED, got error %d\n", GetLastError());
268 SetLastError(0xdeadbeef);
269 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should still be not owned\n");
270 ret
= EmptyClipboard();
271 ok( ret
, "EmptyClipboard error %d\n", GetLastError());
272 ok(GetClipboardOwner() == hWnd1
, "clipboard should be owned by %p, not by %p\n", hWnd1
, GetClipboardOwner());
273 run_thread( empty_clipboard_thread
, 0, __LINE__
);
274 run_thread( set_clipboard_data_thread
, hWnd1
, __LINE__
);
275 ok( IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE not available\n" );
276 ok( GetClipboardData( CF_WAVE
) != 0, "CF_WAVE data not available\n" );
277 run_process( "set_clipboard_data 1" );
279 SetLastError(0xdeadbeef);
280 ret
= OpenClipboard(hWnd2
);
281 ok(!ret
&& (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED
),
282 "OpenClipboard should fail without setting last error value, or with ERROR_ACCESS_DENIED, got error %d\n", GetLastError());
284 ret
= CloseClipboard();
285 ok( ret
, "CloseClipboard error %d\n", GetLastError());
286 ok(GetClipboardOwner() == hWnd1
, "clipboard should still be owned\n");
288 /* any window will do, even from a different process */
289 ret
= OpenClipboard( GetDesktopWindow() );
290 ok( ret
, "OpenClipboard error %d\n", GetLastError());
291 ret
= EmptyClipboard();
292 ok( ret
, "EmptyClipboard error %d\n", GetLastError());
293 ok( GetClipboardOwner() == GetDesktopWindow(), "wrong owner %p/%p\n",
294 GetClipboardOwner(), GetDesktopWindow() );
295 run_thread( set_clipboard_data_thread
, GetDesktopWindow(), __LINE__
);
296 ok( IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE not available\n" );
297 ok( GetClipboardData( CF_WAVE
) != 0, "CF_WAVE data not available\n" );
298 run_process( "set_clipboard_data 2" );
299 ret
= CloseClipboard();
300 ok( ret
, "CloseClipboard error %d\n", GetLastError());
302 ret
= OpenClipboard( hWnd1
);
303 ok( ret
, "OpenClipboard error %d\n", GetLastError());
304 ret
= EmptyClipboard();
305 ok( ret
, "EmptyClipboard error %d\n", GetLastError());
306 SetClipboardData( CF_WAVE
, 0 );
307 SetClipboardViewer( hWnd1
);
308 ok( GetClipboardOwner() == hWnd1
, "wrong owner %p/%p\n", GetClipboardOwner(), hWnd1
);
309 ok( GetClipboardViewer() == hWnd1
, "wrong viewer %p/%p\n", GetClipboardViewer(), hWnd1
);
310 ok( GetOpenClipboardWindow() == hWnd1
, "wrong open win %p/%p\n", GetOpenClipboardWindow(), hWnd1
);
311 ok( IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE not available\n" );
313 old_proc
= (WNDPROC
)SetWindowLongPtrA( hWnd1
, GWLP_WNDPROC
, (LONG_PTR
)winproc_wrapper
);
314 ret
= DestroyWindow(hWnd1
);
315 ok( ret
, "DestroyWindow error %d\n", GetLastError());
316 ret
= DestroyWindow(hWnd2
);
317 ok( ret
, "DestroyWindow error %d\n", GetLastError());
318 SetLastError(0xdeadbeef);
319 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should not be owned\n");
320 ok(!GetClipboardViewer() && GetLastError() == 0xdeadbeef, "viewer still exists\n");
321 ok(!GetOpenClipboardWindow() && GetLastError() == 0xdeadbeef, "clipboard should not be open\n");
322 ok( !IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE available\n" );
324 SetLastError( 0xdeadbeef );
325 ret
= CloseClipboard();
326 ok( !ret
, "CloseClipboard succeeded\n" );
327 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "wrong error %u\n", GetLastError() );
329 ret
= OpenClipboard( 0 );
330 ok( ret
, "OpenClipboard error %d\n", GetLastError());
331 run_thread( set_clipboard_data_thread
, 0, __LINE__
);
332 ok( IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE not available\n" );
333 ok( GetClipboardData( CF_WAVE
) != 0, "CF_WAVE data not available\n" );
334 run_process( "set_clipboard_data 3" );
335 ret
= CloseClipboard();
336 ok( ret
, "CloseClipboard error %d\n", GetLastError());
338 run_thread( open_and_empty_clipboard_thread
, 0, __LINE__
);
339 ok( !GetOpenClipboardWindow(), "wrong open window %p\n", GetOpenClipboardWindow() );
340 ok( !GetClipboardOwner(), "wrong owner window %p\n", GetClipboardOwner() );
342 ret
= OpenClipboard( 0 );
343 ok( ret
, "OpenClipboard error %d\n", GetLastError());
344 run_thread( set_clipboard_data_thread
, 0, __LINE__
);
345 ok( IsClipboardFormatAvailable( CF_WAVE
), "CF_WAVE not available\n" );
346 ok( GetClipboardData( CF_WAVE
) != 0, "CF_WAVE data not available\n" );
347 run_process( "set_clipboard_data 4" );
348 ret
= EmptyClipboard();
349 ok( ret
, "EmptyClipboard error %d\n", GetLastError());
350 ret
= CloseClipboard();
351 ok( ret
, "CloseClipboard error %d\n", GetLastError());
353 SetLastError( 0xdeadbeef );
354 ok( !SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_DDESHARE
| GMEM_ZEROINIT
, 100 )),
355 "SetClipboardData succeeded\n" );
356 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "wrong error %u\n", GetLastError() );
357 ok( !IsClipboardFormatAvailable( CF_WAVE
), "SetClipboardData succeeded\n" );
359 run_thread( open_and_empty_clipboard_thread
, GetDesktopWindow(), __LINE__
);
360 ok( !GetOpenClipboardWindow(), "wrong open window %p\n", GetOpenClipboardWindow() );
361 ok( GetClipboardOwner() == GetDesktopWindow(), "wrong owner window %p / %p\n",
362 GetClipboardOwner(), GetDesktopWindow() );
364 run_thread( open_and_empty_clipboard_win_thread
, 0, __LINE__
);
365 ok( !GetOpenClipboardWindow(), "wrong open window %p\n", GetOpenClipboardWindow() );
366 ok( !GetClipboardOwner(), "wrong owner window %p\n", GetClipboardOwner() );
369 static void test_RegisterClipboardFormatA(void)
372 UINT format_id
, format_id2
;
378 format_id
= RegisterClipboardFormatA("my_cool_clipboard_format");
379 ok(format_id
> 0xc000 && format_id
< 0xffff, "invalid clipboard format id %04x\n", format_id
);
381 format_id2
= RegisterClipboardFormatA("MY_COOL_CLIPBOARD_FORMAT");
382 ok(format_id2
== format_id
, "invalid clipboard format id %04x\n", format_id2
);
384 len
= GetClipboardFormatNameA(format_id
, buf
, 256);
385 ok(len
== lstrlenA("my_cool_clipboard_format"), "wrong format name length %d\n", len
);
386 ok(!lstrcmpA(buf
, "my_cool_clipboard_format"), "wrong format name \"%s\"\n", buf
);
388 len
= GetClipboardFormatNameA(format_id
, NULL
, 0);
389 ok(len
== 0, "wrong format name length %d\n", len
);
391 lstrcpyA(buf
, "foo");
392 SetLastError(0xdeadbeef);
393 len
= GetAtomNameA((ATOM
)format_id
, buf
, 256);
394 ok(len
== 0, "GetAtomNameA should fail\n");
395 ok(GetLastError() == ERROR_INVALID_HANDLE
, "err %d\n", GetLastError());
399 lstrcpyA(buf
, "foo");
400 SetLastError(0xdeadbeef);
401 len
= GlobalGetAtomNameA((ATOM
)format_id
, buf
, 256);
402 ok(len
== 0, "GlobalGetAtomNameA should fail\n");
403 ok(GetLastError() == ERROR_INVALID_HANDLE
, "err %d\n", GetLastError());
406 SetLastError(0xdeadbeef);
407 atom_id
= FindAtomA("my_cool_clipboard_format");
408 ok(atom_id
== 0, "FindAtomA should fail\n");
409 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "err %d\n", GetLastError());
413 /* this relies on the clipboard and global atom table being different */
414 SetLastError(0xdeadbeef);
415 atom_id
= GlobalFindAtomA("my_cool_clipboard_format");
416 ok(atom_id
== 0, "GlobalFindAtomA should fail\n");
417 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "err %d\n", GetLastError());
420 for (format_id
= 0; format_id
< 0x10fff; format_id
++)
422 SetLastError(0xdeadbeef);
423 len
= GetClipboardFormatNameA(format_id
, buf
, 256);
425 if (format_id
< 0xc000 || format_id
> 0xffff)
426 ok(!len
, "GetClipboardFormatNameA should fail, but it returned %d (%s)\n", len
, buf
);
427 else if (len
&& winetest_debug
> 1)
428 trace("%04x: %s\n", format_id
, len
? buf
: "");
431 ret
= OpenClipboard(0);
432 ok( ret
, "OpenClipboard error %d\n", GetLastError());
434 /* try some invalid/unregistered formats */
435 SetLastError( 0xdeadbeef );
436 handle
= SetClipboardData( 0, GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
, 1 ));
437 ok( !handle
, "SetClipboardData succeeded\n" );
438 ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
, "wrong error %u\n", GetLastError());
439 handle
= SetClipboardData( 0x1234, GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
, 1 ));
440 ok( handle
!= 0, "SetClipboardData failed err %d\n", GetLastError());
441 handle
= SetClipboardData( 0x123456, GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
, 1 ));
442 ok( handle
!= 0, "SetClipboardData failed err %d\n", GetLastError());
443 handle
= SetClipboardData( 0xffff8765, GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
, 1 ));
444 ok( handle
!= 0, "SetClipboardData failed err %d\n", GetLastError());
446 ok( IsClipboardFormatAvailable( 0x1234 ), "format missing\n" );
447 ok( IsClipboardFormatAvailable( 0x123456 ), "format missing\n" );
448 ok( IsClipboardFormatAvailable( 0xffff8765 ), "format missing\n" );
449 ok( !IsClipboardFormatAvailable( 0 ), "format available\n" );
450 ok( !IsClipboardFormatAvailable( 0x3456 ), "format available\n" );
451 ok( !IsClipboardFormatAvailable( 0x8765 ), "format available\n" );
453 trace("# of formats available: %d\n", CountClipboardFormats());
456 while ((format_id
= EnumClipboardFormats(format_id
)))
458 ok(IsClipboardFormatAvailable(format_id
), "format %04x was listed as available\n", format_id
);
459 len
= GetClipboardFormatNameA(format_id
, buf
, 256);
460 trace("%04x: %s\n", format_id
, len
? buf
: "");
463 ret
= EmptyClipboard();
464 ok( ret
, "EmptyClipboard error %d\n", GetLastError());
465 ret
=CloseClipboard();
466 ok( ret
, "CloseClipboard error %d\n", GetLastError());
468 if (CountClipboardFormats())
470 SetLastError(0xdeadbeef);
471 ok(!EnumClipboardFormats(0), "EnumClipboardFormats should fail if clipboard wasn't open\n");
472 ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
,
473 "Last error should be set to ERROR_CLIPBOARD_NOT_OPEN, not %d\n", GetLastError());
476 SetLastError(0xdeadbeef);
477 ok(!EmptyClipboard(), "EmptyClipboard should fail if clipboard wasn't open\n");
478 ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN
|| broken(GetLastError() == 0xdeadbeef), /* wow64 */
479 "Wrong error %u\n", GetLastError());
481 format_id
= RegisterClipboardFormatA("#1234");
482 ok(format_id
== 1234, "invalid clipboard format id %04x\n", format_id
);
485 static HGLOBAL
create_textA(void)
487 HGLOBAL h
= GlobalAlloc(GMEM_DDESHARE
|GMEM_MOVEABLE
, 10);
488 char *p
= GlobalLock(h
);
489 memcpy(p
, "test\0\0\0\0\0", 10);
494 static HGLOBAL
create_textW(void)
496 static const WCHAR testW
[] = {'t','e','s','t',0,0,0,0,0,0};
497 HGLOBAL h
= GlobalAlloc(GMEM_DDESHARE
|GMEM_MOVEABLE
, sizeof(testW
));
498 WCHAR
*p
= GlobalLock(h
);
499 memcpy(p
, testW
, sizeof(testW
));
504 static HANDLE
create_metafile(void)
506 const RECT rect
= {0, 0, 100, 100};
510 HDC hdc
= CreateMetaFileA( NULL
);
511 ExtTextOutA( hdc
, 0, 0, ETO_OPAQUE
, &rect
, "Test String", strlen("Test String"), NULL
);
512 mf
= CloseMetaFile( hdc
);
513 ret
= GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
, sizeof(*pict
) );
514 pict
= GlobalLock( ret
);
516 pict
->xExt
= pict
->yExt
= 100;
522 static HENHMETAFILE
create_emf(void)
524 const RECT rect
= {0, 0, 100, 100};
525 HDC hdc
= CreateEnhMetaFileA(NULL
, NULL
, &rect
, "HENHMETAFILE Ole Clipboard Test\0Test\0\0");
526 ExtTextOutA(hdc
, 0, 0, ETO_OPAQUE
, &rect
, "Test String", strlen("Test String"), NULL
);
527 return CloseEnhMetaFile(hdc
);
530 static HBITMAP
create_bitmap(void)
532 HDC hdc
= GetDC( 0 );
533 UINT bpp
= GetDeviceCaps( hdc
, BITSPIXEL
);
535 return CreateBitmap( 10, 10, 1, bpp
, NULL
);
538 static HBITMAP
create_dib( BOOL v5
)
541 BITMAPINFOHEADER
*hdr
;
543 ret
= GlobalAlloc( GMEM_DDESHARE
| GMEM_MOVEABLE
| GMEM_ZEROINIT
,
544 sizeof(BITMAPV5HEADER
) + 256 * sizeof(RGBQUAD
) + 16 * 16 * 4 );
545 hdr
= GlobalLock( ret
);
546 hdr
->biSize
= v5
? sizeof(BITMAPV5HEADER
) : sizeof(*hdr
);
550 hdr
->biBitCount
= 32;
551 hdr
->biCompression
= BI_RGB
;
554 BITMAPV5HEADER
*hdr5
= (BITMAPV5HEADER
*)hdr
;
555 hdr5
->bV5RedMask
= 0x0000ff;
556 hdr5
->bV5GreenMask
= 0x00ff00;
557 hdr5
->bV5BlueMask
= 0xff0000;
558 hdr5
->bV5AlphaMask
= 0xff000000;
564 static LRESULT CALLBACK
renderer_winproc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
566 static UINT rendered
;
571 case WM_RENDERFORMAT
:
572 if (wp
< 32) rendered
|= (1 << wp
);
579 return DefWindowProcA( hwnd
, msg
, wp
, lp
);
582 static void test_synthesized(void)
584 static const struct test
590 /* 0 */ { CF_TEXT
, { CF_TEXT
, CF_LOCALE
, CF_OEMTEXT
, CF_UNICODETEXT
}},
591 { CF_OEMTEXT
, { CF_OEMTEXT
, CF_LOCALE
, CF_TEXT
, CF_UNICODETEXT
}},
592 { CF_UNICODETEXT
, { CF_UNICODETEXT
, CF_LOCALE
, CF_TEXT
, CF_OEMTEXT
}},
593 { CF_ENHMETAFILE
, { CF_ENHMETAFILE
, CF_METAFILEPICT
}},
594 { CF_METAFILEPICT
, { CF_METAFILEPICT
, CF_ENHMETAFILE
}},
595 /* 5 */ { CF_BITMAP
, { CF_BITMAP
, CF_DIB
, CF_DIBV5
}},
596 { CF_DIB
, { CF_DIB
, CF_BITMAP
, CF_DIBV5
}},
597 { CF_DIBV5
, { CF_DIBV5
, CF_BITMAP
, CF_DIB
}},
603 UINT cf
, i
, j
, count
, rendered
, seq
, old_seq
;
607 hwnd
= CreateWindowA( "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
608 SetWindowLongPtrA( hwnd
, GWLP_WNDPROC
, (LONG_PTR
)renderer_winproc
);
610 htext
= create_textA();
613 r
= OpenClipboard(NULL
);
614 ok(r
, "gle %d\n", GetLastError());
615 r
= EmptyClipboard();
616 ok(r
, "gle %d\n", GetLastError());
617 h
= SetClipboardData(CF_TEXT
, htext
);
618 ok(h
== htext
, "got %p\n", h
);
619 h
= SetClipboardData(CF_ENHMETAFILE
, emf
);
620 ok(h
== emf
, "got %p\n", h
);
621 r
= CloseClipboard();
622 ok(r
, "gle %d\n", GetLastError());
624 count
= CountClipboardFormats();
625 ok( count
== 6, "count %u\n", count
);
626 r
= IsClipboardFormatAvailable( CF_TEXT
);
627 ok( r
, "CF_TEXT not available err %d\n", GetLastError());
628 r
= IsClipboardFormatAvailable( CF_LOCALE
);
629 ok( r
, "CF_LOCALE not available err %d\n", GetLastError());
630 r
= IsClipboardFormatAvailable( CF_OEMTEXT
);
631 ok( r
, "CF_OEMTEXT not available err %d\n", GetLastError());
632 r
= IsClipboardFormatAvailable( CF_UNICODETEXT
);
633 ok( r
, "CF_UNICODETEXT not available err %d\n", GetLastError());
634 r
= IsClipboardFormatAvailable( CF_ENHMETAFILE
);
635 ok( r
, "CF_ENHMETAFILE not available err %d\n", GetLastError());
636 r
= IsClipboardFormatAvailable( CF_METAFILEPICT
);
637 ok( r
, "CF_METAFILEPICT not available err %d\n", GetLastError());
639 r
= OpenClipboard(NULL
);
640 ok(r
, "gle %d\n", GetLastError());
641 cf
= EnumClipboardFormats(0);
642 ok(cf
== CF_TEXT
, "cf %08x\n", cf
);
643 data
= GetClipboardData(cf
);
644 ok(data
!= NULL
, "couldn't get data, cf %08x\n", cf
);
646 cf
= EnumClipboardFormats(cf
);
647 ok(cf
== CF_ENHMETAFILE
, "cf %08x\n", cf
);
648 data
= GetClipboardData(cf
);
649 ok(data
!= NULL
, "couldn't get data, cf %08x\n", cf
);
651 cf
= EnumClipboardFormats(cf
);
652 ok(cf
== CF_LOCALE
, "cf %08x\n", cf
);
653 data
= GetClipboardData(cf
);
654 ok(data
!= NULL
, "couldn't get data, cf %08x\n", cf
);
656 cf
= EnumClipboardFormats(cf
);
657 ok(cf
== CF_OEMTEXT
, "cf %08x\n", cf
);
658 data
= GetClipboardData(cf
);
659 ok(data
!= NULL
, "couldn't get data, cf %08x\n", cf
);
661 cf
= EnumClipboardFormats(cf
);
662 ok(cf
== CF_UNICODETEXT
, "cf %08x\n", cf
);
664 cf
= EnumClipboardFormats(cf
);
665 ok(cf
== CF_METAFILEPICT
, "cf %08x\n", cf
);
666 data
= GetClipboardData(cf
);
667 ok(data
!= NULL
, "couldn't get data, cf %08x\n", cf
);
669 cf
= EnumClipboardFormats(cf
);
670 ok(cf
== 0, "cf %08x\n", cf
);
672 r
= EmptyClipboard();
673 ok(r
, "gle %d\n", GetLastError());
675 SetClipboardData( CF_UNICODETEXT
, create_textW() );
676 SetClipboardData( CF_TEXT
, create_textA() );
677 SetClipboardData( CF_OEMTEXT
, create_textA() );
678 r
= CloseClipboard();
679 ok(r
, "gle %d\n", GetLastError());
681 r
= OpenClipboard( NULL
);
682 ok(r
, "gle %d\n", GetLastError());
683 SetLastError( 0xdeadbeef );
684 cf
= EnumClipboardFormats(0);
685 ok( cf
== CF_UNICODETEXT
, "cf %08x\n", cf
);
686 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
687 SetLastError( 0xdeadbeef );
688 cf
= EnumClipboardFormats(cf
);
689 ok( cf
== CF_TEXT
, "cf %08x\n", cf
);
690 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
691 SetLastError( 0xdeadbeef );
692 cf
= EnumClipboardFormats(cf
);
693 ok( cf
== CF_OEMTEXT
, "cf %08x\n", cf
);
694 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
695 SetLastError( 0xdeadbeef );
696 cf
= EnumClipboardFormats(cf
);
697 ok( cf
== CF_LOCALE
, "cf %08x\n", cf
);
698 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
699 SetLastError( 0xdeadbeef );
700 cf
= EnumClipboardFormats( cf
);
701 ok( cf
== 0, "cf %08x\n", cf
);
702 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
703 SetLastError( 0xdeadbeef );
704 cf
= EnumClipboardFormats( 0xdead );
705 ok( cf
== 0, "cf %08x\n", cf
);
706 ok( GetLastError() == ERROR_SUCCESS
, "wrong error %u\n", GetLastError() );
708 r
= EmptyClipboard();
709 ok(r
, "gle %d\n", GetLastError());
711 r
= CloseClipboard();
712 ok(r
, "gle %d\n", GetLastError());
714 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
716 r
= OpenClipboard(NULL
);
717 ok(r
, "%u: gle %d\n", i
, GetLastError());
718 r
= EmptyClipboard();
719 ok(r
, "%u: gle %d\n", i
, GetLastError());
721 switch (tests
[i
].format
)
725 SetClipboardData( tests
[i
].format
, create_textA() );
728 SetClipboardData( CF_UNICODETEXT
, create_textW() );
731 SetClipboardData( CF_ENHMETAFILE
, create_emf() );
733 case CF_METAFILEPICT
:
734 SetClipboardData( CF_METAFILEPICT
, create_metafile() );
737 SetClipboardData( CF_BITMAP
, create_bitmap() );
741 SetClipboardData( tests
[i
].format
, create_dib( tests
[i
].format
== CF_DIBV5
));
745 count
= CountClipboardFormats();
746 ok( count
== 1, "%u: count %u\n", i
, count
);
748 r
= CloseClipboard();
749 ok(r
, "%u: gle %d\n", i
, GetLastError());
751 count
= CountClipboardFormats();
752 for (j
= 0; tests
[i
].expected
[j
]; j
++)
754 r
= IsClipboardFormatAvailable( tests
[i
].expected
[j
] );
755 ok( r
, "%u: %04x not available\n", i
, tests
[i
].expected
[j
] );
757 ok( count
== j
, "%u: count %u instead of %u\n", i
, count
, j
);
759 r
= OpenClipboard( hwnd
);
760 ok(r
, "%u: gle %d\n", i
, GetLastError());
762 for (j
= 0; tests
[i
].expected
[j
]; j
++)
764 cf
= EnumClipboardFormats( cf
);
765 ok(cf
== tests
[i
].expected
[j
], "%u.%u: got %04x instead of %04x\n",
766 i
, j
, cf
, tests
[i
].expected
[j
] );
767 if (cf
!= tests
[i
].expected
[j
]) break;
768 old_seq
= GetClipboardSequenceNumber();
769 data
= GetClipboardData( cf
);
771 broken( tests
[i
].format
== CF_DIBV5
&& cf
== CF_DIB
), /* >= Vista */
772 "%u: couldn't get data, cf %04x err %d\n", i
, cf
, GetLastError());
773 seq
= GetClipboardSequenceNumber();
774 ok(seq
== old_seq
, "sequence changed (test %d %d)\n", i
, cf
);
779 UINT
*ptr
= GlobalLock( data
);
780 ok( GlobalSize( data
) == sizeof(*ptr
), "%u: size %lu\n", i
, GlobalSize( data
));
781 ok( *ptr
== GetUserDefaultLCID() ||
782 broken( *ptr
== MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
)),
783 "%u: CF_LOCALE %08x/%08x\n", i
, *ptr
, GetUserDefaultLCID() );
784 GlobalUnlock( data
);
789 ok( GlobalSize( data
) == 10, "wrong len %ld\n", GlobalSize( data
));
792 ok( GlobalSize( data
) == 10 * sizeof(WCHAR
), "wrong len %ld\n", GlobalSize( data
));
796 if (!tests
[i
].expected
[j
])
798 cf
= EnumClipboardFormats( cf
);
799 ok(cf
== 0, "%u: cf %04x\n", i
, cf
);
802 /* now with delayed rendering */
804 r
= EmptyClipboard();
805 ok(r
, "%u: gle %d\n", i
, GetLastError());
807 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
808 ok( !rendered
, "%u: formats %08x have been rendered\n", i
, rendered
);
810 SetClipboardData( tests
[i
].format
, 0 );
811 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
812 ok( !rendered
, "%u: formats %08x have been rendered\n", i
, rendered
);
814 count
= CountClipboardFormats();
815 ok( count
== 1, "%u: count %u\n", i
, count
);
817 r
= CloseClipboard();
818 ok(r
, "%u: gle %d\n", i
, GetLastError());
819 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
820 ok( !rendered
, "%u: formats %08x have been rendered\n", i
, rendered
);
822 count
= CountClipboardFormats();
823 for (j
= 0; tests
[i
].expected
[j
]; j
++)
825 r
= IsClipboardFormatAvailable( tests
[i
].expected
[j
] );
826 ok( r
, "%u: %04x not available\n", i
, tests
[i
].expected
[j
] );
828 ok( count
== j
, "%u: count %u instead of %u\n", i
, count
, j
);
829 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
830 ok( !rendered
, "%u: formats %08x have been rendered\n", i
, rendered
);
832 r
= OpenClipboard(NULL
);
833 ok(r
, "%u: gle %d\n", i
, GetLastError());
835 for (j
= 0; tests
[i
].expected
[j
]; j
++)
837 cf
= EnumClipboardFormats( cf
);
838 ok(cf
== tests
[i
].expected
[j
], "%u.%u: got %04x instead of %04x\n",
839 i
, j
, cf
, tests
[i
].expected
[j
] );
840 if (cf
!= tests
[i
].expected
[j
]) break;
841 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
842 ok( !rendered
, "%u.%u: formats %08x have been rendered\n", i
, j
, rendered
);
843 data
= GetClipboardData( cf
);
844 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
847 ok(data
!= NULL
, "%u: CF_LOCALE no data\n", i
);
848 ok( !rendered
, "%u.%u: formats %08x have been rendered\n", i
, j
, rendered
);
852 ok(!data
, "%u: format %04x got data %p\n", i
, cf
, data
);
853 ok( rendered
== (1 << tests
[i
].format
),
854 "%u.%u: formats %08x have been rendered\n", i
, j
, rendered
);
855 /* try to render a second time */
856 data
= GetClipboardData( cf
);
857 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
858 ok( rendered
== (1 << tests
[i
].format
),
859 "%u.%u: formats %08x have been rendered\n", i
, j
, rendered
);
862 if (!tests
[i
].expected
[j
])
864 cf
= EnumClipboardFormats( cf
);
865 ok(cf
== 0, "%u: cf %04x\n", i
, cf
);
867 r
= CloseClipboard();
868 ok(r
, "%u: gle %d\n", i
, GetLastError());
869 rendered
= SendMessageA( hwnd
, WM_USER
, 0, 0 );
870 ok( !rendered
, "%u: formats %08x have been rendered\n", i
, rendered
);
873 r
= OpenClipboard(NULL
);
874 ok(r
, "gle %d\n", GetLastError());
875 r
= EmptyClipboard();
876 ok(r
, "gle %d\n", GetLastError());
877 r
= CloseClipboard();
878 ok(r
, "gle %d\n", GetLastError());
879 DestroyWindow( hwnd
);
882 static DWORD WINAPI
clipboard_render_data_thread(void *param
)
884 HANDLE handle
= SetClipboardData( CF_UNICODETEXT
, create_textW() );
885 ok( handle
!= 0, "SetClipboardData failed: %d\n", GetLastError() );
889 static CRITICAL_SECTION clipboard_cs
;
890 static HWND next_wnd
;
891 static UINT wm_drawclipboard
;
892 static UINT wm_clipboardupdate
;
893 static UINT wm_destroyclipboard
;
894 static UINT wm_renderformat
;
895 static UINT nb_formats
;
896 static BOOL cross_thread
;
897 static BOOL do_render_format
;
898 static HANDLE update_event
;
900 static LRESULT CALLBACK
clipboard_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
903 DWORD msg_flags
= InSendMessageEx( NULL
);
906 case WM_DRAWCLIPBOARD
:
907 ok( msg_flags
== (cross_thread
? ISMEX_NOTIFY
: ISMEX_NOSEND
),
908 "WM_DRAWCLIPBOARD wrong flags %x\n", msg_flags
);
909 EnterCriticalSection(&clipboard_cs
);
911 LeaveCriticalSection(&clipboard_cs
);
913 case WM_CHANGECBCHAIN
:
914 ok( msg_flags
== (cross_thread
? ISMEX_SEND
: ISMEX_NOSEND
),
915 "WM_CHANGECBCHAIN wrong flags %x\n", msg_flags
);
916 if (next_wnd
== (HWND
)wp
)
919 SendMessageA(next_wnd
, msg
, wp
, lp
);
921 case WM_DESTROYCLIPBOARD
:
922 ok( msg_flags
== (cross_thread
? ISMEX_SEND
: ISMEX_NOSEND
),
923 "WM_DESTROYCLIPBOARD wrong flags %x\n", msg_flags
);
924 wm_destroyclipboard
++;
925 ok( GetClipboardOwner() == hwnd
, "WM_DESTROYCLIPBOARD owner %p\n", GetClipboardOwner() );
926 nb_formats
= CountClipboardFormats();
928 case WM_RENDERFORMAT
:
929 ok( !wm_renderformat
, "multiple WM_RENDERFORMAT %04x / %04lx\n", wm_renderformat
, wp
);
930 wm_renderformat
= wp
;
932 if (do_render_format
)
937 old_seq
= GetClipboardSequenceNumber();
938 handle
= SetClipboardData( CF_TEXT
, create_textA() );
939 ok( handle
!= 0, "SetClipboardData failed: %d\n", GetLastError() );
940 seq
= GetClipboardSequenceNumber();
941 ok( seq
== old_seq
, "sequence changed\n" );
944 handle
= CreateThread( NULL
, 0, clipboard_render_data_thread
, NULL
, 0, NULL
);
945 ok( handle
!= NULL
, "CreateThread failed: %d\n", GetLastError() );
946 ok( WaitForSingleObject(handle
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n" );
947 CloseHandle( handle
);
948 seq
= GetClipboardSequenceNumber();
949 ok( seq
== old_seq
, "sequence changed\n" );
953 case WM_CLIPBOARDUPDATE
:
954 ok( msg_flags
== ISMEX_NOSEND
, "WM_CLIPBOARDUPDATE wrong flags %x\n", msg_flags
);
955 EnterCriticalSection(&clipboard_cs
);
956 wm_clipboardupdate
++;
957 SetEvent(update_event
);
958 LeaveCriticalSection(&clipboard_cs
);
961 ChangeClipboardChain(hwnd
, next_wnd
);
965 ret
= wm_drawclipboard
;
966 wm_drawclipboard
= 0;
969 ret
= wm_clipboardupdate
;
970 wm_clipboardupdate
= 0;
973 ret
= wm_destroyclipboard
;
974 wm_destroyclipboard
= 0;
977 ret
= wm_renderformat
;
984 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
987 static void get_clipboard_data_process(void)
992 r
= OpenClipboard(0);
993 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
994 data
= GetClipboardData( CF_UNICODETEXT
);
995 ok( data
!= NULL
, "GetClipboardData failed: %d\n", GetLastError());
996 r
= CloseClipboard();
997 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1000 static UINT old_seq
;
1002 static void check_messages_(int line
, HWND win
, UINT seq_diff
, UINT draw
, UINT update
, UINT destroy
, UINT render
)
1005 UINT count
, fmt
, seq
;
1007 seq
= GetClipboardSequenceNumber();
1008 ok_(__FILE__
, line
)(seq
- old_seq
== seq_diff
, "sequence diff %d\n", seq
- old_seq
);
1013 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1016 if (update
&& !broken(!pAddClipboardFormatListener
))
1017 ok(WaitForSingleObject(update_event
, 1000) == WAIT_OBJECT_0
, "wait failed\n");
1019 count
= SendMessageA( win
, WM_USER
+ 1, 0, 0 );
1020 ok_(__FILE__
, line
)(count
== draw
, "WM_DRAWCLIPBOARD %sreceived\n", draw
? "not " : "");
1021 count
= SendMessageA( win
, WM_USER
+ 2, 0, 0 );
1022 ok_(__FILE__
, line
)(count
== update
|| broken(!pAddClipboardFormatListener
),
1023 "WM_CLIPBOARDUPDATE %sreceived\n", update
? "not " : "");
1024 count
= SendMessageA( win
, WM_USER
+ 3, 0, 0 );
1025 ok_(__FILE__
, line
)(count
== destroy
, "WM_DESTROYCLIPBOARD %sreceived\n", destroy
? "not " : "");
1026 fmt
= SendMessageA( win
, WM_USER
+ 4, 0, 0 );
1027 ok_(__FILE__
, line
)(fmt
== render
, "WM_RENDERFORMAT received %04x, expected %04x\n", fmt
, render
);
1029 #define check_messages(a,b,c,d,e,f) check_messages_(__LINE__,a,b,c,d,e,f)
1031 static DWORD WINAPI
clipboard_thread(void *param
)
1033 HWND ret
, win
= param
;
1037 UINT count
, fmt
, formats
;
1039 cross_thread
= (GetWindowThreadProcessId( win
, NULL
) != GetCurrentThreadId());
1040 trace( "%s-threaded test\n", cross_thread
? "multi" : "single" );
1042 old_seq
= GetClipboardSequenceNumber();
1044 EnterCriticalSection(&clipboard_cs
);
1045 SetLastError(0xdeadbeef);
1046 next_wnd
= SetClipboardViewer(win
);
1047 ok(GetLastError() == 0xdeadbeef, "GetLastError = %d\n", GetLastError());
1048 LeaveCriticalSection(&clipboard_cs
);
1050 SetLastError( 0xdeadbeef );
1051 ret
= SetClipboardViewer( (HWND
)0xdead );
1052 ok( !ret
, "SetClipboardViewer succeeded\n" );
1053 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1054 SetLastError( 0xdeadbeef );
1055 r
= ChangeClipboardChain( win
, (HWND
)0xdead );
1056 ok( !r
, "ChangeClipboardChain succeeded\n" );
1057 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1058 SetLastError( 0xdeadbeef );
1059 r
= ChangeClipboardChain( (HWND
)0xdead, next_wnd
);
1060 ok( !r
, "ChangeClipboardChain succeeded\n" );
1061 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1063 if (pAddClipboardFormatListener
)
1065 r
= pAddClipboardFormatListener(win
);
1066 ok( r
, "AddClipboardFormatListener failed err %d\n", GetLastError());
1067 SetLastError( 0xdeadbeef );
1068 r
= pAddClipboardFormatListener( win
);
1069 ok( !r
, "AddClipboardFormatListener succeeded\n" );
1070 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
1071 SetLastError( 0xdeadbeef );
1072 r
= pAddClipboardFormatListener( (HWND
)0xdead );
1073 ok( !r
, "AddClipboardFormatListener succeeded\n" );
1074 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1075 r
= pAddClipboardFormatListener( GetDesktopWindow() );
1076 ok( r
, "AddClipboardFormatListener failed err %d\n", GetLastError());
1077 r
= pRemoveClipboardFormatListener( GetDesktopWindow() );
1078 ok( r
, "RemoveClipboardFormatListener failed err %d\n", GetLastError());
1081 check_messages(win
, 0, 1, 0, 0, 0);
1083 SetLastError( 0xdeadbeef );
1084 r
= OpenClipboard( (HWND
)0xdead );
1085 ok( !r
, "OpenClipboard succeeded\n" );
1086 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1088 r
= OpenClipboard(win
);
1089 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1091 check_messages(win
, 0, 0, 0, 0, 0);
1093 r
= EmptyClipboard();
1094 ok(r
, "EmptyClipboard failed: %d\n", GetLastError());
1096 check_messages(win
, 1, 0, 0, 0, 0);
1098 r
= EmptyClipboard();
1099 ok(r
, "EmptyClipboard failed: %d\n", GetLastError());
1100 /* sequence changes again, even though it was already empty */
1101 check_messages(win
, 1, 0, 0, 1, 0);
1102 count
= SendMessageA( win
, WM_USER
+5, 0, 0 );
1103 ok( !count
, "wrong format count %u on WM_DESTROYCLIPBOARD\n", count
);
1105 handle
= SetClipboardData( CF_TEXT
, create_textA() );
1106 ok(handle
!= 0, "SetClipboardData failed: %d\n", GetLastError());
1108 check_messages(win
, 1, 0, 0, 0, 0);
1110 SetClipboardData( CF_UNICODETEXT
, 0 );
1112 check_messages(win
, 1, 0, 0, 0, 0);
1114 SetClipboardData( CF_UNICODETEXT
, 0 ); /* same data again */
1116 check_messages(win
, 1, 0, 0, 0, 0);
1118 ok( IsClipboardFormatAvailable( CF_TEXT
), "CF_TEXT available\n" );
1119 ok( IsClipboardFormatAvailable( CF_UNICODETEXT
), "CF_UNICODETEXT available\n" );
1120 ok( !IsClipboardFormatAvailable( CF_OEMTEXT
), "CF_OEMTEXT available\n" );
1122 EnterCriticalSection(&clipboard_cs
);
1123 r
= CloseClipboard();
1124 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1125 LeaveCriticalSection(&clipboard_cs
);
1127 check_messages(win
, 2, 1, 1, 0, 0);
1129 r
= OpenClipboard(win
);
1130 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1132 check_messages(win
, 0, 0, 0, 0, 0);
1134 ok( IsClipboardFormatAvailable( CF_TEXT
), "CF_TEXT available\n" );
1135 ok( IsClipboardFormatAvailable( CF_UNICODETEXT
), "CF_UNICODETEXT available\n" );
1136 ok( IsClipboardFormatAvailable( CF_OEMTEXT
), "CF_OEMTEXT available\n" );
1138 ok( GetClipboardOwner() == win
, "wrong owner %p\n", GetClipboardOwner());
1139 handle
= GetClipboardData( CF_UNICODETEXT
);
1140 ok( !handle
, "got data for CF_UNICODETEXT\n" );
1141 fmt
= SendMessageA( win
, WM_USER
+4, 0, 0 );
1142 ok( fmt
== CF_UNICODETEXT
, "WM_RENDERFORMAT received %04x\n", fmt
);
1144 do_render_format
= TRUE
;
1145 handle
= GetClipboardData( CF_OEMTEXT
);
1146 ok( handle
!= NULL
, "didn't get data for CF_OEMTEXT\n" );
1147 fmt
= SendMessageA( win
, WM_USER
+4, 0, 0 );
1148 ok( fmt
== CF_UNICODETEXT
, "WM_RENDERFORMAT received %04x\n", fmt
);
1149 do_render_format
= FALSE
;
1151 SetClipboardData( CF_WAVE
, 0 );
1152 check_messages(win
, 1, 0, 0, 0, 0);
1154 r
= CloseClipboard();
1155 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1156 /* no synthesized format, so CloseClipboard doesn't change the sequence */
1157 check_messages(win
, 0, 1, 1, 0, 0);
1159 r
= OpenClipboard(win
);
1160 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1161 r
= CloseClipboard();
1162 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1163 /* nothing changed */
1164 check_messages(win
, 0, 0, 0, 0, 0);
1166 formats
= CountClipboardFormats();
1167 r
= OpenClipboard(0);
1168 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1169 r
= EmptyClipboard();
1170 ok(r
, "EmptyClipboard failed: %d\n", GetLastError());
1171 r
= CloseClipboard();
1172 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1174 check_messages(win
, 1, 1, 1, 1, 0);
1175 count
= SendMessageA( win
, WM_USER
+5, 0, 0 );
1176 ok( count
== formats
, "wrong format count %u on WM_DESTROYCLIPBOARD\n", count
);
1178 r
= OpenClipboard(win
);
1179 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1180 SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_FIXED
, 1 ));
1181 check_messages(win
, 1, 0, 0, 0, 0);
1183 EnterCriticalSection(&clipboard_cs
);
1184 r
= CloseClipboard();
1185 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1186 LeaveCriticalSection(&clipboard_cs
);
1188 check_messages(win
, 0, 1, 1, 0, 0);
1190 run_process( "grab_clipboard 0" );
1194 /* in this case we get a cross-thread WM_DRAWCLIPBOARD */
1195 cross_thread
= TRUE
;
1196 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1197 cross_thread
= FALSE
;
1199 check_messages(win
, 1, 1, 1, 0, 0);
1201 r
= OpenClipboard(0);
1202 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1203 SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_FIXED
, 1 ));
1204 check_messages(win
, 1, 0, 0, 0, 0);
1206 EnterCriticalSection(&clipboard_cs
);
1207 r
= CloseClipboard();
1208 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1209 LeaveCriticalSection(&clipboard_cs
);
1211 check_messages(win
, 0, 1, 1, 0, 0);
1213 run_process( "grab_clipboard 1" );
1217 /* in this case we get a cross-thread WM_DRAWCLIPBOARD */
1218 cross_thread
= TRUE
;
1219 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1220 cross_thread
= FALSE
;
1222 check_messages(win
, 2, 1, 1, 0, 0);
1224 r
= OpenClipboard(0);
1225 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1226 SetClipboardData( CF_WAVE
, GlobalAlloc( GMEM_FIXED
, 1 ));
1227 check_messages(win
, 1, 0, 0, 0, 0);
1229 EnterCriticalSection(&clipboard_cs
);
1230 r
= CloseClipboard();
1231 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1232 LeaveCriticalSection(&clipboard_cs
);
1234 check_messages(win
, 0, 1, 1, 0, 0);
1238 r
= OpenClipboard( win
);
1239 ok(r
, "OpenClipboard failed: %d\n", GetLastError());
1240 r
= EmptyClipboard();
1241 ok(r
, "EmptyClipboard failed: %d\n", GetLastError());
1242 SetClipboardData( CF_TEXT
, 0 );
1243 r
= CloseClipboard();
1244 ok(r
, "CloseClipboard failed: %d\n", GetLastError());
1246 do_render_format
= TRUE
;
1247 old_seq
= GetClipboardSequenceNumber();
1248 run_process( "get_clipboard_data" );
1249 do_render_format
= FALSE
;
1251 check_messages(win
, 0, 1, 1, 0, CF_TEXT
);
1254 r
= PostMessageA(win
, WM_USER
, 0, 0);
1255 ok(r
, "PostMessage failed: %d\n", GetLastError());
1257 if (pRemoveClipboardFormatListener
)
1259 r
= pRemoveClipboardFormatListener(win
);
1260 ok( r
, "RemoveClipboardFormatListener failed err %d\n", GetLastError());
1261 SetLastError( 0xdeadbeef );
1262 r
= pRemoveClipboardFormatListener(win
);
1263 ok( !r
, "RemoveClipboardFormatListener succeeded\n" );
1264 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error %u\n", GetLastError() );
1265 SetLastError( 0xdeadbeef );
1266 r
= pRemoveClipboardFormatListener( (HWND
)0xdead );
1267 ok( !r
, "RemoveClipboardFormatListener succeeded\n" );
1268 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "wrong error %u\n", GetLastError() );
1273 static void test_messages(void)
1281 InitializeCriticalSection(&clipboard_cs
);
1282 update_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1284 memset(&cls
, 0, sizeof(cls
));
1285 cls
.lpfnWndProc
= clipboard_wnd_proc
;
1286 cls
.hInstance
= GetModuleHandleA(NULL
);
1287 cls
.lpszClassName
= "clipboard_test";
1288 RegisterClassA(&cls
);
1290 win
= CreateWindowA("clipboard_test", NULL
, 0, 0, 0, 0, 0, NULL
, 0, NULL
, 0);
1291 ok(win
!= NULL
, "CreateWindow failed: %d\n", GetLastError());
1293 thread
= CreateThread(NULL
, 0, clipboard_thread
, (void*)win
, 0, &tid
);
1294 ok(thread
!= NULL
, "CreateThread failed: %d\n", GetLastError());
1296 while(GetMessageA(&msg
, NULL
, 0, 0))
1298 ok( msg
.message
!= WM_DRAWCLIPBOARD
, "WM_DRAWCLIPBOARD was posted\n" );
1299 TranslateMessage(&msg
);
1300 DispatchMessageA(&msg
);
1303 ok(WaitForSingleObject(thread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
1304 CloseHandle(thread
);
1306 DestroyWindow( win
);
1308 /* same tests again but inside a single thread */
1310 win
= CreateWindowA( "clipboard_test", NULL
, 0, 0, 0, 0, 0, NULL
, 0, NULL
, 0 );
1311 ok( win
!= NULL
, "CreateWindow failed: %d\n", GetLastError() );
1313 clipboard_thread( win
);
1314 DestroyWindow( win
);
1316 UnregisterClassA("clipboard_test", GetModuleHandleA(NULL
));
1317 DeleteCriticalSection(&clipboard_cs
);
1320 static BOOL
is_moveable( HANDLE handle
)
1322 void *ptr
= GlobalLock( handle
);
1323 if (ptr
) GlobalUnlock( handle
);
1324 return ptr
&& ptr
!= handle
;
1327 static BOOL
is_fixed( HANDLE handle
)
1329 void *ptr
= GlobalLock( handle
);
1330 if (ptr
) GlobalUnlock( handle
);
1331 return ptr
&& ptr
== handle
;
1334 static BOOL
is_freed( HANDLE handle
)
1336 return !GlobalSize( handle
);
1339 static UINT format_id
;
1340 static HBITMAP bitmap
, bitmap2
;
1341 static HPALETTE palette
;
1342 static const LOGPALETTE logpalette
= { 0x300, 1, {{ 0x12, 0x34, 0x56, 0x78 }}};
1344 static void test_handles( HWND hwnd
)
1346 HGLOBAL h
, htext
, htext2
, htext3
, htext4
, htext5
;
1347 HGLOBAL hfixed
, hfixed2
, hmoveable
, empty_fixed
, empty_moveable
;
1349 UINT format_id2
= RegisterClipboardFormatA( "another format" );
1352 HBITMAP bitmap_temp
;
1354 BOOL is_owner
= (GetWindowThreadProcessId( hwnd
, &process
) && process
== GetCurrentProcessId());
1356 trace( "hwnd %p\n", hwnd
);
1357 htext
= create_textA();
1358 htext2
= create_textA();
1359 htext3
= create_textA();
1360 htext4
= create_textA();
1361 htext5
= create_textA();
1362 bitmap
= CreateBitmap( 10, 10, 1, 1, NULL
);
1363 bitmap2
= CreateBitmap( 10, 10, 1, 1, NULL
);
1364 palette
= CreatePalette( &logpalette
);
1366 hfixed
= GlobalAlloc( GMEM_FIXED
, 17 );
1367 hfixed2
= GlobalAlloc( GMEM_FIXED
, 17 );
1368 ok( is_fixed( hfixed
), "expected fixed mem %p\n", hfixed
);
1369 ok( GlobalSize( hfixed
) == 17, "wrong size %lu\n", GlobalSize( hfixed
));
1371 hmoveable
= GlobalAlloc( GMEM_MOVEABLE
, 23 );
1372 ok( is_moveable( hmoveable
), "expected moveable mem %p\n", hmoveable
);
1373 ok( GlobalSize( hmoveable
) == 23, "wrong size %lu\n", GlobalSize( hmoveable
));
1375 empty_fixed
= GlobalAlloc( GMEM_FIXED
, 0 );
1376 ok( is_fixed( empty_fixed
), "expected fixed mem %p\n", empty_fixed
);
1378 empty_moveable
= GlobalAlloc( GMEM_MOVEABLE
, 0 );
1379 /* discarded handles can't be GlobalLock'ed */
1380 ok( is_freed( empty_moveable
), "expected free mem %p\n", empty_moveable
);
1382 r
= OpenClipboard( hwnd
);
1383 ok( r
, "gle %d\n", GetLastError() );
1384 r
= EmptyClipboard();
1385 ok( r
, "gle %d\n", GetLastError() );
1387 h
= SetClipboardData( CF_TEXT
, htext
);
1388 ok( h
== htext
, "got %p\n", h
);
1389 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1390 h
= SetClipboardData( format_id
, htext2
);
1391 ok( h
== htext2
, "got %p\n", h
);
1392 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1393 bitmap_temp
= CreateBitmap( 10, 10, 1, 1, NULL
);
1394 h
= SetClipboardData( CF_BITMAP
, bitmap_temp
);
1395 ok( h
== bitmap_temp
, "got %p\n", h
);
1396 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1397 h
= SetClipboardData( CF_BITMAP
, bitmap
);
1398 ok( h
== bitmap
, "got %p\n", h
);
1399 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1400 ok( !GetObjectType( bitmap_temp
), "expected free object %p\n", bitmap_temp
);
1401 h
= SetClipboardData( CF_DSPBITMAP
, bitmap2
);
1402 ok( h
== bitmap2
, "got %p\n", h
);
1403 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1404 h
= SetClipboardData( CF_PALETTE
, palette
);
1405 ok( h
== palette
, "got %p\n", h
);
1406 ok( GetObjectType( h
) == OBJ_PAL
, "expected palette %p\n", h
);
1407 h
= SetClipboardData( CF_GDIOBJFIRST
+ 3, htext3
);
1408 ok( h
== htext3
, "got %p\n", h
);
1409 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1410 h
= SetClipboardData( CF_PRIVATEFIRST
+ 7, htext5
);
1411 ok( h
== htext5
, "got %p\n", h
);
1412 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1413 h
= SetClipboardData( format_id2
, empty_moveable
);
1414 ok( !h
, "got %p\n", h
);
1415 GlobalFree( empty_moveable
);
1417 if (0) /* crashes on vista64 */
1419 ptr
= HeapAlloc( GetProcessHeap(), 0, 0 );
1420 h
= SetClipboardData( format_id2
, ptr
);
1421 ok( !h
, "got %p\n", h
);
1422 HeapFree( GetProcessHeap(), 0, ptr
);
1425 h
= SetClipboardData( format_id2
, empty_fixed
);
1426 ok( h
== empty_fixed
, "got %p\n", h
);
1427 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1428 h
= SetClipboardData( 0xdeadbeef, hfixed2
);
1429 ok( h
== hfixed2
, "got %p\n", h
);
1430 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1431 h
= SetClipboardData( 0xdeadbabe, hmoveable
);
1432 ok( h
== hmoveable
, "got %p\n", h
);
1433 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1435 ptr
= HeapAlloc( GetProcessHeap(), 0, 37 );
1436 h
= SetClipboardData( 0xdeadfade, ptr
);
1437 ok( h
== ptr
|| !h
, "got %p\n", h
);
1438 if (!h
) /* heap blocks are rejected on >= win8 */
1440 HeapFree( GetProcessHeap(), 0, ptr
);
1444 data
= GetClipboardData( CF_TEXT
);
1445 ok( data
== htext
, "wrong data %p\n", data
);
1446 ok( is_moveable( data
), "expected moveable mem %p\n", data
);
1448 data
= GetClipboardData( format_id
);
1449 ok( data
== htext2
, "wrong data %p, cf %08x\n", data
, format_id
);
1450 ok( is_moveable( data
), "expected moveable mem %p\n", data
);
1452 data
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1453 ok( data
== htext3
, "wrong data %p\n", data
);
1454 ok( is_moveable( data
), "expected moveable mem %p\n", data
);
1456 data
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1457 ok( data
== htext5
, "wrong data %p\n", data
);
1458 ok( is_moveable( data
), "expected moveable mem %p\n", data
);
1460 data
= GetClipboardData( format_id2
);
1461 ok( data
== empty_fixed
, "wrong data %p\n", data
);
1462 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1464 data
= GetClipboardData( 0xdeadbeef );
1465 ok( data
== hfixed2
, "wrong data %p\n", data
);
1466 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1468 data
= GetClipboardData( 0xdeadbabe );
1469 ok( data
== hmoveable
, "wrong data %p\n", data
);
1470 ok( is_moveable( data
), "expected moveable mem %p\n", data
);
1472 data
= GetClipboardData( 0xdeadfade );
1473 ok( data
== ptr
, "wrong data %p\n", data
);
1475 h
= SetClipboardData( CF_PRIVATEFIRST
+ 7, htext4
);
1476 ok( h
== htext4
, "got %p\n", h
);
1477 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1478 ok( is_freed( htext5
), "expected freed mem %p\n", htext5
);
1480 h
= SetClipboardData( 0xdeadbeef, hfixed
);
1481 ok( h
== hfixed
, "got %p\n", h
);
1482 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1483 if (0) /* this test is unreliable / crashes */
1484 ok( is_freed( hfixed2
), "expected freed mem %p\n", hfixed2
);
1486 r
= CloseClipboard();
1487 ok( r
, "gle %d\n", GetLastError() );
1489 /* data handles are still valid */
1490 ok( is_moveable( htext
), "expected moveable mem %p\n", htext
);
1491 ok( is_moveable( htext2
), "expected moveable mem %p\n", htext2
);
1492 ok( is_moveable( htext3
), "expected moveable mem %p\n", htext3
);
1493 ok( is_moveable( htext4
), "expected moveable mem %p\n", htext4
);
1494 ok( GetObjectType( bitmap
) == OBJ_BITMAP
, "expected bitmap %p\n", bitmap
);
1495 ok( GetObjectType( bitmap2
) == OBJ_BITMAP
, "expected bitmap %p\n", bitmap2
);
1496 ok( GetObjectType( palette
) == OBJ_PAL
, "expected palette %p\n", palette
);
1497 ok( is_fixed( hfixed
), "expected fixed mem %p\n", hfixed
);
1498 ok( is_moveable( hmoveable
), "expected moveable mem %p\n", hmoveable
);
1499 ok( is_fixed( empty_fixed
), "expected fixed mem %p\n", empty_fixed
);
1501 r
= OpenClipboard( hwnd
);
1502 ok( r
, "gle %d\n", GetLastError() );
1504 /* and now they are freed, unless we are the owner */
1507 ok( is_freed( htext
), "expected freed mem %p\n", htext
);
1508 ok( is_freed( htext2
), "expected freed mem %p\n", htext2
);
1509 ok( is_freed( htext3
), "expected freed mem %p\n", htext3
);
1510 ok( is_freed( htext4
), "expected freed mem %p\n", htext4
);
1511 ok( is_freed( hmoveable
), "expected freed mem %p\n", hmoveable
);
1513 data
= GetClipboardData( CF_TEXT
);
1514 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1516 data
= GetClipboardData( format_id
);
1517 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1519 data
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1520 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1522 data
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1523 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1525 data
= GetClipboardData( format_id2
);
1526 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1527 ok( GlobalSize( data
) == 1, "wrong size %lu\n", GlobalSize( data
));
1529 data
= GetClipboardData( 0xdeadbeef );
1530 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1531 ok( GlobalSize( data
) == 17, "wrong size %lu\n", GlobalSize( data
));
1533 data
= GetClipboardData( 0xdeadbabe );
1534 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1535 ok( GlobalSize( data
) == 23, "wrong size %lu\n", GlobalSize( data
));
1537 data
= GetClipboardData( 0xdeadfade );
1538 ok( is_fixed( data
) || !ptr
, "expected fixed mem %p\n", data
);
1539 if (ptr
) ok( GlobalSize( data
) == 37, "wrong size %lu\n", GlobalSize( data
));
1543 ok( is_moveable( htext
), "expected moveable mem %p\n", htext
);
1544 ok( is_moveable( htext2
), "expected moveable mem %p\n", htext2
);
1545 ok( is_moveable( htext3
), "expected moveable mem %p\n", htext3
);
1546 ok( is_moveable( htext4
), "expected moveable mem %p\n", htext4
);
1547 ok( is_moveable( hmoveable
), "expected moveable mem %p\n", hmoveable
);
1549 data
= GetClipboardData( CF_TEXT
);
1550 ok( data
== htext
, "wrong data %p\n", data
);
1552 data
= GetClipboardData( format_id
);
1553 ok( data
== htext2
, "wrong data %p, cf %08x\n", data
, format_id
);
1555 data
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1556 ok( data
== htext3
, "wrong data %p\n", data
);
1558 data
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1559 ok( data
== htext4
, "wrong data %p\n", data
);
1561 data
= GetClipboardData( format_id2
);
1562 ok( data
== empty_fixed
, "wrong data %p\n", data
);
1564 data
= GetClipboardData( 0xdeadbeef );
1565 ok( data
== hfixed
, "wrong data %p\n", data
);
1567 data
= GetClipboardData( 0xdeadbabe );
1568 ok( data
== hmoveable
, "wrong data %p\n", data
);
1570 data
= GetClipboardData( 0xdeadfade );
1571 ok( data
== ptr
, "wrong data %p\n", data
);
1574 data
= GetClipboardData( CF_OEMTEXT
);
1575 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1576 data
= GetClipboardData( CF_UNICODETEXT
);
1577 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1578 data
= GetClipboardData( CF_LOCALE
);
1579 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1580 data
= GetClipboardData( CF_BITMAP
);
1581 ok( data
== bitmap
, "expected bitmap %p\n", data
);
1582 data
= GetClipboardData( CF_DSPBITMAP
);
1583 ok( data
== bitmap2
, "expected bitmap %p\n", data
);
1584 data
= GetClipboardData( CF_PALETTE
);
1585 ok( data
== palette
, "expected palette %p\n", data
);
1586 data
= GetClipboardData( CF_DIB
);
1587 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1588 data
= GetClipboardData( CF_DIBV5
);
1589 ok( is_fixed( data
), "expected fixed mem %p\n", data
);
1591 ok( GetObjectType( bitmap
) == OBJ_BITMAP
, "expected bitmap %p\n", bitmap
);
1592 ok( GetObjectType( bitmap2
) == OBJ_BITMAP
, "expected bitmap %p\n", bitmap2
);
1593 ok( GetObjectType( palette
) == OBJ_PAL
, "expected palette %p\n", palette
);
1594 ok( is_fixed( hfixed
), "expected fixed mem %p\n", hfixed
);
1595 ok( is_fixed( empty_fixed
), "expected fixed mem %p\n", empty_fixed
);
1597 r
= EmptyClipboard();
1598 ok( r
, "gle %d\n", GetLastError() );
1600 /* w2003, w2008 don't seem to free the data here */
1601 ok( is_freed( htext
) || broken( !is_freed( htext
)), "expected freed mem %p\n", htext
);
1602 ok( is_freed( htext2
) || broken( !is_freed( htext2
)), "expected freed mem %p\n", htext2
);
1603 ok( is_freed( htext3
) || broken( !is_freed( htext3
)), "expected freed mem %p\n", htext3
);
1604 ok( is_freed( htext4
) || broken( !is_freed( htext4
)), "expected freed mem %p\n", htext4
);
1605 ok( is_freed( hmoveable
) || broken( !is_freed( hmoveable
)), "expected freed mem %p\n", hmoveable
);
1606 ok( is_fixed( empty_fixed
), "expected fixed mem %p\n", empty_fixed
);
1607 ok( is_fixed( hfixed
), "expected fixed mem %p\n", hfixed
);
1608 ok( !GetObjectType( bitmap
), "expected freed handle %p\n", bitmap
);
1609 ok( !GetObjectType( bitmap2
), "expected freed handle %p\n", bitmap2
);
1610 ok( !GetObjectType( palette
), "expected freed handle %p\n", palette
);
1612 r
= CloseClipboard();
1613 ok( r
, "gle %d\n", GetLastError() );
1616 static DWORD WINAPI
test_handles_thread( void *arg
)
1618 trace( "running from different thread\n" );
1619 test_handles( (HWND
)arg
);
1623 static DWORD WINAPI
test_handles_thread2( void *arg
)
1629 r
= OpenClipboard( 0 );
1630 ok( r
, "gle %d\n", GetLastError() );
1631 h
= GetClipboardData( CF_TEXT
);
1632 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1633 ptr
= GlobalLock( h
);
1634 if (ptr
) ok( !strcmp( "test", ptr
), "wrong data '%.5s'\n", ptr
);
1636 h
= GetClipboardData( format_id
);
1637 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1638 ptr
= GlobalLock( h
);
1639 if (ptr
) ok( !strcmp( "test", ptr
), "wrong data '%.5s'\n", ptr
);
1641 h
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1642 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1643 ptr
= GlobalLock( h
);
1644 if (ptr
) ok( !strcmp( "test", ptr
), "wrong data '%.5s'\n", ptr
);
1646 trace( "gdiobj %p\n", h
);
1647 h
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1648 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1649 ptr
= GlobalLock( h
);
1650 if (ptr
) ok( !strcmp( "test", ptr
), "wrong data '%.5s'\n", ptr
);
1652 trace( "private %p\n", h
);
1653 h
= GetClipboardData( CF_BITMAP
);
1654 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1655 ok( h
== bitmap
, "different bitmap %p / %p\n", h
, bitmap
);
1656 trace( "bitmap %p\n", h
);
1657 h
= GetClipboardData( CF_DSPBITMAP
);
1658 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1659 ok( h
== bitmap2
, "different bitmap %p / %p\n", h
, bitmap2
);
1660 trace( "bitmap2 %p\n", h
);
1661 h
= GetClipboardData( CF_PALETTE
);
1662 ok( GetObjectType( h
) == OBJ_PAL
, "expected palette %p\n", h
);
1663 ok( h
== palette
, "different palette %p / %p\n", h
, palette
);
1664 trace( "palette %p\n", h
);
1665 h
= GetClipboardData( CF_DIB
);
1666 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1667 h
= GetClipboardData( CF_DIBV5
);
1668 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1669 r
= CloseClipboard();
1670 ok( r
, "gle %d\n", GetLastError() );
1674 static void test_handles_process( const char *str
)
1683 format_id
= RegisterClipboardFormatA( "my_cool_clipboard_format" );
1684 r
= OpenClipboard( 0 );
1685 ok( r
, "gle %d\n", GetLastError() );
1686 h
= GetClipboardData( CF_TEXT
);
1687 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1688 ptr
= GlobalLock( h
);
1689 ok( !strcmp( str
, ptr
), "wrong data '%.5s'\n", ptr
);
1691 h
= GetClipboardData( format_id
);
1692 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1693 ptr
= GlobalLock( h
);
1694 if (ptr
) ok( !strcmp( str
, ptr
), "wrong data '%.5s'\n", ptr
);
1696 h
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1697 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1698 ptr
= GlobalLock( h
);
1699 ok( !strcmp( str
, ptr
), "wrong data '%.5s'\n", ptr
);
1701 trace( "gdiobj %p\n", h
);
1702 h
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1703 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1704 ptr
= GlobalLock( h
);
1705 ok( !strcmp( str
, ptr
), "wrong data '%.5s'\n", ptr
);
1707 trace( "private %p\n", h
);
1708 h
= GetClipboardData( CF_BITMAP
);
1709 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1710 ok( GetObjectW( h
, sizeof(bm
), &bm
) == sizeof(bm
), "GetObject %p failed\n", h
);
1711 ok( bm
.bmWidth
== 13 && bm
.bmHeight
== 17, "wrong bitmap %ux%u\n", bm
.bmWidth
, bm
.bmHeight
);
1712 trace( "bitmap %p\n", h
);
1713 h
= GetClipboardData( CF_DSPBITMAP
);
1714 ok( !GetObjectType( h
), "expected invalid object %p\n", h
);
1715 trace( "bitmap2 %p\n", h
);
1716 h
= GetClipboardData( CF_PALETTE
);
1717 ok( GetObjectType( h
) == OBJ_PAL
, "expected palette %p\n", h
);
1718 ok( GetPaletteEntries( h
, 0, 1, &entry
) == 1, "GetPaletteEntries %p failed\n", h
);
1719 ok( entry
.peRed
== 0x12 && entry
.peGreen
== 0x34 && entry
.peBlue
== 0x56,
1720 "wrong color %02x,%02x,%02x\n", entry
.peRed
, entry
.peGreen
, entry
.peBlue
);
1721 trace( "palette %p\n", h
);
1722 h
= GetClipboardData( CF_METAFILEPICT
);
1723 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1724 ok( GetObjectType( ((METAFILEPICT
*)h
)->hMF
) == OBJ_METAFILE
,
1725 "wrong object %p\n", ((METAFILEPICT
*)h
)->hMF
);
1726 trace( "metafile %p\n", h
);
1727 h
= GetClipboardData( CF_DSPMETAFILEPICT
);
1728 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1729 ok( GetObjectType( ((METAFILEPICT
*)h
)->hMF
) == OBJ_METAFILE
,
1730 "wrong object %p\n", ((METAFILEPICT
*)h
)->hMF
);
1731 trace( "metafile2 %p\n", h
);
1732 h
= GetClipboardData( CF_ENHMETAFILE
);
1733 ok( GetObjectType( h
) == OBJ_ENHMETAFILE
, "expected enhmetafile %p\n", h
);
1734 ok( GetEnhMetaFileBits( h
, sizeof(buffer
), buffer
) > sizeof(ENHMETAHEADER
),
1735 "GetEnhMetaFileBits failed on %p\n", h
);
1736 ok( ((ENHMETAHEADER
*)buffer
)->nRecords
== 3,
1737 "wrong records %u\n", ((ENHMETAHEADER
*)buffer
)->nRecords
);
1738 trace( "enhmetafile %p\n", h
);
1739 h
= GetClipboardData( CF_DSPENHMETAFILE
);
1740 ok( GetObjectType( h
) == OBJ_ENHMETAFILE
, "expected enhmetafile %p\n", h
);
1741 ok( GetEnhMetaFileBits( h
, sizeof(buffer
), buffer
) > sizeof(ENHMETAHEADER
),
1742 "GetEnhMetaFileBits failed on %p\n", h
);
1743 ok( ((ENHMETAHEADER
*)buffer
)->nRecords
== 3,
1744 "wrong records %u\n", ((ENHMETAHEADER
*)buffer
)->nRecords
);
1745 trace( "enhmetafile2 %p\n", h
);
1746 h
= GetClipboardData( CF_DIB
);
1747 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1748 h
= GetClipboardData( CF_DIBV5
);
1749 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1750 r
= CloseClipboard();
1751 ok( r
, "gle %d\n", GetLastError() );
1754 static void test_handles_process_open( const char *str
)
1756 HANDLE h
, text
= GlobalAlloc( GMEM_DDESHARE
|GMEM_MOVEABLE
, strlen(str
) + 1 );
1757 char *ptr
= GlobalLock( text
);
1760 GlobalUnlock( text
);
1762 /* clipboard already open by parent process */
1763 h
= SetClipboardData( CF_TEXT
, text
);
1764 ok( h
== text
, "wrong mem %p / %p\n", h
, text
);
1765 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1768 static void test_handles_process_dib( const char *str
)
1773 r
= OpenClipboard( 0 );
1774 ok( r
, "gle %d\n", GetLastError() );
1775 h
= GetClipboardData( CF_BITMAP
);
1776 ok( !GetObjectType( h
), "expected invalid object %p\n", h
);
1777 trace( "dibsection %p\n", h
);
1778 r
= CloseClipboard();
1779 ok( r
, "gle %d\n", GetLastError() );
1782 static void test_data_handles(void)
1787 HWND hwnd
= CreateWindowA( "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1791 ok( hwnd
!= 0, "window creation failed\n" );
1792 format_id
= RegisterClipboardFormatA( "my_cool_clipboard_format" );
1794 test_handles( GetDesktopWindow() );
1795 test_handles( hwnd
);
1796 run_thread( test_handles_thread
, hwnd
, __LINE__
);
1798 bitmap
= CreateBitmap( 13, 17, 1, 1, NULL
);
1799 bitmap2
= CreateBitmap( 10, 10, 1, 1, NULL
);
1800 palette
= CreatePalette( &logpalette
);
1802 r
= OpenClipboard( hwnd
);
1803 ok( r
, "gle %d\n", GetLastError() );
1804 r
= EmptyClipboard();
1805 ok( r
, "gle %d\n", GetLastError() );
1806 h
= SetClipboardData( CF_TEXT
, create_textA() );
1807 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1808 h
= SetClipboardData( format_id
, create_textA() );
1809 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1810 h
= SetClipboardData( CF_BITMAP
, bitmap
);
1811 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1812 h
= SetClipboardData( CF_DSPBITMAP
, bitmap2
);
1813 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1814 h
= SetClipboardData( CF_PALETTE
, palette
);
1815 ok( GetObjectType( h
) == OBJ_PAL
, "expected palette %p\n", h
);
1816 h
= SetClipboardData( CF_METAFILEPICT
, create_metafile() );
1817 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1818 trace( "metafile %p\n", h
);
1819 h
= SetClipboardData( CF_DSPMETAFILEPICT
, create_metafile() );
1820 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1821 trace( "metafile2 %p\n", h
);
1822 h
= SetClipboardData( CF_ENHMETAFILE
, create_emf() );
1823 ok( GetObjectType( h
) == OBJ_ENHMETAFILE
, "expected enhmetafile %p\n", h
);
1824 trace( "enhmetafile %p\n", h
);
1825 h
= SetClipboardData( CF_DSPENHMETAFILE
, create_emf() );
1826 ok( GetObjectType( h
) == OBJ_ENHMETAFILE
, "expected enhmetafile %p\n", h
);
1827 trace( "enhmetafile2 %p\n", h
);
1828 h
= SetClipboardData( CF_GDIOBJFIRST
+ 3, create_textA() );
1829 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1830 h
= SetClipboardData( CF_PRIVATEFIRST
+ 7, create_textA() );
1831 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1832 r
= CloseClipboard();
1833 ok( r
, "gle %d\n", GetLastError() );
1835 run_thread( test_handles_thread2
, 0, __LINE__
);
1836 run_process( "handles test" );
1838 r
= OpenClipboard( hwnd
);
1839 ok( r
, "gle %d\n", GetLastError() );
1840 h
= GetClipboardData( CF_TEXT
);
1841 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1842 h
= GetClipboardData( format_id
);
1843 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1844 h
= GetClipboardData( CF_GDIOBJFIRST
+ 3 );
1845 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1846 h
= GetClipboardData( CF_PRIVATEFIRST
+ 7 );
1847 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1849 r
= EmptyClipboard();
1850 ok( r
, "gle %d\n", GetLastError() );
1851 text
= create_textA();
1852 h
= SetClipboardData( CF_TEXT
, text
);
1853 ok( is_moveable( h
), "expected moveable mem %p\n", h
);
1855 run_process( "handles_open foobar" );
1857 ok( is_moveable( text
), "expected moveable mem %p\n", text
);
1858 h
= GetClipboardData( CF_TEXT
);
1859 ok( is_fixed( h
), "expected fixed mem %p\n", h
);
1860 ok( is_moveable( text
), "expected moveable mem %p\n", text
);
1861 ptr
= GlobalLock( h
);
1862 ok( !strcmp( ptr
, "foobar" ), "wrong data '%.8s'\n", ptr
);
1865 r
= EmptyClipboard();
1866 ok( r
, "gle %d\n", GetLastError() );
1867 ok( is_fixed( h
), "expected free mem %p\n", h
);
1868 ok( is_freed( text
) || broken( is_moveable(text
) ), /* w2003, w2008 */
1869 "expected free mem %p\n", text
);
1870 r
= CloseClipboard();
1871 ok( r
, "gle %d\n", GetLastError() );
1873 /* test CF_BITMAP with a DIB section */
1874 memset( &bmi
, 0, sizeof(bmi
) );
1875 bmi
.bmiHeader
.biSize
= sizeof( bmi
.bmiHeader
);
1876 bmi
.bmiHeader
.biWidth
= 29;
1877 bmi
.bmiHeader
.biHeight
= 13;
1878 bmi
.bmiHeader
.biPlanes
= 1;
1879 bmi
.bmiHeader
.biBitCount
= 32;
1880 bitmap
= CreateDIBSection( 0, &bmi
, DIB_RGB_COLORS
, &bits
, 0, 0 );
1882 r
= OpenClipboard( hwnd
);
1883 ok( r
, "gle %d\n", GetLastError() );
1884 r
= EmptyClipboard();
1885 ok( r
, "gle %d\n", GetLastError() );
1886 h
= SetClipboardData( CF_BITMAP
, bitmap
);
1887 ok( GetObjectType( h
) == OBJ_BITMAP
, "expected bitmap %p\n", h
);
1888 trace( "dibsection %p\n", h
);
1889 r
= CloseClipboard();
1890 ok( r
, "gle %d\n", GetLastError() );
1892 run_process( "handles_dib dummy" );
1894 r
= OpenClipboard( hwnd
);
1895 ok( r
, "gle %d\n", GetLastError() );
1896 ok( GetObjectType( bitmap
) == OBJ_BITMAP
, "expected bitmap %p\n", bitmap
);
1897 r
= EmptyClipboard();
1898 ok( r
, "gle %d\n", GetLastError() );
1899 ok( !GetObjectType( bitmap
), "expected deleted %p\n", bitmap
);
1900 r
= CloseClipboard();
1901 ok( r
, "gle %d\n", GetLastError() );
1903 DestroyWindow( hwnd
);
1906 static void test_GetUpdatedClipboardFormats(void)
1909 UINT count
, formats
[256];
1911 if (!pGetUpdatedClipboardFormats
)
1913 win_skip( "GetUpdatedClipboardFormats not supported\n" );
1918 r
= pGetUpdatedClipboardFormats( NULL
, 0, &count
);
1919 ok( r
, "gle %d\n", GetLastError() );
1920 ok( !count
, "wrong count %u\n", count
);
1923 r
= pGetUpdatedClipboardFormats( NULL
, 256, &count
);
1924 ok( r
, "gle %d\n", GetLastError() );
1925 ok( !count
, "wrong count %u\n", count
);
1927 SetLastError( 0xdeadbeef );
1928 r
= pGetUpdatedClipboardFormats( formats
, 256, NULL
);
1929 ok( !r
, "succeeded\n" );
1930 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
1933 r
= pGetUpdatedClipboardFormats( formats
, 256, &count
);
1934 ok( r
, "gle %d\n", GetLastError() );
1935 ok( !count
, "wrong count %u\n", count
);
1937 r
= OpenClipboard( 0 );
1938 ok( r
, "gle %d\n", GetLastError() );
1939 r
= EmptyClipboard();
1940 ok( r
, "gle %d\n", GetLastError() );
1943 r
= pGetUpdatedClipboardFormats( formats
, 256, &count
);
1944 ok( r
, "gle %d\n", GetLastError() );
1945 ok( !count
, "wrong count %u\n", count
);
1947 SetClipboardData( CF_UNICODETEXT
, 0 );
1950 memset( formats
, 0xcc, sizeof(formats
) );
1951 r
= pGetUpdatedClipboardFormats( formats
, 256, &count
);
1952 ok( r
, "gle %d\n", GetLastError() );
1953 ok( count
== 1, "wrong count %u\n", count
);
1954 ok( formats
[0] == CF_UNICODETEXT
, "wrong format %u\n", formats
[0] );
1955 ok( formats
[1] == 0xcccccccc, "wrong format %u\n", formats
[1] );
1957 SetClipboardData( CF_TEXT
, 0 );
1959 memset( formats
, 0xcc, sizeof(formats
) );
1960 r
= pGetUpdatedClipboardFormats( formats
, 256, &count
);
1961 ok( r
, "gle %d\n", GetLastError() );
1962 ok( count
== 2, "wrong count %u\n", count
);
1963 ok( formats
[0] == CF_UNICODETEXT
, "wrong format %u\n", formats
[0] );
1964 ok( formats
[1] == CF_TEXT
, "wrong format %u\n", formats
[1] );
1965 ok( formats
[2] == 0xcccccccc, "wrong format %u\n", formats
[2] );
1967 SetLastError( 0xdeadbeef );
1969 r
= pGetUpdatedClipboardFormats( formats
, 0, &count
);
1970 ok( !r
, "succeeded\n" );
1971 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %u\n", GetLastError() );
1972 ok( count
== 2, "wrong count %u\n", count
);
1974 SetLastError( 0xdeadbeef );
1976 r
= pGetUpdatedClipboardFormats( formats
, 1, &count
);
1977 ok( !r
, "succeeded\n" );
1978 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %u\n", GetLastError() );
1979 ok( count
== 2, "wrong count %u\n", count
);
1981 r
= CloseClipboard();
1982 ok( r
, "gle %d\n", GetLastError() );
1985 memset( formats
, 0xcc, sizeof(formats
) );
1986 r
= pGetUpdatedClipboardFormats( formats
, 256, &count
);
1987 ok( r
, "gle %d\n", GetLastError() );
1988 ok( count
== 4, "wrong count %u\n", count
);
1989 ok( formats
[0] == CF_UNICODETEXT
, "wrong format %u\n", formats
[0] );
1990 ok( formats
[1] == CF_TEXT
, "wrong format %u\n", formats
[1] );
1991 ok( formats
[2] == CF_LOCALE
, "wrong format %u\n", formats
[2] );
1992 ok( formats
[3] == CF_OEMTEXT
, "wrong format %u\n", formats
[3] );
1993 ok( formats
[4] == 0xcccccccc, "wrong format %u\n", formats
[4] );
1996 memset( formats
, 0xcc, sizeof(formats
) );
1997 r
= pGetUpdatedClipboardFormats( formats
, 2, &count
);
1998 ok( !r
, "gle %d\n", GetLastError() );
1999 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %u\n", GetLastError() );
2000 ok( count
== 4, "wrong count %u\n", count
);
2001 ok( formats
[0] == 0xcccccccc, "wrong format %u\n", formats
[0] );
2004 r
= pGetUpdatedClipboardFormats( NULL
, 256, &count
);
2005 ok( !r
, "gle %d\n", GetLastError() );
2006 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
2007 ok( count
== 4, "wrong count %u\n", count
);
2010 r
= pGetUpdatedClipboardFormats( NULL
, 256, &count
);
2011 ok( !r
, "gle %d\n", GetLastError() );
2012 ok( GetLastError() == ERROR_NOACCESS
, "wrong error %u\n", GetLastError() );
2013 ok( count
== 4, "wrong count %u\n", count
);
2023 { "foo", {}, 3 }, /* 0 */
2025 { "foo\0bar", {}, 7 },
2026 { "foo\0bar", {}, 8 },
2027 { "", {'f','o','o'}, 3 * sizeof(WCHAR
) },
2028 { "", {'f','o','o',0}, 4 * sizeof(WCHAR
) }, /* 5 */
2029 { "", {'f','o','o',0,'b','a','r'}, 7 * sizeof(WCHAR
) },
2030 { "", {'f','o','o',0,'b','a','r',0}, 8 * sizeof(WCHAR
) },
2031 { "", {'f','o','o'}, 1 },
2032 { "", {'f','o','o'}, 2 },
2033 { "", {'f','o','o'}, 5 }, /* 10 */
2034 { "", {'f','o','o',0}, 7 },
2035 { "", {'f','o','o',0}, 9 },
2038 static void test_string_data(void)
2047 for (i
= 0; i
< sizeof(test_data
) / sizeof(test_data
[0]); i
++)
2049 /* 1-byte Unicode strings crash on Win64 */
2051 if (!test_data
[i
].strA
[0] && test_data
[i
].len
< sizeof(WCHAR
)) continue;
2053 r
= OpenClipboard( 0 );
2054 ok( r
, "gle %d\n", GetLastError() );
2055 r
= EmptyClipboard();
2056 ok( r
, "gle %d\n", GetLastError() );
2057 data
= GlobalAlloc( GMEM_FIXED
, test_data
[i
].len
);
2058 if (test_data
[i
].strA
[0])
2060 memcpy( data
, test_data
[i
].strA
, test_data
[i
].len
);
2061 SetClipboardData( CF_TEXT
, data
);
2062 memcpy( bufferA
, test_data
[i
].strA
, test_data
[i
].len
);
2063 bufferA
[test_data
[i
].len
- 1] = 0;
2064 ok( !memcmp( data
, bufferA
, test_data
[i
].len
),
2065 "%u: wrong data %.*s\n", i
, test_data
[i
].len
, (char *)data
);
2069 memcpy( data
, test_data
[i
].strW
, test_data
[i
].len
);
2070 SetClipboardData( CF_UNICODETEXT
, data
);
2071 memcpy( bufferW
, test_data
[i
].strW
, test_data
[i
].len
);
2072 bufferW
[(test_data
[i
].len
+ 1) / sizeof(WCHAR
) - 1] = 0;
2073 ok( !memcmp( data
, bufferW
, test_data
[i
].len
),
2074 "%u: wrong data %s\n", i
, wine_dbgstr_wn( data
, (test_data
[i
].len
+ 1) / sizeof(WCHAR
) ));
2076 r
= CloseClipboard();
2077 ok( r
, "gle %d\n", GetLastError() );
2078 sprintf( cmd
, "string_data %u", i
);
2083 static void test_string_data_process( int i
)
2091 r
= OpenClipboard( 0 );
2092 ok( r
, "gle %d\n", GetLastError() );
2093 if (test_data
[i
].strA
[0])
2095 data
= GetClipboardData( CF_TEXT
);
2096 ok( data
!= 0, "%u: could not get data\n", i
);
2097 len
= GlobalSize( data
);
2098 ok( len
== test_data
[i
].len
, "%u: wrong size %u / %u\n", i
, len
, test_data
[i
].len
);
2099 memcpy( bufferA
, test_data
[i
].strA
, test_data
[i
].len
);
2100 bufferA
[test_data
[i
].len
- 1] = 0;
2101 ok( !memcmp( data
, bufferA
, len
), "%u: wrong data %.*s\n", i
, len
, (char *)data
);
2102 data
= GetClipboardData( CF_UNICODETEXT
);
2103 ok( data
!= 0, "%u: could not get data\n", i
);
2104 len
= GlobalSize( data
);
2105 len2
= MultiByteToWideChar( CP_ACP
, 0, bufferA
, test_data
[i
].len
, bufferW
, 12 );
2106 ok( len
== len2
* sizeof(WCHAR
), "%u: wrong size %u / %u\n", i
, len
, len2
);
2107 ok( !memcmp( data
, bufferW
, len
), "%u: wrong data %s\n", i
, wine_dbgstr_wn( data
, len2
));
2111 data
= GetClipboardData( CF_UNICODETEXT
);
2112 ok( data
!= 0, "%u: could not get data\n", i
);
2113 len
= GlobalSize( data
);
2114 ok( len
== test_data
[i
].len
, "%u: wrong size %u / %u\n", i
, len
, test_data
[i
].len
);
2115 memcpy( bufferW
, test_data
[i
].strW
, test_data
[i
].len
);
2116 bufferW
[(test_data
[i
].len
+ 1) / sizeof(WCHAR
) - 1] = 0;
2117 ok( !memcmp( data
, bufferW
, len
),
2118 "%u: wrong data %s\n", i
, wine_dbgstr_wn( data
, (len
+ 1) / sizeof(WCHAR
) ));
2119 data
= GetClipboardData( CF_TEXT
);
2120 if (test_data
[i
].len
>= sizeof(WCHAR
))
2122 ok( data
!= 0, "%u: could not get data\n", i
);
2123 len
= GlobalSize( data
);
2124 len2
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, test_data
[i
].len
/ sizeof(WCHAR
),
2125 bufferA
, 12, NULL
, NULL
);
2126 bufferA
[len2
- 1] = 0;
2127 ok( len
== len2
, "%u: wrong size %u / %u\n", i
, len
, len2
);
2128 ok( !memcmp( data
, bufferA
, len
), "%u: wrong data %.*s\n", i
, len
, (char *)data
);
2132 ok( !data
, "%u: got data for empty string\n", i
);
2133 ok( IsClipboardFormatAvailable( CF_TEXT
), "%u: text not available\n", i
);
2136 r
= CloseClipboard();
2137 ok( r
, "gle %d\n", GetLastError() );
2140 START_TEST(clipboard
)
2143 int argc
= winetest_get_mainargs( &argv
);
2144 HMODULE mod
= GetModuleHandleA( "user32" );
2147 pAddClipboardFormatListener
= (void *)GetProcAddress( mod
, "AddClipboardFormatListener" );
2148 pRemoveClipboardFormatListener
= (void *)GetProcAddress( mod
, "RemoveClipboardFormatListener" );
2149 pGetUpdatedClipboardFormats
= (void *)GetProcAddress( mod
, "GetUpdatedClipboardFormats" );
2151 if (argc
== 4 && !strcmp( argv
[2], "set_clipboard_data" ))
2153 set_clipboard_data_process( atoi( argv
[3] ));
2156 if (argc
== 4 && !strcmp( argv
[2], "grab_clipboard" ))
2158 grab_clipboard_process( atoi( argv
[3] ));
2161 if (argc
== 4 && !strcmp( argv
[2], "handles" ))
2163 test_handles_process( argv
[3] );
2166 if (argc
== 4 && !strcmp( argv
[2], "handles_open" ))
2168 test_handles_process_open( argv
[3] );
2171 if (argc
== 4 && !strcmp( argv
[2], "handles_dib" ))
2173 test_handles_process_dib( argv
[3] );
2176 if (argc
== 4 && !strcmp( argv
[2], "string_data" ))
2178 test_string_data_process( atoi( argv
[3] ));
2181 if (argc
== 3 && !strcmp( argv
[2], "get_clipboard_data" ))
2183 get_clipboard_data_process( );
2187 test_RegisterClipboardFormatA();
2188 test_ClipboardOwner();
2191 test_data_handles();
2192 test_GetUpdatedClipboardFormats();