wine/dlls/windows.security.authentication.onlineid/tests/onlineid.c
2024-02-13 22:37:50 +01:00

135 lines
4.9 KiB
C

/*
* Copyright (C) 2024 Mohamad Al-Jaf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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 COBJMACROS
#include "initguid.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winstring.h"
#include "roapi.h"
#define WIDL_using_Windows_Foundation
#define WIDL_using_Windows_Foundation_Collections
#include "windows.foundation.h"
#define WIDL_using_Windows_Security_Authentication_OnlineId
#include "windows.security.authentication.onlineid.h"
#include "wine/test.h"
#define check_interface( obj, iid ) check_interface_( __LINE__, obj, iid )
static void check_interface_( unsigned int line, void *obj, const IID *iid )
{
IUnknown *iface = obj;
IUnknown *unk;
HRESULT hr;
hr = IUnknown_QueryInterface( iface, iid, (void **)&unk );
ok_(__FILE__, line)( hr == S_OK, "got hr %#lx.\n", hr );
IUnknown_Release( unk );
}
static void test_AuthenticatorStatics(void)
{
static const WCHAR *authenticator_statics_name = L"Windows.Security.Authentication.OnlineId.OnlineIdSystemAuthenticator";
IOnlineIdSystemAuthenticatorForUser *authenticator_for_user = (void *)0xdeadbeef;
IOnlineIdSystemAuthenticatorStatics *authenticator_statics = (void *)0xdeadbeef;
IActivationFactory *factory = (void *)0xdeadbeef;
HSTRING str;
HRESULT hr;
LONG ref;
hr = WindowsCreateString( authenticator_statics_name, wcslen( authenticator_statics_name ), &str );
ok( hr == S_OK, "got hr %#lx.\n", hr );
hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
WindowsDeleteString( str );
ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr );
if (hr == REGDB_E_CLASSNOTREG)
{
win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( authenticator_statics_name ) );
return;
}
check_interface( factory, &IID_IUnknown );
check_interface( factory, &IID_IInspectable );
check_interface( factory, &IID_IAgileObject );
hr = IActivationFactory_QueryInterface( factory, &IID_IOnlineIdSystemAuthenticatorStatics, (void **)&authenticator_statics );
ok( hr == S_OK, "got hr %#lx.\n", hr );
hr = IOnlineIdSystemAuthenticatorStatics_get_Default( authenticator_statics, NULL );
ok( hr == E_POINTER, "got hr %#lx.\n", hr );
hr = IOnlineIdSystemAuthenticatorStatics_get_Default( authenticator_statics, &authenticator_for_user );
ok( hr == S_OK, "got hr %#lx.\n", hr );
check_interface( authenticator_for_user, &IID_IAgileObject );
IOnlineIdSystemAuthenticatorForUser_Release( authenticator_for_user );
ref = IOnlineIdSystemAuthenticatorStatics_Release( authenticator_statics );
ok( ref == 2, "got ref %ld.\n", ref );
ref = IActivationFactory_Release( factory );
ok( ref == 1, "got ref %ld.\n", ref );
}
static void test_TicketStatics(void)
{
static const WCHAR *ticket_statics_name = L"Windows.Security.Authentication.OnlineId.OnlineIdServiceTicketRequest";
IOnlineIdServiceTicketRequest *ticket_statics = (void *)0xdeadbeef;
IActivationFactory *factory = (void *)0xdeadbeef;
HSTRING str;
HRESULT hr;
LONG ref;
hr = WindowsCreateString( ticket_statics_name, wcslen( ticket_statics_name ), &str );
ok( hr == S_OK, "got hr %#lx.\n", hr );
hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
WindowsDeleteString( str );
ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr );
if (hr == REGDB_E_CLASSNOTREG)
{
win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( ticket_statics_name ) );
return;
}
check_interface( factory, &IID_IUnknown );
check_interface( factory, &IID_IInspectable );
hr = IActivationFactory_QueryInterface( factory, &IID_IOnlineIdServiceTicketRequestFactory, (void **)&ticket_statics );
ok( hr == S_OK, "got hr %#lx.\n", hr );
ref = IOnlineIdServiceTicketRequest_Release( ticket_statics );
ok( ref == 2, "got ref %ld.\n", ref );
ref = IActivationFactory_Release( factory );
ok( ref == 1, "got ref %ld.\n", ref );
}
START_TEST(onlineid)
{
HRESULT hr;
hr = RoInitialize( RO_INIT_MULTITHREADED );
ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr );
test_AuthenticatorStatics();
test_TicketStatics();
RoUninitialize();
}