ReactOS 0.4.16-dev-329-g9223134
EmptyClipboard.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for EmptyClipboard
5 * PROGRAMMERS: Giannis Adamopoulos
6 */
7
8#include "precomp.h"
9
11
13
14/* FIXME: test for HWND_TOP, etc...*/
15static int get_iwnd(HWND hWnd)
16{
17 if(hWnd == hWnd1) return 1;
18 else if(hWnd2 && hWnd == hWnd2) return 2;
19 else return 0;
20}
21
23{
24 int iwnd = get_iwnd(hWnd);
25
26 if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
28
29 switch(message)
30 {
31 case WM_GETICON :
32 case WM_SETICON:
33 break;
35 Sleep(1000);
36 default:
38 RECORD_MESSAGE(iwnd, message, SENT, 0,0);
40 }
42}
43
44static void RecordAndDispatch(MSG* pmsg)
45{
46 int iwnd = get_iwnd(pmsg->hwnd);
47 if(!(pmsg->message > WM_USER || !iwnd || IsDWmMsg(pmsg->message) || IseKeyMsg(pmsg->message)))
48 {
50 RECORD_MESSAGE(iwnd, pmsg->message, POST,0,0);
52 }
53 DispatchMessageA( pmsg );
54}
55
56static void FlushMessages()
57{
58 MSG msg;
59 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
61}
62
64{
65 BOOL ret;
66
67 hWnd2 = CreateWindowW(L"clipstest", L"clipstest", WS_OVERLAPPEDWINDOW,
68 20, 20, 300, 300, NULL, NULL, 0, NULL);
69
70 /* Get ownership of the clipboard and record the messages we get */
72 ok (ret, "OpenClipboard failed\n");
73
77
79 ok (ret, "EmptyClipboard failed\n");
80
84
86 ok (ret, "CloseClipboard failed\n");
87
88 /* Record if we got any post messages */
90
91 /* Force the parent thread out of its loop */
93
94 return 0;
95}
96
101 {0,0}};
102
104{
106 DWORD dwThread;
107 BOOL ret;
108 MSG msg;
109
110 /* Initialize the test */
112
114
115 hWnd2 = NULL;
116 hWnd1 = CreateWindowW(L"clipstest", L"clipstest", WS_OVERLAPPEDWINDOW,
117 20, 20, 300, 300, NULL, NULL, 0, NULL);
118 ok (hWnd1 != NULL, "CreateWindowW failed\n");
119
120 EMPTY_CACHE();
121
122 /* Get ownership of the clipboard and record the messages we get */
124 ok (ret, "OpenClipboard failed\n");
125
127 ok (ret, "EmptyClipboard failed\n");
128
130 ok (ret, "CloseClipboard failed\n");
131
132 /* Record posted messages */
135
136 /* Create the child thread and record messages till we get the WM_QUIT */
137 hThread = CreateThread(NULL, 0, ClipThread, NULL, 0, &dwThread);
138
139 while (GetMessage(&msg, 0, 0 ,0))
141
143
145}
146
148{
149 BOOL ret;
150 HWND hWnd, hWndClipOwner;
151
153 ok (ret, "OpenClipboard failed\n");
154
156 ok (ret, "EmptyClipboard failed\n");
157
159 ok (ret, "CloseClipboard failed\n");
160
161 hWndClipOwner = GetClipboardOwner();
162 ok (hWndClipOwner == NULL, "Expected NULL owner\n");
163
164 hWnd = CreateWindowW(L"static", L"static", WS_OVERLAPPEDWINDOW, 20, 20, 300, 300, NULL, NULL, 0, NULL);
165 ok (hWnd != 0 , "CreateWindowW failed\n");
166
168 ok (ret, "OpenClipboard failed\n");
169
170 hWndClipOwner = GetClipboardOwner();
171 ok (hWndClipOwner == NULL, "Expected NULL owner\n");
172
174 ok (ret, "EmptyClipboard failed\n");
175
177 ok (ret, "CloseClipboard failed\n");
178
179 hWndClipOwner = GetClipboardOwner();
180 ok (hWndClipOwner == hWnd, "Expected hWnd owner\n");
181
183}
184
186{
188 TestMessages();
189}
static void FlushMessages()
LRESULT CALLBACK ClipTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
static void RecordAndDispatch(MSG *pmsg)
static DWORD WINAPI ClipThread(PVOID Parameter)
void TestMessages()
static int get_iwnd(HWND hWnd)
static HWND hWnd1
static HWND hWnd2
static CRITICAL_SECTION CritSect
static MSG_ENTRY EmptyClipboard_chain[]
void TestOwnership()
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define CALLBACK
Definition: compat.h:35
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
#define EMPTY_CACHE()
Definition: msgtrace.h:59
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define COMPARE_CACHE(msg_chain)
Definition: msgtrace.h:57
@ POST
Definition: msgtrace.h:7
@ MARKER
Definition: msgtrace.h:11
@ SENT
Definition: msgtrace.h:6
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
unsigned int UINT
Definition: ndis.h:50
HANDLE hThread
Definition: wizard.c:28
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define DefWindowProc
Definition: ros2win.h:31
Definition: msgtrace.h:15
Definition: tftpd.h:60
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
int ret
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define WM_QUIT
Definition: winuser.h:1626
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1871
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
HWND WINAPI GetClipboardOwner(void)
Definition: ntwrapper.h:196
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
#define GetMessage
Definition: winuser.h:5802
#define PM_REMOVE
Definition: winuser.h:1199
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
#define PeekMessage
Definition: winuser.h:5842
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4319
#define WM_USER
Definition: winuser.h:1898
BOOL WINAPI DestroyWindow(_In_ HWND)
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336