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