2 * Copyright 2016 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
18 #define WIN32_LEAN_AND_MEAN
22 #include "wine/test.h"
24 #include "dpnet_test.h"
26 static const GUID appguid
= { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
28 static int cnt_thread_create
= 0;
29 static int cnt_thread_destroy
= 0;
30 static int cnt_complete
= 0;
31 static HANDLE enumevent
= NULL
;
33 static HRESULT WINAPI
DirectPlayThreadHandler(void *context
, DWORD message_id
, void *buffer
)
37 case DPN_MSGID_CREATE_THREAD
:
40 case DPN_MSGID_DESTROY_THREAD
:
43 case DPN_MSGID_ASYNC_OP_COMPLETE
:
49 trace("DirectPlayThreadHandler: 0x%08x\n", message_id
);
54 static void create_threadpool(void)
57 IDirectPlay8ThreadPool
*pool1
= NULL
;
58 IDirectPlay8ThreadPool
*pool2
= NULL
;
61 hr
= CoCreateInstance( &CLSID_DirectPlay8ThreadPool
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8ThreadPool
, (void**)&pool1
);
62 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
64 hr
= CoCreateInstance( &CLSID_DirectPlay8ThreadPool
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8ThreadPool
, (void**)&pool2
);
65 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
67 hr
= IDirectPlay8ThreadPool_Initialize(pool1
, NULL
, NULL
, 0);
68 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
70 hr
= IDirectPlay8ThreadPool_Initialize(pool1
, NULL
, &DirectPlayThreadHandler
, 0);
71 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
73 hr
= IDirectPlay8ThreadPool_Initialize(pool2
, NULL
, &DirectPlayThreadHandler
, 0);
74 ok(hr
== DPNERR_ALREADYINITIALIZED
, "got 0x%08x\n", hr
);
76 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
77 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
78 ok(threadcnt
== 0, "got %d\n", threadcnt
);
80 hr
= IDirectPlay8ThreadPool_SetThreadCount(pool1
, -1, 5, 0);
81 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
82 todo_wine
ok(cnt_thread_create
== 5, "got %d\n", threadcnt
);
84 hr
= IDirectPlay8ThreadPool_SetThreadCount(pool2
, -1, 5, 0);
85 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
86 todo_wine
ok(cnt_thread_create
== 5, "got %d\n", threadcnt
);
88 /* Thead count must be zero before DoWork can be called. */
89 hr
= IDirectPlay8ThreadPool_DoWork(pool1
, 100, 0);
90 todo_wine
ok(hr
== DPNERR_NOTREADY
, "got 0x%08x\n", hr
);
92 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
93 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
94 todo_wine
ok(threadcnt
== 5, "got %d\n", threadcnt
);
96 hr
= IDirectPlay8ThreadPool_SetThreadCount(pool1
, -1, 0, 0);
97 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
98 todo_wine
ok(cnt_thread_destroy
== 5, "got %d\n", threadcnt
);
100 hr
= IDirectPlay8ThreadPool_DoWork(pool1
, 100, 0);
101 ok(hr
== DPN_OK
, "got 0x%08x\n", hr
);
103 hr
= IDirectPlay8ThreadPool_Close(pool1
, 0);
104 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
106 hr
= IDirectPlay8ThreadPool_Close(pool2
, 0);
107 ok(hr
== DPNERR_UNINITIALIZED
, "got 0x%08x\n", hr
);
109 IDirectPlay8ThreadPool_Release(pool1
);
110 IDirectPlay8ThreadPool_Release(pool2
);
113 static void test_enum_hosts(void)
116 IDirectPlay8Client
* client
= NULL
;
117 IDirectPlay8Address
*host
= NULL
;
118 IDirectPlay8Address
*local
= NULL
;
119 IDirectPlay8ThreadPool
*pool1
= NULL
;
120 DPN_APPLICATION_DESC appdesc
;
121 DPNHANDLE async
= 0, async2
= 0;
122 static const WCHAR localhost
[] = {'1','2','7','.','0','.','0','.','1',0};
123 DWORD threadcnt
, threadorig
;
125 enumevent
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
127 memset( &appdesc
, 0, sizeof(DPN_APPLICATION_DESC
) );
128 appdesc
.dwSize
= sizeof( DPN_APPLICATION_DESC
);
129 appdesc
.guidApplication
= appguid
;
131 hr
= CoCreateInstance( &CLSID_DirectPlay8ThreadPool
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8ThreadPool
, (void**)&pool1
);
132 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
134 hr
= IDirectPlay8ThreadPool_Initialize(pool1
, NULL
, &DirectPlayThreadHandler
, 0);
135 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
137 hr
= IDirectPlay8ThreadPool_Initialize(pool1
, NULL
, &DirectPlayThreadHandler
, 0);
138 ok(hr
== DPNERR_ALREADYINITIALIZED
, "got 0x%08x\n", hr
);
140 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
141 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
142 ok(threadcnt
== 0, "got %d\n", threadcnt
);
144 hr
= CoCreateInstance(&CLSID_DirectPlay8Client
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectPlay8Client
, (void **)&client
);
145 ok(hr
== S_OK
, "CoCreateInstance failed with 0x%x\n", hr
);
147 hr
= IDirectPlay8Client_Initialize(client
, NULL
, DirectPlayThreadHandler
, 0);
148 ok(hr
== S_OK
, "IDirectPlay8Client_Initialize failed with %x\n", hr
);
150 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
151 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
152 todo_wine
ok(threadcnt
== 1, "got %d\n", threadcnt
);
154 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&local
);
155 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
157 hr
= IDirectPlay8Address_SetSP(local
, &CLSID_DP8SP_TCPIP
);
158 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
160 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&host
);
161 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
163 hr
= IDirectPlay8Address_SetSP(host
, &CLSID_DP8SP_TCPIP
);
164 ok(hr
== S_OK
, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr
);
166 hr
= IDirectPlay8Address_AddComponent(host
, DPNA_KEY_HOSTNAME
, localhost
, sizeof(localhost
),
167 DPNA_DATATYPE_STRING
);
168 ok(hr
== S_OK
, "IDirectPlay8Address failed with 0x%08x\n", hr
);
170 hr
= IDirectPlay8Client_EnumHosts(client
, &appdesc
, host
, local
, NULL
, 0, INFINITE
, 0, INFINITE
, NULL
, &async
, 0);
171 ok(hr
== DPNSUCCESS_PENDING
, "IDirectPlay8Client_EnumHosts failed with 0x%08x\n", hr
);
172 todo_wine
ok(async
, "No Handle returned\n");
174 /* The first EnumHosts call will increase the thread count */
175 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadorig
, 0);
176 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
177 todo_wine
ok(threadorig
> 1, "got %d\n", threadorig
);
179 hr
= IDirectPlay8Client_EnumHosts(client
, &appdesc
, host
, local
, NULL
, 0, INFINITE
, 0, INFINITE
, NULL
, &async2
, 0);
180 ok(hr
== DPNSUCCESS_PENDING
, "IDirectPlay8Client_EnumHosts failed with 0x%08x\n", hr
);
182 WaitForSingleObject(enumevent
, 1000);
184 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
185 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
186 ok(threadcnt
== threadorig
, "got %d\n", threadcnt
);
188 hr
= IDirectPlay8Client_CancelAsyncOperation(client
, async
, 0);
189 ok(hr
== S_OK
, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr
);
191 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
192 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
193 ok(threadcnt
== threadorig
, "got %d\n", threadcnt
);
195 hr
= IDirectPlay8Client_CancelAsyncOperation(client
, async2
, 0);
196 ok(hr
== S_OK
, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr
);
198 hr
= IDirectPlay8ThreadPool_GetThreadCount(pool1
, -1, &threadcnt
, 0);
199 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
200 ok(threadcnt
== threadorig
, "got %d\n", threadcnt
);
202 IDirectPlay8Address_Release(local
);
203 IDirectPlay8Address_Release(host
);
205 hr
= IDirectPlay8ThreadPool_Close(pool1
, 0);
206 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
208 IDirectPlay8Client_Release(client
);
209 IDirectPlay8ThreadPool_Release(pool1
);
211 CloseHandle(enumevent
);
214 static void test_singleton(void)
217 IDirectPlay8ThreadPool
*pool1
, *pool2
;
219 hr
= CoCreateInstance( &CLSID_DirectPlay8ThreadPool
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8ThreadPool
, (void**)&pool1
);
220 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
222 hr
= CoCreateInstance( &CLSID_DirectPlay8ThreadPool
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8ThreadPool
, (void**)&pool2
);
223 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
224 ok(pool1
!= pool2
, "same pointer returned.\n");
226 hr
= IDirectPlay8ThreadPool_Initialize(pool1
, NULL
, &DirectPlayThreadHandler
, 0);
227 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
229 hr
= IDirectPlay8ThreadPool_Initialize(pool2
, NULL
, &DirectPlayThreadHandler
, 0);
230 ok(hr
== DPNERR_ALREADYINITIALIZED
, "got 0x%08x\n", hr
);
232 hr
= IDirectPlay8ThreadPool_Close(pool1
, 0);
233 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
235 hr
= IDirectPlay8ThreadPool_Close(pool2
, 0);
236 ok(hr
== DPNERR_UNINITIALIZED
, "got 0x%08x\n", hr
);
238 IDirectPlay8ThreadPool_Release(pool1
);
239 IDirectPlay8ThreadPool_Release(pool2
);
245 BOOL firewall_enabled
;
248 if(!GetSystemDirectoryA(path
, MAX_PATH
))
250 skip("Failed to get systems directory\n");
253 strcat(path
, "\\dpnet.dll");
255 if (!winetest_interactive
&& is_stub_dll(path
))
257 win_skip("dpnet is a stub dll, skipping tests\n");
261 if ((firewall_enabled
= is_firewall_enabled()) && !is_process_elevated())
263 skip("no privileges, skipping tests to avoid firewall dialog\n");
267 if (firewall_enabled
)
269 HRESULT hr
= set_firewall(APP_ADD
);
272 skip("can't authorize app in firewall %08x\n", hr
);
277 hr
= CoInitialize(0);
278 ok(hr
== S_OK
, "failed to init com\n");