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 --- .../qcoreapplication/tst_qcoreapplication.cpp | 82 ++++++++++------------ 1 file changed, 37 insertions(+), 45 deletions(-) (limited to 'tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp') 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" -- cgit v1.2.3