wsdapi: Create default XML context in WSDCreateDiscoveryPublisher if required.

Signed-off-by: Owen Rudge <orudge@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Owen Rudge 2017-05-30 23:05:56 +01:00 committed by Alexandre Julliard
parent 9bf2f6b2af
commit 9c9180f606
2 changed files with 61 additions and 2 deletions

View File

@ -360,10 +360,18 @@ HRESULT WINAPI WSDCreateDiscoveryPublisher(IWSDXMLContext *pContext, IWSDiscover
obj->IWSDiscoveryPublisher_iface.lpVtbl = &publisher_vtbl;
obj->ref = 1;
obj->xmlContext = pContext;
if (pContext != NULL)
if (pContext == NULL)
{
if (FAILED(WSDXMLCreateContext(&obj->xmlContext)))
{
WARN("Unable to create XML context\n");
return E_OUTOFMEMORY;
}
}
else
{
obj->xmlContext = pContext;
IWSDXMLContext_AddRef(pContext);
}

View File

@ -162,6 +162,56 @@ static void CreateDiscoveryPublisher_tests(void)
ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
}
static void CreateDiscoveryPublisher_XMLContext_tests(void)
{
IWSDiscoveryPublisher *publisher = NULL;
IWSDXMLContext *xmlContext, *returnedContext;
HRESULT rc;
int ref;
/* Test creating an XML context and supplying it to WSDCreateDiscoveryPublisher */
rc = WSDXMLCreateContext(&xmlContext);
ok(rc == S_OK, "WSDXMLCreateContext failed: %08x\n", rc);
rc = WSDCreateDiscoveryPublisher(xmlContext, &publisher);
ok(rc == S_OK, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: %08x\n", rc);
ok(publisher != NULL, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: publisher == NULL\n");
rc = IWSDiscoveryPublisher_GetXMLContext(publisher, NULL);
ok(rc == E_INVALIDARG, "GetXMLContext returned unexpected value with NULL argument: %08x\n", rc);
rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext);
ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc);
ok(xmlContext == returnedContext, "GetXMLContext returned unexpected value: returnedContext == %p\n", returnedContext);
ref = IWSDXMLContext_Release(returnedContext);
ok(ref == 2, "IWSDXMLContext_Release() has %d references, should have 2\n", ref);
ref = IWSDiscoveryPublisher_Release(publisher);
ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
ref = IWSDXMLContext_Release(returnedContext);
ok(ref == 0, "IWSDXMLContext_Release() has %d references, should have 0\n", ref);
/* Test using a default XML context */
publisher = NULL;
returnedContext = NULL;
rc = WSDCreateDiscoveryPublisher(NULL, &publisher);
ok(rc == S_OK, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc);
ok(publisher != NULL, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n");
rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext);
ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc);
ref = IWSDXMLContext_Release(returnedContext);
ok(ref == 1, "IWSDXMLContext_Release() has %d references, should have 1\n", ref);
ref = IWSDiscoveryPublisher_Release(publisher);
ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
}
static void Publish_tests(void)
{
IWSDiscoveryPublisher *publisher = NULL;
@ -231,6 +281,7 @@ START_TEST(discovery)
CoInitialize(NULL);
CreateDiscoveryPublisher_tests();
CreateDiscoveryPublisher_XMLContext_tests();
Publish_tests();
CoUninitialize();