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
20 #define WIN32_LEAN_AND_MEAN
24 #include "wine/test.h"
26 static char *show_guid(const GUID
*guid
, char *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]);
37 static IDirectPlay8Peer
* peer
= NULL
;
39 static HRESULT WINAPI
DirectPlayMessageHandler(PVOID context
, DWORD message_id
, PVOID buffer
)
44 static void test_init_dp(void)
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
, DirectPlayMessageHandler
, 0);
55 ok(hr
== S_OK
, "IDirectPlay8Peer_Initialize failed with %x\n", hr
);
58 static void test_enum_service_providers(void)
60 DPN_SERVICE_PROVIDER_INFO
*serv_prov_info
;
69 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, NULL
, &size
, &items
, 0);
70 ok(hr
== DPNERR_BUFFERTOOSMALL
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
71 ok(size
!= 0, "size is unexpectedly 0\n");
73 serv_prov_info
= HeapAlloc(GetProcessHeap(), 0, size
);
75 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, NULL
, NULL
, serv_prov_info
, &size
, &items
, 0);
76 ok(hr
== S_OK
, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr
);
77 ok(items
!= 0, "Found unexpectedly no service providers\n");
79 trace("number of items found: %d\n", items
);
83 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info
->pwszName
));
84 trace("Found guid: %s\n", show_guid(&serv_prov_info
->guid
, guid
));
89 serv_prov_info
-= items
; /* set pointer back */
90 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
95 hr
= IDirectPlay8Peer_EnumServiceProviders(peer
, &CLSID_DP8SP_TCPIP
, 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
, &CLSID_DP8SP_TCPIP
, 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 adapter\n");
106 for (i
=0;i
<items
;i
++)
108 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info
->pwszName
));
109 trace("Found adapter guid: %s\n", show_guid(&serv_prov_info
->guid
, guid
));
114 serv_prov_info
-= items
; /* set pointer back */
115 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info
), "Failed freeing server provider info\n");
118 static void test_get_sp_caps(void)
123 memset(&caps
, 0, sizeof(DPN_SP_CAPS
));
125 hr
= IDirectPlay8Peer_GetSPCaps(peer
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
126 ok(hr
== DPNERR_INVALIDPARAM
, "GetSPCaps unexpectedly returned %x\n", hr
);
128 caps
.dwSize
= sizeof(DPN_SP_CAPS
);
130 hr
= IDirectPlay8Peer_GetSPCaps(peer
, &CLSID_DP8SP_TCPIP
, &caps
, 0);
131 ok(hr
== DPN_OK
, "GetSPCaps failed with %x\n", hr
);
134 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
)) ==
135 (DPNSPCAPS_SUPPORTSDPNSRV
| DPNSPCAPS_SUPPORTSBROADCAST
| DPNSPCAPS_SUPPORTSALLADAPTERS
),
136 "unexpected flags %x\n", caps
.dwFlags
);
137 ok(caps
.dwNumThreads
>= 3, "got %d\n", caps
.dwNumThreads
);
138 ok(caps
.dwDefaultEnumCount
== 5, "expected 5, got %d\n", caps
.dwDefaultEnumCount
);
139 ok(caps
.dwDefaultEnumRetryInterval
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumRetryInterval
);
140 ok(caps
.dwDefaultEnumTimeout
== 1500, "expected 1500, got %d\n", caps
.dwDefaultEnumTimeout
);
141 ok(caps
.dwMaxEnumPayloadSize
== 983, "expected 983, got %d\n", caps
.dwMaxEnumPayloadSize
);
142 ok(caps
.dwBuffersPerThread
== 1, "expected 1, got %d\n", caps
.dwBuffersPerThread
);
143 ok(caps
.dwSystemBufferSize
== 8192, "expected 8192, got %d\n", caps
.dwSystemBufferSize
);
146 static void test_cleanup_dp(void)
150 hr
= IDirectPlay8Peer_Close(peer
, 0);
151 ok(hr
== S_OK
, "IDirectPlay8Peer_Close failed with %x\n", hr
);
153 hr
= IDirectPlay8Peer_Release(peer
);
154 ok(hr
== S_OK
, "IDirectPlay8Peer_Release failed with %x\n", hr
);
162 test_enum_service_providers();