win32u: Implement EVENT_SYSTEM_FOREGROUND.
[wine.git] / dlls / dpnet / tests / address.c
blob260d960f42b87a0f07e3ccbd512591118d014ed4
1 /*
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
20 #include <stdio.h>
22 #include <dplay8.h>
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"localhost";
31 static void create_directplay_address(void)
33 HRESULT hr;
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");
38 if(SUCCEEDED(hr))
40 GUID guidsp;
42 hr = IDirectPlay8Address_GetSP(localaddr, NULL);
43 ok(hr == DPNERR_INVALIDPOINTER, "GetSP failed 0x%08lx\n", hr);
45 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
46 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08lx\n", hr);
48 hr = IDirectPlay8Address_SetSP(localaddr, &GUID_NULL);
49 ok(hr == S_OK, "got 0x%08lx\n", hr);
51 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
52 ok(hr == S_OK, "got 0x%08lx\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%08lx\n", hr);
58 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
59 ok(hr == S_OK, "got 0x%08lx\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%08lx\n", hr);
65 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
66 ok(hr == S_OK, "got 0x%08lx\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 char testing[] = "testing";
76 HRESULT hr;
77 IDirectPlay8Address *localaddr = NULL;
79 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
80 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
81 if(SUCCEEDED(hr))
83 GUID compguid;
84 DWORD size, type;
85 DWORD components;
86 DWORD i;
87 DWORD namelen = 0;
88 DWORD bufflen = 0;
89 DWORD port = 8888;
90 WCHAR buffer[256];
91 WCHAR *name = NULL;
93 /* We can add any Component to the Address interface not just the predefined ones. */
94 hr = IDirectPlay8Address_AddComponent(localaddr, L"unknown", &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
95 ok(hr == S_OK, "got 0x%08lx\n", hr);
97 hr = IDirectPlay8Address_AddComponent(localaddr, L"unknown", &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
98 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
100 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
101 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
103 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)/2, DPNA_DATATYPE_STRING);
104 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
106 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing)+2, DPNA_DATATYPE_STRING_ANSI);
107 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
109 /* Show that on error, nothing is added. */
110 size = sizeof(buffer);
111 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
112 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08lx\n", hr);
114 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing), DPNA_DATATYPE_STRING_ANSI);
115 ok(hr == S_OK, "got 0x%08lx\n", hr);
117 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
118 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
120 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
121 ok(hr == S_OK, "got 0x%08lx\n", hr);
123 /* The information doesn't get removed when invalid parameters are used.*/
124 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
125 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
127 size = 0;
128 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, NULL, &size, &type);
129 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
130 ok(size == sizeof(localhost), "Invalid string length: %ld\n", size);
132 size = 1;
133 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, NULL, &size, &type);
134 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
136 size = sizeof(buffer);
137 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
138 ok(hr == S_OK, "got 0x%08lx\n", hr);
139 ok(type == DPNA_DATATYPE_STRING, "incorrect type %ld\n", type);
140 ok(!lstrcmpW(buffer, localhost), "Invalid string: %s\n", wine_dbgstr_w(buffer));
142 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
143 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
145 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
146 ok(hr == S_OK, "got 0x%08lx\n", hr);
148 hr = IDirectPlay8Address_GetComponentByName(localaddr, NULL, &compguid, &size, &type);
149 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
151 size = sizeof(GUID)-1;
152 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", NULL, &size, &type);
153 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
155 size = sizeof(GUID);
156 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", NULL, &size, &type);
157 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
159 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, NULL, &type);
160 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
162 size = sizeof(GUID)-1;
163 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, NULL);
164 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
166 size = sizeof(GUID);
167 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, NULL);
168 ok(hr == E_POINTER, "got 0x%08lx\n", hr);
170 size = sizeof(GUID)-1;
171 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, &type);
172 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
173 ok(size == sizeof(GUID), "got %ld\n", size);
175 size = sizeof(GUID);
176 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, &type);
177 ok(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n");
178 ok(size == sizeof(GUID), "incorrect size got %ld\n", size);
179 ok(type == DPNA_DATATYPE_GUID, "incorrect type\n");
180 ok(hr == S_OK, "got 0x%08lx\n", hr);
182 hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL);
183 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
185 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
186 ok(hr == S_OK, "got 0x%08lx\n", hr);
188 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, &bufflen, &type);
189 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08lx\n", hr);
191 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, NULL, &namelen, NULL, &bufflen, NULL);
192 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
194 bufflen = 100;
195 namelen = 0;
196 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, name, &namelen, buffer, &bufflen, &type);
197 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
199 namelen = 100;
200 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, NULL, &namelen, NULL, &bufflen, &type);
201 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
203 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, NULL, NULL, &bufflen, &type);
204 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
206 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, NULL, &type);
207 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
209 bufflen = 0;
210 namelen = 0;
211 type = 0;
212 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, NULL, &namelen, NULL, &bufflen, &type);
213 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
214 ok(namelen == 8, "namelen expected 8 got %ld\n", namelen);
215 ok(bufflen == 16, "bufflen expected 16 got %ld\n", bufflen);
216 ok(type == DPNA_DATATYPE_GUID, "type expected DPNA_DATATYPE_GUID got %ld\n", type);
218 trace("GetNumComponents=%ld\n", components);
219 for(i=0; i < components; i++)
221 void *buffer;
223 bufflen = 0;
224 namelen = 0;
226 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, NULL, &namelen, NULL, &bufflen, &type);
227 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
229 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
230 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufflen);
232 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, name, &namelen, buffer, &bufflen, &type);
233 ok(hr == S_OK, "got 0x%08lx\n", hr);
234 if(hr == S_OK)
236 switch(type)
238 case DPNA_DATATYPE_STRING:
239 trace("%ld: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
240 break;
241 case DPNA_DATATYPE_DWORD:
242 trace("%ld: %s: %ld\n", i, wine_dbgstr_w(name), *(DWORD*)buffer);
243 break;
244 case DPNA_DATATYPE_GUID:
245 trace("%ld: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_guid( (GUID*)buffer));
246 break;
247 case DPNA_DATATYPE_BINARY:
248 trace("%ld: %s: Binary Data %ld\n", i, wine_dbgstr_w(name), bufflen);
249 break;
250 default:
251 trace(" Unknown\n");
252 break;
256 HeapFree(GetProcessHeap(), 0, name);
257 HeapFree(GetProcessHeap(), 0, buffer);
260 IDirectPlay8Address_Release(localaddr);
264 static void address_setsp(void)
266 HRESULT hr;
267 IDirectPlay8Address *localaddr = NULL;
269 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
270 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
271 if(SUCCEEDED(hr))
273 DWORD components;
274 WCHAR *name;
275 GUID guid = IID_Random;
276 DWORD type;
277 DWORD namelen = 0;
278 DWORD bufflen = 0;
280 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
281 ok(hr == S_OK, "got 0x%08lx\n", hr);
282 ok(components == 0, "components=%ld\n", components);
284 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
285 ok(hr == S_OK, "got 0x%08lx\n", hr);
287 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
288 ok(hr == S_OK, "got 0x%08lx\n", hr);
289 ok(components == 1, "components=%ld\n", components);
291 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, NULL, &namelen, NULL, &bufflen, &type);
292 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
294 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
296 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, name, &namelen, (void*)&guid, &bufflen, &type);
297 ok(hr == S_OK, "got 0x%08lx\n", hr);
298 ok(type == DPNA_DATATYPE_GUID, "wrong datatype: %ld\n", type);
299 ok(IsEqualGUID(&guid, &CLSID_DP8SP_TCPIP), "wrong guid\n");
301 HeapFree(GetProcessHeap(), 0, name);
303 IDirectPlay8Address_Release(localaddr);
307 static void address_urlW(void)
309 HRESULT hr;
310 IDirectPlay8Address *localaddr = NULL;
311 WCHAR buffer[1024];
313 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
314 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
315 if(SUCCEEDED(hr))
317 DWORD bufflen = 0, bufflen2;
318 DWORD port = 4321;
320 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
321 ok(hr == S_OK, "got 0x%08lx\n", hr);
323 hr = IDirectPlay8Address_GetURLW(localaddr, NULL, NULL);
324 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
326 bufflen = 10;
327 hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
328 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
330 bufflen = 0;
331 hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
332 ok(bufflen == 66, "got %ld\n", bufflen);
333 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
335 hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
336 ok(hr == S_OK, "got 0x%08lx\n", hr);
337 ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D", buffer), "got %s\n", wine_dbgstr_w(buffer));
339 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
340 ok(hr == S_OK, "got 0x%08lx\n", hr);
342 bufflen = 0;
343 hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
344 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
346 bufflen2 = bufflen/2;
347 memset( buffer, 0xcc, sizeof(buffer) );
348 hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen2);
349 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
350 ok(buffer[0] == 0xcccc, "buffer modified\n");
352 hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
353 ok(hr == S_OK, "got 0x%08lx\n", hr);
354 ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321", buffer), "got %s\n", wine_dbgstr_w(buffer));
356 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
357 ok(hr == S_OK, "got 0x%08lx\n", hr);
359 bufflen = 0;
360 hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
361 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
363 hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
364 ok(hr == S_OK, "got 0x%08lx\n", hr);
365 ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321;hostname=localhost", buffer), "got %s\n", wine_dbgstr_w(buffer));
367 IDirectPlay8Address_Release(localaddr);
371 static void address_urlA(void)
373 HRESULT hr;
374 IDirectPlay8Address *localaddr = NULL;
375 char buffer[1024];
376 static const char urlA1[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D";
377 static const char urlA2[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321";
378 static const char urlA3[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321;hostname=localhost";
379 static const char localhostA[] = "localhost";
381 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
382 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
383 if(SUCCEEDED(hr))
385 DWORD bufflen = 0, bufflen2;
386 DWORD port = 4321;
388 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
389 ok(hr == S_OK, "got 0x%08lx\n", hr);
391 hr = IDirectPlay8Address_GetURLA(localaddr, NULL, NULL);
392 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
394 bufflen = 10;
395 hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
396 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08lx\n", hr);
398 bufflen = 0;
399 hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
400 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
402 bufflen2 = bufflen/2;
403 memset( buffer, 0x55, sizeof(buffer) );
404 hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen2);
405 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
406 ok(buffer[0] == 0x55, "buffer modified\n");
408 hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
409 ok(hr == S_OK, "got 0x%08lx\n", hr);
410 ok(!lstrcmpA(urlA1, buffer), "got %s\n", buffer);
412 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
413 ok(hr == S_OK, "got 0x%08lx\n", hr);
415 bufflen = 0;
416 hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
417 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
419 hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
420 ok(hr == S_OK, "got 0x%08lx\n", hr);
421 ok(!lstrcmpA(urlA2, buffer), "got %s\n", buffer);
423 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhostA, sizeof(localhostA), DPNA_DATATYPE_STRING_ANSI);
424 ok(hr == S_OK, "got 0x%08lx\n", hr);
426 bufflen = 0;
427 hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
428 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08lx\n", hr);
430 hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
431 ok(hr == S_OK, "got 0x%08lx\n", hr);
432 ok(!lstrcmpA(urlA3, buffer), "got %s\n", buffer);
434 IDirectPlay8Address_Release(localaddr);
438 static void address_duplicate(void)
440 HRESULT hr;
441 IDirectPlay8Address *localaddr = NULL;
442 IDirectPlay8Address *duplicate = NULL;
443 DWORD components, dupcomps;
444 GUID guid = IID_Random;
446 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
447 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
448 if(SUCCEEDED(hr))
450 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
451 ok(hr == S_OK, "got 0x%08lx\n", hr);
453 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
454 ok(hr == S_OK, "got 0x%08lx\n", hr);
456 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
457 ok(hr == S_OK, "got 0x%08lx\n", hr);
458 ok(components == 2, "components=%ld\n", components);
460 hr = IDirectPlay8Address_Duplicate(localaddr, &duplicate);
461 ok(hr == S_OK, "got 0x%08lx\n", hr);
462 if(SUCCEEDED(hr))
464 DWORD size, type;
465 WCHAR buffer[256];
467 hr = IDirectPlay8Address_GetSP(duplicate, &guid);
468 ok(hr == S_OK, "got 0x%08lx\n", hr);
469 ok(IsEqualGUID(&guid, &CLSID_DP8SP_TCPIP), "wrong guid\n");
471 hr = IDirectPlay8Address_GetNumComponents(duplicate, &dupcomps);
472 ok(hr == S_OK, "got 0x%08lx\n", hr);
473 ok(components == dupcomps, "expected %ld got %ld\n", components, dupcomps);
475 size = sizeof(buffer);
476 hr = IDirectPlay8Address_GetComponentByName(duplicate, DPNA_KEY_HOSTNAME, buffer, &size, &type);
477 ok(hr == S_OK, "got 0x%08lx\n", hr);
478 ok(type == DPNA_DATATYPE_STRING, "incorrect type %ld\n", type);
479 ok(!lstrcmpW(buffer, localhost), "Invalid string: %s\n", wine_dbgstr_w(buffer));
481 IDirectPlay8Address_Release(duplicate);
484 IDirectPlay8Address_Release(localaddr);
488 START_TEST(address)
490 HRESULT hr;
491 char path[MAX_PATH];
493 if(!GetSystemDirectoryA(path, MAX_PATH))
495 skip("Failed to get systems directory\n");
496 return;
498 strcat(path, "\\dpnet.dll");
500 if (!winetest_interactive && is_stub_dll(path))
502 win_skip("dpnet is a stub dll, skipping tests\n");
503 return;
506 hr = CoInitialize(0);
507 ok(hr == S_OK, "failed to init com\n");
508 if(hr != S_OK)
509 return;
511 create_directplay_address();
512 address_addcomponents();
513 address_setsp();
514 address_duplicate();
515 address_urlW();
516 address_urlA();
518 CoUninitialize();