Skip to content

Commit

Permalink
QDeclarative tests: Introduce base class for data tests.
Browse files Browse the repository at this point in the history
In tests/auto/shared/util.* replace macros/find functions by
a base class QDeclarativeDataTest with accessors for the
data directory helper functions to create URLs from it.

The class relies on QFINDTESTDATA, which is the standard
way of locating test data. Using the class should reduce
the number of calls to QFileInfo.exists(), etc significantly.

In addition, provide utility functions for messages.

Reviewed-by: Michael Brasser <michael.brasser@nokia.com>

Change-Id: Id2beacb157922ee9412f9e45cf9695cec1f8379a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
  • Loading branch information
Friedemann Kleint authored and Qt by Nokia committed Dec 21, 2011
1 parent 3c21155 commit 8249c72
Show file tree
Hide file tree
Showing 122 changed files with 1,900 additions and 1,917 deletions.
Expand Up @@ -3,10 +3,11 @@ TARGET = tst_qdeclarativedebugjs
QT += declarative-private testlib
macx:CONFIG -= app_bundle

HEADERS += ../shared/debugutil_p.h

HEADERS += ../shared/debugutil_p.h \
../../../shared/util.h
SOURCES += tst_qdeclarativedebugjs.cpp \
../shared/debugutil.cpp
../shared/debugutil.cpp \
../../../shared/util.cpp

INCLUDEPATH += ../shared

Expand Down
Expand Up @@ -159,7 +159,7 @@ do {\

class QJSDebugClient;

class tst_QDeclarativeDebugJS : public QObject
class tst_QDeclarativeDebugJS : public QDeclarativeDataTest
{
Q_OBJECT

Expand Down Expand Up @@ -982,6 +982,7 @@ QByteArray QJSDebugClient::packMessage(const QByteArray &type, const QByteArray

void tst_QDeclarativeDebugJS::initTestCase()
{
QDeclarativeDataTest::initTestCase();
t.start();
process = 0;
client = 0;
Expand Down Expand Up @@ -1014,9 +1015,9 @@ bool tst_QDeclarativeDebugJS::init(const QString &qmlFile, bool blockMode)
systemEnvironment << "QML_DISABLE_OPTIMIZER=1";
process->setEnvironment(systemEnvironment);
if (blockMode)
process->start(QStringList() << QLatin1String(BLOCKMODE) << TESTDATA(qmlFile));
process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(qmlFile));
else
process->start(QStringList() << QLatin1String(NORMALMODE) << TESTDATA(qmlFile));
process->start(QStringList() << QLatin1String(NORMALMODE) << testFile(qmlFile));

if (!process->waitForSessionStart()) {
return false;
Expand Down
Expand Up @@ -2,10 +2,12 @@ CONFIG += testcase
TARGET = tst_qdeclarativedebugtrace
macx:CONFIG -= app_bundle

HEADERS += ../shared/debugutil_p.h
HEADERS += ../shared/debugutil_p.h \
../../../shared/util.h

SOURCES += tst_qdeclarativedebugtrace.cpp \
../shared/debugutil.cpp
../shared/debugutil.cpp \
../../../shared/util.cpp

OTHER_FILES += data/test.qml

Expand Down
Expand Up @@ -75,7 +75,7 @@ class QDeclarativeDebugTraceClient : public QDeclarativeDebugClient
void messageReceived(const QByteArray &message);
};

class tst_QDeclarativeDebugTrace : public QObject
class tst_QDeclarativeDebugTrace : public QDeclarativeDataTest
{
Q_OBJECT

Expand Down Expand Up @@ -190,7 +190,7 @@ void tst_QDeclarativeDebugTrace::connect(bool block)
else
arguments << QString("-qmljsdebugger=port:"STR_PORT);

arguments << QString(TESTDATA(QLatin1String("test.qml")));
arguments << testFile("test.qml");

m_process = new QDeclarativeDebugProcess(executable);
m_process->start(QStringList() << arguments);
Expand Down
Expand Up @@ -2,10 +2,12 @@ CONFIG += testcase
TARGET = tst_qv8profilerservice
macx:CONFIG -= app_bundle

HEADERS += ../shared/debugutil_p.h
HEADERS += ../shared/debugutil_p.h \
../../../shared/util.h

SOURCES += tst_qv8profilerservice.cpp \
../shared/debugutil.cpp
../shared/debugutil.cpp \
../../../shared/util.cpp

OTHER_FILES += data/test.qml

Expand Down
Expand Up @@ -98,7 +98,7 @@ class QV8ProfilerClient : public QDeclarativeDebugClient
void messageReceived(const QByteArray &message);
};

class tst_QV8ProfilerService : public QObject
class tst_QV8ProfilerService : public QDeclarativeDataTest
{
Q_OBJECT

Expand Down Expand Up @@ -174,7 +174,7 @@ void tst_QV8ProfilerService::connect(bool block)
else
arguments << QString("-qmljsdebugger=port:"STR_PORT);

arguments << QString(TESTDATA(QLatin1String("test.qml")));
arguments << QDeclarativeDataTest::instance()->testFile("test.qml");

m_process = new QDeclarativeDebugProcess(executable);
m_process->start(QStringList() << arguments);
Expand Down
Expand Up @@ -2,7 +2,9 @@ CONFIG += testcase
TARGET = tst_qdeclarativebinding
macx:CONFIG -= app_bundle

SOURCES += tst_qdeclarativebinding.cpp
SOURCES += tst_qdeclarativebinding.cpp \
../../shared/util.cpp
HEADERS += ../../shared/util.h

testDataFiles.files = data
testDataFiles.path = .
Expand Down
Expand Up @@ -45,7 +45,7 @@
#include <QtQuick/private/qquickrectangle_p.h>
#include "../../shared/util.h"

class tst_qdeclarativebinding : public QObject
class tst_qdeclarativebinding : public QDeclarativeDataTest
{
Q_OBJECT
public:
Expand All @@ -69,7 +69,7 @@ tst_qdeclarativebinding::tst_qdeclarativebinding()
void tst_qdeclarativebinding::binding()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("test-binding.qml")));
QDeclarativeComponent c(&engine, testFileUrl("test-binding.qml"));
QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
QVERIFY(rect != 0);

Expand Down Expand Up @@ -97,7 +97,7 @@ void tst_qdeclarativebinding::binding()
void tst_qdeclarativebinding::whenAfterValue()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("test-binding2.qml")));
QDeclarativeComponent c(&engine, testFileUrl("test-binding2.qml"));
QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());

QVERIFY(rect != 0);
Expand All @@ -113,7 +113,7 @@ void tst_qdeclarativebinding::whenAfterValue()
void tst_qdeclarativebinding::restoreBinding()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("restoreBinding.qml")));
QDeclarativeComponent c(&engine, testFileUrl("restoreBinding.qml"));
QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
QVERIFY(rect != 0);

Expand Down Expand Up @@ -143,7 +143,7 @@ void tst_qdeclarativebinding::restoreBinding()
void tst_qdeclarativebinding::restoreBindingWithLoop()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("restoreBindingWithLoop.qml")));
QDeclarativeComponent c(&engine, testFileUrl("restoreBindingWithLoop.qml"));
QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
QVERIFY(rect != 0);

Expand Down Expand Up @@ -180,7 +180,7 @@ void tst_qdeclarativebinding::restoreBindingWithLoop()
void tst_qdeclarativebinding::deletedObject()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("deletedObject.qml")));
QDeclarativeComponent c(&engine, testFileUrl("deletedObject.qml"));
QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
QVERIFY(rect != 0);

Expand Down
Expand Up @@ -2,7 +2,9 @@ CONFIG += testcase
TARGET = tst_qdeclarativecomponent
macx:CONFIG -= app_bundle

SOURCES += tst_qdeclarativecomponent.cpp
SOURCES += tst_qdeclarativecomponent.cpp \
../../shared/util.cpp
HEADERS += ../../shared/util.h

testDataFiles.files = data
testDataFiles.path = .
Expand Down
Expand Up @@ -59,7 +59,7 @@ class MyIC : public QObject, public QDeclarativeIncubationController
}
};

class tst_qdeclarativecomponent : public QObject
class tst_qdeclarativecomponent : public QDeclarativeDataTest
{
Q_OBJECT
public:
Expand Down Expand Up @@ -107,7 +107,7 @@ void tst_qdeclarativecomponent::loadEmptyUrl()

void tst_qdeclarativecomponent::qmlIncubateObject()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("incubateObject.qml")));
QDeclarativeComponent component(&engine, testFileUrl("incubateObject.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
QCOMPARE(object->property("test1").toBool(), true);
Expand All @@ -121,7 +121,7 @@ void tst_qdeclarativecomponent::qmlIncubateObject()
void tst_qdeclarativecomponent::qmlCreateObject()
{
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("createObject.qml")));
QDeclarativeComponent component(&engine, testFileUrl("createObject.qml"));
QObject *object = component.create();
QVERIFY(object != 0);

Expand All @@ -138,7 +138,7 @@ void tst_qdeclarativecomponent::qmlCreateObject()
void tst_qdeclarativecomponent::qmlCreateObjectWithProperties()
{
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("createObjectWithScript.qml")));
QDeclarativeComponent component(&engine, testFileUrl("createObjectWithScript.qml"));
QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8());
QObject *object = component.create();
QVERIFY(object != 0);
Expand Down
Expand Up @@ -2,7 +2,9 @@ CONFIG += testcase
TARGET = tst_qdeclarativeconnection
macx:CONFIG -= app_bundle

SOURCES += tst_qdeclarativeconnection.cpp
SOURCES += tst_qdeclarativeconnection.cpp \
../../shared/util.cpp
HEADERS += ../../shared/util.h

testDataFiles.files = data
testDataFiles.path = .
Expand Down
Expand Up @@ -46,7 +46,7 @@
#include "../../shared/util.h"
#include <QtDeclarative/qdeclarativescriptstring.h>

class tst_qdeclarativeconnection : public QObject
class tst_qdeclarativeconnection : public QDeclarativeDataTest
{
Q_OBJECT
public:
Expand Down Expand Up @@ -75,7 +75,7 @@ tst_qdeclarativeconnection::tst_qdeclarativeconnection()
void tst_qdeclarativeconnection::defaultValues()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("test-connection3.qml")));
QDeclarativeComponent c(&engine, testFileUrl("test-connection3.qml"));
QDeclarativeConnections *item = qobject_cast<QDeclarativeConnections*>(c.create());

QVERIFY(item != 0);
Expand All @@ -87,7 +87,7 @@ void tst_qdeclarativeconnection::defaultValues()
void tst_qdeclarativeconnection::properties()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("test-connection2.qml")));
QDeclarativeComponent c(&engine, testFileUrl("test-connection2.qml"));
QDeclarativeConnections *item = qobject_cast<QDeclarativeConnections*>(c.create());

QVERIFY(item != 0);
Expand All @@ -101,7 +101,7 @@ void tst_qdeclarativeconnection::properties()
void tst_qdeclarativeconnection::connection()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("test-connection.qml")));
QDeclarativeComponent c(&engine, testFileUrl("test-connection.qml"));
QQuickItem *item = qobject_cast<QQuickItem*>(c.create());

QVERIFY(item != 0);
Expand All @@ -118,7 +118,7 @@ void tst_qdeclarativeconnection::connection()
void tst_qdeclarativeconnection::trimming()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("trimming.qml")));
QDeclarativeComponent c(&engine, testFileUrl("trimming.qml"));
QQuickItem *item = qobject_cast<QQuickItem*>(c.create());

QVERIFY(item != 0);
Expand All @@ -139,7 +139,7 @@ void tst_qdeclarativeconnection::trimming()
void tst_qdeclarativeconnection::targetChanged()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("connection-targetchange.qml")));
QDeclarativeComponent c(&engine, testFileUrl("connection-targetchange.qml"));
QQuickItem *item = qobject_cast<QQuickItem*>(c.create());
QVERIFY(item != 0);

Expand Down Expand Up @@ -176,7 +176,7 @@ void tst_qdeclarativeconnection::unknownSignals()
QFETCH(QString, file);
QFETCH(QString, error);

QUrl url = QUrl::fromLocalFile(TESTDATA(file));
QUrl url = testFileUrl(file);
if (!error.isEmpty()) {
QTest::ignoreMessage(QtWarningMsg, (url.toString() + error).toLatin1());
} else {
Expand Down Expand Up @@ -214,7 +214,7 @@ void tst_qdeclarativeconnection::errors()
QFETCH(QString, file);
QFETCH(QString, error);

QUrl url = QUrl::fromLocalFile(TESTDATA(file));
QUrl url = testFileUrl(file);

QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, url);
Expand Down Expand Up @@ -264,7 +264,7 @@ static QObject *module_api_factory(QDeclarativeEngine *engine, QJSEngine *script
void tst_qdeclarativeconnection::moduleApiTarget()
{
qmlRegisterModuleApi("MyTestModuleApi", 1, 0, module_api_factory);
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("moduleapi-target.qml")));
QDeclarativeComponent component(&engine, testFileUrl("moduleapi-target.qml"));
QObject *object = component.create();
QVERIFY(object != 0);

