windowscodecs: Implement IWICMetadataQueryReader::GetContainerFormat.
[wine.git] / dlls / wsdapi / tests / discovery.c
blobdb5947d6057ca6530a88a575495a272b834191c0
1 /*
2 * Web Services on Devices
3 * Discovery tests
5 * Copyright 2017 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
24 #include <windows.h>
26 #include "wine/test.h"
27 #include "initguid.h"
28 #include "objbase.h"
29 #include "wsdapi.h"
31 typedef struct IWSDiscoveryPublisherNotifyImpl {
32 IWSDiscoveryPublisherNotify IWSDiscoveryPublisherNotify_iface;
33 LONG ref;
34 } IWSDiscoveryPublisherNotifyImpl;
36 static inline IWSDiscoveryPublisherNotifyImpl *impl_from_IWSDiscoveryPublisherNotify(IWSDiscoveryPublisherNotify *iface)
38 return CONTAINING_RECORD(iface, IWSDiscoveryPublisherNotifyImpl, IWSDiscoveryPublisherNotify_iface);
41 static HRESULT WINAPI IWSDiscoveryPublisherNotifyImpl_QueryInterface(IWSDiscoveryPublisherNotify *iface, REFIID riid, void **ppv)
43 IWSDiscoveryPublisherNotifyImpl *This = impl_from_IWSDiscoveryPublisherNotify(iface);
45 if (!ppv)
47 return E_INVALIDARG;
50 *ppv = NULL;
52 if (IsEqualIID(riid, &IID_IUnknown) ||
53 IsEqualIID(riid, &IID_IWSDiscoveryPublisherNotify))
55 *ppv = &This->IWSDiscoveryPublisherNotify_iface;
57 else
59 return E_NOINTERFACE;
62 IUnknown_AddRef((IUnknown*)*ppv);
63 return S_OK;
66 static ULONG WINAPI IWSDiscoveryPublisherNotifyImpl_AddRef(IWSDiscoveryPublisherNotify *iface)
68 IWSDiscoveryPublisherNotifyImpl *This = impl_from_IWSDiscoveryPublisherNotify(iface);
69 ULONG ref = InterlockedIncrement(&This->ref);
71 trace("IWSDiscoveryPublisherNotifyImpl_AddRef called (%p, ref = %d)\n", This, ref);
72 return ref;
75 static ULONG WINAPI IWSDiscoveryPublisherNotifyImpl_Release(IWSDiscoveryPublisherNotify *iface)
77 IWSDiscoveryPublisherNotifyImpl *This = impl_from_IWSDiscoveryPublisherNotify(iface);
78 ULONG ref = InterlockedDecrement(&This->ref);
80 trace("IWSDiscoveryPublisherNotifyImpl_Release called (%p, ref = %d)\n", This, ref);
82 if (ref == 0)
84 HeapFree(GetProcessHeap(), 0, This);
87 return ref;
90 static HRESULT WINAPI IWSDiscoveryPublisherNotifyImpl_ProbeHandler(IWSDiscoveryPublisherNotify *This, const WSD_SOAP_MESSAGE *pSoap, IWSDMessageParameters *pMessageParameters)
92 trace("IWSDiscoveryPublisherNotifyImpl_ProbeHandler called (%p, %p, %p)\n", This, pSoap, pMessageParameters);
93 return S_OK;
96 static HRESULT WINAPI IWSDiscoveryPublisherNotifyImpl_ResolveHandler(IWSDiscoveryPublisherNotify *This, const WSD_SOAP_MESSAGE *pSoap, IWSDMessageParameters *pMessageParameters)
98 trace("IWSDiscoveryPublisherNotifyImpl_ResolveHandler called (%p, %p, %p)\n", This, pSoap, pMessageParameters);
99 return S_OK;
102 static const IWSDiscoveryPublisherNotifyVtbl publisherNotify_vtbl =
104 IWSDiscoveryPublisherNotifyImpl_QueryInterface,
105 IWSDiscoveryPublisherNotifyImpl_AddRef,
106 IWSDiscoveryPublisherNotifyImpl_Release,
107 IWSDiscoveryPublisherNotifyImpl_ProbeHandler,
108 IWSDiscoveryPublisherNotifyImpl_ResolveHandler
111 static BOOL create_discovery_publisher_notify(IWSDiscoveryPublisherNotify **publisherNotify)
113 IWSDiscoveryPublisherNotifyImpl *obj;
115 *publisherNotify = NULL;
117 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
119 if (!obj)
121 trace("Out of memory creating IWSDiscoveryPublisherNotify\n");
122 return FALSE;
125 obj->IWSDiscoveryPublisherNotify_iface.lpVtbl = &publisherNotify_vtbl;
126 obj->ref = 1;
128 *publisherNotify = &obj->IWSDiscoveryPublisherNotify_iface;
130 return TRUE;
133 static void CreateDiscoveryPublisher_tests(void)
135 IWSDiscoveryPublisher *publisher = NULL;
136 IWSDiscoveryPublisher *publisher2;
137 IUnknown *unknown;
138 HRESULT rc;
139 ULONG ref;
141 rc = WSDCreateDiscoveryPublisher(NULL, NULL);
142 ok((rc == E_POINTER) || (rc == E_INVALIDARG), "WSDCreateDiscoveryPublisher(NULL, NULL) failed: %08x\n", rc);
144 rc = WSDCreateDiscoveryPublisher(NULL, &publisher);
145 ok(rc == S_OK, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc);
146 ok(publisher != NULL, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n");
148 /* Try to query for objects */
149 rc = IWSDiscoveryPublisher_QueryInterface(publisher, &IID_IUnknown, (LPVOID*)&unknown);
150 ok(rc == S_OK,"IWSDiscoveryPublisher_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
152 if (rc == S_OK)
153 IUnknown_Release(unknown);
155 rc = IWSDiscoveryPublisher_QueryInterface(publisher, &IID_IWSDiscoveryPublisher, (LPVOID*)&publisher2);
156 ok(rc == S_OK,"IWSDiscoveryPublisher_QueryInterface(IID_IWSDiscoveryPublisher) failed: %08x\n", rc);
158 if (rc == S_OK)
159 IWSDiscoveryPublisher_Release(publisher2);
161 ref = IWSDiscoveryPublisher_Release(publisher);
162 ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
165 static void CreateDiscoveryPublisher_XMLContext_tests(void)
167 IWSDiscoveryPublisher *publisher = NULL;
168 IWSDXMLContext *xmlContext, *returnedContext;
169 HRESULT rc;
170 int ref;
172 /* Test creating an XML context and supplying it to WSDCreateDiscoveryPublisher */
173 rc = WSDXMLCreateContext(&xmlContext);
174 ok(rc == S_OK, "WSDXMLCreateContext failed: %08x\n", rc);
176 rc = WSDCreateDiscoveryPublisher(xmlContext, &publisher);
177 ok(rc == S_OK, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: %08x\n", rc);
178 ok(publisher != NULL, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: publisher == NULL\n");
180 rc = IWSDiscoveryPublisher_GetXMLContext(publisher, NULL);
181 ok(rc == E_INVALIDARG, "GetXMLContext returned unexpected value with NULL argument: %08x\n", rc);
183 rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext);
184 ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc);
186 ok(xmlContext == returnedContext, "GetXMLContext returned unexpected value: returnedContext == %p\n", returnedContext);
188 ref = IWSDXMLContext_Release(returnedContext);
189 ok(ref == 2, "IWSDXMLContext_Release() has %d references, should have 2\n", ref);
191 ref = IWSDiscoveryPublisher_Release(publisher);
192 ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
194 ref = IWSDXMLContext_Release(returnedContext);
195 ok(ref == 0, "IWSDXMLContext_Release() has %d references, should have 0\n", ref);
197 /* Test using a default XML context */
198 publisher = NULL;
199 returnedContext = NULL;
201 rc = WSDCreateDiscoveryPublisher(NULL, &publisher);
202 ok(rc == S_OK, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc);
203 ok(publisher != NULL, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n");
205 rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext);
206 ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc);
208 ref = IWSDXMLContext_Release(returnedContext);
209 ok(ref == 1, "IWSDXMLContext_Release() has %d references, should have 1\n", ref);
211 ref = IWSDiscoveryPublisher_Release(publisher);
212 ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
215 static void Publish_tests(void)
217 IWSDiscoveryPublisher *publisher = NULL;
218 IWSDiscoveryPublisherNotify *sink1 = NULL, *sink2 = NULL;
219 IWSDiscoveryPublisherNotifyImpl *sink1Impl = NULL, *sink2Impl = NULL;
221 HRESULT rc;
222 ULONG ref;
224 rc = WSDCreateDiscoveryPublisher(NULL, &publisher);
225 ok(rc == S_OK, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc);
226 ok(publisher != NULL, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n");
228 /* Test SetAddressFamily */
229 rc = IWSDiscoveryPublisher_SetAddressFamily(publisher, 12345);
230 ok(rc == E_INVALIDARG, "IWSDiscoveryPublisher_SetAddressFamily(12345) returned unexpected result: %08x\n", rc);
232 rc = IWSDiscoveryPublisher_SetAddressFamily(publisher, WSDAPI_ADDRESSFAMILY_IPV4);
233 ok(rc == S_OK, "IWSDiscoveryPublisher_SetAddressFamily(WSDAPI_ADDRESSFAMILY_IPV4) failed: %08x\n", rc);
235 /* Try to update the address family after already setting it */
236 rc = IWSDiscoveryPublisher_SetAddressFamily(publisher, WSDAPI_ADDRESSFAMILY_IPV6);
237 ok(rc == STG_E_INVALIDFUNCTION, "IWSDiscoveryPublisher_SetAddressFamily(WSDAPI_ADDRESSFAMILY_IPV6) returned unexpected result: %08x\n", rc);
239 /* Create notification sinks */
240 ok(create_discovery_publisher_notify(&sink1) == TRUE, "create_discovery_publisher_notify failed\n");
241 ok(create_discovery_publisher_notify(&sink2) == TRUE, "create_discovery_publisher_notify failed\n");
243 /* Get underlying implementation so we can check the ref count */
244 sink1Impl = impl_from_IWSDiscoveryPublisherNotify(sink1);
245 sink2Impl = impl_from_IWSDiscoveryPublisherNotify(sink2);
247 /* Attempt to unregister sink before registering it */
248 rc = IWSDiscoveryPublisher_UnRegisterNotificationSink(publisher, sink1);
249 ok(rc == E_FAIL, "IWSDiscoveryPublisher_UnRegisterNotificationSink returned unexpected result: %08x\n", rc);
251 /* Register notification sinks */
252 rc = IWSDiscoveryPublisher_RegisterNotificationSink(publisher, sink1);
253 ok(rc == S_OK, "IWSDiscoveryPublisher_RegisterNotificationSink failed: %08x\n", rc);
254 ok(sink1Impl->ref == 2, "Ref count for sink 1 is not as expected: %d\n", sink1Impl->ref);
256 rc = IWSDiscoveryPublisher_RegisterNotificationSink(publisher, sink2);
257 ok(rc == S_OK, "IWSDiscoveryPublisher_RegisterNotificationSink failed: %08x\n", rc);
258 ok(sink2Impl->ref == 2, "Ref count for sink 2 is not as expected: %d\n", sink2Impl->ref);
260 /* Unregister the first sink */
261 rc = IWSDiscoveryPublisher_UnRegisterNotificationSink(publisher, sink1);
262 ok(rc == S_OK, "IWSDiscoveryPublisher_UnRegisterNotificationSink failed: %08x\n", rc);
263 ok(sink1Impl->ref == 1, "Ref count for sink 1 is not as expected: %d\n", sink1Impl->ref);
265 /* TODO: Publish */
267 ref = IWSDiscoveryPublisher_Release(publisher);
268 ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref);
270 /* Check that the sinks have been released by the publisher */
271 ok(sink1Impl->ref == 1, "Ref count for sink 1 is not as expected: %d\n", sink1Impl->ref);
272 ok(sink2Impl->ref == 1, "Ref count for sink 2 is not as expected: %d\n", sink2Impl->ref);
274 /* Release the sinks */
275 IWSDiscoveryPublisherNotify_Release(sink1);
276 IWSDiscoveryPublisherNotify_Release(sink2);
279 START_TEST(discovery)
281 CoInitialize(NULL);
283 CreateDiscoveryPublisher_tests();
284 CreateDiscoveryPublisher_XMLContext_tests();
285 Publish_tests();
287 CoUninitialize();