[PATCH v2 2/4] shell32/tests: Add tests for ShellLinkObject.
Myah Caron
qsniyg at protonmail.com
Sun Sep 13 16:27:37 CDT 2020
Signed-off-by: Myah Caron <qsniyg at protonmail.com>
---
v2:
- Use IShellLinkW instead of IShellLinkA.
- Fix test failures under w2008 by using IShellLink_GetPath instead of synthesizing the path.
Not everything is tested yet. I figured more tests can be added as needed, as this patchset
is primarily intended to implement get_Path.
dlls/shell32/tests/shelldispatch.c | 149 +++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c
index 54957875615..899a6b8de76 100644
--- a/dlls/shell32/tests/shelldispatch.c
+++ b/dlls/shell32/tests/shelldispatch.c
@@ -1408,6 +1408,154 @@ if (0) { /* crashes on winxp/win2k3 */
IShellDispatch_Release(sd);
}
+static void test_ShellLinkObject(void)
+{
+ HRESULT hr;
+ IShellDispatch *sd;
+ WCHAR path[MAX_PATH], orig_dir[MAX_PATH], tempW[MAX_PATH];
+ VARIANT v;
+ Folder2 *folder2;
+ Folder *folder;
+ FolderItem *item;
+ IDispatch *dispatch;
+ IShellLinkW *sl;
+ IShellLinkDual2* sld;
+ IPersistFile *pf;
+ BOOL ret;
+ BSTR str;
+ FILE* fp;
+ int hk;
+
+ hr = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IShellDispatch, (void**)&sd);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ GetTempPathW(MAX_PATH, path);
+ GetCurrentDirectoryW(MAX_PATH, orig_dir);
+ SetCurrentDirectoryW(path);
+ V_VT(&v) = VT_BSTR;
+ V_BSTR(&v) = SysAllocString(path);
+ hr = IShellDispatch_NameSpace(sd, v, &folder);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ VariantClear(&v);
+
+ hr = Folder_QueryInterface(folder, &IID_Folder2, (void**)&folder2);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ Folder_Release(folder);
+
+ hr = Folder2_get_Self(folder2, &item);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ dispatch = (IDispatch*)0xdeadbeef;
+ hr = FolderItem_get_GetLink(item, &dispatch);
+ ok(hr == E_NOTIMPL, "got 0x%08x\n", hr);
+ ok(dispatch == NULL, "got %p\n", dispatch);
+
+ FolderItem_Release(item);
+
+ fp = fopen("winetest_empty_file.txt", "w");
+ ok(!!fp, "got %p\n", fp);
+ fclose(fp);
+
+ hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ GetFullPathNameW(L"winetest_empty_file.txt", MAX_PATH, tempW, NULL);
+ hr = IShellLinkW_SetPath(sl, tempW);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_GetPath(sl, tempW, MAX_PATH, NULL, 0);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_SetDescription(sl, L"description");
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_SetWorkingDirectory(sl, L"working directory");
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_SetArguments(sl, L"arguments");
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_SetHotkey(sl, 1234);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ hr = IShellLinkW_SetShowCmd(sl, 1);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = IPersistFile_Save(pf, L"winetest_filled.lnk", TRUE);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ IPersistFile_Release(pf);
+ IShellLinkW_Release(sl);
+
+ str = SysAllocString(L"winetest_filled.lnk");
+ Folder2_ParseName(folder2, str, &item);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ SysFreeString(str);
+
+ dispatch = (IDispatch*)0xdeadbeef;
+ hr = FolderItem_get_GetLink(item, &dispatch);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine ok(dispatch && dispatch != (IDispatch*)0xdeadbeef, "got %p\n", dispatch);
+
+ if (dispatch) {
+ sld = (IShellLinkDual2*)dispatch;
+
+ str = (BSTR)0xdeadbeef;
+ hr = IShellLinkDual2_get_Path(sld, &str);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ if (hr == S_OK) {
+ ok(!wcscmp(str, tempW), "got %s (wanted %s)\n",
+ wine_dbgstr_w(str), wine_dbgstr_w(tempW));
+ SysFreeString(str);
+ }
+
+ str = (BSTR)0xdeadbeef;
+ hr = IShellLinkDual2_get_Description(sld, &str);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ if (hr == S_OK) {
+ ok(!wcscmp(str, L"description"), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+ }
+
+ str = (BSTR)0xdeadbeef;
+ hr = IShellLinkDual2_get_WorkingDirectory(sld, &str);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ if (hr == S_OK) {
+ ok(!wcscmp(str, L"working directory"), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+ }
+
+ str = (BSTR)0xdeadbeef;
+ hr = IShellLinkDual2_get_Arguments(sld, &str);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ if (hr == S_OK) {
+ ok(!wcscmp(str, L"arguments"), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+ }
+
+ hk = 0;
+ hr = IShellLinkDual2_get_Hotkey(sld, &hk);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine ok(hk == 1234, "got %i\n", hk);
+
+ hk = 0;
+ hr = IShellLinkDual2_get_ShowCommand(sld, &hk);
+ todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine ok(hk == 1, "got %i\n", hk);
+
+ IShellLinkDual2_Release(sld);
+ }
+
+ FolderItem_Release(item);
+
+ ret = DeleteFileA("winetest_filled.lnk");
+ ok(ret, "DeleteFile failed: %08x\n", GetLastError());
+ ret = DeleteFileA("winetest_empty_file.txt");
+ ok(ret, "DeleteFile failed: %08x\n", GetLastError());
+
+ Folder2_Release(folder2);
+ SetCurrentDirectoryW(orig_dir);
+
+ IShellDispatch_Release(sd);
+}
+
static void test_ShellExecute(void)
{
HRESULT hr;
@@ -1466,6 +1614,7 @@ START_TEST(shelldispatch)
test_ShellWindows();
test_ParseName();
test_Verbs();
+ test_ShellLinkObject();
test_ShellExecute();
CoUninitialize();
--
2.28.0
More information about the wine-devel
mailing list