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 <fabian.kosmale@qt.io> (cherry picked from commit b03921eb9fad7a71dc13d92af2e0e994fcc1ca67) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9e18d7ded5
commit
eaff6a7a03
@ -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
|
||||
)
|
||||
|
50
tests/auto/corelib/kernel/qcoreapplication/apphelper.h
Normal file
50
tests/auto/corelib/kernel/qcoreapplication/apphelper.h
Normal file
@ -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 <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qprocess.h>
|
||||
#include <QtCore/qstandardpaths.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
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
|
@ -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);
|
||||
|
@ -7,10 +7,11 @@
|
||||
|
||||
#include <QtCore/QtCore>
|
||||
|
||||
#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();
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include <private/qevent_p.h>
|
||||
#include <private/qhighdpiscaling_p.h>
|
||||
|
||||
#include "../../../corelib/kernel/qcoreapplication/apphelper.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user