dpnet/tests: Add a trailing '\n' to some ok() calls.
[wine.git] / dlls / dpnet / tests / address.c
blob0f0b8ce5a54afd95a3b80699ecaa58637cc2af14
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 /* {6733C6E8-A0D6-450E-8C18-CEACF331DC27} */
26 static const GUID IID_Random = {0x6733c6e8, 0xa0d6, 0x450e, { 0x8c, 0x18, 0xce, 0xac, 0xf3, 0x31, 0xdc, 0x27 } };
28 static void create_directplay_address(void)
30 HRESULT hr;
31 IDirectPlay8Address *localaddr = NULL;
33 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
34 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
35 if(SUCCEEDED(hr))
37 GUID guidsp;
39 hr = IDirectPlay8Address_GetSP(localaddr, NULL);
40 ok(hr == DPNERR_INVALIDPOINTER, "GetSP failed 0x%08x\n", hr);
42 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
43 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
45 hr = IDirectPlay8Address_SetSP(localaddr, &GUID_NULL);
46 ok(hr == S_OK, "got 0x%08x\n", hr);
48 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
49 ok(hr == S_OK, "got 0x%08x\n", hr);
50 ok(IsEqualGUID(&guidsp, &GUID_NULL), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
52 hr = IDirectPlay8Address_SetSP(localaddr, &IID_Random);
53 ok(hr == S_OK, "got 0x%08x\n", hr);
55 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
56 ok(hr == S_OK, "got 0x%08x\n", hr);
57 ok(IsEqualGUID(&guidsp, &IID_Random), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
59 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
60 ok(hr == S_OK, "got 0x%08x\n", hr);
62 hr = IDirectPlay8Address_GetSP(localaddr, &guidsp);
63 ok(hr == S_OK, "got 0x%08x\n", hr);
64 ok(IsEqualGUID(&guidsp, &CLSID_DP8SP_TCPIP), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp));
66 IDirectPlay8Address_Release(localaddr);
70 static void address_addcomponents(void)
72 static const WCHAR UNKNOWN[] = { 'u','n','k','n','o','w','n',0 };
73 static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
74 HRESULT hr;
75 IDirectPlay8Address *localaddr = NULL;
77 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
78 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
79 if(SUCCEEDED(hr))
81 GUID compguid;
82 DWORD size, type;
83 DWORD components;
84 DWORD i;
85 DWORD namelen = 0;
86 DWORD bufflen = 0;
87 DWORD port = 8888;
89 /* We can add any Component to the Address interface not just the predefined ones. */
90 hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
91 ok(hr == S_OK, "got 0x%08x\n", hr);
93 hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
94 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
96 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
97 ok(hr == S_OK, "got 0x%08x\n", hr);
99 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
100 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
102 hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
103 ok(hr == S_OK, "got 0x%08x\n", hr);
105 size = sizeof(GUID);
106 hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, &size, &type);
107 todo_wine ok(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n");
108 ok(size == sizeof(GUID), "incorrect size\n");
109 todo_wine ok(type == DPNA_DATATYPE_GUID, "incorrect type\n");
110 ok(hr == S_OK, "got 0x%08x\n", hr);
112 hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL);
113 ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
115 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
116 ok(hr == S_OK, "got 0x%08x\n", hr);
118 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, &bufflen, &type);
119 todo_wine ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
121 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, NULL, NULL, &bufflen, &type);
122 todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
124 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, NULL, &type);
125 todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
127 trace("GetNumComponents=%d\n", components);
128 for(i=0; i < components; i++)
130 WCHAR *name;
131 void *buffer;
133 bufflen = 0;
134 namelen = 0;
136 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, NULL, &namelen, NULL, &bufflen, &type);
137 todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
139 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
140 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufflen);
142 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, name, &namelen, buffer, &bufflen, &type);
143 ok(hr == S_OK, "got 0x%08x\n", hr);
144 if(hr == S_OK)
146 switch(type)
148 case DPNA_DATATYPE_STRING:
149 trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
150 break;
151 case DPNA_DATATYPE_DWORD:
152 trace("%d: %s: %d\n", i, wine_dbgstr_w(name), *(DWORD*)buffer);
153 break;
154 case DPNA_DATATYPE_GUID:
155 trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_guid( (GUID*)buffer));
156 break;
157 case DPNA_DATATYPE_BINARY:
158 trace("%d: %s: Binary Data %d\n", i, wine_dbgstr_w(name), bufflen);
159 break;
160 default:
161 trace(" Unknown\n");
162 break;
166 HeapFree(GetProcessHeap(), 0, name);
167 HeapFree(GetProcessHeap(), 0, buffer);
170 IDirectPlay8Address_Release(localaddr);
174 static void address_setsp(void)
176 HRESULT hr;
177 IDirectPlay8Address *localaddr = NULL;
179 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
180 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
181 if(SUCCEEDED(hr))
183 DWORD components;
184 WCHAR *name;
185 GUID guid = IID_Random;
186 DWORD type;
187 DWORD namelen = 0;
188 DWORD bufflen = 0;
190 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
191 ok(hr == S_OK, "got 0x%08x\n", hr);
192 ok(components == 0, "components=%d\n", components);
194 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
195 ok(hr == S_OK, "got 0x%08x\n", hr);
197 hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
198 ok(hr == S_OK, "got 0x%08x\n", hr);
199 ok(components == 1, "components=%d\n", components);
201 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, NULL, &namelen, NULL, &bufflen, &type);
202 todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
204 name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
206 hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 0, name, &namelen, (void*)&guid, &bufflen, &type);
207 ok(hr == S_OK, "got 0x%08x\n", hr);
208 todo_wine ok(type == DPNA_DATATYPE_GUID, "wrong datatype: %d\n", type);
209 todo_wine ok(IsEqualGUID(&guid, &CLSID_DP8SP_TCPIP), "wrong guid\n");
211 HeapFree(GetProcessHeap(), 0, name);
213 IDirectPlay8Address_Release(localaddr);
217 START_TEST(address)
219 HRESULT hr;
221 hr = CoInitialize(0);
222 ok(hr == S_OK, "failed to init com\n");
223 if(hr != S_OK)
224 return;
226 create_directplay_address();
227 address_addcomponents();
228 address_setsp();
230 CoUninitialize();