Nikolay Sivov : scrrun: Implement Keys() and Items() of dictionary.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Mar 3 09:42:10 CST 2015
Module: wine
Branch: master
Commit: 1c813d5be31d1e5d1cca4a5dd6928baf1af4133f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1c813d5be31d1e5d1cca4a5dd6928baf1af4133f
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri Feb 27 18:22:32 2015 +0300
scrrun: Implement Keys() and Items() of dictionary.
---
dlls/scrrun/dictionary.c | 72 ++++++++++++++++++++++++++++++++++++++----
dlls/scrrun/tests/dictionary.c | 10 ++----
2 files changed, 68 insertions(+), 14 deletions(-)
diff --git a/dlls/scrrun/dictionary.c b/dlls/scrrun/dictionary.c
index 7c776ee..6543aa0 100644
--- a/dlls/scrrun/dictionary.c
+++ b/dlls/scrrun/dictionary.c
@@ -381,13 +381,43 @@ static HRESULT WINAPI dictionary_Exists(IDictionary *iface, VARIANT *key, VARIAN
return S_OK;
}
-static HRESULT WINAPI dictionary_Items(IDictionary *iface, VARIANT *pItemsArray)
+static HRESULT WINAPI dictionary_Items(IDictionary *iface, VARIANT *items)
{
dictionary *This = impl_from_IDictionary(iface);
+ struct keyitem_pair *pair;
+ SAFEARRAYBOUND bound;
+ SAFEARRAY *sa;
+ VARIANT *v;
+ HRESULT hr;
+ LONG i;
- FIXME("(%p)->(%p)\n", This, pItemsArray);
+ TRACE("(%p)->(%p)\n", This, items);
- return E_NOTIMPL;
+ if (!items)
+ return S_OK;
+
+ bound.lLbound = 0;
+ bound.cElements = This->count;
+ sa = SafeArrayCreate(VT_VARIANT, 1, &bound);
+ if (!sa)
+ return E_OUTOFMEMORY;
+
+ hr = SafeArrayAccessData(sa, (void**)&v);
+ if (FAILED(hr)) {
+ SafeArrayDestroy(sa);
+ return hr;
+ }
+
+ i = 0;
+ LIST_FOR_EACH_ENTRY(pair, &This->pairs, struct keyitem_pair, entry) {
+ VariantCopy(&v[i], &pair->item);
+ i++;
+ }
+ SafeArrayUnaccessData(sa);
+
+ V_VT(items) = VT_ARRAY|VT_VARIANT;
+ V_ARRAY(items) = sa;
+ return S_OK;
}
static HRESULT WINAPI dictionary_put_Key(IDictionary *iface, VARIANT *Key, VARIANT *rhs)
@@ -399,13 +429,43 @@ static HRESULT WINAPI dictionary_put_Key(IDictionary *iface, VARIANT *Key, VARIA
return E_NOTIMPL;
}
-static HRESULT WINAPI dictionary_Keys(IDictionary *iface, VARIANT *pKeysArray)
+static HRESULT WINAPI dictionary_Keys(IDictionary *iface, VARIANT *keys)
{
dictionary *This = impl_from_IDictionary(iface);
+ struct keyitem_pair *pair;
+ SAFEARRAYBOUND bound;
+ SAFEARRAY *sa;
+ VARIANT *v;
+ HRESULT hr;
+ LONG i;
- FIXME("(%p)->(%p)\n", This, pKeysArray);
+ TRACE("(%p)->(%p)\n", This, keys);
- return E_NOTIMPL;
+ if (!keys)
+ return S_OK;
+
+ bound.lLbound = 0;
+ bound.cElements = This->count;
+ sa = SafeArrayCreate(VT_VARIANT, 1, &bound);
+ if (!sa)
+ return E_OUTOFMEMORY;
+
+ hr = SafeArrayAccessData(sa, (void**)&v);
+ if (FAILED(hr)) {
+ SafeArrayDestroy(sa);
+ return hr;
+ }
+
+ i = 0;
+ LIST_FOR_EACH_ENTRY(pair, &This->pairs, struct keyitem_pair, entry) {
+ VariantCopy(&v[i], &pair->key);
+ i++;
+ }
+ SafeArrayUnaccessData(sa);
+
+ V_VT(keys) = VT_ARRAY|VT_VARIANT;
+ V_ARRAY(keys) = sa;
+ return S_OK;
}
static HRESULT WINAPI dictionary_Remove(IDictionary *iface, VARIANT *key)
diff --git a/dlls/scrrun/tests/dictionary.c b/dlls/scrrun/tests/dictionary.c
index 74ab7b9..3637356 100644
--- a/dlls/scrrun/tests/dictionary.c
+++ b/dlls/scrrun/tests/dictionary.c
@@ -495,15 +495,12 @@ static void test_Keys(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDictionary_Keys(dict, NULL);
-todo_wine
ok(hr == S_OK, "got 0x%08x\n", hr);
VariantInit(&keys);
hr = IDictionary_Keys(dict, &keys);
-todo_wine {
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&keys) == (VT_ARRAY|VT_VARIANT), "got %d\n", V_VT(&keys));
-}
VariantClear(&keys);
V_VT(&key) = VT_R4;
@@ -514,12 +511,9 @@ todo_wine {
VariantInit(&keys);
hr = IDictionary_Keys(dict, &keys);
-todo_wine {
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(V_VT(&keys) == (VT_ARRAY|VT_VARIANT), "got %d\n", V_VT(&keys));
-}
-if (hr == S_OK)
-{
+
VariantInit(&key);
index = 0;
hr = SafeArrayGetElement(V_ARRAY(&keys), &index, &key);
@@ -532,7 +526,7 @@ if (hr == S_OK)
hr = SafeArrayGetUBound(V_ARRAY(&keys), 1, &index);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(index == 0, "got %d\n", index);
-}
+
VariantClear(&keys);
IDictionary_Release(dict);
More information about the wine-cvs
mailing list