scrrun: Add basic IDictionary getHasVal support

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Tue Oct 30 03:51:13 CDT 2012


Hi,


Changelog:
     scrrun: Add basic IDictionary getHasVal support


Best Regards
  Alistair Leslie-Hughes
-------------- next part --------------
>From 5b1014feb4cd5a8b851d5d464a4aa4b3951ca52d Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Mon, 29 Oct 2012 16:05:06 +1100
Subject: [PATCH] Add basic IDictionary getHasVal support
To: wine-patches <wine-patches at winehq.org>

---
 dlls/scrrun/dictionary.c       |   31 +++++++++++++++++++++--
 dlls/scrrun/tests/dictionary.c |   54 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 dlls/scrrun/tests/dictionary.c

diff --git a/dlls/scrrun/dictionary.c b/dlls/scrrun/dictionary.c
index b75d23c..34ca270 100644
--- a/dlls/scrrun/dictionary.c
+++ b/dlls/scrrun/dictionary.c
@@ -43,6 +43,21 @@ static inline dictionary *impl_from_IDictionary(IDictionary *iface)
     return CONTAINING_RECORD(iface, dictionary, IDictionary_iface);
 }
 
+static LONG create_hash_val(BSTR name)
+{
+    LONG hash = 0;
+    int len = SysStringLen(name);
+    int i;
+
+    for(i =0; i < len; i++)
+    {
+	hash += name[i];
+    }
+
+    return hash;
+}
+
+
 static HRESULT WINAPI dictionary_QueryInterface(IDictionary *iface, REFIID riid, void **obj)
 {
     dictionary *This = impl_from_IDictionary(iface);
@@ -292,10 +307,22 @@ static HRESULT WINAPI dictionary__NewEnum(IDictionary *iface, IUnknown **ppunk)
 static HRESULT WINAPI dictionary_get_HashVal(IDictionary *iface, VARIANT *Key, VARIANT *HashVal)
 {
     dictionary *This = impl_from_IDictionary(iface);
+    VARIANT keystr;
+    HRESULT hr = S_OK;
 
-    FIXME("(%p)->(%p %p)\n", This, Key, HashVal);
+    TRACE("(%p)->(%p %p)\n", This, Key, HashVal);
 
-    return E_NOTIMPL;
+    keystr = *Key;
+    if(V_VT(&keystr) != VT_BSTR)
+        hr = VariantChangeType(&keystr, &keystr, 0, VT_BSTR);
+
+    if(hr == S_OK)
+    {
+        V_VT(HashVal) = VT_I4;
+        V_I4(HashVal) = create_hash_val(V_BSTR(&keystr));
+    }
+
+    return hr;
 }
 
 
diff --git a/dlls/scrrun/tests/dictionary.c b/dlls/scrrun/tests/dictionary.c
old mode 100644
new mode 100755
index e28bbb1..64d039f
--- a/dlls/scrrun/tests/dictionary.c
+++ b/dlls/scrrun/tests/dictionary.c
@@ -28,6 +28,59 @@
 
 #include "scrrun.h"
 
+
+static void test_hash(void)
+{
+    static const WCHAR key_a[] = {'a', 0};
+    static const WCHAR key_aa[] = {'a', 'a', 0};
+    static const WCHAR key_b[] = {'b', 0};
+    VARIANT key, value;
+    HRESULT hr;
+
+    IDispatch *disp;
+    IDictionary *dict;
+
+    hr = CoCreateInstance(&CLSID_Dictionary, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
+            &IID_IDispatch, (void**)&disp);
+    if(FAILED(hr)) {
+        win_skip("Could not create FileSystem object: %08x\n", hr);
+        return;
+    }
+
+    VariantInit(&key);
+    VariantInit(&value);
+
+    hr = IDispatch_QueryInterface(disp, &IID_IDictionary, (void**)&dict);
+    ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+
+    V_VT(&key) = VT_BSTR;
+    V_BSTR(&key) = SysAllocString(key_a);
+    hr = IDictionary_get_HashVal(dict, &key, &value);
+    ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+    ok(V_I4(&value) == 97, "got %d, expected 97\n", V_I4(&value));
+    VariantClear(&key);
+    VariantClear(&value);
+
+    V_VT(&key) = VT_BSTR;
+    V_BSTR(&key) = SysAllocString(key_b);
+    hr = IDictionary_get_HashVal(dict, &key, &value);
+    ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+    ok(V_I4(&value) == 98, "got %d, expected 98\n", V_I4(&value));
+    VariantClear(&key);
+    VariantClear(&value);
+
+    V_VT(&key) = VT_BSTR;
+    V_BSTR(&key) = SysAllocString(key_aa);
+    hr = IDictionary_get_HashVal(dict, &key, &value);
+    ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
+    todo_wine ok(V_I4(&value) == 545, "got %d, expected 545\n", V_I4(&value));
+    VariantClear(&key);
+    VariantClear(&value);
+
+    IDictionary_Release(dict);
+    IDispatch_Release(disp);
+}
+
 static void test_interfaces(void)
 {
     static const WCHAR key_add[] = {'a', 0};
@@ -96,6 +149,7 @@ START_TEST(dictionary)
     CoInitialize(NULL);
 
     test_interfaces();
+    test_hash();
 
 
     CoUninitialize();
-- 
1.7.10.4



More information about the wine-patches mailing list