dpnet: Store information when Initialize is called.
[wine/wine-gecko.git] / dlls / dpnet / tests / peer.c
blob8ae0afe5e37d8e94b0260b4cb60a44313888aaf1
1 /*
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 INITGUID
20 #define WIN32_LEAN_AND_MEAN
21 #include <stdio.h>
23 #include <dplay8.h>
24 #include "wine/test.h"
26 static char *show_guid(const GUID *guid, char *buf)
28 sprintf(buf,
29 "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
30 guid->Data1, guid->Data2, guid->Data3,
31 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
32 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
34 return buf;
37 static IDirectPlay8Peer* peer = NULL;
39 static HRESULT WINAPI DirectPlayMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
41 return S_OK;
44 static void test_init_dp(void)
46 HRESULT hr;
48 hr = CoInitialize(0);
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 hr = IDirectPlay8Peer_Initialize(peer, NULL, NULL, 0);
55 ok(hr == DPNERR_INVALIDPARAM, "got %x\n", hr);
57 hr = IDirectPlay8Peer_Initialize(peer, NULL, DirectPlayMessageHandler, 0);
58 ok(hr == S_OK, "IDirectPlay8Peer_Initialize failed with %x\n", hr);
61 static void test_enum_service_providers(void)
63 DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
64 DWORD items, size;
65 DWORD i;
66 HRESULT hr;
67 char guid[39] ;
69 size = 0;
70 items = 0;
72 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, &items, 0);
73 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
74 ok(size != 0, "size is unexpectedly 0\n");
76 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
78 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, serv_prov_info, &size, &items, 0);
79 ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
80 ok(items != 0, "Found unexpectedly no service providers\n");
82 trace("number of items found: %d\n", items);
84 for (i=0;i<items;i++)
86 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info->pwszName));
87 trace("Found guid: %s\n", show_guid(&serv_prov_info->guid, guid));
89 serv_prov_info++;
92 serv_prov_info -= items; /* set pointer back */
93 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
95 size = 0;
96 items = 0;
98 hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
99 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
100 ok(size != 0, "size is unexpectedly 0\n");
102 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
104 hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
105 ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
106 ok(items != 0, "Found unexpectedly no adapter\n");
109 for (i=0;i<items;i++)
111 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info->pwszName));
112 trace("Found adapter guid: %s\n", show_guid(&serv_prov_info->guid, guid));
114 serv_prov_info++;
117 serv_prov_info -= items; /* set pointer back */
118 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
121 static void test_get_sp_caps(void)
123 DPN_SP_CAPS caps;
124 HRESULT hr;
126 memset(&caps, 0, sizeof(DPN_SP_CAPS));
128 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
129 ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);
131 caps.dwSize = sizeof(DPN_SP_CAPS);
133 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
134 ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
136 ok((caps.dwFlags &
137 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS)) ==
138 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS),
139 "unexpected flags %x\n", caps.dwFlags);
140 ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
141 ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
142 ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
143 ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
144 ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
145 ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
146 ok(caps.dwSystemBufferSize == 0x10000 || broken(caps.dwSystemBufferSize == 0x2000 /* before Win8 */),
147 "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
150 static void test_cleanup_dp(void)
152 HRESULT hr;
154 hr = IDirectPlay8Peer_Close(peer, 0);
155 ok(hr == S_OK, "IDirectPlay8Peer_Close failed with %x\n", hr);
157 hr = IDirectPlay8Peer_Release(peer);
158 ok(hr == S_OK, "IDirectPlay8Peer_Release failed with %x\n", hr);
160 CoUninitialize();
163 START_TEST(peer)
165 test_init_dp();
166 test_enum_service_providers();
167 test_get_sp_caps();
168 test_cleanup_dp();