wined3d: Pass a wined3d_device_context to wined3d_cs_emit_set_index_buffer().
[wine.git] / dlls / dpnet / tests / address.c
bloba8d31c9854a32746f2087608a61942bcd7e01599
1 /*
2 * Copyright 2014 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
19 #define WIN32_LEAN_AND_MEAN
20 #include <stdio.h>
22 #include <dplay8.h>
23 #include "wine/test.h"
25 #include "dpnet_test.h"
27 /* {6733C6E8-A0D6-450E-8C18-CEACF331DC27} */
28 static const GUID IID_Random = {0x6733c6e8, 0xa0d6, 0x450e, { 0x8c, 0x18, 0xce, 0xac, 0xf3, 0x31, 0xdc, 0x27 } };
29 static const WCHAR localhost[] = L"localhost";
31 static void create_directplay_address(void)
33 HRESULT hr;
34 IDirectPlay8Address *localaddr = NULL;
36 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
37 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
38 if(SUCCEEDED(hr))
40 GUID guidsp;
42 hr = IDirectPlay8Address_GetSP(localaddr, NULL);
43 ok(hr == DPNERR_INVALIDPOINTER, "GetSP failed 0x%08x\n", hr);
45 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
46 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
48 hr = IDirectPlay8Address_SetSP(localaddr, &GUID_NULL);
49 ok(hr == S_OK, "got 0x%08x\n", hr);
51 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
52 ok(hr == S_OK, "got 0x%08x\n", hr);
53 ok(IsEqualGUID(&guidsp, &GUID_NULL), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
55 hr = IDirectPlay8Address_SetSP(localaddr, &IID_Random);
56 ok(hr == S_OK, "got 0x%08x\n", hr);
58 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
59 ok(hr == S_OK, "got 0x%08x\n", hr);
60 ok(IsEqualGUID(&guidsp, &IID_Random), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
62 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
63 ok(hr == S_OK, "got 0x%08x\n", hr);
65 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
66 ok(hr == S_OK, "got 0x%08x\n", hr);
67 ok(IsEqualGUID(&guidsp, &CLSID_DP8SP_TCPIP), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
69 IDirectPlay8Address_Release(localaddr);
73 static void address_addcomponents(void)
75 static const char testing[] = "testing";
76 HRESULT hr;
77 IDirectPlay8Address *localaddr = NULL;
79 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
80 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
81 if(SUCCEEDED(hr))
83 GUID compguid;
84 DWORD size, type;
85 DWORD components;
86 DWORD i;
87 DWORD namelen = 0;
88 DWORD bufflen = 0;
89 DWORD port = 8888;
90 WCHAR buffer[256];
91 WCHAR *name = NULL;
93 /* We can add any Component to the Address interface not just the predefined ones. */
94 hr = IDirectPlay8Address_AddComponent(localaddr, L"unknown", &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
95 ok(hr == S_OK, "got 0x%08x\n", hr);
97 hr = IDirectPlay8Address_AddComponent(localaddr, L"unknown", &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
98 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
100 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
101 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
103 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)/2, DPNA_DATATYPE_STRING);
104 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
106 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing)+2, DPNA_DATATYPE_STRING_ANSI);
107 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
109 /* Show that on error, nothing is added. */
110 size = sizeof(buffer);
111 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
112 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
114 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing), DPNA_DATATYPE_STRING_ANSI);
115 ok(hr == S_OK, "got 0x%08x\n", hr);
117 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
118 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
120 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
121 ok(hr == S_OK, "got 0x%08x\n", hr);
123 /* The information doesn't get removed when invalid parameters are used.*/
124 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
125 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
127 size = 0;
128 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, NULL, &size, &type);
129 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
130 ok(size == sizeof(localhost), "Invalid string length: %d\n", size);
132 size = 1;
133 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, NULL, &size, &type);
134 ok(hr == E_POINTER, "got 0x%08x\n", hr);
136 size = sizeof(buffer);
137 hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
138 ok(hr == S_OK, "got 0x%08x\n", hr);
139 ok(type == DPNA_DATATYPE_STRING, "incorrect type %d\n", type);
140 ok(!lstrcmpW(buffer, localhost), "Invalid string: %s\n", wine_dbgstr_w(buffer));
142 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
143 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
145 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
146 ok(hr == S_OK, "got 0x%08x\n", hr);
148 hr = IDirectPlay8Address_GetComponentByName(localaddr, NULL, &compguid, &size, &type);
149 ok(hr == E_POINTER, "got 0x%08x\n", hr);
151 size = sizeof(GUID)-1;
152 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", NULL, &size, &type);
153 ok(hr == E_POINTER, "got 0x%08x\n", hr);
155 size = sizeof(GUID);
156 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", NULL, &size, &type);
157 ok(hr == E_POINTER, "got 0x%08x\n", hr);
159 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, NULL, &type);
160 ok(hr == E_POINTER, "got 0x%08x\n", hr);
162 size = sizeof(GUID)-1;
163 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, NULL);
164 ok(hr == E_POINTER, "got 0x%08x\n", hr);
166 size = sizeof(GUID);
167 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, NULL);
168 ok(hr == E_POINTER, "got 0x%08x\n", hr);
170 size = sizeof(GUID)-1;
171 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, &type);
172 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
173 ok(size == sizeof(GUID), "got %d\n", size);
175 size = sizeof(GUID);
176 hr = IDirectPlay8Address_GetComponentByName(localaddr, L"unknown", &compguid, &size, &type);
177 ok(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n");
178 ok(size == sizeof(GUID), "incorrect size got %d\n", size);
179 ok(type == DPNA_DATATYPE_GUID, "incorrect type\n");
180 ok(hr == S_OK, "got 0x%08x\n", hr);
182 hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL);
183 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
185 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
186 ok(hr == S_OK, "got 0x%08x\n", hr);
188 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, &bufflen, &type);
189 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
191 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, NULL, &namelen, NULL, &bufflen, NULL);
192 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
194 bufflen = 100;
195 namelen = 0;
196 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, name, &namelen, buffer, &bufflen, &type);
197 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
199 namelen = 100;
200 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 1, NULL, &namelen, NULL, &bufflen, &type);
201 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
203 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, NULL, NULL, &bufflen, &type);
204 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
206 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, NULL, &type);
207 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
209 bufflen = 0;
210 namelen = 0;
211 type = 0;
212 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, NULL, &namelen, NULL, &bufflen, &type);
213 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
214 ok(namelen == 8, "namelen expected 8 got %d\n", namelen);
215 ok(bufflen == 16, "bufflen expected 16 got %d\n", bufflen);
216 ok(type == DPNA_DATATYPE_GUID, "type expected DPNA_DATATYPE_GUID got %d\n", type);
218 trace("GetNumComponents=%d\n", components);
219 for(i=0; i < components; i++)
221 void *buffer;
223 bufflen = 0;
224 namelen = 0;
226 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, NULL, &namelen, NULL, &bufflen, &type);
227 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
229 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
230 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufflen);
232 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, name, &namelen, buffer, &bufflen, &type);
233 ok(hr == S_OK, "got 0x%08x\n", hr);
234 if(hr == S_OK)
236 switch(type)
238 case DPNA_DATATYPE_STRING:
239 trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
240 break;
241 case DPNA_DATATYPE_DWORD:
242 trace("%d: %s: %d\n", i, wine_dbgstr_w(name), *(DWORD*)buffer);
243 break;
244 case DPNA_DATATYPE_GUID:
245 trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_guid( (GUID*)buffer));
246 break;
247 case DPNA_DATATYPE_BINARY:
248 trace("%d: %s: Binary Data %d\n", i, wine_dbgstr_w(name), bufflen);
249 break;
250 default:
251 trace(" Unknown\n");
252 break;
256 HeapFree(GetProcessHeap(), 0, name);
257 HeapFree(GetProcessHeap(), 0, buffer);
260 IDirectPlay8Address_Release(localaddr);
264 static void address_setsp(void)
266 HRESULT hr;
267 IDirectPlay8Address *localaddr = NULL;
269 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
270 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
271 if(SUCCEEDED(hr))
273 DWORD components;
274 WCHAR *name;
275 GUID guid = IID_Random;
276 DWORD type;
277 DWORD namelen = 0;
278 DWORD bufflen = 0;
280 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
281 ok(hr == S_OK, "got 0x%08x\n", hr);
282 ok(components == 0, "components=%d\n", components);
284 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
285 ok(hr == S_OK, "got 0x%08x\n", hr);
287 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
288 ok(hr == S_OK, "got 0x%08x\n", hr);
289 ok(components == 1, "components=%d\n", components);
291 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, NULL, &namelen, NULL, &bufflen, &type);
292 ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
294 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
296 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, name, &namelen, (void*)&guid, &bufflen, &type);
297 ok(hr == S_OK, "got 0x%08x\n", hr);
298 ok(type == DPNA_DATATYPE_GUID, "wrong datatype: %d\n", type);
299 ok(IsEqualGUID(&guid, &CLSID_DP8SP_TCPIP), "wrong guid\n");
301 HeapFree(GetProcessHeap(), 0, name);
303 IDirectPlay8Address_Release(localaddr);
307 static void address_duplicate(void)
309 HRESULT hr;
310 IDirectPlay8Address *localaddr = NULL;
311 IDirectPlay8Address *duplicate = NULL;
312 DWORD components, dupcomps;
313 GUID guid = IID_Random;
315 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
316 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
317 if(SUCCEEDED(hr))
319 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
320 ok(hr == S_OK, "got 0x%08x\n", hr);
322 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
323 ok(hr == S_OK, "got 0x%08x\n", hr);
325 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
326 ok(hr == S_OK, "got 0x%08x\n", hr);
327 ok(components == 2, "components=%d\n", components);
329 hr = IDirectPlay8Address_Duplicate(localaddr, &duplicate);
330 ok(hr == S_OK, "got 0x%08x\n", hr);
331 if(SUCCEEDED(hr))
333 DWORD size, type;
334 WCHAR buffer[256];
336 hr = IDirectPlay8Address_GetSP(duplicate, &guid);
337 ok(hr == S_OK, "got 0x%08x\n", hr);
338 ok(IsEqualGUID(&guid, &CLSID_DP8SP_TCPIP), "wrong guid\n");
340 hr = IDirectPlay8Address_GetNumComponents(duplicate, &dupcomps);
341 ok(hr == S_OK, "got 0x%08x\n", hr);
342 ok(components == dupcomps, "expected %d got %d\n", components, dupcomps);
344 size = sizeof(buffer);
345 hr = IDirectPlay8Address_GetComponentByName(duplicate, DPNA_KEY_HOSTNAME, buffer, &size, &type);
346 ok(hr == S_OK, "got 0x%08x\n", hr);
347 ok(type == DPNA_DATATYPE_STRING, "incorrect type %d\n", type);
348 ok(!lstrcmpW(buffer, localhost), "Invalid string: %s\n", wine_dbgstr_w(buffer));
350 IDirectPlay8Address_Release(duplicate);
353 IDirectPlay8Address_Release(localaddr);
357 START_TEST(address)
359 HRESULT hr;
360 char path[MAX_PATH];
362 if(!GetSystemDirectoryA(path, MAX_PATH))
364 skip("Failed to get systems directory\n");
365 return;
367 strcat(path, "\\dpnet.dll");
369 if (!winetest_interactive && is_stub_dll(path))
371 win_skip("dpnet is a stub dll, skipping tests\n");
372 return;
375 hr = CoInitialize(0);
376 ok(hr == S_OK, "failed to init com\n");
377 if(hr != S_OK)
378 return;
380 create_directplay_address();
381 address_addcomponents();
382 address_setsp();
383 address_duplicate();
385 CoUninitialize();