From eaff6a7a03ed87135d2f9d6f287c379b3f84dde3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 3 Mar 2025 13:14:55 -0300 Subject: [PATCH] tst_Q*Application: centralize even more the running of the helper app Instead of having to make changes to both tst_qcoreapplication.cpp and tst_qapplication.cpp. Pick-to: 6.8 Change-Id: Ib451048e40b163c2c3a3fffdf7b39bcb28c9cccf Reviewed-by: Fabian Kosmale (cherry picked from commit b03921eb9fad7a71dc13d92af2e0e994fcc1ca67) Reviewed-by: Qt Cherry-pick Bot --- .../kernel/qcoreapplication/CMakeLists.txt | 1 + .../kernel/qcoreapplication/apphelper.h | 50 +++++++++++++++++++ .../qcoreapplication/tst_qcoreapplication.cpp | 27 ---------- .../qcoreapplication/tst_qcoreapplication.h | 15 +++--- .../kernel/qapplication/tst_qapplication.cpp | 40 +++------------ 5 files changed, 66 insertions(+), 67 deletions(-) create mode 100644 tests/auto/corelib/kernel/qcoreapplication/apphelper.h diff --git a/tests/auto/corelib/kernel/qcoreapplication/CMakeLists.txt b/tests/auto/corelib/kernel/qcoreapplication/CMakeLists.txt index 9a4e57a0972..687b4744b28 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/CMakeLists.txt +++ b/tests/auto/corelib/kernel/qcoreapplication/CMakeLists.txt @@ -25,6 +25,7 @@ qt_internal_add_test(tst_qcoreapplication VERSION ${target_version} SOURCES tst_qcoreapplication.cpp tst_qcoreapplication.h + apphelper.h LIBRARIES Qt::CorePrivate ) diff --git a/tests/auto/corelib/kernel/qcoreapplication/apphelper.h b/tests/auto/corelib/kernel/qcoreapplication/apphelper.h new file mode 100644 index 00000000000..13747153d20 --- /dev/null +++ b/tests/auto/corelib/kernel/qcoreapplication/apphelper.h @@ -0,0 +1,50 @@ +// Copyright (C) 2025 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef APPHELPER_H +#define APPHELPER_H + +#include +#include +#include + +#include + +namespace QCoreApplicationTestHelper { +#if !QT_CONFIG(process) +inline void run() +{ + QSKIP("No QProcess in this build."); +} +#elif defined(Q_OS_ANDROID) +inline void run() +{ + QSKIP("Skipped on Android: helper not present"); +} +#else +# if defined(Q_OS_WIN) +# define EXE ".exe" +# else +# define EXE "" +# endif + +inline void run() +{ + int argc = 0; + QCoreApplication app(argc, nullptr); + QProcess process; + process.start(QFINDTESTDATA("apphelper" EXE), { QTest::currentTestFunction() }); + QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); + if (qint8(process.exitCode()) == -1) + QSKIP("Process requested skip: " + process.readAllStandardOutput().trimmed()); + + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.readAllStandardError(), QString()); + QCOMPARE(process.exitCode(), 0); +} +#undef EXE +#endif // QT_CONFIG(process) +} // namespace + + +#endif // APPHELPER_H diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 9b721a28d3d..6505700ed70 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -1210,33 +1210,6 @@ void tst_QCoreApplication::threadedEventDelivery() } -#if QT_CONFIG(process) -#if defined(Q_OS_WIN) -# define EXE ".exe" -#else -# define EXE "" -#endif -void tst_QCoreApplication::runHelperTest() -{ -# ifdef Q_OS_ANDROID - QSKIP("Skipped on Android: helper not present"); -# endif - int argc = 0; - QCoreApplication app(argc, nullptr); - QProcess process; - process.start(QFINDTESTDATA("apphelper" EXE), { QTest::currentTestFunction() }); - QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); - if (qint8(process.exitCode()) == -1) - QSKIP("Process requested skip: " + process.readAllStandardOutput().trimmed()); - - - QCOMPARE(process.readAllStandardError(), QString()); - QCOMPARE(process.exitStatus(), QProcess::NormalExit); - QCOMPARE(process.exitCode(), 0); -} -#undef EXE -#endif - void tst_QCoreApplication::testTrWithPercantegeAtTheEnd() { QCoreApplication::translate("testcontext", "this will crash%", "testdisamb", 3); diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index cd1224e2cc7..4d044c4a6e8 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -7,10 +7,11 @@ #include +#include "apphelper.h" + class tst_QCoreApplication: public QObject { Q_OBJECT - void runHelperTest(); private slots: void sendEventsOnProcessEvents(); // this must be the first test @@ -47,13 +48,13 @@ private slots: void applicationEventFilters_auxThread(); void threadedEventDelivery_data(); void threadedEventDelivery(); -#if QT_CONFIG(process) + // also add to tst_qapplication.cpp - void exitFromEventLoop() { runHelperTest(); } - void exitFromThread() { runHelperTest(); } - void exitFromThreadedEventLoop() { runHelperTest(); } - void mainAppInAThread() { runHelperTest(); } -#endif + void exitFromEventLoop() { QCoreApplicationTestHelper::run(); } + void exitFromThread() { QCoreApplicationTestHelper::run(); } + void exitFromThreadedEventLoop() { QCoreApplicationTestHelper::run(); } + void mainAppInAThread() { QCoreApplicationTestHelper::run(); } + void testTrWithPercantegeAtTheEnd(); #if QT_CONFIG(library) void addRemoveLibPaths(); diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 2fafa287a8c..7198f0f9832 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -46,6 +46,8 @@ #include #include +#include "../../../corelib/kernel/qcoreapplication/apphelper.h" + #include QT_BEGIN_NAMESPACE @@ -57,7 +59,6 @@ class tst_QApplication : public QObject { Q_OBJECT - void runHelperTest(); private slots: void cleanup(); void sendEventsOnProcessEvents(); // this must be the first test @@ -92,12 +93,11 @@ private slots: void sendPostedEvents(); #endif // ifdef QT_BUILD_INTERNAL -#if QT_CONFIG(process) - void exitFromEventLoop() { runHelperTest(); } - void exitFromThread() { runHelperTest(); } - void exitFromThreadedEventLoop() { runHelperTest(); } - void mainAppInAThread() { runHelperTest(); } -#endif + void exitFromEventLoop() { QCoreApplicationTestHelper::run(); } + void exitFromThread() { QCoreApplicationTestHelper::run(); } + void exitFromThreadedEventLoop() { QCoreApplicationTestHelper::run(); } + void mainAppInAThread() { QCoreApplicationTestHelper::run(); } + void thread(); void desktopSettingsAware(); @@ -993,32 +993,6 @@ void tst_QApplication::sendPostedEvents() } #endif -#if QT_CONFIG(process) -#if defined(Q_OS_WIN) -# define EXE ".exe" -#else -# define EXE "" -#endif -void tst_QApplication::runHelperTest() -{ -# ifdef Q_OS_ANDROID - QSKIP("Skipped on Android: helper not present"); -# endif - int argc = 0; - QCoreApplication app(argc, nullptr); - QProcess process; - process.start(QFINDTESTDATA("apphelper" EXE), { QTest::currentTestFunction() }); - QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); - if (qint8(process.exitCode()) == -1) - QSKIP("Process requested skip: " + process.readAllStandardOutput().trimmed()); - - QCOMPARE(process.readAllStandardError(), QString()); - QCOMPARE(process.exitStatus(), QProcess::NormalExit); - QCOMPARE(process.exitCode(), 0); -} -#undef EXE -#endif - void tst_QApplication::thread() { QThread *currentThread = QThread::currentThread();