[PATCH 2/4] shell32/tests: Add tests for ShellLinkObject.

Myah Caron qsniyg at protonmail.com
Sun Sep 13 15:34:07 CDT 2020


Signed-off-by: Myah Caron <qsniyg at protonmail.com>
---
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 | 148 +++++++++++++++++++++++++++++
 1 file changed, 148 insertions(+)

diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c
index 54957875615..3c1c473dede 100644
--- a/dlls/shell32/tests/shelldispatch.c
+++ b/dlls/shell32/tests/shelldispatch.c
@@ -1408,6 +1408,153 @@ 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];
+    CHAR tempA[MAX_PATH];
+    VARIANT v;
+    Folder2 *folder2;
+    Folder *folder;
+    FolderItem *item;
+    IDispatch *dispatch;
+    IShellLinkA *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_IShellLinkA, (LPVOID*)&sl);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    GetFullPathNameA("winetest_empty_file.txt", MAX_PATH, tempA, NULL);
+    hr = IShellLinkA_SetPath(sl, tempA);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IShellLinkA_SetDescription(sl, "description");
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IShellLinkA_SetWorkingDirectory(sl, "working directory");
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IShellLinkA_SetArguments(sl, "arguments");
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IShellLinkA_SetHotkey(sl, 1234);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    hr = IShellLinkA_SetShowCmd(sl, 1);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = IShellLinkA_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);
+    IShellLinkA_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) {
+            GetFullPathNameW(L"winetest_empty_file.txt", MAX_PATH, tempW, NULL);
+            ok(!wcscmp(str, tempW), "got %s\n", wine_dbgstr_w(str));
+            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 +1613,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