From 2c925906f516e7e47db9e82ed8bda1f675ab414a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Sep 2013 16:28:24 +0200 Subject: Base tst_QGuiApplication on tst_QCoreApplication to increase GUI ED coverage The QCoreApplication test has quite a few test cases that we would like to exercise using the GUI event-dispatcher. Instead of duplicating the tests for the GUI dispatcher, we inherit tst_QCoreApplication, which also lets us add extra tests that are specific to tst_QGuiApplication. Change-Id: Ib411457131b8d3fed871f682c1c0568577f6127d Reviewed-by: Gabriel de Dietrich --- .../kernel/qcoreapplication/qcoreapplication.pro | 1 + .../qcoreapplication/tst_qcoreapplication.cpp | 82 ++++++++++------------ .../kernel/qcoreapplication/tst_qcoreapplication.h | 73 +++++++++++++++++++ .../gui/kernel/qguiapplication/qguiapplication.pro | 11 ++- .../kernel/qguiapplication/tst_qguiapplication.cpp | 4 +- 5 files changed, 122 insertions(+), 49 deletions(-) create mode 100644 tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro index 14df20c986..0602b9fc38 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro +++ b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro @@ -2,3 +2,4 @@ CONFIG += testcase parallel_test TARGET = tst_qcoreapplication QT = core testlib core-private SOURCES = tst_qcoreapplication.cpp +HEADERS = tst_qcoreapplication.h diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 78f2cdae69..760303a027 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ +#include "tst_qcoreapplication.h" + #include #include @@ -46,31 +48,12 @@ #include #include -class tst_QCoreApplication: public QObject -{ - Q_OBJECT -private slots: - void sendEventsOnProcessEvents(); // this must be the first test - void getSetCheck(); - void qAppName(); -#ifndef Q_OS_WIN - void argc(); -#endif - void postEvent(); - void removePostedEvents(); -#ifndef QT_NO_THREAD - void deliverInDefinedOrder(); +#ifdef QT_GUI_LIB +#include +typedef QGuiApplication TestApplication; +#else +typedef QCoreApplication TestApplication; #endif - void applicationPid(); - void globalPostedEventsCount(); - void processEventsAlwaysSendsPostedEvents(); - void reexec(); - void execAfterExit(); - void eventLoopExecAfterExit(); - void customEventDispatcher(); - void testQuitLock(); - void QTBUG31606_QEventDestructorDeadLock(); -}; class EventSpy : public QObject { @@ -89,7 +72,7 @@ void tst_QCoreApplication::sendEventsOnProcessEvents() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); EventSpy spy; app.installEventFilter(&spy); @@ -111,7 +94,7 @@ void tst_QCoreApplication::getSetCheck() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCOMPARE(app.property("applicationVersion").toString(), v); } v = QString(); @@ -121,11 +104,17 @@ void tst_QCoreApplication::getSetCheck() void tst_QCoreApplication::qAppName() { +#ifdef QT_GUI_LIB + const char* appName = "tst_qguiapplication"; +#else + const char* appName = "tst_qcoreapplication"; +#endif + int argc = 1; - char *argv[] = { const_cast("tst_qcoreapplication") }; - QCoreApplication app(argc, argv); - QCOMPARE(::qAppName(), QString::fromLatin1("tst_qcoreapplication")); - QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1("tst_qcoreapplication")); + char *argv[] = { const_cast(appName) }; + TestApplication app(argc, argv); + QCOMPARE(::qAppName(), QString::fromLatin1(appName)); + QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1(appName)); } // "QCoreApplication::arguments() always parses arguments from actual command line on Windows @@ -136,7 +125,7 @@ void tst_QCoreApplication::argc() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.arguments().count(), 1); } @@ -147,7 +136,7 @@ void tst_QCoreApplication::argc() const_cast("arg1"), const_cast("arg2"), const_cast("arg3") }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCOMPARE(argc, 4); QCOMPARE(app.arguments().count(), 4); } @@ -155,7 +144,7 @@ void tst_QCoreApplication::argc() { int argc = 0; char **argv = 0; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCOMPARE(argc, 0); QCOMPARE(app.arguments().count(), 0); } @@ -164,7 +153,7 @@ void tst_QCoreApplication::argc() int argc = 2; char *argv[] = { const_cast(QTest::currentAppName()), const_cast("-qmljsdebugger=port:3768,block") }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.arguments().count(), 1); } @@ -197,7 +186,7 @@ void tst_QCoreApplication::postEvent() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); EventSpy spy; EventGenerator odd, even; @@ -282,7 +271,7 @@ void tst_QCoreApplication::removePostedEvents() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); EventSpy spy; QObject one, two; @@ -461,7 +450,7 @@ void tst_QCoreApplication::deliverInDefinedOrder() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); DeliverInDefinedOrderObject obj(&app); // causes sendPostedEvents() to recurse twice @@ -501,7 +490,7 @@ void tst_QCoreApplication::globalPostedEventsCount() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QCoreApplication::sendPostedEvents(); QCOMPARE(qGlobalPostedEventsCount(), 0u); @@ -547,7 +536,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); ProcessEventsAlwaysSendsPostedEventsObject object; QTime t; @@ -565,7 +554,7 @@ void tst_QCoreApplication::reexec() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); // exec once QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); @@ -580,7 +569,7 @@ void tst_QCoreApplication::execAfterExit() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); app.exit(1); QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); @@ -591,7 +580,7 @@ void tst_QCoreApplication::eventLoopExecAfterExit() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); // exec once and exit QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); @@ -649,7 +638,7 @@ void tst_QCoreApplication::customEventDispatcher() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); // instantiating app should not overwrite the ED QCOMPARE(QCoreApplication::eventDispatcher(), ed); QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection); @@ -764,7 +753,7 @@ void tst_QCoreApplication::testQuitLock() { int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); QuitTester tester; app.exec(); @@ -783,7 +772,7 @@ void tst_QCoreApplication::QTBUG31606_QEventDestructorDeadLock() int argc = 1; char *argv[] = { const_cast(QTest::currentAppName()) }; - QCoreApplication app(argc, argv); + TestApplication app(argc, argv); EventSpy spy; app.installEventFilter(&spy); @@ -810,5 +799,8 @@ static void createQObjectOnDestruction() } Q_DESTRUCTOR_FUNCTION(createQObjectOnDestruction) +#ifndef QT_GUI_LIB QTEST_APPLESS_MAIN(tst_QCoreApplication) +#endif + #include "tst_qcoreapplication.moc" diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h new file mode 100644 index 0000000000..16ade27f83 --- /dev/null +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TST_QCOREAPPLICATION_H +#define TST_QCOREAPPLICATION_H + +#include + +class tst_QCoreApplication: public QObject +{ + Q_OBJECT +private slots: + void sendEventsOnProcessEvents(); // this must be the first test + void getSetCheck(); + void qAppName(); +#ifndef Q_OS_WIN + void argc(); +#endif + void postEvent(); + void removePostedEvents(); +#ifndef QT_NO_THREAD + void deliverInDefinedOrder(); +#endif + void applicationPid(); + void globalPostedEventsCount(); + void processEventsAlwaysSendsPostedEvents(); + void reexec(); + void execAfterExit(); + void eventLoopExecAfterExit(); + void customEventDispatcher(); + void testQuitLock(); + void QTBUG31606_QEventDestructorDeadLock(); +}; + +#endif // TST_QCOREAPPLICATION_H diff --git a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro index a9baf29996..79acb9e5f1 100644 --- a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro +++ b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro @@ -1,4 +1,9 @@ -CONFIG += testcase +CORE_TEST_PATH = ../../../corelib/kernel/qcoreapplication + +VPATH += $$CORE_TEST_PATH +include($${CORE_TEST_PATH}/qcoreapplication.pro) +INCLUDEPATH += $$CORE_TEST_PATH + TARGET = tst_qguiapplication -QT += core gui gui-private testlib -SOURCES = tst_qguiapplication.cpp +QT += gui gui-private +SOURCES += tst_qguiapplication.cpp diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 7884426d68..d4237b135f 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -50,9 +50,11 @@ #include +#include "tst_qcoreapplication.h" + enum { spacing = 50, windowSize = 200 }; -class tst_QGuiApplication: public QObject +class tst_QGuiApplication: public tst_QCoreApplication { Q_OBJECT -- cgit v1.2.3