Andrew Eikum : hlink: Add tests and fix error handling in IHlink::{Get, Set}StringReference.

Alexandre Julliard julliard at winehq.org
Wed Dec 23 10:04:12 CST 2009


Module: wine
Branch: master
Commit: fc4a9e2e69316818292bfa360d7b3f40aefed931
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fc4a9e2e69316818292bfa360d7b3f40aefed931

Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Tue Dec 22 17:43:26 2009 -0600

hlink: Add tests and fix error handling in IHlink::{Get, Set}StringReference.

---

 dlls/hlink/link.c        |   21 +++++++++-
 dlls/hlink/tests/hlink.c |   95 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/dlls/hlink/link.c b/dlls/hlink/link.c
index 30530ca..78b6c1e 100644
--- a/dlls/hlink/link.c
+++ b/dlls/hlink/link.c
@@ -245,6 +245,10 @@ static HRESULT WINAPI IHlink_fnSetStringReference(IHlink* iface,
     TRACE("(%p)->(%i %s %s)\n", This, grfHLSETF, debugstr_w(pwzTarget),
             debugstr_w(pwzLocation));
 
+    if(grfHLSETF > (HLINKSETF_TARGET | HLINKSETF_LOCATION) &&
+            grfHLSETF < -(HLINKSETF_TARGET | HLINKSETF_LOCATION))
+        return grfHLSETF;
+
     if (grfHLSETF & HLINKSETF_TARGET)
     {
         heap_free(This->Target);
@@ -281,7 +285,20 @@ static HRESULT WINAPI IHlink_fnGetStringReference (IHlink* iface,
 {
     HlinkImpl  *This = (HlinkImpl*)iface;
 
-    FIXME("(%p) -> (%i %p %p)\n", This, dwWhichRef, ppwzTarget, ppwzLocation);
+    TRACE("(%p) -> (%i %p %p)\n", This, dwWhichRef, ppwzTarget, ppwzLocation);
+
+    /* note: undocumented behavior with dwWhichRef == -1 */
+    if(dwWhichRef != -1 && dwWhichRef & ~(HLINKGETREF_DEFAULT | HLINKGETREF_ABSOLUTE | HLINKGETREF_RELATIVE))
+    {
+        if(ppwzTarget)
+            *ppwzTarget = NULL;
+        if(ppwzLocation)
+            *ppwzLocation = NULL;
+        return E_INVALIDARG;
+    }
+
+    if(dwWhichRef != HLINKGETREF_DEFAULT)
+        FIXME("unhandled flags: 0x%x\n", dwWhichRef);
 
     if (ppwzTarget)
     {
@@ -300,8 +317,6 @@ static HRESULT WINAPI IHlink_fnGetStringReference (IHlink* iface,
                 IBindCtx_Release(pbc);
                 IMoniker_Release(mon);
             }
-            else
-                FIXME("Unhandled case, no set Target and no moniker\n");
         }
     }
     if (ppwzLocation)
diff --git a/dlls/hlink/tests/hlink.c b/dlls/hlink/tests/hlink.c
index 1a7536f..6999187 100644
--- a/dlls/hlink/tests/hlink.c
+++ b/dlls/hlink/tests/hlink.c
@@ -1121,6 +1121,100 @@ static void test_HlinkGetSetMonikerReference(void)
     IMoniker_Release(dummy);
 }
 
+static void test_HlinkGetSetStringReference(void)
+{
+    IHlink *link;
+    static const WCHAR one[] = {'1',0};
+    static const WCHAR two[] = {'2',0};
+    static const WCHAR three[] = {'3',0};
+    static const WCHAR empty[] = {0};
+    WCHAR *fnd_tgt, *fnd_loc;
+    HRESULT hres;
+
+    /* create a new hlink: target => NULL, location => one */
+    hres = HlinkCreateFromMoniker(NULL, one, empty, NULL, 0, NULL, &IID_IHlink, (void**)&link);
+    ok(hres == S_OK, "HlinkCreateFromMoniker failed: 0x%08x\n", hres);
+
+    /* test setting/getting location */
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(fnd_tgt == NULL, "Found target should have been NULL, was: %s\n", wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, one), "Found location should have been %s, was: %s\n", wine_dbgstr_w(one), wine_dbgstr_w(fnd_loc));
+
+    hres = IHlink_SetStringReference(link, HLINKSETF_LOCATION, one, two);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(fnd_tgt == NULL, "Found target should have been NULL, was: %s\n", wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, two), "Found location should have been %s, was: %s\n", wine_dbgstr_w(two), wine_dbgstr_w(fnd_loc));
+
+    hres = IHlink_SetStringReference(link, -HLINKSETF_LOCATION, two, one);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(fnd_tgt == NULL, "Found target should have been NULL, was: %s\n", wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, one), "Found location should have been %s, was: %s\n", wine_dbgstr_w(one), wine_dbgstr_w(fnd_loc));
+
+    /* test setting/getting target */
+    hres = IHlink_SetStringReference(link, HLINKSETF_TARGET, two, three);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(!lstrcmpW(fnd_tgt, two), "Found target should have been %s, was: %s\n", wine_dbgstr_w(two), wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, one), "Found location should have been %s, was: %s\n", wine_dbgstr_w(one), wine_dbgstr_w(fnd_loc));
+
+    hres = IHlink_SetStringReference(link, -HLINKSETF_TARGET, three, two);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(!lstrcmpW(fnd_tgt, three), "Found target should have been %s, was: %s\n", wine_dbgstr_w(three), wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, two), "Found location should have been %s, was: %s\n", wine_dbgstr_w(two), wine_dbgstr_w(fnd_loc));
+
+    /* test setting/getting both */
+    hres = IHlink_SetStringReference(link, HLINKSETF_TARGET | HLINKSETF_LOCATION, one, two);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(!lstrcmpW(fnd_tgt, one), "Found target should have been %s, was: %s\n", wine_dbgstr_w(one), wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, two), "Found location should have been %s, was: %s\n", wine_dbgstr_w(two), wine_dbgstr_w(fnd_loc));
+
+    hres = IHlink_SetStringReference(link, -(HLINKSETF_TARGET | HLINKSETF_LOCATION), three, one);
+    ok(hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+
+    hres = IHlink_GetStringReference(link, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+    ok(hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+    ok(!lstrcmpW(fnd_tgt, three), "Found target should have been %s, was: %s\n", wine_dbgstr_w(three), wine_dbgstr_w(fnd_tgt));
+    ok(!lstrcmpW(fnd_loc, two), "Found location should have been %s, was: %s\n", wine_dbgstr_w(two), wine_dbgstr_w(fnd_loc));
+
+    /* test invalid flags/params */
+    hres = IHlink_GetStringReference(link, 4, &fnd_tgt, &fnd_loc);
+    ok(hres == E_INVALIDARG, "IHlink_GetStringReference should have failed "
+           "with E_INVALIDARG (0x%08x), instead: 0x%08x\n", E_INVALIDARG, hres);
+    ok(fnd_tgt == NULL, "Found target should have been NULL, was: %s\n", wine_dbgstr_w(fnd_tgt));
+    ok(fnd_loc == NULL, "Found location should have been NULL, was: %s\n", wine_dbgstr_w(fnd_loc));
+
+    hres = IHlink_GetStringReference(link, -1, &fnd_tgt, &fnd_loc);
+    todo_wine ok(hres == E_FAIL, "IHlink_GetStringReference should have failed "
+           "with E_FAIL (0x%08x), instead: 0x%08x\n", E_FAIL, hres);
+
+    hres = IHlink_GetStringReference(link, -2, &fnd_tgt, &fnd_loc);
+    ok(hres == E_INVALIDARG, "IHlink_GetStringReference should have failed "
+           "with E_INVALIDARG (0x%08x), instead: 0x%08x\n", E_INVALIDARG, hres);
+
+    hres = IHlink_SetStringReference(link, 4, NULL, NULL);
+    ok(hres == 4, "IHlink_SetStringReference should have failed with 0x4, instead: 0x%08x\n", hres);
+
+    hres = IHlink_SetStringReference(link, -4, NULL, NULL);
+    ok(hres == -4, "IHlink_SetStringReference should have failed with 0xFFFFFFFC, instead: 0x%08x\n", hres);
+
+    IHlink_Release(link);
+}
+
 START_TEST(hlink)
 {
     CoInitialize(NULL);
@@ -1133,6 +1227,7 @@ START_TEST(hlink)
     test_HlinkParseDisplayName();
     test_HlinkResolveMonikerForData();
     test_HlinkGetSetMonikerReference();
+    test_HlinkGetSetStringReference();
 
     CoUninitialize();
 }




More information about the wine-cvs mailing list