[1/3] scrrun: Implement IDictionary_Add and Count (try 2)
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Tue Oct 9 04:26:06 CDT 2012
Hi,
Changelog:
scrrun: Implement IDictionary_Add and Count
Best Regards
Alistair Leslie-Hughes
-------------- next part --------------
>From 14bd5f68e2b3d2d1fe22e1ba6f1f304a8ff3c99b Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Fri, 5 Oct 2012 09:15:44 +1000
Subject: [PATCH] Implement IDictionary_Add and Count
To: wine-patches <wine-patches at winehq.org>
---
dlls/scrrun/dictionary.c | 84 ++++++++++++++++++++++++++++++++++++++--
dlls/scrrun/tests/dictionary.c | 13 ++++++-
2 files changed, 91 insertions(+), 6 deletions(-)
diff --git a/dlls/scrrun/dictionary.c b/dlls/scrrun/dictionary.c
index b75d23c..62abb7f 100644
--- a/dlls/scrrun/dictionary.c
+++ b/dlls/scrrun/dictionary.c
@@ -27,17 +27,73 @@
#include "scrrun.h"
#include "scrrun_private.h"
+#include "wine/list.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
+
+typedef struct dictitem
+{
+ struct list entry;
+
+ VARIANT name;
+ VARIANT value;
+} dictitem;
+
typedef struct
{
IDictionary IDictionary_iface;
LONG ref;
+
+ struct list items;
+ LONG count;
} dictionary;
+static const char *debugstr_variant(const VARIANT *v)
+{
+ if(!v)
+ return "(null)";
+
+ switch(V_VT(v)) {
+ case VT_EMPTY:
+ return "{VT_EMPTY}";
+ case VT_NULL:
+ return "{VT_NULL}";
+ case VT_I4:
+ return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
+ case VT_UI4:
+ return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
+ case VT_R8:
+ return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
+ case VT_BSTR:
+ return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
+ case VT_DISPATCH:
+ return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
+ case VT_BOOL:
+ return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
+ case VT_ARRAY|VT_VARIANT:
+ return "{VT_ARRAY|VT_VARIANT: ...}";
+ default:
+ return wine_dbg_sprintf("{vt %d}", V_VT(v));
+ }
+}
+
+static void remove_all_items(dictionary *This)
+{
+ struct dictitem *cursor, *cursor2;
+
+ LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->items, struct dictitem, entry)
+ {
+ VariantClear(&cursor->name);
+ VariantClear(&cursor->value);
+
+ list_remove(&cursor->entry);
+ HeapFree(GetProcessHeap(), 0, cursor);
+ }
+}
+
static inline dictionary *impl_from_IDictionary(IDictionary *iface)
{
return CONTAINING_RECORD(iface, dictionary, IDictionary_iface);
@@ -96,6 +152,8 @@ static ULONG WINAPI dictionary_Release(IDictionary *iface)
ref = InterlockedDecrement(&This->ref);
if(ref == 0)
{
+ remove_all_items(This);
+
HeapFree(GetProcessHeap(), 0, This);
}
@@ -191,19 +249,34 @@ static HRESULT WINAPI dictionary_get_Item(IDictionary *iface, VARIANT *Key, VARI
static HRESULT WINAPI dictionary_Add(IDictionary *iface, VARIANT *Key, VARIANT *Item)
{
dictionary *This = impl_from_IDictionary(iface);
+ struct dictitem *newitem;
- FIXME("(%p)->(%p %p)\n", This, Key, Item);
+ TRACE("(%p)->(%s %s)\n", This, debugstr_variant(Key), debugstr_variant(Item));
- return E_NOTIMPL;
+ newitem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dictitem));
+ if(!newitem)
+ return E_OUTOFMEMORY;
+
+ VariantInit(&newitem->name);
+ VariantInit(&newitem->value);
+
+ VariantCopy(&newitem->name, Key);
+ VariantCopy(&newitem->value, Item);
+
+ list_add_tail(&This->items, &newitem->entry);
+
+ This->count++;
+
+ return S_OK;
}
static HRESULT WINAPI dictionary_get_Count(IDictionary *iface, LONG *pCount)
{
dictionary *This = impl_from_IDictionary(iface);
- FIXME("(%p)->(%p)\n", This, pCount);
+ TRACE("(%p)->(%p)\n", This, pCount);
- *pCount = 0;
+ *pCount = This->count;
return S_OK;
}
@@ -338,6 +411,9 @@ HRESULT WINAPI Dictionary_CreateInstance(IClassFactory *factory,IUnknown *outer,
This->IDictionary_iface.lpVtbl = &dictionary_vtbl;
This->ref = 1;
+ This->count = 0;
+
+ list_init(&This->items);
*obj = &This->IDictionary_iface;
diff --git a/dlls/scrrun/tests/dictionary.c b/dlls/scrrun/tests/dictionary.c
index e28bbb1..7df76e9 100644
--- a/dlls/scrrun/tests/dictionary.c
+++ b/dlls/scrrun/tests/dictionary.c
@@ -66,9 +66,18 @@ static void test_interfaces(void)
V_VT(&value) = VT_BSTR;
V_BSTR(&value) = SysAllocString(key_add_value);
hr = IDictionary_Add(dict, &key, &value);
- todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+ ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
VariantClear(&value);
+ /* The following tests crash under windows */
+#if 0
+ hr = IDictionary_Add(dict, NULL, &value);
+ ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, S_OK)
+
+ hr = IDictionary_Add(dict, &key, NULL);
+ ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+#endif
+
exists = VARIANT_FALSE;
hr = IDictionary_Exists(dict, &key, &exists);
todo_wine ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
@@ -85,7 +94,7 @@ static void test_interfaces(void)
hr = IDictionary_get_Count(dict, &count);
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
- todo_wine ok(count == 1, "got %d, expected 1\n", count);
+ ok(count == 1, "got %d, expected 1\n", count);
IDictionary_Release(dict);
IDispatch_Release(disp);
--
1.7.9.5
More information about the wine-patches
mailing list