dpnet: Implement IDirectPlay8Address GetURLW/A.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alistair Leslie-Hughes 2021-08-25 18:04:59 +10:00 committed by Alexandre Julliard
parent 16a7976de9
commit 7a4237fd25
2 changed files with 218 additions and 10 deletions

View File

@ -256,20 +256,96 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_Clear(IDirectPlay8Address *iface)
return DPN_OK;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address *iface, WCHAR *pwszURL,
DWORD *pdwNumChars)
static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address *iface, WCHAR *url, DWORD *length)
{
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
TRACE("(%p): stub\n", This);
return DPN_OK;
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
HRESULT hr = DPNERR_BUFFERTOOSMALL;
int i;
WCHAR buffer[1024];
int position = 0;
TRACE("(%p, %p, %p)\n", This, url, length);
if(!length || (!url && *length != 0))
return DPNERR_INVALIDPOINTER;
for(i=0; i < This->comp_count; i++)
{
struct component *entry = This->components[i];
if (position) buffer[position++] = ';';
switch(entry->type)
{
case DPNA_DATATYPE_GUID:
position += swprintf( &buffer[position], ARRAY_SIZE(buffer) - position,
L"%s=%%7B%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X%%7D",
entry->name, entry->data.guid.Data1, entry->data.guid.Data2, entry->data.guid.Data3,
entry->data.guid.Data4[0], entry->data.guid.Data4[1], entry->data.guid.Data4[2],
entry->data.guid.Data4[3], entry->data.guid.Data4[4], entry->data.guid.Data4[5],
entry->data.guid.Data4[6], entry->data.guid.Data4[7] );
break;
case DPNA_DATATYPE_STRING:
position += swprintf(&buffer[position], ARRAY_SIZE(buffer) - position, L"%s=%s", entry->name, entry->data.string);
break;
case DPNA_DATATYPE_DWORD:
position += swprintf(&buffer[position], ARRAY_SIZE(buffer) - position, L"%s=%d", entry->name, entry->data.value);
break;
case DPNA_DATATYPE_STRING_ANSI:
position += swprintf(&buffer[position], ARRAY_SIZE(buffer) - position, L"%s=%hs", entry->name, entry->data.ansi);
break;
case DPNA_DATATYPE_BINARY:
default:
FIXME("Unsupported type %d\n", entry->type);
}
}
buffer[position] = 0;
if(url && *length >= lstrlenW(buffer) + lstrlenW(DPNA_HEADER) + 1)
{
lstrcpyW(url, DPNA_HEADER);
lstrcatW(url, buffer);
hr = DPN_OK;
}
*length = lstrlenW(buffer) + lstrlenW(DPNA_HEADER) + 1;
return hr;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface, CHAR *pszURL,
DWORD *pdwNumChars)
static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface, char *url, DWORD *length)
{
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
TRACE("(%p): stub\n", This);
return DPN_OK;
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
HRESULT hr;
WCHAR *buffer = NULL;
TRACE("(%p, %p %p)\n", This, url, length);
if(!length || (!url && *length != 0))
return DPNERR_INVALIDPOINTER;
if(url && *length)
{
url[0] = '\0';
buffer = heap_alloc(*length * sizeof(WCHAR));
}
hr = IDirectPlay8Address_GetURLW(iface, buffer, length);
if(hr == DPN_OK)
{
DWORD size;
size = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
if(size <= *length)
WideCharToMultiByte(CP_ACP, 0, buffer, -1, url, *length, NULL, NULL);
else
{
*length = size;
hr = DPNERR_BUFFERTOOSMALL;
}
}
heap_free(buffer);
return hr;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP)

View File

@ -304,6 +304,136 @@ static void address_setsp(void)
}
}
static void address_urlW(void)
{
HRESULT hr;
IDirectPlay8Address *localaddr = NULL;
WCHAR buffer[1024];
hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
if(SUCCEEDED(hr))
{
DWORD bufflen = 0, bufflen2;
DWORD port = 4321;
hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLW(localaddr, NULL, NULL);
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
bufflen = 10;
hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
ok(bufflen == 66, "got %d\n", bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D", buffer), "got %s\n", wine_dbgstr_w(buffer));
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
ok(hr == S_OK, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
bufflen2 = bufflen/2;
memset( buffer, 0xcc, sizeof(buffer) );
hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen2);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
ok(buffer[0] == 0xcccc, "buffer modified\n");
hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321", buffer), "got %s\n", wine_dbgstr_w(buffer));
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
ok(hr == S_OK, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLW(localaddr, NULL, &bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLW(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpW(L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321;hostname=localhost", buffer), "got %s\n", wine_dbgstr_w(buffer));
IDirectPlay8Address_Release(localaddr);
}
}
static void address_urlA(void)
{
HRESULT hr;
IDirectPlay8Address *localaddr = NULL;
char buffer[1024];
static const char urlA1[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D";
static const char urlA2[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321";
static const char urlA3[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;port=4321;hostname=localhost";
static const char localhostA[] = "localhost";
hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
if(SUCCEEDED(hr))
{
DWORD bufflen = 0, bufflen2;
DWORD port = 4321;
hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLA(localaddr, NULL, NULL);
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
bufflen = 10;
hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
bufflen2 = bufflen/2;
hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen2);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
ok(!strlen(buffer), "wrong length\n");
hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpA(urlA1, buffer), "got %s\n", buffer);
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
ok(hr == S_OK, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpA(urlA2, buffer), "got %s\n", buffer);
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhostA, sizeof(localhostA), DPNA_DATATYPE_STRING_ANSI);
ok(hr == S_OK, "got 0x%08x\n", hr);
bufflen = 0;
hr = IDirectPlay8Address_GetURLA(localaddr, NULL, &bufflen);
ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetURLA(localaddr, buffer, &bufflen);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpA(urlA3, buffer), "got %s\n", buffer);
IDirectPlay8Address_Release(localaddr);
}
}
static void address_duplicate(void)
{
HRESULT hr;
@ -381,6 +511,8 @@ START_TEST(address)
address_addcomponents();
address_setsp();
address_duplicate();
address_urlW();
address_urlA();
CoUninitialize();
}