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 /* {6733C6E8-A0D6-450E-8C18-CEACF331DC27} */
26 static const GUID IID_Random
= {0x6733c6e8, 0xa0d6, 0x450e, { 0x8c, 0x18, 0xce, 0xac, 0xf3, 0x31, 0xdc, 0x27 } };
27 static const WCHAR localhost
[] = {'l','o','c','a','l','h','o','s','t',0};
29 static void create_directplay_address(void)
32 IDirectPlay8Address
*localaddr
= NULL
;
34 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
35 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
40 hr
= IDirectPlay8Address_GetSP(localaddr
, NULL
);
41 ok(hr
== DPNERR_INVALIDPOINTER
, "GetSP failed 0x%08x\n", hr
);
43 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
44 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
46 hr
= IDirectPlay8Address_SetSP(localaddr
, &GUID_NULL
);
47 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
49 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
50 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
51 ok(IsEqualGUID(&guidsp
, &GUID_NULL
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
53 hr
= IDirectPlay8Address_SetSP(localaddr
, &IID_Random
);
54 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
56 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
57 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
58 ok(IsEqualGUID(&guidsp
, &IID_Random
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
60 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
61 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
63 hr
= IDirectPlay8Address_GetSP(localaddr
, &guidsp
);
64 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
65 ok(IsEqualGUID(&guidsp
, &CLSID_DP8SP_TCPIP
), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp
));
67 IDirectPlay8Address_Release(localaddr
);
71 static void address_addcomponents(void)
73 static const WCHAR UNKNOWN
[] = { 'u','n','k','n','o','w','n',0 };
74 static const char testing
[] = "testing";
76 IDirectPlay8Address
*localaddr
= NULL
;
78 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
79 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
92 /* We can add any Component to the Address interface not just the predefined ones. */
93 hr
= IDirectPlay8Address_AddComponent(localaddr
, UNKNOWN
, &IID_Random
, sizeof(GUID
), DPNA_DATATYPE_GUID
);
94 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
96 hr
= IDirectPlay8Address_AddComponent(localaddr
, UNKNOWN
, &IID_Random
, sizeof(GUID
)+1, DPNA_DATATYPE_GUID
);
97 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
99 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)+2, DPNA_DATATYPE_STRING
);
100 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
102 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)/2, DPNA_DATATYPE_STRING
);
103 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
105 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, testing
, sizeof(testing
)+2, DPNA_DATATYPE_STRING_ANSI
);
106 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
108 /* Show that on error, nothing is added. */
109 size
= sizeof(buffer
);
110 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
111 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
113 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, testing
, sizeof(testing
), DPNA_DATATYPE_STRING_ANSI
);
114 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
116 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
)+2, DPNA_DATATYPE_DWORD
);
117 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
119 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
), DPNA_DATATYPE_STRING
);
120 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
122 /* The information doesn't get removed when invalid parameters are used.*/
123 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
)+2, DPNA_DATATYPE_STRING
);
124 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
127 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, NULL
, &size
, &type
);
128 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
129 ok(size
== sizeof(localhost
), "Invalid string length: %d\n", size
);
132 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, NULL
, &size
, &type
);
133 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
135 size
= sizeof(buffer
);
136 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
137 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
138 ok(type
== DPNA_DATATYPE_STRING
, "incorrect type %d\n", type
);
139 ok(!lstrcmpW(buffer
, localhost
), "Invalid string: %s\n", wine_dbgstr_w(buffer
));
141 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
)+2, DPNA_DATATYPE_DWORD
);
142 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
144 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_PORT
, &port
, sizeof(DWORD
), DPNA_DATATYPE_DWORD
);
145 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
147 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, NULL
, &compguid
, &size
, &type
);
148 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
150 size
= sizeof(GUID
)-1;
151 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, NULL
, &size
, &type
);
152 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
155 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, NULL
, &size
, &type
);
156 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
158 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, NULL
, &type
);
159 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
161 size
= sizeof(GUID
)-1;
162 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, NULL
);
163 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
166 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, NULL
);
167 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
169 size
= sizeof(GUID
)-1;
170 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, &type
);
171 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
172 ok(size
== sizeof(GUID
), "got %d\n", size
);
175 hr
= IDirectPlay8Address_GetComponentByName(localaddr
, UNKNOWN
, &compguid
, &size
, &type
);
176 ok(IsEqualGUID(&compguid
, &IID_Random
), "incorrect guid\n");
177 ok(size
== sizeof(GUID
), "incorrect size got %d\n", size
);
178 ok(type
== DPNA_DATATYPE_GUID
, "incorrect type\n");
179 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
181 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, NULL
);
182 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
184 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
185 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
187 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, &namelen
, NULL
, &bufflen
, &type
);
188 ok(hr
== DPNERR_DOESNOTEXIST
, "got 0x%08x\n", hr
);
190 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, NULL
, &namelen
, NULL
, &bufflen
, NULL
);
191 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
195 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, name
, &namelen
, buffer
, &bufflen
, &type
);
196 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
199 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 1, NULL
, &namelen
, NULL
, &bufflen
, &type
);
200 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
202 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, NULL
, NULL
, &bufflen
, &type
);
203 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
205 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 100, NULL
, &namelen
, NULL
, NULL
, &type
);
206 ok(hr
== DPNERR_INVALIDPOINTER
, "got 0x%08x\n", hr
);
211 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, NULL
, &namelen
, NULL
, &bufflen
, &type
);
212 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
213 ok(namelen
== 8, "namelen expected 8 got %d\n", namelen
);
214 ok(bufflen
== 16, "bufflen expected 16 got %d\n", bufflen
);
215 ok(type
== DPNA_DATATYPE_GUID
, "type expected DPNA_DATATYPE_GUID got %d\n", type
);
217 trace("GetNumComponents=%d\n", components
);
218 for(i
=0; i
< components
; i
++)
225 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, i
, NULL
, &namelen
, NULL
, &bufflen
, &type
);
226 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
228 name
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, namelen
* sizeof(WCHAR
));
229 buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, bufflen
);
231 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, i
, name
, &namelen
, buffer
, &bufflen
, &type
);
232 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
237 case DPNA_DATATYPE_STRING
:
238 trace("%d: %s: %s\n", i
, wine_dbgstr_w(name
), wine_dbgstr_w(buffer
));
240 case DPNA_DATATYPE_DWORD
:
241 trace("%d: %s: %d\n", i
, wine_dbgstr_w(name
), *(DWORD
*)buffer
);
243 case DPNA_DATATYPE_GUID
:
244 trace("%d: %s: %s\n", i
, wine_dbgstr_w(name
), wine_dbgstr_guid( (GUID
*)buffer
));
246 case DPNA_DATATYPE_BINARY
:
247 trace("%d: %s: Binary Data %d\n", i
, wine_dbgstr_w(name
), bufflen
);
255 HeapFree(GetProcessHeap(), 0, name
);
256 HeapFree(GetProcessHeap(), 0, buffer
);
259 IDirectPlay8Address_Release(localaddr
);
263 static void address_setsp(void)
266 IDirectPlay8Address
*localaddr
= NULL
;
268 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
269 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
274 GUID guid
= IID_Random
;
279 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
280 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
281 ok(components
== 0, "components=%d\n", components
);
283 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
284 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
286 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
287 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
288 ok(components
== 1, "components=%d\n", components
);
290 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, NULL
, &namelen
, NULL
, &bufflen
, &type
);
291 ok(hr
== DPNERR_BUFFERTOOSMALL
, "got 0x%08x\n", hr
);
293 name
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, namelen
* sizeof(WCHAR
));
295 hr
= IDirectPlay8Address_GetComponentByIndex(localaddr
, 0, name
, &namelen
, (void*)&guid
, &bufflen
, &type
);
296 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
297 ok(type
== DPNA_DATATYPE_GUID
, "wrong datatype: %d\n", type
);
298 ok(IsEqualGUID(&guid
, &CLSID_DP8SP_TCPIP
), "wrong guid\n");
300 HeapFree(GetProcessHeap(), 0, name
);
302 IDirectPlay8Address_Release(localaddr
);
306 static void address_duplicate(void)
309 IDirectPlay8Address
*localaddr
= NULL
;
310 IDirectPlay8Address
*duplicate
= NULL
;
311 DWORD components
, dupcomps
;
312 GUID guid
= IID_Random
;
314 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
315 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
318 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
319 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
321 hr
= IDirectPlay8Address_AddComponent(localaddr
, DPNA_KEY_HOSTNAME
, &localhost
, sizeof(localhost
), DPNA_DATATYPE_STRING
);
322 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
324 hr
= IDirectPlay8Address_GetNumComponents(localaddr
, &components
);
325 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
326 ok(components
== 2, "components=%d\n", components
);
328 hr
= IDirectPlay8Address_Duplicate(localaddr
, &duplicate
);
329 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
335 hr
= IDirectPlay8Address_GetSP(duplicate
, &guid
);
336 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
337 ok(IsEqualGUID(&guid
, &CLSID_DP8SP_TCPIP
), "wrong guid\n");
339 hr
= IDirectPlay8Address_GetNumComponents(duplicate
, &dupcomps
);
340 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
341 ok(components
== dupcomps
, "expected %d got %d\n", components
, dupcomps
);
343 size
= sizeof(buffer
);
344 hr
= IDirectPlay8Address_GetComponentByName(duplicate
, DPNA_KEY_HOSTNAME
, buffer
, &size
, &type
);
345 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
346 ok(type
== DPNA_DATATYPE_STRING
, "incorrect type %d\n", type
);
347 ok(!lstrcmpW(buffer
, localhost
), "Invalid string: %s\n", wine_dbgstr_w(buffer
));
349 IDirectPlay8Address_Release(duplicate
);
352 IDirectPlay8Address_Release(localaddr
);
360 hr
= CoInitialize(0);
361 ok(hr
== S_OK
, "failed to init com\n");
365 create_directplay_address();
366 address_addcomponents();