/* * Copyright 2014 Alistair Leslie-Hughes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #define WIN32_LEAN_AND_MEAN #include #include #define COBJMACROS #include #include "wine/test.h" #include "dpnet_test.h" /* {CD0C3D4B-E15E-4CF2-9EA8-6E1D6548C5A5} */ static const GUID appguid = { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } }; static WCHAR sessionname[] = L"winegamesserver"; static BOOL nCreatePlayer; static BOOL nDestroyPlayer; static HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer) { trace("msgid: 0x%08x\n", dwMessageId); switch(dwMessageId) { case DPN_MSGID_CREATE_PLAYER: nCreatePlayer = TRUE; break; case DPN_MSGID_DESTROY_PLAYER: nDestroyPlayer = TRUE; break; } return S_OK; } static void create_server(void) { HRESULT hr; IDirectPlay8Server *server = NULL; hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (LPVOID*)&server); ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n"); if( SUCCEEDED(hr) ) { hr = IDirectPlay8Server_Close(server, 0); todo_wine ok(hr == DPNERR_UNINITIALIZED, "got 0x%08x\n", hr); hr = IDirectPlay8Server_Initialize(server, NULL, NULL, 0); ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr); hr = IDirectPlay8Server_Initialize(server, NULL, DirectPlayMessageHandler, 0); ok(hr == S_OK, "got 0x%08x\n", hr); if(hr == S_OK) { IDirectPlay8Address *localaddr = NULL; DPN_APPLICATION_DESC appdesc; hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr); ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n"); hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP); ok(hr == S_OK, "got 0x%08x\n", hr); memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) ); appdesc.dwSize = sizeof( DPN_APPLICATION_DESC ); appdesc.dwFlags = DPNSESSION_CLIENT_SERVER; appdesc.guidApplication = appguid; appdesc.pwszSessionName = sessionname; hr = IDirectPlay8Server_Host(server, &appdesc, &localaddr, 1, NULL, NULL, NULL, 0); todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); todo_wine ok(nCreatePlayer, "No DPN_MSGID_CREATE_PLAYER Message\n"); ok(!nDestroyPlayer, "Received DPN_MSGID_DESTROY_PLAYER Message\n"); hr = IDirectPlay8Server_Close(server, 0); todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); todo_wine ok(nDestroyPlayer, "No DPN_MSGID_DESTROY_PLAYER Message\n"); IDirectPlay8Address_Release(localaddr); } IDirectPlay8Server_Release(server); } } static void test_server_info(void) { HRESULT hr; DPN_PLAYER_INFO info; WCHAR name[] = L"wine"; WCHAR name2[] = L"wine2"; WCHAR data[] = L"XXXX"; IDirectPlay8Server *server = NULL; hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (LPVOID*)&server); ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n"); if( SUCCEEDED(hr) ) { ZeroMemory( &info, sizeof(DPN_PLAYER_INFO) ); info.dwSize = sizeof(DPN_PLAYER_INFO); info.dwInfoFlags = DPNINFO_NAME; hr = IDirectPlay8Server_SetServerInfo(server, NULL, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == E_POINTER, "got %x\n", hr); info.pwszName = name; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == DPNERR_UNINITIALIZED, "got %x\n", hr); hr = IDirectPlay8Server_Initialize(server, NULL, DirectPlayMessageHandler, 0); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDirectPlay8Server_SetServerInfo(server, NULL, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == E_POINTER, "got %x\n", hr); info.pwszName = NULL; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.pwszName = name; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.dwInfoFlags = DPNINFO_NAME; info.pwszName = name2; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.dwInfoFlags = DPNINFO_DATA; info.pwszName = NULL; info.pvData = NULL; info.dwDataSize = sizeof(data); hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == E_POINTER, "got %x\n", hr); info.dwInfoFlags = DPNINFO_DATA; info.pwszName = NULL; info.pvData = data; info.dwDataSize = 0; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.dwInfoFlags = DPNINFO_DATA; info.pwszName = NULL; info.pvData = data; info.dwDataSize = sizeof(data); hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME; info.pwszName = name; info.pvData = data; info.dwDataSize = sizeof(data); hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME; info.pwszName = name; info.pvData = NULL; info.dwDataSize = 0; hr = IDirectPlay8Server_SetServerInfo(server, &info, NULL, NULL, DPNSETSERVERINFO_SYNC); ok(hr == S_OK, "got %x\n", hr); IDirectPlay8Server_Release(server); } } static void test_enum_service_providers(void) { DPN_SERVICE_PROVIDER_INFO *serv_prov_info = NULL; IDirectPlay8Server *server = NULL; DWORD items, size; DWORD i; HRESULT hr; hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (LPVOID*)&server); ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n"); if (FAILED(hr)) return; size = 0; items = 0; hr = IDirectPlay8Server_EnumServiceProviders(server, NULL, NULL, serv_prov_info, &size, &items, 0); ok(hr == DPNERR_UNINITIALIZED, "got %x\n", hr); hr = IDirectPlay8Server_Initialize(server, NULL, DirectPlayMessageHandler, 0); ok(hr == S_OK, "got 0x%08x\n", hr); if (FAILED(hr)) { IDirectPlay8Server_Release(server); return; } size = 0; items = 0; hr = IDirectPlay8Server_EnumServiceProviders(server, NULL, NULL, NULL, &size, NULL, 0); ok(hr == E_POINTER, "IDirectPlay8Server_EnumServiceProviders failed with %x\n", hr); hr = IDirectPlay8Server_EnumServiceProviders(server, NULL, NULL, NULL, NULL, &items, 0); ok(hr == E_POINTER, "IDirectPlay8Server_EnumServiceProviders failed with %x\n", hr); hr = IDirectPlay8Server_EnumServiceProviders(server, NULL, NULL, NULL, &size, &items, 0); ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Server_EnumServiceProviders failed with %x\n", hr); ok(size != 0, "size is unexpectedly 0\n"); serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size); hr = IDirectPlay8Server_EnumServiceProviders(server, NULL, NULL, serv_prov_info, &size, &items, 0); ok(hr == S_OK, "IDirectPlay8Server_EnumServiceProviders failed with %x\n", hr); ok(items != 0, "Found unexpectedly no service providers\n"); trace("number of items found: %d\n", items); for (i=0;i