[HNETCFG_WINETEST] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / modules / rostests / winetests / hnetcfg / policy.c
1 /*
2 * Copyright 2016 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 COBJMACROS
19 #include <stdio.h>
20
21 #include "windows.h"
22 #include "ole2.h"
23 #include "oleauto.h"
24 #include "olectl.h"
25 #include "dispex.h"
26
27 #include "wine/test.h"
28
29 #include "netfw.h"
30 #include "natupnp.h"
31
32 static void test_policy2_rules(INetFwPolicy2 *policy2)
33 {
34 HRESULT hr;
35 INetFwRules *rules, *rules2;
36 INetFwServiceRestriction *restriction;
37
38 hr = INetFwPolicy2_QueryInterface(policy2, &IID_INetFwRules, (void**)&rules);
39 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
40
41 hr = INetFwPolicy2_get_Rules(policy2, &rules);
42 ok(hr == S_OK, "got %08x\n", hr);
43
44 hr = INetFwPolicy2_get_Rules(policy2, &rules2);
45 ok(hr == S_OK, "got %08x\n", hr);
46 ok(rules == rules2, "Different pointers\n");
47
48 hr = INetFwPolicy2_get_ServiceRestriction(policy2, &restriction);
49 todo_wine ok(hr == S_OK, "got %08x\n", hr);
50 if(hr == S_OK)
51 {
52 INetFwRules *rules3;
53
54 hr = INetFwServiceRestriction_get_Rules(restriction, &rules3);
55 ok(hr == S_OK, "got %08x\n", hr);
56 ok(rules != rules3, "same pointers\n");
57
58 if(rules3)
59 INetFwRules_Release(rules3);
60 INetFwServiceRestriction_Release(restriction);
61 }
62
63 hr = INetFwRules_get__NewEnum(rules, NULL);
64 ok(hr == E_POINTER, "got %08x\n", hr);
65
66 INetFwRules_Release(rules);
67 INetFwRules_Release(rules2);
68 }
69
70 static void test_interfaces(void)
71 {
72 INetFwMgr *manager;
73 INetFwPolicy *policy;
74 INetFwPolicy2 *policy2;
75 HRESULT hr;
76
77 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
78 &IID_INetFwMgr, (void**)&manager);
79 ok(hr == S_OK, "NetFwMgr create failed: %08x\n", hr);
80
81 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy, (void**)&policy);
82 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
83
84 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy2, (void**)&policy2);
85 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
86
87 hr = INetFwMgr_get_LocalPolicy(manager, &policy);
88 ok(hr == S_OK, "got 0x%08x\n", hr);
89
90 hr = INetFwPolicy_QueryInterface(policy, &IID_INetFwPolicy2, (void**)&policy2);
91 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
92
93 INetFwPolicy_Release(policy);
94
95 hr = CoCreateInstance(&CLSID_NetFwPolicy2, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
96 &IID_INetFwPolicy2, (void**)&policy2);
97 if(hr == S_OK)
98 {
99 test_policy2_rules(policy2);
100
101 INetFwPolicy2_Release(policy2);
102 }
103 else
104 win_skip("NetFwPolicy2 object is not supported: %08x\n", hr);
105
106 INetFwMgr_Release(manager);
107 }
108
109 static void test_NetFwAuthorizedApplication(void)
110 {
111 INetFwAuthorizedApplication *app;
112 static WCHAR empty[] = {0};
113 UNIVERSAL_NAME_INFOW *info;
114 WCHAR fullpath[MAX_PATH];
115 WCHAR netpath[MAX_PATH];
116 WCHAR image[MAX_PATH];
117 HRESULT hr;
118 BSTR bstr;
119 DWORD sz;
120
121 hr = CoCreateInstance(&CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
122 &IID_INetFwAuthorizedApplication, (void**)&app);
123 ok(hr == S_OK, "got: %08x\n", hr);
124
125 hr = GetModuleFileNameW(NULL, image, ARRAY_SIZE(image));
126 ok(hr, "GetModuleFileName failed: %u\n", GetLastError());
127
128 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, NULL);
129 ok(hr == E_POINTER, "got: %08x\n", hr);
130
131 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
132 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY), "got: %08x\n", hr);
133 ok(!bstr, "got: %s\n", wine_dbgstr_w(bstr));
134
135 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, NULL);
136 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr);
137
138 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, empty);
139 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr);
140
141 bstr = SysAllocString(image);
142 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, bstr);
143 ok(hr == S_OK, "got: %08x\n", hr);
144 SysFreeString(bstr);
145
146 GetFullPathNameW(image, ARRAY_SIZE(fullpath), fullpath, NULL);
147 GetLongPathNameW(fullpath, fullpath, ARRAY_SIZE(fullpath));
148
149 info = (UNIVERSAL_NAME_INFOW *)&netpath;
150 sz = sizeof(netpath);
151 hr = WNetGetUniversalNameW(image, UNIVERSAL_NAME_INFO_LEVEL, info, &sz);
152 if (hr != NO_ERROR)
153 {
154 info->lpUniversalName = netpath + sizeof(*info)/sizeof(WCHAR);
155 lstrcpyW(info->lpUniversalName, fullpath);
156 }
157
158 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
159 ok(hr == S_OK, "got: %08x\n", hr);
160 ok(!lstrcmpW(bstr,info->lpUniversalName), "expected %s, got %s\n",
161 wine_dbgstr_w(info->lpUniversalName), wine_dbgstr_w(bstr));
162 SysFreeString(bstr);
163
164 INetFwAuthorizedApplication_Release(app);
165 }
166
167 static void test_IUPnPNAT(void)
168 {
169 IUPnPNAT *nat;
170 IStaticPortMappingCollection *static_ports;
171 IDynamicPortMappingCollection *dync_ports;
172 INATEventManager *manager;
173 IProvideClassInfo *provider;
174 HRESULT hr;
175
176 hr = CoCreateInstance(&CLSID_UPnPNAT, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUPnPNAT, (void**)&nat);
177 ok(hr == S_OK, "got: %08x\n", hr);
178
179 hr = IUPnPNAT_QueryInterface(nat, &IID_IProvideClassInfo, (void**)&provider);
180 ok(hr == E_NOINTERFACE, "got: %08x\n", hr);
181
182 hr = IUPnPNAT_get_StaticPortMappingCollection(nat, &static_ports);
183 todo_wine ok(hr == S_OK, "got: %08x\n", hr);
184 if(hr == S_OK && static_ports)
185 IStaticPortMappingCollection_Release(static_ports);
186
187 hr = IUPnPNAT_get_DynamicPortMappingCollection(nat, &dync_ports);
188 ok(hr == S_OK || hr == E_NOTIMPL /* Windows 8.1 */, "got: %08x\n", hr);
189 if(hr == S_OK && dync_ports)
190 IDynamicPortMappingCollection_Release(dync_ports);
191
192 hr = IUPnPNAT_get_NATEventManager(nat, &manager);
193 todo_wine ok(hr == S_OK, "got: %08x\n", hr);
194 if(hr == S_OK && manager)
195 INATEventManager_Release(manager);
196
197 IUPnPNAT_Release(nat);
198 }
199
200 START_TEST(policy)
201 {
202 INetFwMgr *manager;
203 HRESULT hr;
204
205 CoInitialize(NULL);
206
207 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
208 &IID_INetFwMgr, (void**)&manager);
209 if(FAILED(hr))
210 {
211 win_skip("NetFwMgr object is not supported: %08x\n", hr);
212 CoUninitialize();
213 return;
214 }
215
216 INetFwMgr_Release(manager);
217
218 test_interfaces();
219 test_NetFwAuthorizedApplication();
220 test_IUPnPNAT();
221
222 CoUninitialize();
223 }