4a093876f48a387eab7fa54d690bd50a9b9698a4
[reactos.git] / modules / rostests / winetests / netcfgx / netcfgx.c
1 /*
2 * Copyright 2014 Alistair Leslie-Hughes
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdio.h>
20
21 #define WIN32_LEAN_AND_MEAN
22 #define COBJMACROS
23 #include <wine/test.h>
24 #include <objbase.h>
25 #include <netcfgx.h>
26
27 static void create_configuration(void)
28 {
29 static const WCHAR tcpipW[] = {'M','S','_','T','C','P','I','P',0};
30 static const WCHAR myclient[] = {'M','Y',' ','C','L','I','E','N','T',0};
31 HRESULT hr;
32 INetCfg *config = NULL;
33 INetCfgLock *netlock = NULL;
34 INetCfgComponent *component = NULL;
35 LPWSTR client = NULL;
36
37 hr = CoCreateInstance( &CLSID_CNetCfg, NULL, CLSCTX_ALL, &IID_INetCfg, (LPVOID*)&config);
38 ok(hr == S_OK, "Failed to create object\n");
39 if(SUCCEEDED(hr))
40 {
41 hr = INetCfg_QueryInterface(config, &IID_INetCfgLock, (LPVOID*)&netlock);
42 ok(hr == S_OK, "got 0x%08x\n", hr);
43
44 hr = INetCfgLock_AcquireWriteLock(netlock, 5000, myclient, &client);
45 ok(hr == S_OK ||
46 hr == E_ACCESSDENIED /* Not run as admin */, "got 0x%08x\n", hr);
47 if(hr == S_OK)
48 {
49 trace("Lock value: %s\n", wine_dbgstr_w(client));
50 CoTaskMemFree(client);
51 }
52 else if(hr == E_ACCESSDENIED)
53 trace("Not run with Admin permissions\n");
54
55 hr = INetCfg_Initialize(config, NULL);
56 ok(hr == S_OK, "got 0x%08x\n", hr);
57
58 /* AcquireWriteLock needs to be run before Initialize */
59 hr = INetCfgLock_AcquireWriteLock(netlock, 5000, myclient, &client);
60 todo_wine ok(hr == NETCFG_E_ALREADY_INITIALIZED || hr == E_ACCESSDENIED, "got 0x%08x\n", hr);
61
62 hr = INetCfg_FindComponent(config, tcpipW, &component);
63 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
64 if(hr == S_OK)
65 {
66 INetCfgComponent_Release(component);
67 }
68
69 hr = INetCfg_Apply(config);
70 todo_wine ok(hr == S_OK || hr == NETCFG_E_NO_WRITE_LOCK, "got 0x%08x\n", hr);
71
72 hr = INetCfg_Uninitialize(config);
73 ok(hr == S_OK, "got 0x%08x\n", hr);
74
75 hr = INetCfgLock_ReleaseWriteLock(netlock);
76 ok(hr == S_OK, "got 0x%08x\n", hr);
77
78 INetCfgLock_Release(netlock);
79 INetCfg_Release(config);
80 }
81 }
82
83 START_TEST(netcfgx)
84 {
85 HRESULT hr;
86
87 hr = CoInitialize(0);
88 ok( hr == S_OK, "failed to init com\n");
89 if (hr != S_OK)
90 return;
91
92 create_configuration();
93
94 CoUninitialize();
95 }