From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.web/Makefile.in | 1 + dlls/windows.web/json_value.c | 174 ++++++++++++++++++++++++++++++++++ dlls/windows.web/main.c | 2 + dlls/windows.web/private.h | 39 ++++++++ dlls/windows.web/tests/web.c | 35 +++++++ 5 files changed, 251 insertions(+) create mode 100644 dlls/windows.web/json_value.c
diff --git a/dlls/windows.web/Makefile.in b/dlls/windows.web/Makefile.in index 75b6e0712e2..ebcf7bbc2f3 100644 --- a/dlls/windows.web/Makefile.in +++ b/dlls/windows.web/Makefile.in @@ -4,4 +4,5 @@ IMPORTS = combase SOURCES = \ classes.idl \ json_object.c \ + json_value.c \ main.c diff --git a/dlls/windows.web/json_value.c b/dlls/windows.web/json_value.c new file mode 100644 index 00000000000..98d41d2c7cf --- /dev/null +++ b/dlls/windows.web/json_value.c @@ -0,0 +1,174 @@ +/* WinRT Windows.Data.Json.JsonValue Implementation + * + * 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 + */ + +#include "private.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(web); + +struct json_value_statics +{ + IActivationFactory IActivationFactory_iface; + IJsonValueStatics IJsonValueStatics_iface; + LONG ref; +}; + +static inline struct json_value_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct json_value_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct json_value_statics *impl = impl_from_IActivationFactory( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + *out = &impl->IActivationFactory_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IJsonValueStatics )) + { + *out = &impl->IJsonValueStatics_iface; + IInspectable_AddRef( *out ); + 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 json_value_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI factory_Release( IActivationFactory *iface ) +{ + struct json_value_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount to %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( json_value_statics, IJsonValueStatics, struct json_value_statics, IActivationFactory_iface ) + +static HRESULT WINAPI json_value_statics_Parse( IJsonValueStatics *iface, HSTRING input, IJsonValue **value ) +{ + FIXME( "iface %p, input %s, value %p stub!\n", iface, debugstr_hstring( input ), value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_value_statics_TryParse( IJsonValueStatics *iface, HSTRING input, IJsonValue **result, boolean *succeeded ) +{ + FIXME( "iface %p, input %s, result %p, succeeded %p stub!\n", iface, debugstr_hstring( input ), result, succeeded ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_value_statics_CreateBooleanValue( IJsonValueStatics *iface, boolean input, IJsonValue **value ) +{ + FIXME( "iface %p, input %d, value %p stub!\n", iface, input, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_value_statics_CreateNumberValue( IJsonValueStatics *iface, DOUBLE input, IJsonValue **value ) +{ + FIXME( "iface %p, input %f, value %p stub!\n", iface, input, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_value_statics_CreateStringValue( IJsonValueStatics *iface, HSTRING input, IJsonValue **value ) +{ + FIXME( "iface %p, input %s, value %p stub!\n", iface, debugstr_hstring( input ), value ); + return E_NOTIMPL; +} + +static const struct IJsonValueStaticsVtbl json_value_statics_vtbl = +{ + json_value_statics_QueryInterface, + json_value_statics_AddRef, + json_value_statics_Release, + /* IInspectable methods */ + json_value_statics_GetIids, + json_value_statics_GetRuntimeClassName, + json_value_statics_GetTrustLevel, + /* IJsonValueStatics methods */ + json_value_statics_Parse, + json_value_statics_TryParse, + json_value_statics_CreateBooleanValue, + json_value_statics_CreateNumberValue, + json_value_statics_CreateStringValue, +}; + +static struct json_value_statics json_value_statics = +{ + {&factory_vtbl}, + {&json_value_statics_vtbl}, + 1, +}; + +IActivationFactory *json_value_factory = &json_value_statics.IActivationFactory_iface; diff --git a/dlls/windows.web/main.c b/dlls/windows.web/main.c index 5c5013824e4..60e95fdba0c 100644 --- a/dlls/windows.web/main.c +++ b/dlls/windows.web/main.c @@ -40,6 +40,8 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **fa
if (!wcscmp( buffer, RuntimeClass_Windows_Data_Json_JsonObject )) IActivationFactory_QueryInterface( json_object_factory, &IID_IActivationFactory, (void **)factory ); + if (!wcscmp( buffer, RuntimeClass_Windows_Data_Json_JsonValue )) + IActivationFactory_QueryInterface( json_value_factory, &IID_IActivationFactory, (void **)factory );
if (*factory) return S_OK; return CLASS_E_CLASSNOTAVAILABLE; diff --git a/dlls/windows.web/private.h b/dlls/windows.web/private.h index f9ebd94ad48..393affd61e1 100644 --- a/dlls/windows.web/private.h +++ b/dlls/windows.web/private.h @@ -36,5 +36,44 @@ #include "windows.data.json.h"
extern IActivationFactory *json_object_factory; +extern IActivationFactory *json_value_factory; + +#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ + static inline impl_type *impl_from( iface_type *iface ) \ + { \ + return CONTAINING_RECORD( iface, impl_type, iface_mem ); \ + } \ + static HRESULT WINAPI pfx##_QueryInterface( iface_type *iface, REFIID iid, void **out ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_QueryInterface( (IInspectable *)(expr), iid, out ); \ + } \ + static ULONG WINAPI pfx##_AddRef( iface_type *iface ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_AddRef( (IInspectable *)(expr) ); \ + } \ + static ULONG WINAPI pfx##_Release( iface_type *iface ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_Release( (IInspectable *)(expr) ); \ + } \ + static HRESULT WINAPI pfx##_GetIids( iface_type *iface, ULONG *iid_count, IID **iids ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetIids( (IInspectable *)(expr), iid_count, iids ); \ + } \ + static HRESULT WINAPI pfx##_GetRuntimeClassName( iface_type *iface, HSTRING *class_name ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetRuntimeClassName( (IInspectable *)(expr), class_name ); \ + } \ + static HRESULT WINAPI pfx##_GetTrustLevel( iface_type *iface, TrustLevel *trust_level ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetTrustLevel( (IInspectable *)(expr), trust_level ); \ + } +#define DEFINE_IINSPECTABLE( pfx, iface_type, impl_type, base_iface ) \ + DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from_##iface_type, iface_type##_iface, &impl->base_iface )
#endif diff --git a/dlls/windows.web/tests/web.c b/dlls/windows.web/tests/web.c index 4d876b52669..15d0d3c8b35 100644 --- a/dlls/windows.web/tests/web.c +++ b/dlls/windows.web/tests/web.c @@ -90,6 +90,40 @@ static void test_JsonObjectStatics(void) ok( ref == 1, "got ref %ld.\n", ref ); }
+static void test_JsonValueStatics(void) +{ + static const WCHAR *json_value_statics_name = L"Windows.Data.Json.JsonValue"; + IJsonValueStatics *json_value_statics = (void *)0xdeadbeef; + IActivationFactory *factory = (void *)0xdeadbeef; + HSTRING str; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( json_value_statics_name, wcslen( json_value_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( json_value_statics_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown ); + check_interface( factory, &IID_IInspectable ); + check_interface( factory, &IID_IAgileObject ); + + hr = IActivationFactory_QueryInterface( factory, &IID_IJsonValueStatics, (void **)&json_value_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IJsonValueStatics_Release( json_value_statics ); + ok( ref == 2, "got ref %ld.\n", ref ); + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + START_TEST(web) { HRESULT hr; @@ -98,6 +132,7 @@ START_TEST(web) ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr );
test_JsonObjectStatics(); + test_JsonValueStatics();
RoUninitialize(); }