diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-20 11:51:21 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-20 17:12:17 +0200 |
commit | 354c7577188cfffd417fd973b8611d84174eba85 (patch) | |
tree | 1382935302b2b2ec00b6b8a922d663db14dfaecf /tests/postbuild | |
parent | c1917763a500cf9606a5b638410c62824ec06fb9 (diff) |
guiapplauncher: Fix deprecated API
- Use QString::fromUtf16 with char16_t in Qt 6
- Use QThread::msleep() which is public since Qt 5
- Polish a bit, add override
Change-Id: Ia0f599d66d4b71689cc0c7577242c9b87261bb9c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/postbuild')
-rw-r--r-- | tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp | 7 | ||||
-rw-r--r-- | tests/postbuild/guiapplauncher/windowmanager.cpp | 51 | ||||
-rw-r--r-- | tests/postbuild/guiapplauncher/windowmanager.h | 2 |
3 files changed, 28 insertions, 32 deletions
diff --git a/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp b/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp index c3aa3615..0bf62cad 100644 --- a/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp +++ b/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp @@ -29,6 +29,7 @@ #include "windowmanager.h" #include <QtCore/QDir> +#include <QtCore/QThread> #include <QtCore/QString> #include <QtTest/QtTest> #include <QtCore/QProcess> @@ -190,7 +191,7 @@ void tst_GuiAppLauncher::run() QFETCH(AppLaunchData, data); const bool rc = runApp(data, &errorMessage); if (!rc) // Wait for windows to disappear after kill - WindowManager::sleepMS(500); + QThread::msleep(500); QVERIFY2(rc, qPrintable(errorMessage)); } @@ -348,10 +349,10 @@ bool tst_GuiAppLauncher::runApp(const AppLaunchData &data, QString *errorMessage } qDebug("Window: %s\n", qPrintable(winId)); // Wait a bit, then send close - WindowManager::sleepMS(data.upTimeMS); + QThread::msleep(data.upTimeMS); if (m_wm->sendCloseEvent(winId, process.pid(), errorMessage)) { qDebug("Sent close to window: %s\n", qPrintable(winId)); - } else { + } else { ensureTerminated(&process); return false; } diff --git a/tests/postbuild/guiapplauncher/windowmanager.cpp b/tests/postbuild/guiapplauncher/windowmanager.cpp index c2e9f774..2cc82cc7 100644 --- a/tests/postbuild/guiapplauncher/windowmanager.cpp +++ b/tests/postbuild/guiapplauncher/windowmanager.cpp @@ -40,16 +40,10 @@ # include <X11/Xmd.h> // CARD32 #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -# include <windows.h> +#if defined(Q_OS_WIN) +# include <qt_windows.h> #endif -// Export the sleep function -class FriendlySleepyThread : public QThread { -public: - static void sleepMS(int milliSeconds) { msleep(milliSeconds); } -}; - #ifdef Q_WS_X11 // X11 Window manager @@ -58,7 +52,7 @@ public: // can be checked after calls. static unsigned x11ErrorCount = 0; -static const char *currentX11Function = 0; +static const char *currentX11Function = nullptr; int xErrorHandler(Display *, XErrorEvent *e) { @@ -189,10 +183,12 @@ public: ~X11_WindowManager(); protected: - virtual bool isDisplayOpenImpl() const; - virtual bool openDisplayImpl(QString *errorMessage); - virtual QString waitForTopLevelWindowImpl(unsigned count, Q_PID, int timeOutMS, QString *errorMessage); - virtual bool sendCloseEventImpl(const QString &winId, Q_PID pid, QString *errorMessage); + bool isDisplayOpenImpl() const override; + bool openDisplayImpl(QString *errorMessage) override; + QString waitForTopLevelWindowImpl(unsigned count, Q_PID, int timeOutMS, + QString *errorMessage) override; + bool sendCloseEventImpl(const QString &winId, Q_PID pid, + QString *errorMessage) override; private: Display *m_display; @@ -282,19 +278,23 @@ QString X11_WindowManager::waitForTopLevelWindowImpl(unsigned count, Q_PID, int #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) // Windows QString winErrorMessage(unsigned long error) { QString rc = QString::fromLatin1("#%1: ").arg(error); - ushort *lpMsgBuf; + char16_t *lpMsgBuf; const int len = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL); + NULL, error, 0, reinterpret_cast<LPTSTR>(&lpMsgBuf), 0, nullptr); if (len) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) rc = QString::fromUtf16(lpMsgBuf, len); +#else + rc = QString::fromUtf16(reinterpret_cast<const ushort *>(lpMsgBuf), len); +#endif LocalFree(lpMsgBuf); } else { rc += QString::fromLatin1("<unknown error>"); @@ -308,10 +308,12 @@ QString X11_WindowManager::waitForTopLevelWindowImpl(unsigned count, Q_PID, int Win_WindowManager() {} protected: - virtual bool isDisplayOpenImpl() const; - virtual bool openDisplayImpl(QString *errorMessage); - virtual QString waitForTopLevelWindowImpl(unsigned count, Q_PID, int timeOutMS, QString *errorMessage); - virtual bool sendCloseEventImpl(const QString &winId, Q_PID pid, QString *errorMessage); + bool isDisplayOpenImpl() const override; + bool openDisplayImpl(QString *errorMessage) override; + QString waitForTopLevelWindowImpl(unsigned count, Q_PID, int timeOutMS, + QString *errorMessage) override; + virtual bool sendCloseEventImpl(const QString &winId, Q_PID pid, + QString *errorMessage) override; private: }; @@ -384,14 +386,14 @@ QString Win_WindowManager::waitForTopLevelWindowImpl(unsigned /* count */, Q_PID EnumWindows(findProcessWindowEnumWindowProc, reinterpret_cast<LPARAM>(&context)); if (context.window) return QLatin1String("0x") + QString::number(reinterpret_cast<quintptr>(context.window), 16); - sleepMS(intervalMilliSeconds); + QThread::msleep(intervalMilliSeconds); } *errorMessage = QString::fromLatin1("Unable to find toplevel of process %1 after %2ms.").arg(pid->dwProcessId).arg(timeOutMS); return QString(); } bool Win_WindowManager::sendCloseEventImpl(const QString &winId, Q_PID, QString *errorMessage) -{ +{ // Convert window back. quintptr winIdIntPtr; QTextStream str(const_cast<QString*>(&winId), QIODevice::ReadOnly); @@ -488,8 +490,3 @@ bool WindowManager::sendCloseEventImpl(const QString &, Q_PID, QString *errorMes *errorMessage = QLatin1String("Not implemented."); return false; } - -void WindowManager::sleepMS(int milliSeconds) -{ - FriendlySleepyThread::sleepMS(milliSeconds); -} diff --git a/tests/postbuild/guiapplauncher/windowmanager.h b/tests/postbuild/guiapplauncher/windowmanager.h index 1c346159..e61ea4ac 100644 --- a/tests/postbuild/guiapplauncher/windowmanager.h +++ b/tests/postbuild/guiapplauncher/windowmanager.h @@ -51,8 +51,6 @@ public: QString waitForTopLevelWindow(unsigned count, Q_PID pid, int timeOutMS, QString *errorMessage); bool sendCloseEvent(const QString &winId, Q_PID pid, QString *errorMessage); - static void sleepMS(int milliSeconds); - protected: WindowManager(); |