From: Hans Leidekker hans@codeweavers.com
--- dlls/dpnet/tests/client.c | 19 +--- dlls/dpnet/tests/dpnet_test.h | 9 -- dlls/dpnet/tests/server.c | 165 +--------------------------------- dlls/dpnet/tests/thread.c | 22 ++--- 4 files changed, 16 insertions(+), 199 deletions(-)
diff --git a/dlls/dpnet/tests/client.c b/dlls/dpnet/tests/client.c index 2f7d6335a97..ba6ae1e9742 100644 --- a/dlls/dpnet/tests/client.c +++ b/dlls/dpnet/tests/client.c @@ -25,6 +25,7 @@ #include <winver.h> #define COBJMACROS #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -963,7 +964,6 @@ static void test_cleanup_dp_peer(void)
START_TEST(client) { - BOOL firewall_enabled; HRESULT hr; char path[MAX_PATH];
@@ -980,22 +980,12 @@ START_TEST(client) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_client", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok(hr == S_OK, "CoInitialize failed with %lx\n", hr);
@@ -1028,7 +1018,6 @@ START_TEST(client) CloseHandle(enumevent);
done: - if (firewall_enabled) set_firewall(APP_REMOVE); - + winetest_set_firewall(L"dpnet_client", WINETEST_FW_APP_REMOVE); CoUninitialize(); } diff --git a/dlls/dpnet/tests/dpnet_test.h b/dlls/dpnet/tests/dpnet_test.h index 1de25590bdc..b95dacf4f1c 100644 --- a/dlls/dpnet/tests/dpnet_test.h +++ b/dlls/dpnet/tests/dpnet_test.h @@ -18,15 +18,6 @@ #ifndef __DPNET_PRIVATE_H__ #define __DPNET_PRIVATE_H__
-enum firewall_op -{ - APP_ADD, - APP_REMOVE -}; - -extern BOOL is_firewall_enabled(void) DECLSPEC_HIDDEN; -extern BOOL is_process_elevated(void) DECLSPEC_HIDDEN; -extern HRESULT set_firewall( enum firewall_op op ) DECLSPEC_HIDDEN; extern BOOL is_stub_dll(const char *filename) DECLSPEC_HIDDEN;
#endif diff --git a/dlls/dpnet/tests/server.c b/dlls/dpnet/tests/server.c index 94a9da0d47f..7f92f7e0f3e 100644 --- a/dlls/dpnet/tests/server.c +++ b/dlls/dpnet/tests/server.c @@ -21,8 +21,8 @@
#include <dplay8.h> #define COBJMACROS -#include <netfw.h> #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -269,152 +269,6 @@ static void test_enum_service_providers(void) IDirectPlay8Server_Release(server); }
-BOOL is_process_elevated(void) -{ - HANDLE token; - if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token )) - { - TOKEN_ELEVATION_TYPE type; - DWORD size; - BOOL ret; - - ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size ); - CloseHandle( token ); - return (ret && type == TokenElevationTypeFull); - } - return FALSE; -} - -BOOL is_firewall_enabled(void) -{ - HRESULT hr, init; - INetFwMgr *mgr = NULL; - INetFwPolicy *policy = NULL; - INetFwProfile *profile = NULL; - VARIANT_BOOL enabled = VARIANT_FALSE; - - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); - if (hr != S_OK) goto done; - - hr = INetFwProfile_get_FirewallEnabled( profile, &enabled ); - ok( hr == S_OK, "got %08lx\n", hr ); - -done: - if (policy) INetFwPolicy_Release( policy ); - if (profile) INetFwProfile_Release( profile ); - if (mgr) INetFwMgr_Release( mgr ); - if (SUCCEEDED( init )) CoUninitialize(); - return (enabled == VARIANT_TRUE); -} - -HRESULT set_firewall( enum firewall_op op ) -{ - HRESULT hr, init; - INetFwMgr *mgr = NULL; - INetFwPolicy *policy = NULL; - INetFwProfile *profile = NULL; - INetFwAuthorizedApplication *app = NULL; - INetFwAuthorizedApplications *apps = NULL; - BSTR name, image = SysAllocStringLen( NULL, MAX_PATH ); - WCHAR path[MAX_PATH]; - - if (!GetModuleFileNameW( NULL, image, MAX_PATH )) - { - SysFreeString( image ); - return E_FAIL; - } - - if(!GetSystemDirectoryW(path, MAX_PATH)) - { - SysFreeString( image ); - return E_FAIL; - } - lstrcatW(path, L"\dpnsvr.exe"); - - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); - if (hr != S_OK) goto done; - - hr = INetFwProfile_get_AuthorizedApplications( profile, &apps ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, - &IID_INetFwAuthorizedApplication, (void **)&app ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dpnet_client" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - if (op == APP_ADD) - hr = INetFwAuthorizedApplications_Add( apps, app ); - else if (op == APP_REMOVE) - hr = INetFwAuthorizedApplications_Remove( apps, image ); - else - hr = E_INVALIDARG; - if (hr != S_OK) goto done; - - INetFwAuthorizedApplication_Release( app ); - hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, - &IID_INetFwAuthorizedApplication, (void **)&app ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - SysFreeString( image ); - image = SysAllocString( path ); - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dpnet_server" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - if (op == APP_ADD) - hr = INetFwAuthorizedApplications_Add( apps, app ); - else if (op == APP_REMOVE) - hr = INetFwAuthorizedApplications_Remove( apps, image ); - -done: - if (app) INetFwAuthorizedApplication_Release( app ); - if (apps) INetFwAuthorizedApplications_Release( apps ); - if (policy) INetFwPolicy_Release( policy ); - if (profile) INetFwProfile_Release( profile ); - if (mgr) INetFwMgr_Release( mgr ); - if (SUCCEEDED( init )) CoUninitialize(); - SysFreeString( image ); - return hr; -} - /* taken from programs/winetest/main.c */ BOOL is_stub_dll(const char *filename) { @@ -445,7 +299,6 @@ BOOL is_stub_dll(const char *filename) START_TEST(server) { HRESULT hr; - BOOL firewall_enabled; char path[MAX_PATH];
if(!GetSystemDirectoryA(path, MAX_PATH)) @@ -461,22 +314,12 @@ START_TEST(server) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_server", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - HRESULT hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok( hr == S_OK, "failed to init com\n"); if (hr != S_OK) @@ -489,5 +332,5 @@ START_TEST(server) CoUninitialize();
done: - if (firewall_enabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"dpnet_server", WINETEST_FW_APP_REMOVE); } diff --git a/dlls/dpnet/tests/thread.c b/dlls/dpnet/tests/thread.c index 76d71b8f940..1e5c9d0a547 100644 --- a/dlls/dpnet/tests/thread.c +++ b/dlls/dpnet/tests/thread.c @@ -15,11 +15,14 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ + #define WIN32_LEAN_AND_MEAN #include <stdio.h>
#include <dplay8.h> +#define COBJMACROS #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -241,7 +244,6 @@ static void test_singleton(void) START_TEST(thread) { HRESULT hr; - BOOL firewall_enabled; char path[MAX_PATH];
if(!GetSystemDirectoryA(path, MAX_PATH)) @@ -257,30 +259,22 @@ START_TEST(thread) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_thread", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - HRESULT hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok(hr == S_OK, "failed to init com\n"); if(hr != S_OK) - return; + goto done;
create_threadpool(); test_enum_hosts(); test_singleton();
CoUninitialize(); +done: + winetest_set_firewall(L"dpnet_thread", WINETEST_FW_APP_REMOVE); }