Release 1.4.1.
[wine] / dlls / dpnet / tests / peer.c
1 /*
2  * Copyright 2011 Louis Lenders
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define INITGUID
20 #define WIN32_LEAN_AND_MEAN
21 #include <stdio.h>
22
23 #include <dplay8.h>
24 #include "wine/test.h"
25
26 static char *show_guid(const GUID *guid, char *buf)
27 {
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]);
33
34     return buf;
35 }
36
37 static IDirectPlay8Peer* peer = NULL;
38
39 static HRESULT WINAPI DirectPlayMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
40 {
41     return S_OK;
42 }
43
44 static void test_init_dp(void)
45 {
46     HRESULT hr;
47
48     hr = CoInitialize(0);
49     ok(hr == S_OK, "CoInitialize failed with %x\n", hr);
50
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);
53
54     hr = IDirectPlay8Peer_Initialize(peer, NULL, DirectPlayMessageHandler, 0);
55     ok(hr == S_OK, "IDirectPlay8Peer_Initialize failed with %x\n", hr);
56 }
57
58 static void test_enum_service_providers(void)
59 {
60     DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
61     DWORD items, size;
62     DWORD i;
63     HRESULT hr;
64     char guid[39] ;
65
66     size = 0;
67     items = 0;
68
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");
72
73     serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
74
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");
78
79     trace("number of items found: %d\n", items);
80
81     for (i=0;i<items;i++)
82     {
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));
85
86         serv_prov_info++;
87     }
88
89     serv_prov_info -= items; /* set pointer back */
90     ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
91
92     size = 0;
93     items = 0;
94
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");
98
99     serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
100
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");
104
105
106     for (i=0;i<items;i++)
107     {
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));
110
111         serv_prov_info++;
112     }
113
114     serv_prov_info -= items; /* set pointer back */
115     ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
116 }
117
118 static void test_get_sp_caps(void)
119 {
120     DPN_SP_CAPS caps;
121     HRESULT hr;
122
123     memset(&caps, 0, sizeof(DPN_SP_CAPS));
124
125     hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
126     ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);
127
128     caps.dwSize = sizeof(DPN_SP_CAPS);
129
130     hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
131     ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
132
133     ok((caps.dwFlags &
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);
144 }
145
146 static void test_cleanup_dp(void)
147 {
148     HRESULT hr;
149
150     hr = IDirectPlay8Peer_Close(peer, 0);
151     ok(hr == S_OK, "IDirectPlay8Peer_Close failed with %x\n", hr);
152
153     hr = IDirectPlay8Peer_Release(peer);
154     ok(hr == S_OK, "IDirectPlay8Peer_Release failed with %x\n", hr);
155
156     CoUninitialize();
157 }
158
159 START_TEST(peer)
160 {
161     test_init_dp();
162     test_enum_service_providers();
163     test_get_sp_caps();
164     test_cleanup_dp();
165 }