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.9 6.8 Change-Id: Ib451048e40b163c2c3a3fffdf7b39bcb28c9cccf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
00a30f4312
commit
b03921eb9f
@ -25,6 +25,7 @@ qt_internal_add_test(tst_qcoreapplication
|
|||||||
VERSION ${target_version}
|
VERSION ${target_version}
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_qcoreapplication.cpp tst_qcoreapplication.h
|
tst_qcoreapplication.cpp tst_qcoreapplication.h
|
||||||
|
apphelper.h
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
Qt::CorePrivate
|
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()
|
void tst_QCoreApplication::testTrWithPercantegeAtTheEnd()
|
||||||
{
|
{
|
||||||
QCoreApplication::translate("testcontext", "this will crash%", "testdisamb", 3);
|
QCoreApplication::translate("testcontext", "this will crash%", "testdisamb", 3);
|
||||||
|
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
#include <QtCore/QtCore>
|
#include <QtCore/QtCore>
|
||||||
|
|
||||||
|
#include "apphelper.h"
|
||||||
|
|
||||||
class tst_QCoreApplication: public QObject
|
class tst_QCoreApplication: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
void runHelperTest();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void sendEventsOnProcessEvents(); // this must be the first test
|
void sendEventsOnProcessEvents(); // this must be the first test
|
||||||
@ -47,13 +48,13 @@ private slots:
|
|||||||
void applicationEventFilters_auxThread();
|
void applicationEventFilters_auxThread();
|
||||||
void threadedEventDelivery_data();
|
void threadedEventDelivery_data();
|
||||||
void threadedEventDelivery();
|
void threadedEventDelivery();
|
||||||
#if QT_CONFIG(process)
|
|
||||||
// also add to tst_qapplication.cpp
|
// also add to tst_qapplication.cpp
|
||||||
void exitFromEventLoop() { runHelperTest(); }
|
void exitFromEventLoop() { QCoreApplicationTestHelper::run(); }
|
||||||
void exitFromThread() { runHelperTest(); }
|
void exitFromThread() { QCoreApplicationTestHelper::run(); }
|
||||||
void exitFromThreadedEventLoop() { runHelperTest(); }
|
void exitFromThreadedEventLoop() { QCoreApplicationTestHelper::run(); }
|
||||||
void mainAppInAThread() { runHelperTest(); }
|
void mainAppInAThread() { QCoreApplicationTestHelper::run(); }
|
||||||
#endif
|
|
||||||
void testTrWithPercantegeAtTheEnd();
|
void testTrWithPercantegeAtTheEnd();
|
||||||
#if QT_CONFIG(library)
|
#if QT_CONFIG(library)
|
||||||
void addRemoveLibPaths();
|
void addRemoveLibPaths();
|
||||||
|
@ -47,6 +47,8 @@
|
|||||||
#include <private/qevent_p.h>
|
#include <private/qevent_p.h>
|
||||||
#include <private/qhighdpiscaling_p.h>
|
#include <private/qhighdpiscaling_p.h>
|
||||||
|
|
||||||
|
#include "../../../corelib/kernel/qcoreapplication/apphelper.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -58,7 +60,6 @@ class tst_QApplication : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
void runHelperTest();
|
|
||||||
private slots:
|
private slots:
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void sendEventsOnProcessEvents(); // this must be the first test
|
void sendEventsOnProcessEvents(); // this must be the first test
|
||||||
@ -93,12 +94,11 @@ private slots:
|
|||||||
void sendPostedEvents();
|
void sendPostedEvents();
|
||||||
#endif // ifdef QT_BUILD_INTERNAL
|
#endif // ifdef QT_BUILD_INTERNAL
|
||||||
|
|
||||||
#if QT_CONFIG(process)
|
void exitFromEventLoop() { QCoreApplicationTestHelper::run(); }
|
||||||
void exitFromEventLoop() { runHelperTest(); }
|
void exitFromThread() { QCoreApplicationTestHelper::run(); }
|
||||||
void exitFromThread() { runHelperTest(); }
|
void exitFromThreadedEventLoop() { QCoreApplicationTestHelper::run(); }
|
||||||
void exitFromThreadedEventLoop() { runHelperTest(); }
|
void mainAppInAThread() { QCoreApplicationTestHelper::run(); }
|
||||||
void mainAppInAThread() { runHelperTest(); }
|
|
||||||
#endif
|
|
||||||
void thread();
|
void thread();
|
||||||
void desktopSettingsAware();
|
void desktopSettingsAware();
|
||||||
|
|
||||||
@ -994,32 +994,6 @@ void tst_QApplication::sendPostedEvents()
|
|||||||
}
|
}
|
||||||
#endif
|
#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()
|
void tst_QApplication::thread()
|
||||||
{
|
{
|
||||||
QThread *currentThread = QThread::currentThread();
|
QThread *currentThread = QThread::currentThread();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user