Commit d0a60ca8 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

windows.devices.enumeration: Create stub DeviceAccessInformation class.

parent 51e1c706
......@@ -2,6 +2,7 @@ MODULE = windows.devices.enumeration.dll
IMPORTS = combase uuid
C_SRCS = \
access.c \
event_handlers.c \
main.c
......
/* WinRT Windows.Devices.Enumeration implementation
*
* Copyright 2022 Paul Gofman for CodeWeavers
*
* 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
*/
#include "private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
struct device_access_information_statics
{
IActivationFactory IActivationFactory_iface;
IDeviceAccessInformationStatics IDeviceAccessInformationStatics_iface;
LONG ref;
};
static inline struct device_access_information_statics *impl_from_IActivationFactory( IActivationFactory *iface )
{
return CONTAINING_RECORD( iface, struct device_access_information_statics, IActivationFactory_iface );
}
static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out )
{
struct device_access_information_statics *impl = impl_from_IActivationFactory( iface );
TRACE( "iface %p, iid %s, out %p stub!\n", iface, debugstr_guid( iid ), out );
if (IsEqualGUID( iid, &IID_IUnknown ) ||
IsEqualGUID( iid, &IID_IInspectable ) ||
IsEqualGUID( iid, &IID_IActivationFactory ))
{
IInspectable_AddRef( (*out = &impl->IActivationFactory_iface) );
return S_OK;
}
if (IsEqualGUID( iid, &IID_IDeviceAccessInformationStatics ))
{
IInspectable_AddRef( (*out = &impl->IDeviceAccessInformationStatics_iface) );
return S_OK;
}
FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
*out = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI factory_AddRef( IActivationFactory *iface )
{
struct device_access_information_statics *impl = impl_from_IActivationFactory( iface );
ULONG ref = InterlockedIncrement( &impl->ref );
TRACE( "iface %p, ref %lu.\n", iface, ref );
return ref;
}
static ULONG WINAPI factory_Release( IActivationFactory *iface )
{
struct device_access_information_statics *impl = impl_from_IActivationFactory( iface );
ULONG ref = InterlockedDecrement( &impl->ref );
TRACE( "iface %p, ref %lu.\n", iface, ref );
return ref;
}
static HRESULT WINAPI factory_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids )
{
FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
return E_NOTIMPL;
}
static HRESULT WINAPI factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name )
{
FIXME( "iface %p, class_name %p stub!\n", iface, class_name );
return E_NOTIMPL;
}
static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level )
{
FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
return E_NOTIMPL;
}
static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance )
{
FIXME( "iface %p, instance %p stub!\n", iface, instance );
return E_NOTIMPL;
}
static const struct IActivationFactoryVtbl factory_vtbl =
{
factory_QueryInterface,
factory_AddRef,
factory_Release,
/* IInspectable methods */
factory_GetIids,
factory_GetRuntimeClassName,
factory_GetTrustLevel,
/* IActivationFactory methods */
factory_ActivateInstance,
};
DEFINE_IINSPECTABLE( statics, IDeviceAccessInformationStatics, struct device_access_information_statics, IActivationFactory_iface );
static HRESULT WINAPI statics_CreateFromId( IDeviceAccessInformationStatics *iface,
HSTRING device_id, IDeviceAccessInformation **value)
{
FIXME( "device_id %s, value %p stub.\n", debugstr_hstring( device_id ), value );
return E_NOTIMPL;
}
static HRESULT WINAPI statics_CreateFromDeviceClassId( IDeviceAccessInformationStatics *iface,
GUID device_class_id, IDeviceAccessInformation **value)
{
FIXME( "device_class_id %s, value %p stub.\n", debugstr_guid( &device_class_id ), value );
return E_NOTIMPL;
}
static HRESULT WINAPI statics_CreateFromDeviceClass( IDeviceAccessInformationStatics *iface,
enum DeviceClass device_class, IDeviceAccessInformation **value)
{
FIXME( "device_class %d, value %p stub.\n", device_class, value );
return E_NOTIMPL;
}
static const struct IDeviceAccessInformationStaticsVtbl statics_vtbl =
{
statics_QueryInterface,
statics_AddRef,
statics_Release,
/* IInspectable methods */
statics_GetIids,
statics_GetRuntimeClassName,
statics_GetTrustLevel,
/* IDeviceAccessInformationStatics methods */
statics_CreateFromId,
statics_CreateFromDeviceClassId,
statics_CreateFromDeviceClass,
};
static struct device_access_information_statics device_access_information_statics =
{
{&factory_vtbl},
{&statics_vtbl},
1
};
IActivationFactory *device_access_factory = &device_access_information_statics.IActivationFactory_iface;
......@@ -25,7 +25,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(enumeration);
static const char *debugstr_hstring( HSTRING hstr )
const char *debugstr_hstring( HSTRING hstr )
{
const WCHAR *str;
UINT32 len;
......@@ -395,8 +395,18 @@ HRESULT WINAPI DllGetClassObject( REFCLSID clsid, REFIID riid, void **out )
HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **factory )
{
const WCHAR *buffer = WindowsGetStringRawBuffer( classid, NULL );
TRACE( "classid %s, factory %p.\n", debugstr_hstring( classid ), factory );
*factory = &device_information_statics.IActivationFactory_iface;
IUnknown_AddRef( *factory );
return S_OK;
*factory = NULL;
if (!wcscmp( buffer, RuntimeClass_Windows_Devices_Enumeration_DeviceInformation ))
IActivationFactory_QueryInterface( &device_information_statics.IActivationFactory_iface,
&IID_IActivationFactory, (void **)factory );
else if (!wcscmp( buffer, RuntimeClass_Windows_Devices_Enumeration_DeviceAccessInformation ))
IActivationFactory_QueryInterface( device_access_factory, &IID_IActivationFactory, (void **)factory );
if (*factory) return S_OK;
return CLASS_E_CLASSNOTAVAILABLE;
}
......@@ -39,6 +39,10 @@
#include "wine/list.h"
extern IActivationFactory *device_access_factory;
extern const char *debugstr_hstring( HSTRING hstr );
HRESULT typed_event_handlers_append( struct list *list, ITypedEventHandler_IInspectable_IInspectable *handler, EventRegistrationToken *token );
HRESULT typed_event_handlers_remove( struct list *list, EventRegistrationToken *token );
HRESULT typed_event_handlers_notify( struct list *list, IInspectable *sender, IInspectable *args );
......
......@@ -154,9 +154,6 @@ static void test_DeviceInformation( void )
stopped_handler.event = CreateEventW( NULL, FALSE, FALSE, NULL );
ok( !!stopped_handler.event, "failed to create event, got error %lu\n", GetLastError() );
hr = RoInitialize( RO_INIT_MULTITHREADED );
ok( hr == S_OK, "got hr %#lx\n", hr );
hr = WindowsCreateString( device_info_name, wcslen( device_info_name ), &str );
ok( hr == S_OK, "got hr %#lx\n", hr );
hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
......@@ -233,11 +230,74 @@ skip_device_statics2:
done:
WindowsDeleteString( str );
CloseHandle( stopped_handler.event );
}
RoUninitialize();
static void test_DeviceAccessInformation( void )
{
static const WCHAR *device_access_info_name = L"Windows.Devices.Enumeration.DeviceAccessInformation";
static const WCHAR *device_info_name = L"Windows.Devices.Enumeration.DeviceInformation";
IDeviceAccessInformationStatics *statics;
IActivationFactory *factory, *factory2;
IDeviceAccessInformation *access_info;
enum DeviceAccessStatus access_status;
HSTRING str;
HRESULT hr;
ULONG ref;
hr = WindowsCreateString( device_access_info_name, wcslen( device_access_info_name ), &str );
ok( hr == S_OK, "got hr %#lx\n", hr );
hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory );
ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx\n", hr );
WindowsDeleteString( str );
if (hr == REGDB_E_CLASSNOTREG)
{
win_skip( "%s runtimeclass not registered.\n", wine_dbgstr_w(device_access_info_name) );
return;
}
hr = WindowsCreateString( device_info_name, wcslen( device_info_name ), &str );
ok( hr == S_OK, "got hr %#lx\n", hr );
hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory2 );
ok( hr == S_OK, "got hr %#lx\n", hr );
WindowsDeleteString( str );
ok( factory != factory2, "Got the same factory.\n" );
IActivationFactory_Release( factory2 );
check_interface( factory, &IID_IAgileObject, FALSE );
check_interface( factory, &IID_IDeviceAccessInformation, FALSE );
hr = IActivationFactory_QueryInterface( factory, &IID_IDeviceAccessInformationStatics, (void **)&statics );
ok( hr == S_OK, "got hr %#lx\n", hr );
hr = IDeviceAccessInformationStatics_CreateFromDeviceClass( statics, DeviceClass_AudioCapture, &access_info );
todo_wine ok( hr == S_OK || broken( hr == RPC_E_CALL_COMPLETE ) /* broken on some Testbot machines */, "got hr %#lx\n", hr );
if (hr == S_OK)
{
hr = IDeviceAccessInformation_get_CurrentStatus( access_info, &access_status );
ok( hr == S_OK, "got hr %#lx\n", hr );
ok( access_status == DeviceAccessStatus_Allowed, "got %d.\n", access_status );
ref = IDeviceAccessInformation_Release( access_info );
ok( !ref, "got ref %lu\n", ref );
}
ref = IDeviceAccessInformationStatics_Release( statics );
ok( ref == 2, "got ref %lu\n", ref );
ref = IActivationFactory_Release( factory );
ok( ref == 1, "got ref %lu\n", ref );
}
START_TEST( devices )
{
HRESULT hr;
hr = RoInitialize( RO_INIT_MULTITHREADED );
ok( hr == S_OK, "got hr %#lx\n", hr );
test_DeviceInformation();
test_DeviceAccessInformation();
RoUninitialize();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment