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 <gabriel.dedietrich@digia.com>
This commit is contained in:
Tor Arne Vestbø 2013-09-25 16:28:24 +02:00 committed by The Qt Project
parent 3bcc44268e
commit 2c925906f5
5 changed files with 122 additions and 49 deletions

View File

@ -2,3 +2,4 @@ CONFIG += testcase parallel_test
TARGET = tst_qcoreapplication
QT = core testlib core-private
SOURCES = tst_qcoreapplication.cpp
HEADERS = tst_qcoreapplication.h

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "tst_qcoreapplication.h"
#include <QtCore/QtCore>
#include <QtTest/QtTest>
@ -46,31 +48,12 @@
#include <private/qeventloop_p.h>
#include <private/qthread_p.h>
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();
#ifdef QT_GUI_LIB
#include <QtGui/QGuiApplication>
typedef QGuiApplication TestApplication;
#else
typedef QCoreApplication TestApplication;
#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();
};
class EventSpy : public QObject
{
@ -89,7 +72,7 @@ void tst_QCoreApplication::sendEventsOnProcessEvents()
{
int argc = 1;
char *argv[] = { const_cast<char*>(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<char*>(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<char*>("tst_qcoreapplication") };
QCoreApplication app(argc, argv);
QCOMPARE(::qAppName(), QString::fromLatin1("tst_qcoreapplication"));
QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1("tst_qcoreapplication"));
char *argv[] = { const_cast<char*>(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<char*>(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<char*>("arg1"),
const_cast<char*>("arg2"),
const_cast<char*>("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<char*>(QTest::currentAppName()),
const_cast<char*>("-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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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<char*>(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"

View File

@ -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 <QtCore/QtCore>
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

View File

@ -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

View File

@ -50,9 +50,11 @@
#include <QDebug>
#include "tst_qcoreapplication.h"
enum { spacing = 50, windowSize = 200 };
class tst_QGuiApplication: public QObject
class tst_QGuiApplication: public tst_QCoreApplication
{
Q_OBJECT