Expand Down
@@ -1,6 +1,8 @@
CONFIG += testcase
TARGET = tst_qdeclarativeconsole
SOURCES += tst_qdeclarativeconsole.cpp
SOURCES += tst_qdeclarativeconsole.cpp \
../../shared/util.cpp
HEADERS += ../../shared/util.h
macx:CONFIG -= app_bundle

testDataFiles.files = data
Expand Down
Expand Up @@ -44,7 +44,7 @@
#include <QDeclarativeComponent>
#include "../../shared/util.h"

class tst_qdeclarativeconsole : public QObject
class tst_qdeclarativeconsole : public QDeclarativeDataTest
{
Q_OBJECT
public:
Expand All @@ -58,11 +58,6 @@ private slots:
QDeclarativeEngine engine;
};

inline QUrl TEST_FILE(const QString &filename)
{
return QUrl::fromLocalFile(TESTDATA(filename));
}

void tst_qdeclarativeconsole::init()
{
qputenv("QML_CONSOLE_EXTENDED", QByteArray("1"));
Expand All @@ -71,37 +66,38 @@ void tst_qdeclarativeconsole::init()
void tst_qdeclarativeconsole::consoleLogExtended()
{
int startLineNumber = 15;
QUrl testFileUrl = TEST_FILE("consoleLog.qml");
QString testString = QString(QLatin1String("completed ok (%1:%2)")).arg(testFileUrl.toString());
QUrl testUrl = testFileUrl("consoleLog.qml");
const QString testUrlString = testUrl.toString();
QString testString = QString(QLatin1String("completed ok (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++)));
QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++)));
QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++)));
QTest::ignoreMessage(QtWarningMsg, qPrintable(testString.arg(startLineNumber++)));
QTest::ignoreMessage(QtCriticalMsg, qPrintable(testString.arg(startLineNumber++)));

QString testArray = QString(QLatin1String("[1,2] (%1:%2)")).arg(testFileUrl.toString());
QString testArray = QString(QLatin1String("[1,2] (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testArray.arg(startLineNumber++)));
QString testObject = QString(QLatin1String("Object (%1:%2)")).arg(testFileUrl.toString());
QString testObject = QString(QLatin1String("Object (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++)));
QString testUndefined = QString(QLatin1String("undefined (%1:%2)")).arg(testFileUrl.toString());
QString testUndefined = QString(QLatin1String("undefined (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testUndefined.arg(startLineNumber++)));
QString testNumber = QString(QLatin1String("12 (%1:%2)")).arg(testFileUrl.toString());
QString testNumber = QString(QLatin1String("12 (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testNumber.arg(startLineNumber++)));
QString testFunction = QString(QLatin1String("function () { return 5;} (%1:%2)")).arg(testFileUrl.toString());
QString testFunction = QString(QLatin1String("function () { return 5;} (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testFunction.arg(startLineNumber++)));
QString testBoolean = QString(QLatin1String("true (%1:%2)")).arg(testFileUrl.toString());
QString testBoolean = QString(QLatin1String("true (%1:%2)")).arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testBoolean.arg(startLineNumber++)));
QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++)));
QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++)));
QString testMix = QString::fromLatin1("1 pong! Object (%1:%2)").arg(testFileUrl.toString());
QString testMix = QString::fromLatin1("1 pong! Object (%1:%2)").arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testMix.arg(startLineNumber++)));
testMix = QString::fromLatin1("1 [ping,pong] Object 2 (%1:%2)").arg(testFileUrl.toString());
testMix = QString::fromLatin1("1 [ping,pong] Object 2 (%1:%2)").arg(testUrlString);
QTest::ignoreMessage(QtDebugMsg, qPrintable(testMix.arg(startLineNumber++)));

QString testException = QString(QLatin1String("%1:%2: ReferenceError: Can't find variable: exception")).arg(testFileUrl.toString());
QString testException = QString(QLatin1String("%1:%2: ReferenceError: Can't find variable: exception")).arg(testUrlString);
QTest::ignoreMessage(QtWarningMsg, qPrintable(testException.arg(startLineNumber++)));

QDeclarativeComponent component(&engine, testFileUrl);
QDeclarativeComponent component(&engine, testUrl);
QObject *object = component.create();
QVERIFY(object != 0);
delete object;
Expand Down

0 comments on commit 8249c72

Please sign in to comment.