2 * Copyright 2011 Louis Lenders
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
24 #include "wine/test.h"
27 static IDirectPlay8Peer
* peer
= NULL
;
28 static IDirectPlay8LobbiedApplication
* lobbied
= NULL
;
30 static HRESULT WINAPI
DirectPlayMessageHandler(PVOID context
, DWORD message_id
, PVOID buffer
)
32 trace("DirectPlayMessageHandler: 0x%08x\n", message_id
);
36 static HRESULT WINAPI
DirectPlayLobbyMessageHandler(PVOID context
, DWORD message_id
, PVOID buffer
)
38 trace("DirectPlayLobbyMessageHandler: 0x%08x\n", message_id
);
42 static void test_init_dp(void)
46 DPNHANDLE lobbyConnection
;
49 ok(hr
== S_OK
, "CoInitialize failed with %x\n", hr
);
51 hr
= CoCreateInstance(&CLSID_DirectPlay8Peer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectPlay8Peer
, (void **)&peer
);
52 ok(hr
== S_OK
, "CoCreateInstance failed with 0x%x\n", hr
);
54 memset(&caps
, 0, sizeof(DPN_SP_CAPS
));
55 caps
.dwSize
= sizeof(DPN_SP_CAPS
);
57 hr
= IDirectPlay8Peer_GetSPCaps(peer
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
58 ok(hr
== DPNERR_UNINITIALIZED
, "GetSPCaps failed with %x\n", hr
);
60 hr
= IDirectPlay8Peer_Initialize(peer
, NULL
, NULL
, 0);
61 ok(hr
== DPNERR_INVALIDPARAM
, "got %x\n", hr
);
63 hr
= IDirectPlay8Peer_Initialize(peer
, NULL
, DirectPlayMessageHandler
, 0);
64 ok(hr
== S_OK
, "IDirectPlay8Peer_Initialize failed with %x\n", hr
);
66 hr
= CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
67 &IID_IDirectPlay8LobbiedApplication
, (void **)&lobbied
);
68 ok(hr
== S_OK
, "CoCreateInstance failed with 0x%x\n", hr
);
70 hr
= IDirectPlay8LobbiedApplication_Initialize(lobbied
, NULL
, NULL
,
72 ok(hr
== DPNERR_INVALIDPOINTER
, "Failed with %x\n", hr
);
74 hr
= IDirectPlay8LobbiedApplication_Initialize(lobbied
, NULL
, DirectPlayLobbyMessageHandler
,
76 ok(hr
== S_OK
, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr
);
79 static void test_enum_service_providers(void)
81 DPN_SERVICE_PROVIDER_INFO
*serv_prov_info
;
89 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, NULL
, &size
, NULL
, 0);
90 ok(hr
== E_POINTER
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
92 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, NULL
, NULL
, &items
, 0);
93 ok(hr
== E_POINTER
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
95 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, NULL
, &size
, &items
, 0);
96 ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
97 ok(size
!= 0, "size is unexpectedly 0\n");
99 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
101 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, serv_prov_info
, &size
, &items
, 0);
102 ok(hr
== S_OK
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
103 ok(items
!= 0, "Found unexpectedly no service providers\n");
105 trace("number of items found: %d\n", items
);
107 for (i
=0;i
<items
;i
++)
109 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info
->pwszName
));
110 trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info
->guid
));
115 serv_prov_info
-= items
; /* set pointer back */
116 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
121 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, &CLSID_DP8SP_TCPIP
, NULL
, NULL
, &size
, &items
, 0);
122 ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
123 ok(size
!= 0, "size is unexpectedly 0\n");
125 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
127 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, &CLSID_DP8SP_TCPIP
, NULL
, serv_prov_info
, &size
, &items
, 0);
128 ok(hr
== S_OK
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
129 ok(items
!= 0, "Found unexpectedly no adapter\n");
132 for (i
=0;i
<items
;i
++)
134 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info
->pwszName
));
135 trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info
->guid
));
140 serv_prov_info
-= items
; /* set pointer back */
141 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
144 static const GUID appguid
= { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
146 static void test_enum_hosts(void)
149 IDirectPlay8Address
*host
= NULL
;
150 IDirectPlay8Address
*local
= NULL
;
151 DPN_APPLICATION_DESC appdesc
;
153 static const WCHAR localhost
[] = {'1','2','7','.','0','.','0','.','1',0};
155 memset( &appdesc
, 0, sizeof(DPN_APPLICATION_DESC
) );
156 appdesc
.dwSize
= sizeof( DPN_APPLICATION_DESC
);
157 appdesc
.guidApplication
= appguid
;
159 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&local
);
160 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
162 hr
= IDirectPlay8Address_SetSP(local
, &CLSID_DP8SP_TCPIP
);
163 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
165 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&host
);
166 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
168 hr
= IDirectPlay8Address_SetSP(host
, &CLSID_DP8SP_TCPIP
);
169 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
171 hr
= IDirectPlay8Address_AddComponent(host
, DPNA_KEY_HOSTNAME
, localhost
, sizeof(localhost
),
172 DPNA_DATATYPE_STRING
);
173 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
175 hr
= IDirectPlay8Peer_EnumHosts(peer
, &appdesc
, host
, local
, NULL
, 0, INFINITE
, 0, INFINITE
, NULL
, &async
, 0);
176 todo_wine
ok(hr
== DPNSUCCESS_PENDING
, "IDirectPlay8Peer_EnumServiceProviders failed with 0x%08x\n", hr
);
177 todo_wine
ok(async
, "No Handle returned\n");
179 hr
= IDirectPlay8Peer_CancelAsyncOperation(peer
, async
, 0);
180 todo_wine
ok(hr
== S_OK
, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr
);
182 IDirectPlay8Address_Release(local
);
183 IDirectPlay8Address_Release(host
);
186 static void test_get_sp_caps(void)
191 memset(&caps
, 0, sizeof(DPN_SP_CAPS
));
193 hr
= IDirectPlay8Peer_GetSPCaps(peer
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
194 ok(hr
== DPNERR_INVALIDPARAM
, "GetSPCaps unexpectedly returned %x\n", hr
);
196 caps
.dwSize
= sizeof(DPN_SP_CAPS
);
198 hr
= IDirectPlay8Peer_GetSPCaps(peer
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
199 ok(hr
== DPN_OK
, "GetSPCaps failed with %x\n", hr
);
201 ok(caps
.dwSize
== sizeof(DPN_SP_CAPS
), "got %d\n", caps
.dwSize
);
203 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
)) ==
204 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
),
205 "unexpected flags %x\n", caps
.dwFlags
);
206 ok(caps
.dwNumThreads
>= 3, "got %d\n", caps
.dwNumThreads
);
207 ok(caps
.dwDefaultEnumCount
== 5, "expected 5, got %d\n", caps
.dwDefaultEnumCount
);
208 ok(caps
.dwDefaultEnumRetryInterval
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumRetryInterval
);
209 ok(caps
.dwDefaultEnumTimeout
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumTimeout
);
210 ok(caps
.dwMaxEnumPayloadSize
== 983, "expected 983, got %d\n", caps
.dwMaxEnumPayloadSize
);
211 ok(caps
.dwBuffersPerThread
== 1, "expected 1, got %d\n", caps
.dwBuffersPerThread
);
212 ok(caps
.dwSystemBufferSize
== 0x10000 || broken(caps
.dwSystemBufferSize
== 0x2000 /* before Win8 */),
213 "expected 0x10000, got 0x%x\n", caps
.dwSystemBufferSize
);
216 static void test_player_info(void)
219 DPN_PLAYER_INFO info
;
220 WCHAR name
[] = {'w','i','n','e',0};
221 WCHAR name2
[] = {'w','i','n','e','2',0};
222 WCHAR data
[] = {'X','X','X','X',0};
224 ZeroMemory( &info
, sizeof(DPN_PLAYER_INFO
) );
225 info
.dwSize
= sizeof(DPN_PLAYER_INFO
);
226 info
.dwInfoFlags
= DPNINFO_NAME
;
228 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, NULL
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
229 ok(hr
== E_POINTER
, "got %x\n", hr
);
231 info
.pwszName
= NULL
;
232 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
233 ok(hr
== S_OK
, "got %x\n", hr
);
235 info
.pwszName
= name
;
236 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
237 ok(hr
== S_OK
, "got %x\n", hr
);
239 info
.dwInfoFlags
= DPNINFO_NAME
;
240 info
.pwszName
= name2
;
241 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
242 ok(hr
== S_OK
, "got %x\n", hr
);
244 if(0) /* Crashes on windows */
246 info
.dwInfoFlags
= DPNINFO_DATA
;
247 info
.pwszName
= NULL
;
249 info
.dwDataSize
= sizeof(data
);
250 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
251 ok(hr
== S_OK
, "got %x\n", hr
);
254 info
.dwInfoFlags
= DPNINFO_DATA
;
255 info
.pwszName
= NULL
;
258 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
259 ok(hr
== S_OK
, "got %x\n", hr
);
261 info
.dwInfoFlags
= DPNINFO_DATA
;
262 info
.pwszName
= NULL
;
264 info
.dwDataSize
= sizeof(data
);
265 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
266 ok(hr
== S_OK
, "got %x\n", hr
);
268 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
269 info
.pwszName
= name
;
271 info
.dwDataSize
= sizeof(data
);
272 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
273 ok(hr
== S_OK
, "got %x\n", hr
);
275 /* Leave PeerInfo with only the name set. */
276 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
277 info
.pwszName
= name
;
280 hr
= IDirectPlay8Peer_SetPeerInfo(peer
, &info
, NULL
, NULL
, DPNSETPEERINFO_SYNC
);
281 ok(hr
== S_OK
, "got %x\n", hr
);
284 static void test_cleanup_dp(void)
288 hr
= IDirectPlay8Peer_Close(peer
, 0);
289 ok(hr
== S_OK
, "IDirectPlay8Peer_Close failed with %x\n", hr
);
293 hr
= IDirectPlay8LobbiedApplication_Close(lobbied
, 0);
294 ok(hr
== S_OK
, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr
);
296 IDirectPlay8LobbiedApplication_Release(lobbied
);
299 IDirectPlay8Peer_Release(peer
);
307 test_enum_service_providers();