2 * Copyright 2014 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_LEAN_AND_MEAN
23 #include "wine/test.h"
25 #include "dpnet_test.h"
27 /* {6733C6E8-A0D6-450E-8C18-CEACF331DC27} */
28 static const GUID IID_Random
= {0x6733c6e8, 0xa0d6, 0x450e, { 0x8c, 0x18, 0xce, 0xac, 0xf3, 0x31, 0xdc, 0x27 } };
29 static const WCHAR localhost
[] = {'l','o','c','a','l','h','o','s','t',0};
31 static void create_directplay_address(void)
34 IDirectPlay8Address
*localaddr
= NULL
;
36 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
37 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
42 hr
= IDirectPlay8Address_GetSP(localaddr
, NULL
);
43 ok(hr
== DPNERR_INVALIDPOINTER
, "GetSP failed 0x%08x\n", hr
);
45 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
46 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
48 hr
= IDirectPlay8Address_SetSP(localaddr
, &GUID_NULL
);
49 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
51 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
52 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
53 ok(IsEqualGUID(&guidsp
, &GUID_NULL
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
55 hr
= IDirectPlay8Address_SetSP(localaddr
, &IID_Random
);
56 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
58 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
59 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
60 ok(IsEqualGUID(&guidsp
, &IID_Random
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
62 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
63 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
65 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
66 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
67 ok(IsEqualGUID(&guidsp
, &CLSID_DP8SP_TCPIP
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
69 IDirectPlay8Address_Release(localaddr
);
73 static void address_addcomponents(void)
75 static const WCHAR UNKNOWN
[] = { 'u','n','k','n','o','w','n',0 };
76 static const char testing
[] = "testing";
78 IDirectPlay8Address
*localaddr
= NULL
;
80 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
81 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
94 /* We can add any Component to the Address interface not just the predefined ones. */
95 hr
= IDirectPlay8Address_AddComponent(localaddr
, UNKNOWN
, &IID_Random
, sizeof(GUID
), DPNA_DATATYPE_GUID
);
96 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
98 hr
= IDirectPlay8Address_AddComponent(localaddr
, UNKNOWN
, &IID_Random
, sizeof(GUID
)+1, DPNA_DATATYPE_GUID
);
99 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
101 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)+2, DPNA_DATATYPE_STRING
);
102 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
104 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)/2, DPNA_DATATYPE_STRING
);
105 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
107 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, testing
, sizeof(testing
)+2, DPNA_DATATYPE_STRING_ANSI
);
108 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
110 /* Show that on error, nothing is added. */
111 size
= sizeof(buffer
);
112 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
113 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
115 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, testing
, sizeof(testing
), DPNA_DATATYPE_STRING_ANSI
);
116 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
118 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
)+2, DPNA_DATATYPE_DWORD
);
119 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
121 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
), DPNA_DATATYPE_STRING
);
122 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
124 /* The information doesn't get removed when invalid parameters are used.*/
125 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)+2, DPNA_DATATYPE_STRING
);
126 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
129 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, NULL
, &size
, &type
);
130 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
131 ok(size
== sizeof(localhost
), "Invalid string length: %d\n", size
);
134 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, NULL
, &size
, &type
);
135 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
137 size
= sizeof(buffer
);
138 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
139 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
140 ok(type
== DPNA_DATATYPE_STRING
, "incorrect type %d\n", type
);
141 ok(!lstrcmpW(buffer
, localhost
), "Invalid string: %s\n", wine_dbgstr_w(buffer
));
143 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
)+2, DPNA_DATATYPE_DWORD
);
144 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
146 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
), DPNA_DATATYPE_DWORD
);
147 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
149 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, NULL
, &compguid
, &size
, &type
);
150 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
152 size
= sizeof(GUID
)-1;
153 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, NULL
, &size
, &type
);
154 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
157 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, NULL
, &size
, &type
);
158 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
160 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, NULL
, &type
);
161 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
163 size
= sizeof(GUID
)-1;
164 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, NULL
);
165 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
168 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, NULL
);
169 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
171 size
= sizeof(GUID
)-1;
172 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, &type
);
173 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
174 ok(size
== sizeof(GUID
), "got %d\n", size
);
177 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, &type
);
178 ok(IsEqualGUID(&compguid
, &IID_Random
), "incorrect guid\n");
179 ok(size
== sizeof(GUID
), "incorrect size got %d\n", size
);
180 ok(type
== DPNA_DATATYPE_GUID
, "incorrect type\n");
181 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
183 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, NULL
);
184 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
186 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
187 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
189 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, &namelen
, NULL
, &bufflen
, &type
);
190 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
192 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, NULL
, &namelen
, NULL
, &bufflen
, NULL
);
193 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
197 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, name
, &namelen
, buffer
, &bufflen
, &type
);
198 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
201 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, NULL
, &namelen
, NULL
, &bufflen
, &type
);
202 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
204 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, NULL
, NULL
, &bufflen
, &type
);
205 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
207 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, &namelen
, NULL
, NULL
, &type
);
208 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
213 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, NULL
, &namelen
, NULL
, &bufflen
, &type
);
214 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
215 ok(namelen
== 8, "namelen expected 8 got %d\n", namelen
);
216 ok(bufflen
== 16, "bufflen expected 16 got %d\n", bufflen
);
217 ok(type
== DPNA_DATATYPE_GUID
, "type expected DPNA_DATATYPE_GUID got %d\n", type
);
219 trace("GetNumComponents=%d\n", components
);
220 for(i
=0; i
< components
; i
++)
227 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, i
, NULL
, &namelen
, NULL
, &bufflen
, &type
);
228 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
230 name
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, namelen
* sizeof(WCHAR
));
231 buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, bufflen
);
233 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, i
, name
, &namelen
, buffer
, &bufflen
, &type
);
234 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
239 case DPNA_DATATYPE_STRING
:
240 trace("%d: %s: %s\n", i
, wine_dbgstr_w(name
), wine_dbgstr_w(buffer
));
242 case DPNA_DATATYPE_DWORD
:
243 trace("%d: %s: %d\n", i
, wine_dbgstr_w(name
), *(DWORD
*)buffer
);
245 case DPNA_DATATYPE_GUID
:
246 trace("%d: %s: %s\n", i
, wine_dbgstr_w(name
), wine_dbgstr_guid( (GUID
*)buffer
));
248 case DPNA_DATATYPE_BINARY
:
249 trace("%d: %s: Binary Data %d\n", i
, wine_dbgstr_w(name
), bufflen
);
257 HeapFree(GetProcessHeap(), 0, name
);
258 HeapFree(GetProcessHeap(), 0, buffer
);
261 IDirectPlay8Address_Release(localaddr
);
265 static void address_setsp(void)
268 IDirectPlay8Address
*localaddr
= NULL
;
270 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
271 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
276 GUID guid
= IID_Random
;
281 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
282 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
283 ok(components
== 0, "components=%d\n", components
);
285 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
286 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
288 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
289 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
290 ok(components
== 1, "components=%d\n", components
);
292 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, NULL
, &namelen
, NULL
, &bufflen
, &type
);
293 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
295 name
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, namelen
* sizeof(WCHAR
));
297 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, name
, &namelen
, (void*)&guid
, &bufflen
, &type
);
298 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
299 ok(type
== DPNA_DATATYPE_GUID
, "wrong datatype: %d\n", type
);
300 ok(IsEqualGUID(&guid
, &CLSID_DP8SP_TCPIP
), "wrong guid\n");
302 HeapFree(GetProcessHeap(), 0, name
);
304 IDirectPlay8Address_Release(localaddr
);
308 static void address_duplicate(void)
311 IDirectPlay8Address
*localaddr
= NULL
;
312 IDirectPlay8Address
*duplicate
= NULL
;
313 DWORD components
, dupcomps
;
314 GUID guid
= IID_Random
;
316 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
317 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
320 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
321 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
323 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
), DPNA_DATATYPE_STRING
);
324 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
326 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
327 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
328 ok(components
== 2, "components=%d\n", components
);
330 hr
= IDirectPlay8Address_Duplicate(localaddr
, &duplicate
);
331 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
337 hr
= IDirectPlay8Address_GetSP(duplicate
, &guid
);
338 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
339 ok(IsEqualGUID(&guid
, &CLSID_DP8SP_TCPIP
), "wrong guid\n");
341 hr
= IDirectPlay8Address_GetNumComponents(duplicate
, &dupcomps
);
342 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
343 ok(components
== dupcomps
, "expected %d got %d\n", components
, dupcomps
);
345 size
= sizeof(buffer
);
346 hr
= IDirectPlay8Address_GetComponentByName(duplicate
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
347 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
348 ok(type
== DPNA_DATATYPE_STRING
, "incorrect type %d\n", type
);
349 ok(!lstrcmpW(buffer
, localhost
), "Invalid string: %s\n", wine_dbgstr_w(buffer
));
351 IDirectPlay8Address_Release(duplicate
);
354 IDirectPlay8Address_Release(localaddr
);
363 if(!GetSystemDirectoryA(path
, MAX_PATH
))
365 skip("Failed to get systems directory\n");
368 strcat(path
, "\\dpnet.dll");
370 if (!winetest_interactive
&& is_stub_dll(path
))
372 win_skip("dpnet is a stub dll, skipping tests\n");
376 hr
= CoInitialize(0);
377 ok(hr
== S_OK
, "failed to init com\n");
381 create_directplay_address();
382 address_addcomponents();