ReactOS  0.4.14-dev-77-gd9e7c48
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...*/
15 static 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 
44 static 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 
56 static 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 
78  ret = EmptyClipboard();
79  ok (ret, "EmptyClipboard failed\n");
80 
84 
85  ret = CloseClipboard();
86  ok (ret, "CloseClipboard failed\n");
87 
88  /* Record if we got any post messages */
89  FlushMessages();
90 
91  /* Force the parent thread out of its loop */
92  PostMessageW(hWnd1, WM_QUIT, 0, 0);
93 
94  return 0;
95 }
96 
100  {1,WM_DESTROYCLIPBOARD, MARKER, 1},
101  {0,0}};
102 
104 {
105  HANDLE hThread;
106  DWORD dwThread;
107  BOOL ret;
108  MSG msg;
109 
110  /* Initialize the test */
112 
113  RegisterSimpleClass(ClipTestProc, L"clipstest");
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 
126  ret = EmptyClipboard();
127  ok (ret, "EmptyClipboard failed\n");
128 
129  ret = CloseClipboard();
130  ok (ret, "CloseClipboard failed\n");
131 
132  /* Record posted messages */
133  FlushMessages();
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 
155  ret = EmptyClipboard();
156  ok (ret, "EmptyClipboard failed\n");
157 
158  ret = CloseClipboard();
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 
173  ret = EmptyClipboard();
174  ok (ret, "EmptyClipboard failed\n");
175 
176  ret = CloseClipboard();
177  ok (ret, "CloseClipboard failed\n");
178 
179  hWndClipOwner = GetClipboardOwner();
180  ok (hWndClipOwner == hWnd, "Expected hWnd owner\n");
181 
183 }
184 
186 {
187  TestOwnership();
188  TestMessages();
189 }
static void FlushMessages()
static void RecordAndDispatch(MSG *pmsg)
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
Definition: tftpd.h:59
#define PeekMessage
Definition: winuser.h:5731
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
Definition: msgtrace.h:14
CRITICAL_SECTION CritSect
HWND hWnd2
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
#define WM_QUIT
Definition: winuser.h:1605
static DWORD WINAPI ClipThread(PVOID Parameter)
UINT_PTR WPARAM
Definition: windef.h:207
_In_ PVOID Parameter
Definition: ldrtypes.h:241
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4217
WPARAM wParam
Definition: combotst.c:138
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
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:136
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DefWindowProc
Definition: ros2win.h:31
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
#define COMPARE_CACHE(msg_chain)
Definition: msgtrace.h:57
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
int ret
Definition: msgtrace.h:7
static const WCHAR L[]
Definition: oid.c:1250
#define EMPTY_CACHE()
Definition: msgtrace.h:59
#define WM_USER
Definition: winuser.h:1877
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
static int get_iwnd(HWND hWnd)
HWND WINAPI GetClipboardOwner(void)
Definition: ntwrapper.h:196
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
#define GetMessage
Definition: winuser.h:5691
void TestMessages()
HANDLE hThread
Definition: wizard.c:27
Definition: msgtrace.h:6
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1850
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
void TestOwnership()
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
#define PM_REMOVE
Definition: winuser.h:1182
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LONG_PTR LRESULT
Definition: windef.h:209
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
START_TEST(EmptyClipboard)
LPARAM lParam
Definition: combotst.c:139
LRESULT CALLBACK ClipTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HWND hWnd1
MSG_ENTRY EmptyClipboard_chain[]