[HLINK_WINETEST] Sync with Wine 3.0. CORE-14225
authorAmine Khaldi <amine.khaldi@reactos.org>
Thu, 18 Jan 2018 23:24:20 +0000 (00:24 +0100)
committerAmine Khaldi <amine.khaldi@reactos.org>
Thu, 18 Jan 2018 23:24:20 +0000 (00:24 +0100)
modules/rostests/winetests/hlink/browse_ctx.c
modules/rostests/winetests/hlink/hlink.c

index 40d132b..3193525 100644 (file)
@@ -131,12 +131,82 @@ static void test_BrowseWindowInfo(void)
     IHlinkBrowseContext_Release(bc);
 }
 
+static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
+{
+    *ppv = NULL;
+
+    if (IsEqualIID(riid, &IID_IUnknown))
+    {
+        *ppv = iface;
+        return S_OK;
+    }
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
+{
+    return 2;
+}
+
+static ULONG WINAPI Unknown_Release(IUnknown *iface)
+{
+    return 1;
+}
+
+static IUnknownVtbl UnknownVtbl = {
+    Unknown_QueryInterface,
+    Unknown_AddRef,
+    Unknown_Release,
+};
+
+static IUnknown Unknown = { &UnknownVtbl };
+
+static void test_GetObject(void)
+{
+    IHlinkBrowseContext *bc;
+    IMoniker *dummy;
+    IBindCtx *bindctx;
+    IUnknown *unk;
+    WCHAR one[] = {'1',0};
+    WCHAR five[] = {'5',0};
+    DWORD cookie;
+    HRESULT hres;
+
+    hres = CreateBindCtx(0, &bindctx);
+    ok(hres == S_OK, "CreateBindCtx() failed: 0x%08x\n", hres);
+
+    hres = CreateItemMoniker(one, five, &dummy);
+    ok(hres == S_OK, "CreateItemMoniker() failed: 0x%08x\n", hres);
+
+    hres = HlinkCreateBrowseContext(NULL, &IID_IHlinkBrowseContext, (void **)&bc);
+    ok(hres == S_OK, "HlinkCreateBrowseContext() failed: 0x%08x\n", hres);
+
+    hres = IHlinkBrowseContext_GetObject(bc, dummy, FALSE, &unk);
+    ok(hres == MK_E_UNAVAILABLE, "expected MK_E_UNAVAILABLE, got 0x%08x\n", hres);
+
+    hres = IHlinkBrowseContext_Register(bc, 0, &Unknown, dummy, &cookie);
+    ok(hres == S_OK, "Register() failed: 0x%08x\n", hres);
+
+    hres = IHlinkBrowseContext_GetObject(bc, dummy, FALSE, &unk);
+    ok(hres == S_OK, "GetObject() failed: 0x%08x\n", hres);
+    ok(unk == &Unknown, "wrong object returned\n");
+
+    hres = IHlinkBrowseContext_Revoke(bc, cookie);
+    ok(hres == S_OK, "Revoke() failed: 0x%08x\n", hres);
+
+    hres = IHlinkBrowseContext_GetObject(bc, dummy, FALSE, &unk);
+    ok(hres == MK_E_UNAVAILABLE, "expected MK_E_UNAVAILABLE, got 0x%08x\n", hres);
+
+    IHlinkBrowseContext_Release(bc);
+}
+
 START_TEST(browse_ctx)
 {
     CoInitialize(NULL);
 
     test_SetInitialHlink();
     test_BrowseWindowInfo();
+    test_GetObject();
 
     CoUninitialize();
 }
index 50f61d5..e40807c 100644 (file)
@@ -67,9 +67,13 @@ DEFINE_EXPECT(GetClassID);
 DEFINE_EXPECT(Save);
 
 DEFINE_EXPECT(HBC_QueryInterface_IHlinkHistory);
+DEFINE_EXPECT(HBC_QueryInterface_IMarshal);
+DEFINE_EXPECT(HBC_QueryInterface_IdentityUnmarshal);
+DEFINE_EXPECT(HBC_QueryInterface_IUnknown);
 DEFINE_EXPECT(HBC_GetObject);
 DEFINE_EXPECT(HBC_UpdateHlink);
 
+DEFINE_EXPECT(HT_QueryInterface_IHlinkTarget);
 DEFINE_EXPECT(HT_SetBrowseContext);
 DEFINE_EXPECT(HT_GetBrowseContext);
 DEFINE_EXPECT(HT_Navigate);
@@ -77,8 +81,16 @@ DEFINE_EXPECT(HT_GetFriendlyName);
 
 DEFINE_EXPECT(HLF_UpdateHlink);
 
+DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
 DEFINE_GUID(IID_IHlinkHistory,0x79eac9c8,0xbaf9,0x11ce,0x8c,0x82,0x00,0xaa,0x00,0x4b,0xa9,0x0b);
 
+static const WCHAR winehq_urlW[] =
+        {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',
+         '/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
+static const WCHAR winehq_404W[] =
+        {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',
+         '/','t','e','s','t','s','/','f','a','k','e','u','r','l',0};
+
 static void test_HlinkIsShortcut(void)
 {
     UINT i;
@@ -627,9 +639,6 @@ static void test_HlinkParseDisplayName(void)
     IBindCtx *bctx;
     HRESULT hres;
 
-    static const WCHAR winehq_urlW[] =
-            {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
-            '/','s','i','t','e','/','a','b','o','u','t',0};
     static const WCHAR invalid_urlW[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
     static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
             '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
@@ -829,12 +838,17 @@ static HRESULT WINAPI HlinkBrowseContext_QueryInterface(
 {
     *ppv = NULL;
 
-    if(IsEqualGUID(&IID_IHlinkHistory, riid)) {
+    if (IsEqualGUID(&IID_IHlinkHistory, riid))
         CHECK_EXPECT(HBC_QueryInterface_IHlinkHistory);
-        return E_NOINTERFACE;
-    }
+    else if (IsEqualGUID(&IID_IMarshal, riid))
+        CHECK_EXPECT2(HBC_QueryInterface_IMarshal);
+    else if (IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
+        CHECK_EXPECT(HBC_QueryInterface_IdentityUnmarshal);
+    else if (IsEqualGUID(&IID_IUnknown, riid))
+        CHECK_EXPECT(HBC_QueryInterface_IUnknown);
+    else
+        ok(0, "unexpected interface: %s\n", wine_dbgstr_guid(riid));
 
-    ok(0, "unexpected interface: %s\n", wine_dbgstr_guid(riid));
     return E_NOINTERFACE;
 }
 
@@ -855,16 +869,29 @@ static HRESULT WINAPI HlinkBrowseContext_Register(IHlinkBrowseContext *iface,
     return E_NOTIMPL;
 }
 
+static IUnknown *HBC_object;
+
 static IMoniker Moniker;
 static HRESULT WINAPI HlinkBrowseContext_GetObject(IHlinkBrowseContext *iface,
         IMoniker *pimk, BOOL fBindIfRootRegistered, IUnknown **ppiunk)
 {
+    IBindCtx *bctx;
+    WCHAR *name;
+    HRESULT hr;
+
     CHECK_EXPECT(HBC_GetObject);
 
-    ok(pimk == &Moniker, "pimk != &Moniker\n");
+    CreateBindCtx(0, &bctx);
+    hr = IMoniker_GetDisplayName(pimk, bctx, NULL, &name);
+    ok(hr == S_OK, "Failed to get display name, hr %#x.\n", hr);
+    ok(!lstrcmpW(winehq_urlW, name) || !lstrcmpW(winehq_404W, name), "got unexpected url\n");
+    CoTaskMemFree(name);
+    IBindCtx_Release(bctx);
+
     ok(fBindIfRootRegistered == 1, "fBindIfRootRegistered = %x\n", fBindIfRootRegistered);
-    *ppiunk = NULL;
-    return S_FALSE;
+
+    *ppiunk = HBC_object;
+    return HBC_object ? S_OK : S_FALSE;
 }
 
 static HRESULT WINAPI HlinkBrowseContext_Revoke(IHlinkBrowseContext *iface, DWORD dwRegister)
@@ -974,6 +1001,7 @@ static IHlinkBrowseContext HlinkBrowseContext = { &HlinkBrowseContextVtbl };
 static HRESULT WINAPI HlinkTarget_QueryInterface(IHlinkTarget *iface, REFIID riid, void **ppv)
 {
     if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
+        CHECK_EXPECT(HT_QueryInterface_IHlinkTarget);
         *ppv = iface;
         return S_OK;
     }
@@ -1205,10 +1233,6 @@ static HRESULT WINAPI Moniker_RelativePathTo(IMoniker *iface, IMoniker *pmkOther
 static HRESULT WINAPI Moniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc,
         IMoniker *pmkToLeft, LPOLESTR *ppszDisplayName)
 {
-    static const WCHAR winehq_urlW[] =
-            {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
-            '/','s','i','t','e','/','a','b','o','u','t',0};
-
     CHECK_EXPECT2(GetDisplayName);
 
     ok(pbc != NULL, "pbc == NULL\n");
@@ -2171,6 +2195,8 @@ static void test_Hlink_Navigate(void)
     ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
     _bctx = pbc;
 
+    HBC_object = NULL;
+
     SET_EXPECT(Reduce);
     SET_EXPECT(Enum);
     SET_EXPECT(IsSystemMoniker);
@@ -2188,6 +2214,7 @@ static void test_Hlink_Navigate(void)
     SET_EXPECT(HBC_GetObject);
     SET_EXPECT(Reduce);
     SET_EXPECT(BindToObject);
+    SET_EXPECT(HT_QueryInterface_IHlinkTarget);
     SET_EXPECT(HT_GetBrowseContext);
     SET_EXPECT(HT_SetBrowseContext);
     SET_EXPECT(HBC_QueryInterface_IHlinkHistory);
@@ -2196,16 +2223,83 @@ static void test_Hlink_Navigate(void)
     hres = IHlink_Navigate(hlink, 0, pbc, NULL, &HlinkBrowseContext);
     ok(hres == S_OK, "Navigate failed: %08x\n", hres);
     CHECK_CALLED(IsSystemMoniker);
-    todo_wine CHECK_CALLED(GetDisplayName);
-    todo_wine CHECK_CALLED(HBC_GetObject);
+    CHECK_CALLED(GetDisplayName);
+    CHECK_CALLED(HBC_GetObject);
     todo_wine CHECK_CALLED(Reduce);
     CHECK_CALLED(BindToObject);
+    CHECK_CALLED(HT_QueryInterface_IHlinkTarget);
     todo_wine CHECK_CALLED(HT_GetBrowseContext);
     CHECK_CALLED(HT_SetBrowseContext);
     todo_wine CHECK_CALLED(HBC_QueryInterface_IHlinkHistory);
     CHECK_CALLED(HT_Navigate);
     todo_wine CHECK_CALLED(HT_GetFriendlyName);
 
+    /* Test with valid return from HlinkBrowseContext::GetObject */
+    HBC_object = (IUnknown *)&HlinkTarget;
+
+    SET_EXPECT(IsSystemMoniker);
+    SET_EXPECT(GetDisplayName);
+    SET_EXPECT(HBC_GetObject);
+    SET_EXPECT(HT_QueryInterface_IHlinkTarget);
+    SET_EXPECT(HT_Navigate);
+    SET_EXPECT(HT_GetFriendlyName);
+    hres = IHlink_Navigate(hlink, 0, pbc, NULL, &HlinkBrowseContext);
+    ok(hres == S_OK, "Navigate failed: %08x\n", hres);
+    CHECK_CALLED(IsSystemMoniker);
+    CHECK_CALLED(GetDisplayName);
+    CHECK_CALLED(HBC_GetObject);
+    CHECK_CALLED(HT_QueryInterface_IHlinkTarget);
+    CHECK_CALLED(HT_Navigate);
+    todo_wine CHECK_CALLED(HT_GetFriendlyName);
+
+    HBC_object = NULL;
+
+if (0) {    /* these currently open a browser window on wine */
+    /* Test from string */
+    SET_EXPECT(HBC_GetObject);
+    hres = HlinkNavigateToStringReference(winehq_404W, NULL, NULL, 0, NULL, 0, pbc, NULL, &HlinkBrowseContext);
+    todo_wine ok(hres == INET_E_OBJECT_NOT_FOUND, "Expected INET_E_OBJECT_NOT_FOUND, got %08x\n", hres);
+    CHECK_CALLED(HBC_GetObject);
+
+    /* MSDN claims browse context and bind context can't be null, but they can */
+    SET_EXPECT(HBC_GetObject);
+    hres = HlinkNavigateToStringReference(winehq_404W, NULL, NULL, 0, NULL, 0, NULL, NULL, &HlinkBrowseContext);
+    todo_wine ok(hres == INET_E_OBJECT_NOT_FOUND, "Expected INET_E_OBJECT_NOT_FOUND, got %08x\n", hres);
+    CHECK_CALLED(HBC_GetObject);
+}
+
+    /* these open a browser window, so mark them interactive only */
+    if (winetest_interactive)
+    {
+        /* both parameters null */
+        SET_EXPECT(IsSystemMoniker);
+        SET_EXPECT(GetDisplayName);
+        hres = IHlink_Navigate(hlink, 0, NULL, NULL, NULL);
+        ok(hres == DRAGDROP_S_DROP, "Expected DRAGDROP_S_DROP, got %08x\n", hres);
+        CHECK_CALLED(IsSystemMoniker);
+        CHECK_CALLED(GetDisplayName);
+
+        /* same, from string */
+        hres = HlinkNavigateToStringReference(winehq_404W, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
+        ok(hres == DRAGDROP_S_DROP, "Expected DRAGDROP_S_DROP, got %08x\n", hres);
+
+        /* try basic test with valid URL */
+        SET_EXPECT(HBC_GetObject);
+        SET_EXPECT(HBC_QueryInterface_IHlinkHistory);
+        SET_EXPECT(HBC_QueryInterface_IMarshal);
+        SET_EXPECT(HBC_QueryInterface_IdentityUnmarshal);
+        SET_EXPECT(HBC_QueryInterface_IUnknown);
+        hres = HlinkNavigateToStringReference(winehq_urlW, NULL, NULL, 0, NULL, 0, pbc, NULL, &HlinkBrowseContext);
+        ok(hres == S_OK, "Expected S_OK, got %08x\n", hres);
+        CHECK_CALLED(HBC_GetObject);
+        todo_wine CHECK_CALLED(HBC_QueryInterface_IHlinkHistory);
+        todo_wine CHECK_CALLED(HBC_QueryInterface_IMarshal);
+        todo_wine CHECK_CALLED(HBC_QueryInterface_IdentityUnmarshal);
+        todo_wine CHECK_CALLED(HBC_QueryInterface_IUnknown);
+    }
+    else
+        skip("interactive IHlink_Navigate tests\n");
+
     IHlink_Release(hlink);
     IBindCtx_Release(pbc);
     _bctx = NULL;