push(c) 7dcddf6204ed5518706a76fe66fd836d81e70dd4
[wine/hacks.git] / dlls / user32 / tests / dde.c
blobb5e05c4fb9960345f2fd74bd7debca6023e01b38
1 /*
2 * Unit tests for DDE functions
4 * Copyright (c) 2004 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
21 #include <assert.h>
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "dde.h"
27 #include "ddeml.h"
28 #include "winerror.h"
30 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
32 static char exec_cmdA[] = "ANSI dde command";
33 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
35 static WNDPROC old_dde_client_wndproc;
37 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
39 UINT_PTR lo, hi;
41 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
43 switch (msg)
45 case WM_DDE_ACK:
46 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
47 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
48 break;
50 default:
51 break;
53 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
56 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
58 trace("dde_server_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
60 switch (msg)
62 case WM_DDE_INITIATE:
64 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
66 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
68 if (LOWORD(lparam) == aService)
70 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
71 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
72 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
73 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
75 else
76 GlobalDeleteAtom(aService);
77 return 0;
80 case WM_DDE_EXECUTE:
82 DDEACK ack;
83 WORD status;
84 LPCSTR cmd;
85 UINT_PTR lo, hi;
87 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
89 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
90 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
92 ack.bAppReturnCode = 0;
93 ack.reserved = 0;
94 ack.fBusy = 0;
96 cmd = GlobalLock((HGLOBAL)hi);
98 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
100 trace("ignoring unknown WM_DDE_EXECUTE command\n");
101 /* We have to send a negative acknowledge even if we don't
102 * accept the command, otherwise Windows goes mad and next time
103 * we send an acknowledge DDEML drops the connection.
104 * Not sure how to call it: a bug or a feature.
106 ack.fAck = 0;
108 else
109 ack.fAck = 1;
110 GlobalUnlock((HGLOBAL)hi);
112 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
114 status = *((WORD *)&ack);
115 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
117 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
118 return 0;
121 case WM_DDE_TERMINATE:
123 DDEACK ack;
124 WORD status;
126 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
128 ack.bAppReturnCode = 0;
129 ack.reserved = 0;
130 ack.fBusy = 0;
131 ack.fAck = 1;
133 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
135 status = *((WORD *)&ack);
136 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
138 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
139 return 0;
142 default:
143 break;
146 return DefWindowProcW(hwnd, msg, wparam, lparam);
149 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
151 return DefWindowProcA(hwnd, msg, wparam, lparam);
154 static BOOL create_dde_windows(HWND *hwnd_client, HWND *hwnd_server)
156 WNDCLASSA wcA;
157 WNDCLASSW wcW;
158 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
159 static const char client_class_name[] = "dde_client_window";
161 memset(&wcW, 0, sizeof(wcW));
162 wcW.lpfnWndProc = dde_server_wndproc;
163 wcW.lpszClassName = server_class_name;
164 wcW.hInstance = GetModuleHandleA(0);
165 if (!RegisterClassW(&wcW)) return FALSE;
167 memset(&wcA, 0, sizeof(wcA));
168 wcA.lpfnWndProc = dde_client_wndproc;
169 wcA.lpszClassName = client_class_name;
170 wcA.hInstance = GetModuleHandleA(0);
171 assert(RegisterClassA(&wcA));
173 *hwnd_server = CreateWindowExW(0, server_class_name, NULL,
174 WS_POPUP,
175 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
176 GetDesktopWindow(), 0,
177 GetModuleHandleA(0), NULL);
178 assert(*hwnd_server);
180 *hwnd_client = CreateWindowExA(0, client_class_name, NULL,
181 WS_POPUP,
182 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
183 GetDesktopWindow(), 0,
184 GetModuleHandleA(0), NULL);
185 assert(*hwnd_client);
187 trace("server hwnd %p, client hwnd %p\n", *hwnd_server, *hwnd_client);
189 ok(IsWindowUnicode(*hwnd_server), "server has to be a unicode window\n");
190 ok(!IsWindowUnicode(*hwnd_client), "client has to be an ANSI window\n");
192 return TRUE;
195 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
196 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
197 ULONG_PTR dwData1, ULONG_PTR dwData2)
199 static const char * const cmd_type[15] = {
200 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
201 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
202 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
203 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
204 UINT type;
205 const char *cmd_name;
207 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
208 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
210 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
211 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
212 return 0;
215 static void test_dde_transaction(void)
217 HSZ hsz_server;
218 DWORD dde_inst, ret, err;
219 HCONV hconv;
220 HWND hwnd_client, hwnd_server;
221 CONVINFO info;
222 HDDEDATA hdata;
223 static char test_cmd[] = "test dde command";
225 /* server: unicode, client: ansi */
226 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
228 dde_inst = 0;
229 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
230 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
231 ret, DdeGetLastError(dde_inst));
233 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
235 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
236 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
237 err = DdeGetLastError(dde_inst);
238 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
240 info.cb = sizeof(info);
241 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
242 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
243 /* should be CP_WINANSI since we used DdeInitializeA */
244 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
245 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
246 todo_wine {
247 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
249 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
250 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
251 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
253 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
255 trace("sending test client transaction command\n");
256 ret = 0xdeadbeef;
257 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
258 ok(!hdata, "DdeClientTransaction succeeded\n");
259 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
260 err = DdeGetLastError(dde_inst);
261 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
263 trace("sending ANSI client transaction command\n");
264 ret = 0xdeadbeef;
265 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
266 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
267 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
269 err = DdeGetLastError(dde_inst);
270 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
272 trace("sending unicode client transaction command\n");
273 ret = 0xdeadbeef;
274 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
275 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
276 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
277 err = DdeGetLastError(dde_inst);
278 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
280 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
282 info.cb = sizeof(info);
283 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
284 ok(!ret, "DdeQueryConvInfo should fail\n");
285 err = DdeGetLastError(dde_inst);
286 todo_wine {
287 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
290 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
292 /* This call hangs on win2k SP4 and XP SP1.
293 DdeUninitialize(dde_inst);*/
295 DestroyWindow(hwnd_client);
296 DestroyWindow(hwnd_server);
299 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
301 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
302 HSZ str_handle;
303 WCHAR bufW[256];
304 char buf[256];
305 ATOM atom;
306 int ret;
308 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
309 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
310 DdeGetLastError(dde_inst));
312 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
313 if (codepage == CP_WINANSI)
314 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
315 else
316 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
318 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
319 if (codepage == CP_WINANSI)
321 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
322 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
324 else
326 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
327 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
330 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
331 if (codepage == CP_WINANSI)
333 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
334 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
336 else
338 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
339 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
342 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
343 if (codepage == CP_WINANSI)
345 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
346 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
348 else
350 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
351 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
354 if (codepage == CP_WINANSI)
356 atom = FindAtomA((LPSTR)dde_string);
357 ok(atom != 0, "Expected a valid atom\n");
359 SetLastError(0xdeadbeef);
360 atom = GlobalFindAtomA((LPSTR)dde_string);
361 ok(atom == 0, "Expected 0, got %d\n", atom);
362 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
363 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
365 else
367 atom = FindAtomW(dde_string);
368 ok(atom != 0, "Expected a valid atom\n");
370 SetLastError(0xdeadbeef);
371 atom = GlobalFindAtomW(dde_string);
372 ok(atom == 0, "Expected 0, got %d\n", atom);
373 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
374 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
377 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
380 static void test_DdeCreateStringHandle(void)
382 DWORD dde_inst, ret;
384 dde_inst = 0xdeadbeef;
385 SetLastError(0xdeadbeef);
386 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
387 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
389 trace("Skipping the DDE test on a Win9x platform\n");
390 return;
393 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
394 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
396 dde_inst = 0;
397 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
398 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
399 ret, DdeGetLastError(dde_inst));
401 test_DdeCreateStringHandleW(dde_inst, 0);
402 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
403 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
405 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
408 static void test_FreeDDElParam(void)
410 HGLOBAL val, hglobal;
411 BOOL ret;
413 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
414 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
416 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
417 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
418 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
419 val = GlobalFree(hglobal);
420 ok(val == NULL, "Expected NULL, got %p\n", val);
422 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
423 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
424 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
425 val = GlobalFree(hglobal);
426 ok(val == hglobal, "Expected hglobal, got %p\n", val);
427 ok(GetLastError() == ERROR_INVALID_HANDLE,
428 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
430 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
431 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
432 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
433 val = GlobalFree(hglobal);
434 ok(val == NULL, "Expected NULL, got %p\n", val);
436 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
437 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
438 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
439 val = GlobalFree(hglobal);
440 ok(val == hglobal, "Expected hglobal, got %p\n", val);
441 ok(GetLastError() == ERROR_INVALID_HANDLE,
442 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
444 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
445 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
446 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
447 val = GlobalFree(hglobal);
448 ok(val == hglobal, "Expected hglobal, got %p\n", val);
449 ok(GetLastError() == ERROR_INVALID_HANDLE,
450 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
452 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
453 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
454 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
455 val = GlobalFree(hglobal);
456 ok(val == NULL, "Expected NULL, got %p\n", val);
458 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
459 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
460 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
461 val = GlobalFree(hglobal);
462 ok(val == hglobal, "Expected hglobal, got %p\n", val);
463 ok(GetLastError() == ERROR_INVALID_HANDLE,
464 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
466 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
467 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
468 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
469 val = GlobalFree(hglobal);
470 ok(val == NULL, "Expected NULL, got %p\n", val);
473 static void test_PackDDElParam(void)
475 UINT_PTR lo, hi, *ptr;
476 HGLOBAL hglobal;
477 LPARAM lparam;
478 BOOL ret;
480 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
481 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
482 ok(GlobalLock((HGLOBAL)lparam) == NULL,
483 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
484 ok(GetLastError() == ERROR_INVALID_HANDLE,
485 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
487 lo = hi = 0;
488 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
489 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
490 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
491 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
493 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
494 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
496 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
497 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
498 ok(GlobalLock((HGLOBAL)lparam) == NULL,
499 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
500 ok(GetLastError() == ERROR_INVALID_HANDLE,
501 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
503 lo = hi = 0;
504 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
505 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
506 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
507 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
509 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
510 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
512 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
513 ptr = GlobalLock((HGLOBAL)lparam);
514 ok(ptr != NULL, "Expected non-NULL ptr\n");
515 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
516 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
518 ret = GlobalUnlock((HGLOBAL)lparam);
519 ok(ret == 1, "Expected 1, got %d\n", ret);
521 lo = hi = 0;
522 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
523 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
524 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
525 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
527 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
528 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
530 hglobal = GlobalFree((HGLOBAL)lparam);
531 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
532 ok(GetLastError() == ERROR_INVALID_HANDLE,
533 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
535 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
536 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
537 ok(GlobalLock((HGLOBAL)lparam) == NULL,
538 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
539 ok(GetLastError() == ERROR_INVALID_HANDLE,
540 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
542 lo = hi = 0;
543 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
544 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
545 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
546 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
548 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
549 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
551 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
552 ptr = GlobalLock((HGLOBAL)lparam);
553 ok(ptr != NULL, "Expected non-NULL ptr\n");
554 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
555 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
557 ret = GlobalUnlock((HGLOBAL)lparam);
558 ok(ret == 1, "Expected 1, got %d\n", ret);
560 lo = hi = 0;
561 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
562 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
563 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
564 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
566 ret = FreeDDElParam(WM_DDE_ACK, lparam);
567 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
569 hglobal = GlobalFree((HGLOBAL)lparam);
570 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
571 ok(GetLastError() == ERROR_INVALID_HANDLE,
572 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
574 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
575 ptr = GlobalLock((HGLOBAL)lparam);
576 ok(ptr != NULL, "Expected non-NULL ptr\n");
577 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
578 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
580 ret = GlobalUnlock((HGLOBAL)lparam);
581 ok(ret == 1, "Expected 1, got %d\n", ret);
583 lo = hi = 0;
584 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
585 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
586 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
587 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
589 ret = FreeDDElParam(WM_DDE_DATA, lparam);
590 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
592 hglobal = GlobalFree((HGLOBAL)lparam);
593 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
594 ok(GetLastError() == ERROR_INVALID_HANDLE,
595 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
597 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
598 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
599 ok(GlobalLock((HGLOBAL)lparam) == NULL,
600 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
601 ok(GetLastError() == ERROR_INVALID_HANDLE,
602 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
604 lo = hi = 0;
605 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
606 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
607 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
608 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
610 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
611 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
613 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
614 ptr = GlobalLock((HGLOBAL)lparam);
615 ok(ptr != NULL, "Expected non-NULL ptr\n");
616 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
617 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
619 ret = GlobalUnlock((HGLOBAL)lparam);
620 ok(ret == 1, "Expected 1, got %d\n", ret);
622 lo = hi = 0;
623 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
624 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
625 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
626 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
628 ret = FreeDDElParam(WM_DDE_POKE, lparam);
629 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
631 hglobal = GlobalFree((HGLOBAL)lparam);
632 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
633 ok(GetLastError() == ERROR_INVALID_HANDLE,
634 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
636 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
637 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
638 ok(GlobalLock((HGLOBAL)lparam) == NULL,
639 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
640 ok(GetLastError() == ERROR_INVALID_HANDLE,
641 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
643 lo = hi = 0;
644 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
645 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
646 ok(lo == 0, "Expected 0, got %08lx\n", lo);
647 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
649 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
650 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
653 static void test_UnpackDDElParam(void)
655 UINT_PTR lo, hi, *ptr;
656 HGLOBAL hglobal;
657 BOOL ret;
659 /* NULL lParam */
660 lo = 0xdead;
661 hi = 0xbeef;
662 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
663 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
664 ok(lo == 0, "Expected 0, got %08lx\n", lo);
665 ok(hi == 0, "Expected 0, got %08lx\n", hi);
667 /* NULL lo */
668 lo = 0xdead;
669 hi = 0xbeef;
670 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
671 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
672 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
673 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
675 /* NULL hi */
676 lo = 0xdead;
677 hi = 0xbeef;
678 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
679 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
680 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
681 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
683 lo = 0xdead;
684 hi = 0xbeef;
685 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
686 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
687 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
688 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
690 lo = 0xdead;
691 hi = 0xbeef;
692 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
693 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
694 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
695 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
697 lo = 0xdead;
698 hi = 0xbeef;
699 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
700 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
701 ok(lo == 0, "Expected 0, got %08lx\n", lo);
702 ok(hi == 0, "Expected 0, got %08lx\n", hi);
704 lo = 0xdead;
705 hi = 0xbeef;
706 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
707 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
708 ok(lo == 0, "Expected 0, got %08lx\n", lo);
709 ok(hi == 0, "Expected 0, got %08lx\n", hi);
711 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
712 ptr = GlobalLock(hglobal);
713 ptr[0] = 0xcafebabe;
714 ptr[1] = 0xdeadbeef;
715 GlobalUnlock(hglobal);
717 lo = 0xdead;
718 hi = 0xbeef;
719 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
720 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
721 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
722 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
724 lo = 0xdead;
725 hi = 0xbeef;
726 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
727 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
728 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
729 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
731 lo = 0xdead;
732 hi = 0xbeef;
733 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
734 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
735 ok(lo == 0, "Expected 0, got %08lx\n", lo);
736 ok(hi == 0, "Expected 0, got %08lx\n", hi);
738 lo = 0xdead;
739 hi = 0xbeef;
740 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
741 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
742 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
743 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
745 lo = 0xdead;
746 hi = 0xbeef;
747 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
748 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
749 ok(lo == 0, "Expected 0, got %08lx\n", lo);
750 ok(hi == 0, "Expected 0, got %08lx\n", hi);
752 lo = 0xdead;
753 hi = 0xbeef;
754 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
755 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
756 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
757 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
759 lo = 0xdead;
760 hi = 0xbeef;
761 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
762 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
763 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
764 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
766 lo = 0xdead;
767 hi = 0xbeef;
768 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
769 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
770 ok(lo == 0, "Expected 0, got %08lx\n", lo);
771 ok(hi == 0, "Expected 0, got %08lx\n", hi);
773 lo = 0xdead;
774 hi = 0xbeef;
775 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
776 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
777 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
778 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
780 lo = 0xdead;
781 hi = 0xbeef;
782 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
783 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
784 ok(lo == 0, "Expected 0, got %08lx\n", lo);
785 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
788 START_TEST(dde)
790 test_dde_transaction();
791 test_DdeCreateStringHandle();
792 test_FreeDDElParam();
793 test_PackDDElParam();
794 test_UnpackDDElParam();