diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-22 08:29:11 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-22 11:03:20 +0100 |
commit | 7b62a85892572f77b811ead26363ce8b1b220829 (patch) | |
tree | 994bbe67b3f97764dcd5374f69bab6cc679a7f24 /tests/postbuild | |
parent | 3fde5410cdcc1167768cc00b941c407ba3db87a8 (diff) |
Fix build of the manual gui app launcher test on Windows
Remove the dependency on Q_PID returned in 5.15 and obtain
the process handle via pid.
Fix the test to work with 5.15 and 6.
Pick-to: master
Fixes: QTBUG-91268
Change-Id: Id9058b30e98811626157111971201536e40d627a
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'tests/postbuild')
-rw-r--r-- | tests/postbuild/guiapplauncher/windowmanager.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/tests/postbuild/guiapplauncher/windowmanager.cpp b/tests/postbuild/guiapplauncher/windowmanager.cpp index f628efb6..c3372235 100644 --- a/tests/postbuild/guiapplauncher/windowmanager.cpp +++ b/tests/postbuild/guiapplauncher/windowmanager.cpp @@ -341,7 +341,7 @@ struct FindProcessWindowEnumContext { static inline bool isQtMainWindow(HWND hwnd) { static char buffer[MAX_PATH]; - if (!GetClassNameA(hwnd, buffer, MAX_PATH) || qstrcmp(buffer, "QWidget")) + if (!GetClassNameA(hwnd, buffer, MAX_PATH) || qstrncmp(buffer, "Qt", 2)) return false; WINDOWINFO windowInfo; if (!GetWindowInfo(hwnd, &windowInfo)) @@ -349,8 +349,8 @@ static inline bool isQtMainWindow(HWND hwnd) if (!(windowInfo.dwWindowStatus & WS_ACTIVECAPTION)) return false; // Check the style for a real mainwindow - const DWORD excluded = WS_DISABLED | WS_POPUP; - const DWORD required = WS_CAPTION | WS_SYSMENU | WS_VISIBLE; + const DWORD excluded = WS_DISABLED; + const DWORD required = WS_CAPTION | WS_SYSMENU | WS_VISIBLE; return (windowInfo.dwStyle & excluded) == 0 && (windowInfo.dwStyle & required) == required; } @@ -367,12 +367,36 @@ static BOOL CALLBACK findProcessWindowEnumWindowProc(HWND hwnd, LPARAM lParam) return TRUE; } +class ScopedHandle +{ +public: + explicit ScopedHandle(HANDLE h) : m_handle(h) {} + ~ScopedHandle() { CloseHandle(m_handle); } + operator HANDLE() const { return m_handle; } + + ScopedHandle(const ScopedHandle &) = delete; + ScopedHandle &operator=(const ScopedHandle &) = delete; + +private: + const HANDLE m_handle; +}; + QString Win_WindowManager::waitForTopLevelWindowImpl(unsigned /* count */, qint64 pid, int timeOutMS, QString *errorMessage) { + const auto processId = DWORD(pid); + const ScopedHandle hProcess(OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, + processId)); + if (hProcess == nullptr) { + const int errorCode = GetLastError(); + qErrnoWarning(errorCode, "OpenProcess() failed (error %d).", errorCode); + *errorMessage = QString::fromLatin1("OpenProcess()"); + return QString(); + } + QElapsedTimer elapsed; elapsed.start(); // First, wait until the application is up - if (WaitForInputIdle(pid->hProcess, timeOutMS) != 0) { + if (WaitForInputIdle(hProcess, timeOutMS) != 0) { *errorMessage = QString::fromLatin1("WaitForInputIdle time out after %1ms").arg(timeOutMS); return QString(); } @@ -382,13 +406,14 @@ QString Win_WindowManager::waitForTopLevelWindowImpl(unsigned /* count */, qint6 const int attempts = 10; const int intervalMilliSeconds = remainingMilliSeconds / attempts; for (int a = 0; a < attempts; a++) { - FindProcessWindowEnumContext context(pid->dwProcessId); + FindProcessWindowEnumContext context(processId); EnumWindows(findProcessWindowEnumWindowProc, reinterpret_cast<LPARAM>(&context)); if (context.window) return QLatin1String("0x") + QString::number(reinterpret_cast<quintptr>(context.window), 16); QThread::msleep(intervalMilliSeconds); } - *errorMessage = QString::fromLatin1("Unable to find toplevel of process %1 after %2ms.").arg(pid->dwProcessId).arg(timeOutMS); + *errorMessage = QString::fromLatin1("Unable to find toplevel of process %1 after %2ms.") + .arg(pid).arg(timeOutMS); return QString(); } |