From: Olivia Ryan <olivia.r.dev@gmail.com> --- dlls/windows.web/json_array.c | 50 +++++++++--- dlls/windows.web/tests/web.c | 149 ++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 10 deletions(-) diff --git a/dlls/windows.web/json_array.c b/dlls/windows.web/json_array.c index 63bb6cc11d3..fdbaff28840 100644 --- a/dlls/windows.web/json_array.c +++ b/dlls/windows.web/json_array.c @@ -123,32 +123,62 @@ static HRESULT WINAPI json_array_GetTrustLevel( IJsonArray *iface, TrustLevel *t static HRESULT WINAPI json_array_GetObjectAt( IJsonArray *iface, UINT32 index, IJsonObject **value ) { - FIXME( "iface %p, index %u, value %p\n", iface, index, value ); - return E_NOTIMPL; + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_INVALIDARG; + if (index >= impl->length) return E_BOUNDS; + + return IJsonValue_GetObject( impl->elements[index], value ); } static HRESULT WINAPI json_array_GetArrayAt( IJsonArray *iface, UINT32 index, IJsonArray **value ) { - FIXME( "iface %p, index %u, value %p\n", iface, index, value ); - return E_NOTIMPL; + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_INVALIDARG; + if (index >= impl->length) return E_BOUNDS; + + return IJsonValue_GetArray( impl->elements[index], value ); } static HRESULT WINAPI json_array_GetStringAt( IJsonArray *iface, UINT32 index, HSTRING *value ) { - FIXME( "iface %p, index %u, value %p\n", iface, index, value ); - return E_NOTIMPL; + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_INVALIDARG; + if (index >= impl->length) return E_BOUNDS; + + return IJsonValue_GetString( impl->elements[index], value ); } static HRESULT WINAPI json_array_GetNumberAt( IJsonArray *iface, UINT32 index, double *value ) { - FIXME( "iface %p, index %u, value %p\n", iface, index, value ); - return E_NOTIMPL; + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_INVALIDARG; + if (index >= impl->length) return E_BOUNDS; + + return IJsonValue_GetNumber( impl->elements[index], value ); } static HRESULT WINAPI json_array_GetBooleanAt( IJsonArray *iface, UINT32 index, boolean *value ) { - FIXME( "iface %p, index %u, value %p\n", iface, index, value ); - return E_NOTIMPL; + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_INVALIDARG; + if (index >= impl->length) return E_BOUNDS; + + return IJsonValue_GetBoolean( impl->elements[index], value ); } static const struct IJsonArrayVtbl json_array_vtbl = diff --git a/dlls/windows.web/tests/web.c b/dlls/windows.web/tests/web.c index bf133d02ea0..1678d5f644e 100644 --- a/dlls/windows.web/tests/web.c +++ b/dlls/windows.web/tests/web.c @@ -47,14 +47,37 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid ) static void test_JsonArrayStatics(void) { + static const WCHAR *json_value_statics_name = L"Windows.Data.Json.JsonValue"; static const WCHAR *json_array_name = L"Windows.Data.Json.JsonArray"; + IJsonValueStatics *json_value_statics = (void *)0xdeadbeef; IActivationFactory *factory = (void *)0xdeadbeef; IInspectable *inspectable = (void *)0xdeadbeef; + IJsonObject *child_object = (void *)0xdeadbeef; + IJsonArray *child_array = (void *)0xdeadbeef; IJsonArray *json_array = (void *)0xdeadbeef; + IJsonValue *json_value = (void *)0xdeadbeef; + BOOLEAN child_boolean; + HSTRING child_string; + DOUBLE child_number; HSTRING str = NULL; 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; + } + + hr = IActivationFactory_QueryInterface( factory, &IID_IJsonValueStatics, (void **)&json_value_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ref = IActivationFactory_Release( factory ); + hr = WindowsCreateString( json_array_name, wcslen( json_array_name ), &str ); ok( hr == S_OK, "got hr %#lx.\n", hr ); hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); @@ -84,10 +107,136 @@ static void test_JsonArrayStatics(void) check_interface( inspectable, &IID_IAgileObject ); + hr = IJsonArray_GetObjectAt( json_array, 0, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == E_BOUNDS, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == E_BOUNDS, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == E_BOUNDS, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == E_BOUNDS, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == E_BOUNDS, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); IInspectable_Release( inspectable ); ref = IActivationFactory_Release( factory ); ok( ref == 1, "got ref %ld.\n", ref ); + + hr = WindowsCreateString( L"[{}]", wcslen( L"[{}]" ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + hr = IJsonValue_GetArray( json_value, &json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonValue_Release( json_value ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonObject_Release( child_object ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); + + hr = WindowsCreateString( L"[[]]", wcslen( L"[[]]" ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + hr = IJsonValue_GetArray( json_value, &json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonValue_Release( json_value ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonArray_Release( child_array ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); + + hr = WindowsCreateString( L"[\"Hello, World!\"]", wcslen( L"[\"Hello, World!\"]" ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + hr = IJsonValue_GetArray( json_value, &json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonValue_Release( json_value ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( child_string ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); + + hr = WindowsCreateString( L"[12.6]", wcslen( L"[12.6]" ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + hr = IJsonValue_GetArray( json_value, &json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonValue_Release( json_value ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); + + hr = WindowsCreateString( L"[true]", wcslen( L"[true]" ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + hr = IJsonValue_GetArray( json_value, &json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonValue_Release( json_value ); + hr = IJsonArray_GetObjectAt( json_array, 0, &child_object ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetArrayAt( json_array, 0, &child_array ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetStringAt( json_array, 0, &child_string ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetNumberAt( json_array, 0, &child_number ); + ok( hr == E_ILLEGAL_METHOD_CALL, "got hr %#lx.\n", hr ); + hr = IJsonArray_GetBooleanAt( json_array, 0, &child_boolean ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + IJsonArray_Release( json_array ); + + IJsonValueStatics_Release( json_value_statics ); } static void test_JsonObjectStatics(void) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10457