2 * Web Services on Devices
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
26 #include "wine/test.h"
31 typedef struct IWSDiscoveryPublisherNotifyImpl
{
32 IWSDiscoveryPublisherNotify IWSDiscoveryPublisherNotify_iface
;
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
);
52 if (IsEqualIID(riid
, &IID_IUnknown
) ||
53 IsEqualIID(riid
, &IID_IWSDiscoveryPublisherNotify
))
55 *ppv
= &This
->IWSDiscoveryPublisherNotify_iface
;
62 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
84 HeapFree(GetProcessHeap(), 0, This
);
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
);
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
);
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
));
121 trace("Out of memory creating IWSDiscoveryPublisherNotify\n");
125 obj
->IWSDiscoveryPublisherNotify_iface
.lpVtbl
= &publisherNotify_vtbl
;
128 *publisherNotify
= &obj
->IWSDiscoveryPublisherNotify_iface
;
133 static void CreateDiscoveryPublisher_tests(void)
135 IWSDiscoveryPublisher
*publisher
= NULL
;
136 IWSDiscoveryPublisher
*publisher2
;
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
);
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
);
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 Publish_tests(void)
167 IWSDiscoveryPublisher
*publisher
= NULL
;
168 IWSDiscoveryPublisherNotify
*sink1
= NULL
, *sink2
= NULL
;
169 IWSDiscoveryPublisherNotifyImpl
*sink1Impl
= NULL
, *sink2Impl
= NULL
;
174 rc
= WSDCreateDiscoveryPublisher(NULL
, &publisher
);
175 ok(rc
== S_OK
, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc
);
176 ok(publisher
!= NULL
, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n");
178 /* Test SetAddressFamily */
179 rc
= IWSDiscoveryPublisher_SetAddressFamily(publisher
, 12345);
180 ok(rc
== E_INVALIDARG
, "IWSDiscoveryPublisher_SetAddressFamily(12345) returned unexpected result: %08x\n", rc
);
182 rc
= IWSDiscoveryPublisher_SetAddressFamily(publisher
, WSDAPI_ADDRESSFAMILY_IPV4
);
183 ok(rc
== S_OK
, "IWSDiscoveryPublisher_SetAddressFamily(WSDAPI_ADDRESSFAMILY_IPV4) failed: %08x\n", rc
);
185 /* Try to update the address family after already setting it */
186 rc
= IWSDiscoveryPublisher_SetAddressFamily(publisher
, WSDAPI_ADDRESSFAMILY_IPV6
);
187 ok(rc
== STG_E_INVALIDFUNCTION
, "IWSDiscoveryPublisher_SetAddressFamily(WSDAPI_ADDRESSFAMILY_IPV6) returned unexpected result: %08x\n", rc
);
189 /* Create notification sinks */
190 ok(create_discovery_publisher_notify(&sink1
) == TRUE
, "create_discovery_publisher_notify failed\n");
191 ok(create_discovery_publisher_notify(&sink2
) == TRUE
, "create_discovery_publisher_notify failed\n");
193 /* Get underlying implementation so we can check the ref count */
194 sink1Impl
= impl_from_IWSDiscoveryPublisherNotify(sink1
);
195 sink2Impl
= impl_from_IWSDiscoveryPublisherNotify(sink2
);
197 /* Attempt to unregister sink before registering it */
198 rc
= IWSDiscoveryPublisher_UnRegisterNotificationSink(publisher
, sink1
);
199 ok(rc
== E_FAIL
, "IWSDiscoveryPublisher_UnRegisterNotificationSink returned unexpected result: %08x\n", rc
);
201 /* Register notification sinks */
202 rc
= IWSDiscoveryPublisher_RegisterNotificationSink(publisher
, sink1
);
203 ok(rc
== S_OK
, "IWSDiscoveryPublisher_RegisterNotificationSink failed: %08x\n", rc
);
204 ok(sink1Impl
->ref
== 2, "Ref count for sink 1 is not as expected: %d\n", sink1Impl
->ref
);
206 rc
= IWSDiscoveryPublisher_RegisterNotificationSink(publisher
, sink2
);
207 ok(rc
== S_OK
, "IWSDiscoveryPublisher_RegisterNotificationSink failed: %08x\n", rc
);
208 ok(sink2Impl
->ref
== 2, "Ref count for sink 2 is not as expected: %d\n", sink2Impl
->ref
);
210 /* Unregister the first sink */
211 rc
= IWSDiscoveryPublisher_UnRegisterNotificationSink(publisher
, sink1
);
212 ok(rc
== S_OK
, "IWSDiscoveryPublisher_UnRegisterNotificationSink failed: %08x\n", rc
);
213 ok(sink1Impl
->ref
== 1, "Ref count for sink 1 is not as expected: %d\n", sink1Impl
->ref
);
217 ref
= IWSDiscoveryPublisher_Release(publisher
);
218 ok(ref
== 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref
);
220 /* Check that the sinks have been released by the publisher */
221 ok(sink1Impl
->ref
== 1, "Ref count for sink 1 is not as expected: %d\n", sink1Impl
->ref
);
222 ok(sink2Impl
->ref
== 1, "Ref count for sink 2 is not as expected: %d\n", sink2Impl
->ref
);
224 /* Release the sinks */
225 IWSDiscoveryPublisherNotify_Release(sink1
);
226 IWSDiscoveryPublisherNotify_Release(sink2
);
229 START_TEST(discovery
)
233 CreateDiscoveryPublisher_tests();