From 1bc4c57e551e3d92ac2776d0e65d9a6d96a4acdd Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 27 Feb 2015 18:13:04 +0300 Subject: [PATCH] scrrun: Implement Item() property for dictionary. --- dlls/scrrun/dictionary.c | 24 ++++++++++++++++++------ dlls/scrrun/tests/dictionary.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/dlls/scrrun/dictionary.c b/dlls/scrrun/dictionary.c index 524485b4889..a7c90dbbf5c 100644 --- a/dlls/scrrun/dictionary.c +++ b/dlls/scrrun/dictionary.c @@ -316,22 +316,34 @@ static HRESULT WINAPI dictionary_putref_Item(IDictionary *iface, VARIANT *Key, V return E_NOTIMPL; } -static HRESULT WINAPI dictionary_put_Item(IDictionary *iface, VARIANT *Key, VARIANT *pRetItem) +static HRESULT WINAPI dictionary_put_Item(IDictionary *iface, VARIANT *key, VARIANT *item) { dictionary *This = impl_from_IDictionary(iface); + struct keyitem_pair *pair; - FIXME("(%p)->(%p %p)\n", This, Key, pRetItem); + TRACE("(%p)->(%s %s)\n", This, debugstr_variant(key), debugstr_variant(item)); - return E_NOTIMPL; + if ((pair = get_keyitem_pair(This, key))) + return VariantCopyInd(&pair->item, item); + + return IDictionary_Add(iface, key, item); } -static HRESULT WINAPI dictionary_get_Item(IDictionary *iface, VARIANT *Key, VARIANT *pRetItem) +static HRESULT WINAPI dictionary_get_Item(IDictionary *iface, VARIANT *key, VARIANT *item) { dictionary *This = impl_from_IDictionary(iface); + struct keyitem_pair *pair; - FIXME("(%p)->(%p %p)\n", This, Key, pRetItem ); + TRACE("(%p)->(%s %p)\n", This, debugstr_variant(key), item); - return E_NOTIMPL; + if ((pair = get_keyitem_pair(This, key))) + VariantCopy(item, &pair->item); + else { + VariantInit(item); + return IDictionary_Add(iface, key, item); + } + + return S_OK; } static HRESULT WINAPI dictionary_Add(IDictionary *iface, VARIANT *key, VARIANT *item) diff --git a/dlls/scrrun/tests/dictionary.c b/dlls/scrrun/tests/dictionary.c index 066a5ab0da9..c9e71a542a8 100644 --- a/dlls/scrrun/tests/dictionary.c +++ b/dlls/scrrun/tests/dictionary.c @@ -574,6 +574,34 @@ todo_wine IDictionary_Release(dict); } +static void test_Item(void) +{ + VARIANT key, item; + IDictionary *dict; + HRESULT hr; + + hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, + &IID_IDictionary, (void**)&dict); + ok(hr == S_OK, "got 0x%08x\n", hr); + + V_VT(&key) = VT_I2; + V_I2(&key) = 10; + V_VT(&item) = VT_I2; + V_I2(&item) = 123; + hr = IDictionary_get_Item(dict, &key, &item); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(V_VT(&item) == VT_EMPTY, "got %d\n", V_VT(&item)); + + V_VT(&key) = VT_I2; + V_I2(&key) = 10; + V_VT(&item) = VT_I2; + hr = IDictionary_get_Item(dict, &key, &item); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(V_VT(&item) == VT_EMPTY, "got %d\n", V_VT(&item)); + + IDictionary_Release(dict); +} + START_TEST(dictionary) { IDispatch *disp; @@ -596,6 +624,7 @@ START_TEST(dictionary) test_Exists(); test_Keys(); test_Remove(); + test_Item(); CoUninitialize(); }