Added user32 regression tests that we pass to the regtests system. Working on reviewi...
[reactos.git] / reactos / regtests / user32 / dde.c
1 /*
2 * Unit tests for DDE functions
3 *
4 * Copyright (c) 2004 Dmitry Timoshkov
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <assert.h>
22
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ddeml.h"
27 #include "winerror.h"
28
29 static HDDEDATA CALLBACK DdeCallback(UINT uType, UINT uFmt, HCONV hconv,
30 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
31 ULONG_PTR dwData1, ULONG_PTR dwData2)
32 {
33 return 0;
34 }
35
36 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
37 {
38 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
39 HSZ str_handle;
40 WCHAR bufW[256];
41 char buf[256];
42 int ret;
43
44 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
45 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
46 DdeGetLastError(dde_inst));
47
48 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
49 if (codepage == CP_WINANSI)
50 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
51 else
52 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
53
54 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
55 if (codepage == CP_WINANSI)
56 {
57 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
58 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
59 }
60 else
61 {
62 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
63 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
64 }
65
66 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
67 if (codepage == CP_WINANSI)
68 {
69 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
70 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
71 }
72 else
73 {
74 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
75 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
76 }
77
78 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
79 if (codepage == CP_WINANSI)
80 {
81 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
82 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
83 }
84 else
85 {
86 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
87 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
88 }
89
90 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
91 }
92
93 START_TEST(dde)
94 {
95 DWORD dde_inst, ret;
96
97 dde_inst = 0xdeadbeef;
98 SetLastError(0xdeadbeef);
99 ret = DdeInitializeW(&dde_inst, DdeCallback, APPCMD_CLIENTONLY, 0);
100 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
101 {
102 trace("Skipping the DDE test on a Win9x platform\n");
103 return;
104 }
105
106 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04lx instead\n", ret);
107 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
108
109 dde_inst = 0;
110 ret = DdeInitializeW(&dde_inst, DdeCallback, APPCMD_CLIENTONLY, 0);
111 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04lx (%08x)\n",
112 ret, DdeGetLastError(dde_inst));
113
114 test_DdeCreateStringHandleW(dde_inst, 0);
115 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
116 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
117
118 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
119 }