[SHELL32_APITEST] ShellExecuteEx: Add test for 'properties' verb
authorMark Jansen <mark.jansen@reactos.org>
Tue, 1 Feb 2022 22:22:44 +0000 (23:22 +0100)
committerMark Jansen <mark.jansen@reactos.org>
Thu, 3 Feb 2022 20:50:34 +0000 (21:50 +0100)
CORE-18035

modules/rostests/apitests/shell32/ShellExecuteEx.cpp

index 6f32157..3e33c07 100644 (file)
@@ -256,7 +256,11 @@ static VOID DoTestEntry(const TEST_ENTRY *pEntry)
     free(s_wi1.phwnd);
     ZeroMemory(&s_wi1, sizeof(s_wi1));
 
-    WaitForSingleObject(info.hProcess, INFINITE);
+    if (WaitForSingleObject(info.hProcess, 10 * 1000) == WAIT_TIMEOUT)
+    {
+        TerminateProcess(info.hProcess, 11);
+        ok(0, "Process %s did not quit!\n", pEntry->file);
+    }
     CloseHandle(info.hProcess);
 }
 
@@ -364,8 +368,101 @@ static void DoTestEntries(void)
     free(s_wi0.phwnd);
 }
 
+WCHAR* ExeName = NULL;
+
+BOOL CALLBACK EnumProc(_In_ HWND hwnd, _In_ LPARAM lParam)
+{
+    DWORD pid = 0;
+    GetWindowThreadProcessId(hwnd, &pid);
+    if (pid == GetCurrentProcessId() &&
+        IsWindowVisible(hwnd))
+    {
+        WCHAR Buffer[512] = {0};
+
+        GetWindowTextW(hwnd, Buffer, _countof(Buffer) - 1);
+        if (Buffer[0] && StrStrIW(Buffer, ExeName))
+        {
+            HWND* pHwnd = (HWND*)lParam;
+            *pHwnd = hwnd;
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
+
+BOOL WaitAndCloseWindow()
+{
+    HWND hWnd = NULL;
+    for (int n = 0; n < 100; ++n)
+    {
+        Sleep(50);
+
+        EnumWindows(EnumProc, (LPARAM)&hWnd);
+
+        if (hWnd)
+        {
+            SendMessageW(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
+            return TRUE;
+            break;
+        }
+    }
+    return FALSE;
+}
+
+static void test_properties()
+{
+    WCHAR Buffer[MAX_PATH * 4];
+
+    CoInitialize(NULL);
+
+    GetModuleFileNameW(NULL, Buffer, _countof(Buffer));
+    SHELLEXECUTEINFOW info = { 0 };
+
+    info.cbSize = sizeof(SHELLEXECUTEINFOW);
+    info.fMask = SEE_MASK_INVOKEIDLIST | SEE_MASK_FLAG_NO_UI;
+    info.lpVerb = L"properties";
+    info.lpFile = Buffer;
+    info.lpParameters = L"";
+    info.nShow = SW_SHOW;
+
+    BOOL bRet = ShellExecuteExW(&info);
+    ok(bRet, "Failed! (GetLastError(): %d)\n", (int)GetLastError());
+    ok_ptr(info.hInstApp, (HINSTANCE)42);
+
+    ExeName = PathFindFileNameW(Buffer);
+    WCHAR* Extension = PathFindExtensionW(Buffer);
+    if (Extension)
+    {
+        // The inclusion of this depends on the file display settings!
+        *Extension = UNICODE_NULL;
+    }
+
+    if (bRet)
+    {
+        ok(WaitAndCloseWindow(), "Could not find properties window!\n");
+    }
+
+    // Now retry it with the extension cut off
+    bRet = ShellExecuteExW(&info);
+    ok(bRet, "Failed! (GetLastError(): %d)\n", (int)GetLastError());
+    ok_ptr(info.hInstApp, (HINSTANCE)42);
+
+    if (bRet)
+    {
+        ok(WaitAndCloseWindow(), "Could not find properties window!\n");
+    }
+
+    info.lpFile = L"complete garbage, cannot run this!";
+
+    // Now retry it with complete garabage
+    bRet = ShellExecuteExW(&info);
+    ok(bRet == 0, "Succeeded!\n");
+    ok_ptr(info.hInstApp, (HINSTANCE)2);
+}
+
 START_TEST(ShellExecuteEx)
 {
     DoAppPathTest();
     DoTestEntries();
+    test_properties();
 }