cmd: DIR command outputs free space for the path.
[wine.git] / dlls / dpnet / tests / thread.c
blob76d71b8f940efbf6ccff0d7f0169d04b75806d9f
1 /*
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
19 #include <stdio.h>
21 #include <dplay8.h>
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)
35 switch(message_id)
37 case DPN_MSGID_CREATE_THREAD:
38 cnt_thread_create++;
39 break;
40 case DPN_MSGID_DESTROY_THREAD:
41 cnt_thread_destroy++;
42 break;
43 case DPN_MSGID_ASYNC_OP_COMPLETE:
44 cnt_complete++;
45 if(cnt_complete >= 2)
46 SetEvent(enumevent);
47 break;
48 default:
49 trace("DirectPlayThreadHandler: 0x%08lx\n", message_id);
51 return S_OK;
54 static void create_threadpool(void)
56 HRESULT hr;
57 IDirectPlay8ThreadPool *pool1 = NULL;
58 IDirectPlay8ThreadPool *pool2 = NULL;
59 DWORD threadcnt = 10;
61 hr = CoCreateInstance( &CLSID_DirectPlay8ThreadPool, NULL, CLSCTX_ALL, &IID_IDirectPlay8ThreadPool, (void**)&pool1);
62 ok(hr == S_OK, "got 0x%08lx\n", hr);
64 hr = CoCreateInstance( &CLSID_DirectPlay8ThreadPool, NULL, CLSCTX_ALL, &IID_IDirectPlay8ThreadPool, (void**)&pool2);
65 ok(hr == S_OK, "got 0x%08lx\n", hr);
67 hr = IDirectPlay8ThreadPool_Initialize(pool1, NULL, NULL, 0);
68 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08lx\n", hr);
70 hr = IDirectPlay8ThreadPool_Initialize(pool1, NULL, &DirectPlayThreadHandler, 0);
71 ok(hr == S_OK, "got 0x%08lx\n", hr);
73 hr = IDirectPlay8ThreadPool_Initialize(pool2, NULL, &DirectPlayThreadHandler, 0);
74 ok(hr == DPNERR_ALREADYINITIALIZED, "got 0x%08lx\n", hr);
76 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
77 ok(hr == S_OK, "got 0x%08lx\n", hr);
78 ok(threadcnt == 0, "got %ld\n", threadcnt);
80 hr = IDirectPlay8ThreadPool_SetThreadCount(pool1, -1, 5, 0);
81 ok(hr == S_OK, "got 0x%08lx\n", hr);
82 todo_wine ok(cnt_thread_create == 5, "got %ld\n", threadcnt);
84 hr = IDirectPlay8ThreadPool_SetThreadCount(pool2, -1, 5, 0);
85 ok(hr == S_OK, "got 0x%08lx\n", hr);
86 todo_wine ok(cnt_thread_create == 5, "got %ld\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%08lx\n", hr);
92 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
93 ok(hr == S_OK, "got 0x%08lx\n", hr);
94 todo_wine ok(threadcnt == 5, "got %ld\n", threadcnt);
96 hr = IDirectPlay8ThreadPool_SetThreadCount(pool1, -1, 0, 0);
97 ok(hr == S_OK, "got 0x%08lx\n", hr);
98 todo_wine ok(cnt_thread_destroy == 5, "got %ld\n", threadcnt);
100 hr = IDirectPlay8ThreadPool_DoWork(pool1, 100, 0);
101 ok(hr == DPN_OK, "got 0x%08lx\n", hr);
103 hr = IDirectPlay8ThreadPool_Close(pool1, 0);
104 ok(hr == S_OK, "got 0x%08lx\n", hr);
106 hr = IDirectPlay8ThreadPool_Close(pool2, 0);
107 ok(hr == DPNERR_UNINITIALIZED, "got 0x%08lx\n", hr);
109 IDirectPlay8ThreadPool_Release(pool1);
110 IDirectPlay8ThreadPool_Release(pool2);
113 static void test_enum_hosts(void)
115 HRESULT hr;
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 DWORD threadcnt, threadorig;
124 enumevent = CreateEventA( NULL, TRUE, FALSE, NULL);
126 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
127 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
128 appdesc.guidApplication = appguid;
130 hr = CoCreateInstance( &CLSID_DirectPlay8ThreadPool, NULL, CLSCTX_ALL, &IID_IDirectPlay8ThreadPool, (void**)&pool1);
131 ok(hr == S_OK, "got 0x%08lx\n", hr);
133 hr = IDirectPlay8ThreadPool_Initialize(pool1, NULL, &DirectPlayThreadHandler, 0);
134 ok(hr == S_OK, "got 0x%08lx\n", hr);
136 hr = IDirectPlay8ThreadPool_Initialize(pool1, NULL, &DirectPlayThreadHandler, 0);
137 ok(hr == DPNERR_ALREADYINITIALIZED, "got 0x%08lx\n", hr);
139 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
140 ok(hr == S_OK, "got 0x%08lx\n", hr);
141 ok(threadcnt == 0, "got %ld\n", threadcnt);
143 hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client);
144 ok(hr == S_OK, "CoCreateInstance failed with 0x%lx\n", hr);
146 hr = IDirectPlay8Client_Initialize(client, NULL, DirectPlayThreadHandler, 0);
147 ok(hr == S_OK, "IDirectPlay8Client_Initialize failed with %lx\n", hr);
149 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
150 ok(hr == S_OK, "got 0x%08lx\n", hr);
151 todo_wine ok(threadcnt == 1, "got %ld\n", threadcnt);
153 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&local);
154 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08lx\n", hr);
156 hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
157 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08lx\n", hr);
159 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&host);
160 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08lx\n", hr);
162 hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
163 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08lx\n", hr);
165 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, L"127.0.0.1", sizeof(L"127.0.0.1"),
166 DPNA_DATATYPE_STRING);
167 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08lx\n", hr);
169 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
170 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumHosts failed with 0x%08lx\n", hr);
171 todo_wine ok(async, "No Handle returned\n");
173 /* The first EnumHosts call will increase the thread count */
174 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadorig, 0);
175 ok(hr == S_OK, "got 0x%08lx\n", hr);
176 todo_wine ok(threadorig > 1, "got %ld\n", threadorig);
178 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async2, 0);
179 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumHosts failed with 0x%08lx\n", hr);
181 WaitForSingleObject(enumevent, 1000);
183 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
184 ok(hr == S_OK, "got 0x%08lx\n", hr);
185 ok(threadcnt == threadorig, "got %ld\n", threadcnt);
187 hr = IDirectPlay8Client_CancelAsyncOperation(client, async, 0);
188 ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08lx\n", hr);
190 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
191 ok(hr == S_OK, "got 0x%08lx\n", hr);
192 ok(threadcnt == threadorig, "got %ld\n", threadcnt);
194 hr = IDirectPlay8Client_CancelAsyncOperation(client, async2, 0);
195 ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08lx\n", hr);
197 hr = IDirectPlay8ThreadPool_GetThreadCount(pool1, -1, &threadcnt, 0);
198 ok(hr == S_OK, "got 0x%08lx\n", hr);
199 ok(threadcnt == threadorig, "got %ld\n", threadcnt);
201 IDirectPlay8Address_Release(local);
202 IDirectPlay8Address_Release(host);
204 hr = IDirectPlay8ThreadPool_Close(pool1, 0);
205 ok(hr == S_OK, "got 0x%08lx\n", hr);
207 IDirectPlay8Client_Release(client);
208 IDirectPlay8ThreadPool_Release(pool1);
210 CloseHandle(enumevent);
213 static void test_singleton(void)
215 HRESULT hr;
216 IDirectPlay8ThreadPool *pool1, *pool2;
218 hr = CoCreateInstance( &CLSID_DirectPlay8ThreadPool, NULL, CLSCTX_ALL, &IID_IDirectPlay8ThreadPool, (void**)&pool1);
219 ok(hr == S_OK, "got 0x%08lx\n", hr);
221 hr = CoCreateInstance( &CLSID_DirectPlay8ThreadPool, NULL, CLSCTX_ALL, &IID_IDirectPlay8ThreadPool, (void**)&pool2);
222 ok(hr == S_OK, "got 0x%08lx\n", hr);
223 ok(pool1 != pool2, "same pointer returned.\n");
225 hr = IDirectPlay8ThreadPool_Initialize(pool1, NULL, &DirectPlayThreadHandler, 0);
226 ok(hr == S_OK, "got 0x%08lx\n", hr);
228 hr = IDirectPlay8ThreadPool_Initialize(pool2, NULL, &DirectPlayThreadHandler, 0);
229 ok(hr == DPNERR_ALREADYINITIALIZED, "got 0x%08lx\n", hr);
231 hr = IDirectPlay8ThreadPool_Close(pool1, 0);
232 ok(hr == S_OK, "got 0x%08lx\n", hr);
234 hr = IDirectPlay8ThreadPool_Close(pool2, 0);
235 ok(hr == DPNERR_UNINITIALIZED, "got 0x%08lx\n", hr);
237 IDirectPlay8ThreadPool_Release(pool1);
238 IDirectPlay8ThreadPool_Release(pool2);
241 START_TEST(thread)
243 HRESULT hr;
244 BOOL firewall_enabled;
245 char path[MAX_PATH];
247 if(!GetSystemDirectoryA(path, MAX_PATH))
249 skip("Failed to get systems directory\n");
250 return;
252 strcat(path, "\\dpnet.dll");
254 if (!winetest_interactive && is_stub_dll(path))
256 win_skip("dpnet is a stub dll, skipping tests\n");
257 return;
260 if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated())
262 skip("no privileges, skipping tests to avoid firewall dialog\n");
263 return;
266 if (firewall_enabled)
268 HRESULT hr = set_firewall(APP_ADD);
269 if (hr != S_OK)
271 skip("can't authorize app in firewall %08lx\n", hr);
272 return;
276 hr = CoInitialize(0);
277 ok(hr == S_OK, "failed to init com\n");
278 if(hr != S_OK)
279 return;
281 create_threadpool();
282 test_enum_hosts();
283 test_singleton();
285 CoUninitialize();