2 * Copyright 2014 Hans Leidekker for CodeWeavers
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
25 #include "netlistmgr.h"
26 #include "wine/test.h"
28 static void test_INetwork( INetwork
*network
)
30 NLM_NETWORK_CATEGORY category
;
31 NLM_CONNECTIVITY connectivity
;
32 NLM_DOMAIN_TYPE domain_type
;
33 VARIANT_BOOL connected
;
39 hr
= INetwork_GetName( network
, &str
);
40 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
41 todo_wine
ok( str
!= NULL
, "str not set\n" );
42 if (str
) trace( "name %s\n", wine_dbgstr_w(str
) );
46 hr
= INetwork_GetDescription( network
, &str
);
47 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
48 todo_wine
ok( str
!= NULL
, "str not set\n" );
49 if (str
) trace( "description %s\n", wine_dbgstr_w(str
) );
52 memset( &id
, 0, sizeof(id
) );
53 hr
= INetwork_GetNetworkId( network
, &id
);
54 ok( hr
== S_OK
, "got %08x\n", hr
);
55 trace("network id %s\n", wine_dbgstr_guid(&id
));
57 domain_type
= 0xdeadbeef;
58 hr
= INetwork_GetDomainType( network
, &domain_type
);
59 ok( hr
== S_OK
, "got %08x\n", hr
);
60 ok( domain_type
!= 0xdeadbeef, "domain_type not set\n" );
61 trace( "domain type %08x\n", domain_type
);
63 category
= 0xdeadbeef;
64 hr
= INetwork_GetCategory( network
, &category
);
65 ok( hr
== S_OK
, "got %08x\n", hr
);
66 ok( category
!= 0xdeadbeef, "category not set\n" );
67 trace( "category %08x\n", category
);
69 connectivity
= 0xdeadbeef;
70 hr
= INetwork_GetConnectivity( network
, &connectivity
);
71 ok( hr
== S_OK
, "got %08x\n", hr
);
72 ok( connectivity
!= 0xdeadbeef, "connectivity not set\n" );
73 trace( "connectivity %08x\n", connectivity
);
76 hr
= INetwork_get_IsConnected( network
, &connected
);
77 ok( hr
== S_OK
, "got %08x\n", hr
);
78 trace("connected %d\n", connected
);
81 hr
= INetwork_get_IsConnectedToInternet( network
, &connected
);
82 ok( hr
== S_OK
, "got %08x\n", hr
);
83 trace("connected to internet %d\n", connected
);
86 static void test_INetworkConnection( INetworkConnection
*conn
)
89 INetworkConnectionCost
*conn_cost
;
90 NLM_CONNECTIVITY connectivity
;
91 NLM_DOMAIN_TYPE domain_type
;
92 VARIANT_BOOL connected
;
96 memset( &id
, 0, sizeof(id
) );
97 hr
= INetworkConnection_GetAdapterId( conn
, &id
);
98 ok( hr
== S_OK
, "got %08x\n", hr
);
99 trace("adapter id %s\n", wine_dbgstr_guid(&id
));
101 memset( &id
, 0, sizeof(id
) );
102 hr
= INetworkConnection_GetConnectionId( conn
, &id
);
103 ok( hr
== S_OK
, "got %08x\n", hr
);
104 trace("connection id %s\n", wine_dbgstr_guid(&id
));
106 connectivity
= 0xdeadbeef;
107 hr
= INetworkConnection_GetConnectivity( conn
, &connectivity
);
108 ok( hr
== S_OK
, "got %08x\n", hr
);
109 ok( connectivity
!= 0xdeadbeef, "connectivity not set\n" );
110 trace( "connectivity %08x\n", connectivity
);
112 domain_type
= 0xdeadbeef;
113 hr
= INetworkConnection_GetDomainType( conn
, &domain_type
);
114 ok( hr
== S_OK
, "got %08x\n", hr
);
115 ok( domain_type
!= 0xdeadbeef, "domain_type not set\n" );
116 trace( "domain type %08x\n", domain_type
);
119 hr
= INetworkConnection_get_IsConnected( conn
, &connected
);
120 ok( hr
== S_OK
, "got %08x\n", hr
);
121 trace("connected %d\n", connected
);
124 hr
= INetworkConnection_get_IsConnectedToInternet( conn
, &connected
);
125 ok( hr
== S_OK
, "got %08x\n", hr
);
126 trace("connected to internet %d\n", connected
);
129 hr
= INetworkConnection_GetNetwork( conn
, &network
);
130 ok( hr
== S_OK
, "got %08x\n", hr
);
133 test_INetwork( network
);
134 INetwork_Release( network
);
138 hr
= INetworkConnection_QueryInterface( conn
, &IID_INetworkConnectionCost
, (void **)&conn_cost
);
139 ok( hr
== S_OK
|| broken(hr
== E_NOINTERFACE
), "got %08x\n", hr
);
143 NLM_DATAPLAN_STATUS status
;
146 hr
= INetworkConnectionCost_GetCost( conn_cost
, &cost
);
147 ok( hr
== S_OK
, "got %08x\n", hr
);
148 ok( cost
!= 0xdeadbeef, "cost not set\n" );
149 trace("cost %08x\n", cost
);
151 memset( &status
, 0,sizeof(status
) );
152 hr
= INetworkConnectionCost_GetDataPlanStatus( conn_cost
, &status
);
153 ok( hr
== S_OK
, "got %08x\n", hr
);
154 trace("InterfaceGuid %s\n", wine_dbgstr_guid(&status
.InterfaceGuid
));
156 INetworkConnectionCost_Release( conn_cost
);
160 static HRESULT WINAPI
Unknown_QueryInterface(INetworkListManagerEvents
*iface
, REFIID riid
, void **ppv
)
162 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
168 return E_NOINTERFACE
;
171 static HRESULT WINAPI
NetworkListManagerEvents_QueryInterface(INetworkListManagerEvents
*iface
,
172 REFIID riid
, void **ppv
)
174 if(IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_INetworkListManagerEvents
)) {
180 return E_NOINTERFACE
;
183 static ULONG WINAPI
NetworkListManagerEvents_AddRef(INetworkListManagerEvents
*iface
)
188 static ULONG WINAPI
NetworkListManagerEvents_Release(INetworkListManagerEvents
*iface
)
193 static HRESULT WINAPI
NetworkListManagerEvents_ConnectivityChanged(INetworkListManagerEvents
*iface
,
194 NLM_CONNECTIVITY newConnectivity
)
196 ok(0, "unexpected call\n");
200 static const INetworkListManagerEventsVtbl mgr_sink_vtbl
= {
201 NetworkListManagerEvents_QueryInterface
,
202 NetworkListManagerEvents_AddRef
,
203 NetworkListManagerEvents_Release
,
204 NetworkListManagerEvents_ConnectivityChanged
207 static INetworkListManagerEvents mgr_sink
= { &mgr_sink_vtbl
};
209 static const INetworkListManagerEventsVtbl mgr_sink_unk_vtbl
= {
210 Unknown_QueryInterface
,
211 NetworkListManagerEvents_AddRef
,
212 NetworkListManagerEvents_Release
,
213 NetworkListManagerEvents_ConnectivityChanged
216 static INetworkListManagerEvents mgr_sink_unk
= { &mgr_sink_unk_vtbl
};
218 static void test_INetworkListManager( void )
220 IConnectionPointContainer
*cpc
, *cpc2
;
221 INetworkListManager
*mgr
;
222 INetworkCostManager
*cost_mgr
;
223 NLM_CONNECTIVITY connectivity
;
224 VARIANT_BOOL connected
;
225 IConnectionPoint
*pt
, *pt2
;
226 IEnumNetworks
*network_iter
;
228 IEnumNetworkConnections
*conn_iter
;
229 INetworkConnection
*conn
;
232 ULONG ref1
, ref2
, fetched
;
235 hr
= CoCreateInstance( &CLSID_NetworkListManager
, NULL
, CLSCTX_INPROC_SERVER
,
236 &IID_INetworkListManager
, (void **)&mgr
);
239 win_skip( "can't create instance of NetworkListManager\n" );
243 connectivity
= 0xdeadbeef;
244 hr
= INetworkListManager_GetConnectivity( mgr
, &connectivity
);
245 ok( hr
== S_OK
, "got %08x\n", hr
);
246 ok( connectivity
!= 0xdeadbeef, "unchanged value\n" );
247 trace( "GetConnectivity: %08x\n", connectivity
);
250 hr
= INetworkListManager_IsConnected( mgr
, &connected
);
251 ok( hr
== S_OK
, "got %08x\n", hr
);
252 ok( connected
== VARIANT_TRUE
|| connected
== VARIANT_FALSE
, "expected boolean value\n" );
255 hr
= INetworkListManager_IsConnectedToInternet( mgr
, &connected
);
256 ok( hr
== S_OK
, "got %08x\n", hr
);
257 ok( connected
== VARIANT_TRUE
|| connected
== VARIANT_FALSE
, "expected boolean value\n" );
259 /* INetworkCostManager is supported starting Win8 */
261 hr
= INetworkListManager_QueryInterface( mgr
, &IID_INetworkCostManager
, (void **)&cost_mgr
);
262 ok( hr
== S_OK
|| broken(hr
== E_NOINTERFACE
), "got %08x\n", hr
);
266 NLM_DATAPLAN_STATUS status
;
268 hr
= INetworkCostManager_GetCost( cost_mgr
, NULL
, NULL
);
269 ok( hr
== E_POINTER
, "got %08x\n", hr
);
272 hr
= INetworkCostManager_GetCost( cost_mgr
, &cost
, NULL
);
273 ok( hr
== S_OK
, "got %08x\n", hr
);
274 ok( cost
!= 0xdeadbeef, "cost not set\n" );
276 hr
= INetworkCostManager_GetDataPlanStatus( cost_mgr
, NULL
, NULL
);
277 ok( hr
== E_POINTER
, "got %08x\n", hr
);
279 hr
= INetworkCostManager_GetDataPlanStatus( cost_mgr
, &status
, NULL
);
280 ok( hr
== S_OK
, "got %08x\n", hr
);
282 INetworkCostManager_Release( cost_mgr
);
285 hr
= INetworkListManager_QueryInterface( mgr
, &IID_IConnectionPointContainer
, (void**)&cpc
);
286 ok( hr
== S_OK
, "got %08x\n", hr
);
288 ref1
= IConnectionPointContainer_AddRef( cpc
);
290 hr
= IConnectionPointContainer_FindConnectionPoint( cpc
, &IID_INetworkListManagerEvents
, &pt
);
291 ok( hr
== S_OK
, "got %08x\n", hr
);
293 ref2
= IConnectionPointContainer_AddRef( cpc
);
294 ok( ref2
== ref1
+ 2, "Expected refcount %d, got %d\n", ref1
+ 2, ref2
);
296 IConnectionPointContainer_Release( cpc
);
297 IConnectionPointContainer_Release( cpc
);
299 hr
= IConnectionPoint_GetConnectionPointContainer( pt
, &cpc2
);
300 ok( hr
== S_OK
, "got %08x\n", hr
);
301 ok( cpc2
== cpc
, "Expected cpc2 == %p, but got %p\n", cpc
, cpc2
);
302 IConnectionPointContainer_Release( cpc2
);
304 memset( &iid
, 0, sizeof(iid
) );
305 hr
= IConnectionPoint_GetConnectionInterface( pt
, &iid
);
306 ok( hr
== S_OK
, "got %08x\n", hr
);
307 ok( !memcmp( &iid
, &IID_INetworkListManagerEvents
, sizeof(iid
) ),
308 "Expected iid to be IID_INetworkListManagerEvents\n" );
310 hr
= IConnectionPoint_Advise( pt
, (IUnknown
*)&mgr_sink_unk
, &cookie
);
311 ok( hr
== CO_E_FAILEDTOOPENTHREADTOKEN
, "Advise failed: %08x\n", hr
);
313 hr
= IConnectionPoint_Advise( pt
, (IUnknown
*)&mgr_sink
, &cookie
);
314 ok( hr
== S_OK
, "Advise failed: %08x\n", hr
);
316 hr
= IConnectionPoint_Unadvise( pt
, 0xdeadbeef );
317 ok( hr
== OLE_E_NOCONNECTION
|| hr
== CO_E_FAILEDTOIMPERSONATE
, "Unadvise failed: %08x\n", hr
);
319 hr
= IConnectionPoint_Unadvise( pt
, cookie
);
320 ok( hr
== S_OK
, "Unadvise failed: %08x\n", hr
);
322 hr
= IConnectionPointContainer_FindConnectionPoint( cpc
, &IID_INetworkListManagerEvents
, &pt2
);
323 ok( hr
== S_OK
, "got %08x\n", hr
);
324 ok( pt
== pt2
, "pt != pt2\n");
325 IConnectionPoint_Release( pt2
);
327 hr
= IConnectionPointContainer_FindConnectionPoint( cpc
, &IID_INetworkCostManagerEvents
, &pt
);
328 ok( hr
== S_OK
|| hr
== CO_E_FAILEDTOIMPERSONATE
, "got %08x\n", hr
);
329 if (hr
== S_OK
) IConnectionPoint_Release( pt
);
331 hr
= IConnectionPointContainer_FindConnectionPoint( cpc
, &IID_INetworkConnectionEvents
, &pt
);
332 ok( hr
== S_OK
|| hr
== CO_E_FAILEDTOIMPERSONATE
, "got %08x\n", hr
);
333 if (hr
== S_OK
) IConnectionPoint_Release( pt
);
335 hr
= IConnectionPointContainer_FindConnectionPoint( cpc
, &IID_INetworkEvents
, &pt
);
336 ok( hr
== S_OK
, "got %08x\n", hr
);
337 IConnectionPoint_Release( pt
);
338 IConnectionPointContainer_Release( cpc
);
341 hr
= INetworkListManager_GetNetworks( mgr
, NLM_ENUM_NETWORK_ALL
, &network_iter
);
342 ok( hr
== S_OK
, "got %08x\n", hr
);
345 while ((hr
= IEnumNetworks_Next( network_iter
, 1, &network
, NULL
)) == S_OK
)
347 test_INetwork( network
);
348 INetwork_Release( network
);
350 IEnumNetworks_Release( network_iter
);
354 hr
= INetworkListManager_GetNetworkConnections( mgr
, &conn_iter
);
355 ok( hr
== S_OK
, "got %08x\n", hr
);
359 hr
= IEnumNetworkConnections_Next( conn_iter
, 1, NULL
, &fetched
);
360 ok( hr
== E_POINTER
, "got hr %#x.\n", hr
);
361 ok( fetched
== 256, "got wrong feteched: %d.\n", fetched
);
363 hr
= IEnumNetworkConnections_Next( conn_iter
, 0, NULL
, &fetched
);
364 ok( hr
== E_POINTER
, "got hr %#x.\n", hr
);
365 ok( fetched
== 256, "got wrong feteched: %d.\n", fetched
);
367 while ((hr
= IEnumNetworkConnections_Next( conn_iter
, 1, &conn
, NULL
)) == S_OK
)
369 test_INetworkConnection( conn
);
370 INetworkConnection_Release( conn
);
371 conn
= (void *)0xdeadbeef;
373 ok( !conn
, "got wrong pointer: %p.\n", conn
);
374 IEnumNetworkConnections_Release( conn_iter
);
377 /* cps and their container share the same ref count */
378 IConnectionPoint_AddRef( pt
);
379 IConnectionPoint_AddRef( pt
);
381 ref1
= IConnectionPoint_Release( pt
);
382 ref2
= INetworkListManager_Release( mgr
);
383 ok( ref2
== ref1
- 1, "ref = %u\n", ref1
);
385 IConnectionPoint_Release( pt
);
386 ref1
= IConnectionPoint_Release( pt
);
387 ok( !ref1
, "ref = %u\n", ref1
);
392 CoInitialize( NULL
);
393 test_INetworkListManager();