2 * Copyright 2011 Louis Lenders
3 * Copyright 2014 Alistair Leslie-Hughes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define WIN32_LEAN_AND_MEAN
25 #include "wine/test.h"
28 static IDirectPlay8Client
* client
= NULL
;
29 static IDirectPlay8LobbiedApplication
* lobbied
= NULL
;
30 static const GUID appguid
= { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
32 static HRESULT WINAPI
DirectPlayMessageHandler(PVOID context
, DWORD message_id
, PVOID buffer
)
34 trace("DirectPlayMessageHandler: 0x%08x\n", message_id
);
38 static HRESULT WINAPI
DirectPlayLobbyMessageHandler(PVOID context
, DWORD message_id
, PVOID buffer
)
40 trace("DirectPlayLobbyMessageHandler: 0x%08x\n", message_id
);
44 static HRESULT WINAPI
DirectPlayLobbyClientMessageHandler(void *context
, DWORD message_id
, void* buffer
)
46 trace("DirectPlayLobbyClientMessageHandler: 0x%08x\n", message_id
);
50 static BOOL
test_init_dp(void)
54 DPNHANDLE lobbyConnection
;
57 ok(hr
== S_OK
, "CoInitialize failed with %x\n", hr
);
59 hr
= CoCreateInstance(&CLSID_DirectPlay8Client
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectPlay8Client
, (void **)&client
);
60 ok(hr
== S_OK
, "CoCreateInstance failed with 0x%x\n", hr
);
62 memset(&caps
, 0, sizeof(DPN_SP_CAPS
));
63 caps
.dwSize
= sizeof(DPN_SP_CAPS
);
65 hr
= IDirectPlay8Client_GetSPCaps(client
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
66 ok(hr
== DPNERR_UNINITIALIZED
, "GetSPCaps failed with %x\n", hr
);
68 hr
= IDirectPlay8Client_Initialize(client
, NULL
, NULL
, 0);
69 ok(hr
== DPNERR_INVALIDPARAM
, "got %x\n", hr
);
71 hr
= IDirectPlay8Client_Initialize(client
, NULL
, DirectPlayMessageHandler
, 0);
72 ok(hr
== S_OK
, "IDirectPlay8Client_Initialize failed with %x\n", hr
);
74 hr
= CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
75 &IID_IDirectPlay8LobbiedApplication
, (void **)&lobbied
);
76 ok(hr
== S_OK
, "CoCreateInstance failed with 0x%x\n", hr
);
78 hr
= IDirectPlay8LobbiedApplication_Initialize(lobbied
, NULL
, DirectPlayLobbyMessageHandler
,
80 ok(hr
== S_OK
, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr
);
82 return client
!= NULL
;
85 static void test_enum_service_providers(void)
87 DPN_SERVICE_PROVIDER_INFO
*serv_prov_info
;
95 hr
= IDirectPlay8Client_EnumServiceProviders(client
, NULL
, NULL
, NULL
, &size
, NULL
, 0);
96 todo_wine
ok(hr
== E_POINTER
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
98 hr
= IDirectPlay8Client_EnumServiceProviders(client
, NULL
, NULL
, NULL
, NULL
, &items
, 0);
99 todo_wine
ok(hr
== E_POINTER
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
101 hr
= IDirectPlay8Client_EnumServiceProviders(client
, NULL
, NULL
, NULL
, &size
, &items
, 0);
102 todo_wine
ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
103 todo_wine
ok(size
!= 0, "size is unexpectedly 0\n");
105 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
107 hr
= IDirectPlay8Client_EnumServiceProviders(client
, NULL
, NULL
, serv_prov_info
, &size
, &items
, 0);
108 ok(hr
== S_OK
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
109 todo_wine
ok(items
!= 0, "Found unexpectedly no service providers\n");
111 trace("number of items found: %d\n", items
);
113 for (i
=0;i
<items
;i
++)
115 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info
[i
].pwszName
));
116 trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info
[i
].guid
));
119 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
124 hr
= IDirectPlay8Client_EnumServiceProviders(client
, &CLSID_DP8SP_TCPIP
, NULL
, NULL
, &size
, &items
, 0);
125 todo_wine
ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
126 todo_wine
ok(size
!= 0, "size is unexpectedly 0\n");
128 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
130 hr
= IDirectPlay8Client_EnumServiceProviders(client
, &CLSID_DP8SP_TCPIP
, NULL
, serv_prov_info
, &size
, &items
, 0);
131 ok(hr
== S_OK
, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr
);
132 todo_wine
ok(items
!= 0, "Found unexpectedly no adapter\n");
135 for (i
=0;i
<items
;i
++)
137 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info
[i
].pwszName
));
138 trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info
[i
].guid
));
141 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
144 static void test_enum_hosts(void)
147 IDirectPlay8Address
*host
= NULL
;
148 IDirectPlay8Address
*local
= NULL
;
149 DPN_APPLICATION_DESC appdesc
;
151 static const WCHAR localhost
[] = {'1','2','7','.','0','.','0','.','1',0};
153 memset( &appdesc
, 0, sizeof(DPN_APPLICATION_DESC
) );
154 appdesc
.dwSize
= sizeof( DPN_APPLICATION_DESC
);
155 appdesc
.guidApplication
= appguid
;
157 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&local
);
158 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
160 hr
= IDirectPlay8Address_SetSP(local
, &CLSID_DP8SP_TCPIP
);
161 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
163 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&host
);
164 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
166 hr
= IDirectPlay8Address_SetSP(host
, &CLSID_DP8SP_TCPIP
);
167 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
169 hr
= IDirectPlay8Address_AddComponent(host
, DPNA_KEY_HOSTNAME
, localhost
, sizeof(localhost
),
170 DPNA_DATATYPE_STRING
);
171 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
173 /* Since we are running asynchronously, EnumHosts returns DPNSUCCESS_PENDING. */
174 hr
= IDirectPlay8Client_EnumHosts(client
, &appdesc
, host
, local
, NULL
, 0, INFINITE
, 0, INFINITE
, NULL
, &async
, 0);
175 todo_wine
ok(hr
== DPNSUCCESS_PENDING
, "IDirectPlay8Client_EnumServiceProviders failed with 0x%08x\n", hr
);
176 todo_wine
ok(async
, "No Handle returned\n");
178 hr
= IDirectPlay8Client_CancelAsyncOperation(client
, async
, 0);
179 ok(hr
== S_OK
, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr
);
181 IDirectPlay8Address_Release(local
);
182 IDirectPlay8Address_Release(host
);
185 static void test_get_sp_caps(void)
190 memset(&caps
, 0, sizeof(DPN_SP_CAPS
));
192 hr
= IDirectPlay8Client_GetSPCaps(client
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
193 ok(hr
== DPNERR_INVALIDPARAM
, "GetSPCaps unexpectedly returned %x\n", hr
);
195 caps
.dwSize
= sizeof(DPN_SP_CAPS
);
197 hr
= IDirectPlay8Client_GetSPCaps(client
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
198 ok(hr
== DPN_OK
, "GetSPCaps failed with %x\n", hr
);
201 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
)) ==
202 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
),
203 "unexpected flags %x\n", caps
.dwFlags
);
204 ok(caps
.dwNumThreads
>= 3, "got %d\n", caps
.dwNumThreads
);
205 ok(caps
.dwDefaultEnumCount
== 5, "expected 5, got %d\n", caps
.dwDefaultEnumCount
);
206 ok(caps
.dwDefaultEnumRetryInterval
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumRetryInterval
);
207 ok(caps
.dwDefaultEnumTimeout
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumTimeout
);
208 ok(caps
.dwMaxEnumPayloadSize
== 983, "expected 983, got %d\n", caps
.dwMaxEnumPayloadSize
);
209 ok(caps
.dwBuffersPerThread
== 1, "expected 1, got %d\n", caps
.dwBuffersPerThread
);
210 ok(caps
.dwSystemBufferSize
== 0x10000 || broken(caps
.dwSystemBufferSize
== 0x2000 /* before Win8 */),
211 "expected 0x10000, got 0x%x\n", caps
.dwSystemBufferSize
);
214 static void test_lobbyclient(void)
217 IDirectPlay8LobbyClient
*client
= NULL
;
219 hr
= CoCreateInstance( &CLSID_DirectPlay8LobbyClient
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8LobbyClient
, (void**)&client
);
220 ok(hr
== S_OK
, "Failed to create object\n");
223 hr
= IDirectPlay8LobbyClient_Initialize(client
, NULL
, DirectPlayLobbyClientMessageHandler
, 0);
224 todo_wine
ok(hr
== S_OK
, "got 0x%08x\n", hr
);
226 hr
= IDirectPlay8LobbyClient_Close(client
, 0);
227 todo_wine
ok(hr
== S_OK
, "got 0x%08x\n", hr
);
229 IDirectPlay8LobbyClient_Release(client
);
233 static void test_cleanup_dp(void)
237 hr
= IDirectPlay8Client_Close(client
, 0);
238 ok(hr
== S_OK
, "IDirectPlay8Client_Close failed with %x\n", hr
);
242 hr
= IDirectPlay8LobbiedApplication_Close(lobbied
, 0);
243 ok(hr
== S_OK
, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr
);
245 IDirectPlay8LobbiedApplication_Release(lobbied
);
248 IDirectPlay8Client_Release(client
);
258 test_enum_service_providers();