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
25 #include "wine/test.h"
27 #include "dpnet_test.h"
29 /* {CD0C3D4B-E15E-4CF2-9EA8-6E1D6548C5A5} */
30 static const GUID appguid
= { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
31 static WCHAR sessionname
[] = L
"winegamesserver";
33 static BOOL nCreatePlayer
;
34 static BOOL nDestroyPlayer
;
36 static HRESULT WINAPI
DirectPlayMessageHandler(PVOID pvUserContext
, DWORD dwMessageId
, PVOID pMsgBuffer
)
38 trace("msgid: 0x%08lx\n", dwMessageId
);
42 case DPN_MSGID_CREATE_PLAYER
:
45 case DPN_MSGID_DESTROY_PLAYER
:
46 nDestroyPlayer
= TRUE
;
53 static void create_server(void)
56 IDirectPlay8Server
*server
= NULL
;
58 hr
= CoCreateInstance( &CLSID_DirectPlay8Server
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Server
, (LPVOID
*)&server
);
59 ok(hr
== S_OK
, "Failed to create IDirectPlay8Server object\n");
62 hr
= IDirectPlay8Server_Close(server
, 0);
63 todo_wine
ok(hr
== DPNERR_UNINITIALIZED
, "got 0x%08lx\n", hr
);
65 hr
= IDirectPlay8Server_Initialize(server
, NULL
, NULL
, 0);
66 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08lx\n", hr
);
68 hr
= IDirectPlay8Server_Initialize(server
, NULL
, DirectPlayMessageHandler
, 0);
69 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
72 IDirectPlay8Address
*localaddr
= NULL
;
73 DPN_APPLICATION_DESC appdesc
;
75 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
76 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
78 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
79 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
81 memset( &appdesc
, 0, sizeof(DPN_APPLICATION_DESC
) );
82 appdesc
.dwSize
= sizeof( DPN_APPLICATION_DESC
);
83 appdesc
.dwFlags
= DPNSESSION_CLIENT_SERVER
;
84 appdesc
.guidApplication
= appguid
;
85 appdesc
.pwszSessionName
= sessionname
;
87 hr
= IDirectPlay8Server_Host(server
, &appdesc
, &localaddr
, 1, NULL
, NULL
, NULL
, 0);
88 todo_wine
ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
90 todo_wine
ok(nCreatePlayer
, "No DPN_MSGID_CREATE_PLAYER Message\n");
91 ok(!nDestroyPlayer
, "Received DPN_MSGID_DESTROY_PLAYER Message\n");
93 hr
= IDirectPlay8Server_Close(server
, 0);
94 todo_wine
ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
96 todo_wine
ok(nDestroyPlayer
, "No DPN_MSGID_DESTROY_PLAYER Message\n");
98 IDirectPlay8Address_Release(localaddr
);
101 IDirectPlay8Server_Release(server
);
105 static void test_server_info(void)
108 DPN_PLAYER_INFO info
;
109 WCHAR name
[] = L
"wine";
110 WCHAR name2
[] = L
"wine2";
111 WCHAR data
[] = L
"XXXX";
112 IDirectPlay8Server
*server
= NULL
;
114 hr
= CoCreateInstance( &CLSID_DirectPlay8Server
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Server
, (LPVOID
*)&server
);
115 ok(hr
== S_OK
, "Failed to create IDirectPlay8Server object\n");
118 ZeroMemory( &info
, sizeof(DPN_PLAYER_INFO
) );
119 info
.dwSize
= sizeof(DPN_PLAYER_INFO
);
120 info
.dwInfoFlags
= DPNINFO_NAME
;
122 hr
= IDirectPlay8Server_SetServerInfo(server
, NULL
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
123 ok(hr
== E_POINTER
, "got %lx\n", hr
);
125 info
.pwszName
= name
;
126 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
127 ok(hr
== DPNERR_UNINITIALIZED
, "got %lx\n", hr
);
129 hr
= IDirectPlay8Server_Initialize(server
, NULL
, DirectPlayMessageHandler
, 0);
130 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
132 hr
= IDirectPlay8Server_SetServerInfo(server
, NULL
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
133 ok(hr
== E_POINTER
, "got %lx\n", hr
);
135 info
.pwszName
= NULL
;
136 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
137 ok(hr
== S_OK
, "got %lx\n", hr
);
139 info
.pwszName
= name
;
140 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
141 ok(hr
== S_OK
, "got %lx\n", hr
);
143 info
.dwInfoFlags
= DPNINFO_NAME
;
144 info
.pwszName
= name2
;
145 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
146 ok(hr
== S_OK
, "got %lx\n", hr
);
148 info
.dwInfoFlags
= DPNINFO_DATA
;
149 info
.pwszName
= NULL
;
151 info
.dwDataSize
= sizeof(data
);
152 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
153 ok(hr
== E_POINTER
, "got %lx\n", hr
);
155 info
.dwInfoFlags
= DPNINFO_DATA
;
156 info
.pwszName
= NULL
;
159 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
160 ok(hr
== S_OK
, "got %lx\n", hr
);
162 info
.dwInfoFlags
= DPNINFO_DATA
;
163 info
.pwszName
= NULL
;
165 info
.dwDataSize
= sizeof(data
);
166 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
167 ok(hr
== S_OK
, "got %lx\n", hr
);
169 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
170 info
.pwszName
= name
;
172 info
.dwDataSize
= sizeof(data
);
173 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
174 ok(hr
== S_OK
, "got %lx\n", hr
);
176 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
177 info
.pwszName
= name
;
180 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
181 ok(hr
== S_OK
, "got %lx\n", hr
);
183 IDirectPlay8Server_Release(server
);
187 static void test_enum_service_providers(void)
189 DPN_SERVICE_PROVIDER_INFO
*serv_prov_info
= NULL
;
190 IDirectPlay8Server
*server
= NULL
;
195 hr
= CoCreateInstance( &CLSID_DirectPlay8Server
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Server
, (LPVOID
*)&server
);
196 ok(hr
== S_OK
, "Failed to create IDirectPlay8Server object\n");
202 hr
= IDirectPlay8Server_EnumServiceProviders(server
, NULL
, NULL
, serv_prov_info
, &size
, &items
, 0);
203 ok(hr
== DPNERR_UNINITIALIZED
, "got %lx\n", hr
);
205 hr
= IDirectPlay8Server_Initialize(server
, NULL
, DirectPlayMessageHandler
, 0);
206 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
209 IDirectPlay8Server_Release(server
);
216 hr
= IDirectPlay8Server_EnumServiceProviders(server
, NULL
, NULL
, NULL
, &size
, NULL
, 0);
217 ok(hr
== E_POINTER
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
219 hr
= IDirectPlay8Server_EnumServiceProviders(server
, NULL
, NULL
, NULL
, NULL
, &items
, 0);
220 ok(hr
== E_POINTER
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
222 hr
= IDirectPlay8Server_EnumServiceProviders(server
, NULL
, NULL
, NULL
, &size
, &items
, 0);
223 ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
224 ok(size
!= 0, "size is unexpectedly 0\n");
226 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
228 hr
= IDirectPlay8Server_EnumServiceProviders(server
, NULL
, NULL
, serv_prov_info
, &size
, &items
, 0);
229 ok(hr
== S_OK
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
230 ok(items
!= 0, "Found unexpectedly no service providers\n");
232 trace("number of items found: %ld\n", items
);
234 for (i
=0;i
<items
;i
++)
236 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info
[i
].pwszName
));
237 trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info
[i
].guid
));
240 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
245 hr
= IDirectPlay8Server_EnumServiceProviders(server
, &CLSID_DP8SP_TCPIP
, NULL
, NULL
, &size
, &items
, 0);
246 ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
247 ok(size
!= 0, "size is unexpectedly 0\n");
249 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
251 hr
= IDirectPlay8Server_EnumServiceProviders(server
, &CLSID_DP8SP_TCPIP
, NULL
, serv_prov_info
, &size
, &items
, 0);
252 ok(hr
== S_OK
, "IDirectPlay8Server_EnumServiceProviders failed with %lx\n", hr
);
253 ok(items
!= 0, "Found unexpectedly no adapter\n");
256 for (i
=0;i
<items
;i
++)
258 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info
[i
].pwszName
));
259 trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info
[i
].guid
));
264 hr
= IDirectPlay8Server_EnumServiceProviders(server
, &appguid
, NULL
, serv_prov_info
, &size
, &items
, 0);
265 ok(hr
== DPNERR_DOESNOTEXIST
, "IDirectPlay8Peer_EnumServiceProviders failed with %lx\n", hr
);
266 ok(items
== 88, "Found adapter %ld\n", items
);
268 HeapFree(GetProcessHeap(), 0, serv_prov_info
);
269 IDirectPlay8Server_Release(server
);
272 BOOL
is_process_elevated(void)
275 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
))
277 TOKEN_ELEVATION_TYPE type
;
281 ret
= GetTokenInformation( token
, TokenElevationType
, &type
, sizeof(type
), &size
);
282 CloseHandle( token
);
283 return (ret
&& type
== TokenElevationTypeFull
);
288 BOOL
is_firewall_enabled(void)
291 INetFwMgr
*mgr
= NULL
;
292 INetFwPolicy
*policy
= NULL
;
293 INetFwProfile
*profile
= NULL
;
294 VARIANT_BOOL enabled
= VARIANT_FALSE
;
296 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
298 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
300 ok( hr
== S_OK
, "got %08lx\n", hr
);
301 if (hr
!= S_OK
) goto done
;
303 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
304 ok( hr
== S_OK
, "got %08lx\n", hr
);
305 if (hr
!= S_OK
) goto done
;
307 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
308 if (hr
!= S_OK
) goto done
;
310 hr
= INetFwProfile_get_FirewallEnabled( profile
, &enabled
);
311 ok( hr
== S_OK
, "got %08lx\n", hr
);
314 if (policy
) INetFwPolicy_Release( policy
);
315 if (profile
) INetFwProfile_Release( profile
);
316 if (mgr
) INetFwMgr_Release( mgr
);
317 if (SUCCEEDED( init
)) CoUninitialize();
318 return (enabled
== VARIANT_TRUE
);
321 HRESULT
set_firewall( enum firewall_op op
)
324 INetFwMgr
*mgr
= NULL
;
325 INetFwPolicy
*policy
= NULL
;
326 INetFwProfile
*profile
= NULL
;
327 INetFwAuthorizedApplication
*app
= NULL
;
328 INetFwAuthorizedApplications
*apps
= NULL
;
329 BSTR name
, image
= SysAllocStringLen( NULL
, MAX_PATH
);
330 WCHAR path
[MAX_PATH
];
332 if (!GetModuleFileNameW( NULL
, image
, MAX_PATH
))
334 SysFreeString( image
);
338 if(!GetSystemDirectoryW(path
, MAX_PATH
))
340 SysFreeString( image
);
343 lstrcatW(path
, L
"\\dpnsvr.exe");
345 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
347 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
349 ok( hr
== S_OK
, "got %08lx\n", hr
);
350 if (hr
!= S_OK
) goto done
;
352 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
353 ok( hr
== S_OK
, "got %08lx\n", hr
);
354 if (hr
!= S_OK
) goto done
;
356 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
357 if (hr
!= S_OK
) goto done
;
359 hr
= INetFwProfile_get_AuthorizedApplications( profile
, &apps
);
360 ok( hr
== S_OK
, "got %08lx\n", hr
);
361 if (hr
!= S_OK
) goto done
;
363 hr
= CoCreateInstance( &CLSID_NetFwAuthorizedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
364 &IID_INetFwAuthorizedApplication
, (void **)&app
);
365 ok( hr
== S_OK
, "got %08lx\n", hr
);
366 if (hr
!= S_OK
) goto done
;
368 hr
= INetFwAuthorizedApplication_put_ProcessImageFileName( app
, image
);
369 if (hr
!= S_OK
) goto done
;
371 name
= SysAllocString( L
"dpnet_client" );
372 hr
= INetFwAuthorizedApplication_put_Name( app
, name
);
373 SysFreeString( name
);
374 ok( hr
== S_OK
, "got %08lx\n", hr
);
375 if (hr
!= S_OK
) goto done
;
378 hr
= INetFwAuthorizedApplications_Add( apps
, app
);
379 else if (op
== APP_REMOVE
)
380 hr
= INetFwAuthorizedApplications_Remove( apps
, image
);
383 if (hr
!= S_OK
) goto done
;
385 INetFwAuthorizedApplication_Release( app
);
386 hr
= CoCreateInstance( &CLSID_NetFwAuthorizedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
387 &IID_INetFwAuthorizedApplication
, (void **)&app
);
388 ok( hr
== S_OK
, "got %08lx\n", hr
);
389 if (hr
!= S_OK
) goto done
;
391 SysFreeString( image
);
392 image
= SysAllocString( path
);
393 hr
= INetFwAuthorizedApplication_put_ProcessImageFileName( app
, image
);
394 if (hr
!= S_OK
) goto done
;
396 name
= SysAllocString( L
"dpnet_server" );
397 hr
= INetFwAuthorizedApplication_put_Name( app
, name
);
398 SysFreeString( name
);
399 ok( hr
== S_OK
, "got %08lx\n", hr
);
400 if (hr
!= S_OK
) goto done
;
403 hr
= INetFwAuthorizedApplications_Add( apps
, app
);
404 else if (op
== APP_REMOVE
)
405 hr
= INetFwAuthorizedApplications_Remove( apps
, image
);
408 if (app
) INetFwAuthorizedApplication_Release( app
);
409 if (apps
) INetFwAuthorizedApplications_Release( apps
);
410 if (policy
) INetFwPolicy_Release( policy
);
411 if (profile
) INetFwProfile_Release( profile
);
412 if (mgr
) INetFwMgr_Release( mgr
);
413 if (SUCCEEDED( init
)) CoUninitialize();
414 SysFreeString( image
);
418 /* taken from programs/winetest/main.c */
419 BOOL
is_stub_dll(const char *filename
)
426 size
= GetFileVersionInfoSizeA(filename
, &ver
);
427 if (!size
) return FALSE
;
429 data
= HeapAlloc(GetProcessHeap(), 0, size
);
430 if (!data
) return FALSE
;
432 if (GetFileVersionInfoA(filename
, ver
, size
, data
))
436 sprintf(buf
, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), 1200);
437 if (VerQueryValueA(data
, buf
, (void**)&p
, &size
))
438 isstub
= !lstrcmpiA("wcodstub.dll", p
);
440 HeapFree(GetProcessHeap(), 0, data
);
448 BOOL firewall_enabled
;
451 if(!GetSystemDirectoryA(path
, MAX_PATH
))
453 skip("Failed to get systems directory\n");
456 strcat(path
, "\\dpnet.dll");
458 if (!winetest_interactive
&& is_stub_dll(path
))
460 win_skip("dpnet is a stub dll, skipping tests\n");
464 if ((firewall_enabled
= is_firewall_enabled()) && !is_process_elevated())
466 skip("no privileges, skipping tests to avoid firewall dialog\n");
470 if (firewall_enabled
)
472 HRESULT hr
= set_firewall(APP_ADD
);
475 skip("can't authorize app in firewall %08lx\n", hr
);
480 hr
= CoInitialize(0);
481 ok( hr
== S_OK
, "failed to init com\n");
487 test_enum_service_providers();
492 if (firewall_enabled
) set_firewall(APP_REMOVE
);