r = IHlink_GetStringReference(lnk, HLINKGETREF_DEFAULT, &str, NULL);
ok(r == S_OK, "failed\n");
- todo_wine {
ok(!lstrcmpW(str, url2), "url wrong\n");
- }
CoTaskMemFree(str);
r = IHlink_GetStringReference(lnk, HLINKGETREF_DEFAULT, NULL, NULL);
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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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));
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(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);
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(fnd_loc);
+
+ 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);
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(fnd_loc);
+
+ 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);
+}
+
+#define setStringRef(h,f,t,l) r_setStringRef(__LINE__,h,f,t,l)
+static void r_setStringRef(unsigned line, IHlink *hlink, DWORD flags, const WCHAR *tgt, const WCHAR *loc)
+{
+ HRESULT hres;
+ hres = IHlink_SetStringReference(hlink, flags, tgt, loc);
+ ok_(__FILE__,line) (hres == S_OK, "IHlink_SetStringReference failed: 0x%08x\n", hres);
+}
+
+#define getStringRef(h,t,l) r_getStringRef(__LINE__,h,t,l)
+static void r_getStringRef(unsigned line, IHlink *hlink, const WCHAR *exp_tgt, const WCHAR *exp_loc)
+{
+ HRESULT hres;
+ WCHAR *fnd_tgt, *fnd_loc;
+
+ hres = IHlink_GetStringReference(hlink, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+ ok_(__FILE__,line) (hres == S_OK, "IHlink_GetStringReference failed: 0x%08x\n", hres);
+
+ if(exp_tgt)
+ ok_(__FILE__,line) (!lstrcmpW(fnd_tgt, exp_tgt), "Found string target should have been %s, was: %s\n", wine_dbgstr_w(exp_tgt), wine_dbgstr_w(fnd_tgt));
+ else
+ ok_(__FILE__,line) (exp_tgt == NULL, "Found string target should have been NULL, was: %s\n", wine_dbgstr_w(fnd_tgt));
+
+ if(exp_loc)
+ ok_(__FILE__,line) (!lstrcmpW(fnd_loc, exp_loc), "Found string location should have been %s, was: %s\n", wine_dbgstr_w(exp_loc), wine_dbgstr_w(fnd_loc));
+ else
+ ok_(__FILE__,line) (exp_loc == NULL, "Found string location should have been NULL, was: %s\n", wine_dbgstr_w(fnd_loc));
+
+ CoTaskMemFree(fnd_tgt);
+ CoTaskMemFree(fnd_loc);
+}
+
+#define setMonikerRef(h,f,t,l) r_setMonikerRef(__LINE__,h,f,t,l)
+static void r_setMonikerRef(unsigned line, IHlink *hlink, DWORD flags, IMoniker *tgt, const WCHAR *loc)
+{
+ HRESULT hres;
+ hres = IHlink_SetMonikerReference(hlink, flags, tgt, loc);
+ ok_(__FILE__,line) (hres == S_OK, "IHlink_SetMonikerReference failed: 0x%08x\n", hres);
+}
+
+/* passing 0xFFFFFFFF as exp_tgt will return the retrieved target & not test it */
+#define getMonikerRef(h,t,l) r_getMonikerRef(__LINE__,h,t,l)
+static IMoniker *r_getMonikerRef(unsigned line, IHlink *hlink, IMoniker *exp_tgt, const WCHAR *exp_loc)
+{
+ HRESULT hres;
+ IMoniker *fnd_tgt;
+ WCHAR *fnd_loc;
+
+ hres = IHlink_GetMonikerReference(hlink, HLINKGETREF_DEFAULT, &fnd_tgt, &fnd_loc);
+ ok_(__FILE__,line) (hres == S_OK, "IHlink_GetMonikerReference failed: 0x%08x\n", hres);
+
+ if(exp_loc)
+ ok_(__FILE__,line) (!lstrcmpW(fnd_loc, exp_loc), "Found string location should have been %s, was: %s\n", wine_dbgstr_w(exp_loc), wine_dbgstr_w(fnd_loc));
+ else
+ ok_(__FILE__,line) (exp_loc == NULL, "Found string location should have been NULL, was: %s\n", wine_dbgstr_w(fnd_loc));
+
+ CoTaskMemFree(fnd_loc);
+
+ if(exp_tgt == (IMoniker*)0xFFFFFFFF)
+ return fnd_tgt;
+
+ ok_(__FILE__,line) (fnd_tgt == exp_tgt, "Found moniker target should have been %p, was: %p\n", exp_tgt, fnd_tgt);
+
+ if(fnd_tgt)
+ IMoniker_Release(fnd_tgt);
+
+ return NULL;
+}
+
+static void test_HlinkMoniker(void)
+{
+ IHlink *hlink;
+ IMoniker *aMon, *file_mon;
+ static const WCHAR emptyW[] = {0};
+ static const WCHAR wordsW[] = {'w','o','r','d','s',0};
+ static const WCHAR aW[] = {'a',0};
+ static const WCHAR bW[] = {'b',0};
+ HRESULT hres;
+
+ hres = HlinkCreateFromString(NULL, NULL, NULL, NULL, 0, NULL, &IID_IHlink, (void**)&hlink);
+ ok(hres == S_OK, "HlinkCreateFromString failed: 0x%08x\n", hres);
+ getStringRef(hlink, NULL, NULL);
+ getMonikerRef(hlink, NULL, NULL);
+
+ /* setting a string target creates a moniker reference */
+ setStringRef(hlink, HLINKSETF_TARGET | HLINKSETF_LOCATION, aW, wordsW);
+ getStringRef(hlink, aW, wordsW);
+ aMon = getMonikerRef(hlink, (IMoniker*)0xFFFFFFFF, wordsW);
+ ok(aMon != NULL, "Moniker from %s target should not be NULL\n", wine_dbgstr_w(aW));
+ if(aMon)
+ IMoniker_Release(aMon);
+
+ /* setting target & location to the empty string deletes the moniker
+ * reference */
+ setStringRef(hlink, HLINKSETF_TARGET | HLINKSETF_LOCATION, emptyW, emptyW);
+ getStringRef(hlink, NULL, NULL);
+ getMonikerRef(hlink, NULL, NULL);
+
+ /* setting a moniker target also sets the target string to that moniker's
+ * display name */
+ hres = CreateFileMoniker(bW, &file_mon);
+ ok(hres == S_OK, "CreateFileMoniker failed: 0x%08x\n", hres);
+
+ setMonikerRef(hlink, HLINKSETF_TARGET | HLINKSETF_LOCATION, file_mon, wordsW);
+ getStringRef(hlink, bW, wordsW);
+ getMonikerRef(hlink, file_mon, wordsW);
+
+ IMoniker_Release(file_mon);
+
+ IHlink_Release(hlink);
+}
+
START_TEST(hlink)
{
CoInitialize(NULL);
test_HlinkParseDisplayName();
test_HlinkResolveMonikerForData();
test_HlinkGetSetMonikerReference();
+ test_HlinkGetSetStringReference();
+ test_HlinkMoniker();
CoUninitialize();
}