From: Michael Brasser Date: Fri, 14 Oct 2011 02:02:43 +0000 (+1000) Subject: More use of TESTDATA macro. X-Git-Tag: qt-v5.0.0-alpha1~1383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=619e567e8f4cca6f4f97128057302f820ec03d43;p=profile%2Fivi%2Fqtdeclarative.git More use of TESTDATA macro. Change-Id: I65ff7aa44e18a60e431d30efec2717d2ce5f95e4 Reviewed-on: http://codereview.qt-project.org/6641 Reviewed-by: Rohan McGovern --- diff --git a/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro b/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro index 0e9b76b..a6f005e 100644 --- a/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro +++ b/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro @@ -10,11 +10,9 @@ SOURCES += tst_qdeclarativedebugjs.cpp \ INCLUDEPATH += ../shared -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -# LIBS += -lgcov - -OTHER_FILES = data/test.qml \ - data/test.js +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles CONFIG += parallel_test diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index 14e13a8..fbc1ff6 100644 --- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -52,6 +52,7 @@ //QDeclarativeDebugTest #include "../../../shared/util.h" #include "../shared/debugutil_p.h" +#include "../shared/util.h" const char *SEQ = "seq"; const char *TYPE = "type"; @@ -131,12 +132,6 @@ const char *JSFILE = "test.js"; jsonVal.setProperty(SEQ,QJSValue(seq++)); \ jsonVal.setProperty(TYPE,REQUEST); -inline QString TEST_FILE(const QString &filename) -{ - QFileInfo fileInfo(__FILE__); - return fileInfo.absoluteDir().filePath("data/" + filename); -} - class QJSDebugProcess; class QJSDebugClient; @@ -1056,7 +1051,7 @@ void tst_QDeclarativeDebugJS::init() process = new QJSDebugProcess(); client = new QJSDebugClient(connection); - process->start(QStringList() << QLatin1String(BLOCKMODE) << TEST_FILE(QLatin1String(QMLFILE))); + process->start(QStringList() << QLatin1String(BLOCKMODE) << TESTDATA(QLatin1String(QMLFILE))); QVERIFY(process->waitForSessionStart()); connection->connectToHost("127.0.0.1", 3771); diff --git a/tests/auto/declarative/qdeclarativeerror/test.txt b/tests/auto/declarative/qdeclarativeerror/data/test.txt similarity index 100% rename from tests/auto/declarative/qdeclarativeerror/test.txt rename to tests/auto/declarative/qdeclarativeerror/data/test.txt diff --git a/tests/auto/declarative/qdeclarativeerror/qdeclarativeerror.pro b/tests/auto/declarative/qdeclarativeerror/qdeclarativeerror.pro index b24c97e..11f6bea 100644 --- a/tests/auto/declarative/qdeclarativeerror/qdeclarativeerror.pro +++ b/tests/auto/declarative/qdeclarativeerror/qdeclarativeerror.pro @@ -3,8 +3,10 @@ TARGET = tst_qdeclarativeerror SOURCES += tst_qdeclarativeerror.cpp macx:CONFIG -= app_bundle -DEFINES += SRCDIR=\\\"$$PWD\\\" - CONFIG += parallel_test +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + QT += core-private gui-private declarative-private testlib diff --git a/tests/auto/declarative/qdeclarativeerror/tst_qdeclarativeerror.cpp b/tests/auto/declarative/qdeclarativeerror/tst_qdeclarativeerror.cpp index b05db9c..ab97d04 100644 --- a/tests/auto/declarative/qdeclarativeerror/tst_qdeclarativeerror.cpp +++ b/tests/auto/declarative/qdeclarativeerror/tst_qdeclarativeerror.cpp @@ -42,6 +42,7 @@ #include #include #include +#include "../shared/util.h" class tst_qdeclarativeerror : public QObject { @@ -207,7 +208,7 @@ void tst_qdeclarativeerror::debug() } { - QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt"))); + QUrl url(QUrl::fromLocalFile(TESTDATA("")).resolved(QUrl("test.txt"))); QDeclarativeError error; error.setUrl(url); error.setDescription("An Error"); @@ -221,7 +222,7 @@ void tst_qdeclarativeerror::debug() } { - QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt"))); + QUrl url(QUrl::fromLocalFile(TESTDATA("")).resolved(QUrl("foo.txt"))); QDeclarativeError error; error.setUrl(url); error.setDescription("An Error"); diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp index d9df460..4ac625e 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp +++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp @@ -46,6 +46,7 @@ #include "../shared/testhttpserver.h" #include "../../../shared/util.h" +#include "../shared/util.h" #define SERVER_ADDR "http://127.0.0.1:14450" #define SERVER_PORT 14450 @@ -81,7 +82,7 @@ private slots: QVERIFY(!component.isError()); \ QVERIFY(component.errors().isEmpty()); \ } else { \ - QString verify_errors_file_name = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + QLatin1String(errorfile); \ + QString verify_errors_file_name = TESTDATA(errorfile); \ QFile file(verify_errors_file_name); \ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \ QByteArray data = file.readAll(); \ @@ -101,7 +102,7 @@ private slots: qWarning() << "Expected:" << expected << "Actual:" << actual; \ } \ if (qgetenv("QDECLARATIVELANGUAGE_UPDATEERRORS") != "" && expected != actual) {\ - QFile file(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + QLatin1String(errorfile)); \ + QFile file(TESTDATA(errorfile)); \ QVERIFY(file.open(QIODevice::WriteOnly)); \ for (int ii = 0; ii < actual.count(); ++ii) { \ file.write(actual.at(ii)); file.write("\n"); \ @@ -114,17 +115,38 @@ private slots: inline QUrl TEST_FILE(const QString &filename) { - QFileInfo fileInfo(__FILE__); - return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename)); + return QUrl::fromLocalFile(TESTDATA(filename)); +} + +QString IMPORTSDIR() +{ + // Try to find it relative to the binary. + QDir appDir(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("imports")); + if (appDir.exists()) { + return appDir.absolutePath(); + } + + // Else try to find it in the source tree + QDir sourceDir(QFileInfo(__FILE__).absoluteDir().filePath(QLatin1String("imports"))); + if (sourceDir.exists()) { + return sourceDir.absolutePath(); + } + + qWarning("requested importsPath could not be found (looked at: %s, %s)", + qPrintable(appDir.path()), + qPrintable(sourceDir.path()) + ); + + return QString(); } void tst_qdeclarativemoduleplugin::importsPlugin() { QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); QTest::ignoreMessage(QtWarningMsg, "plugin created"); QTest::ignoreMessage(QtWarningMsg, "import worked"); - QDeclarativeComponent component(&engine, TEST_FILE("data/works.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("works.qml")); foreach (QDeclarativeError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); @@ -137,10 +159,10 @@ void tst_qdeclarativemoduleplugin::importsPlugin() void tst_qdeclarativemoduleplugin::importsPlugin2() { QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); QTest::ignoreMessage(QtWarningMsg, "plugin2 created"); QTest::ignoreMessage(QtWarningMsg, "import2 worked"); - QDeclarativeComponent component(&engine, TEST_FILE("data/works2.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("works2.qml")); foreach (QDeclarativeError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); @@ -153,10 +175,10 @@ void tst_qdeclarativemoduleplugin::importsPlugin2() void tst_qdeclarativemoduleplugin::importsPlugin21() { QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); QTest::ignoreMessage(QtWarningMsg, "plugin2.1 created"); QTest::ignoreMessage(QtWarningMsg, "import2.1 worked"); - QDeclarativeComponent component(&engine, TEST_FILE("data/works21.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("works21.qml")); foreach (QDeclarativeError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); @@ -169,9 +191,9 @@ void tst_qdeclarativemoduleplugin::importsPlugin21() void tst_qdeclarativemoduleplugin::incorrectPluginCase() { QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); - QDeclarativeComponent component(&engine, TEST_FILE("data/incorrectCase.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("incorrectCase.qml")); QList errors = component.errors(); QCOMPARE(errors.count(), 1); @@ -182,7 +204,7 @@ void tst_qdeclarativemoduleplugin::incorrectPluginCase() #elif defined(Q_OS_WIN32) QString libname = "PluGin.dll"; #endif - QString expectedError = QLatin1String("plugin cannot be loaded for module \"com.nokia.WrongCase\": File name case mismatch for \"") + QFileInfo(__FILE__).absoluteDir().filePath("imports/com/nokia/WrongCase/" + libname) + QLatin1String("\""); + QString expectedError = QLatin1String("plugin cannot be loaded for module \"com.nokia.WrongCase\": File name case mismatch for \"") + QDir(IMPORTSDIR()).filePath("com/nokia/WrongCase/" + libname) + QLatin1String("\""); #else QString expectedError = QLatin1String("module \"com.nokia.WrongCase\" plugin \"PluGin\" not found"); #endif @@ -192,7 +214,7 @@ void tst_qdeclarativemoduleplugin::incorrectPluginCase() void tst_qdeclarativemoduleplugin::importPluginWithQmlFile() { - QString path = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports"); + QString path = IMPORTSDIR(); // QTBUG-16885: adding an import path with a lower-case "c:" causes assert failure // (this only happens if the plugin includes pure QML files) @@ -204,7 +226,7 @@ void tst_qdeclarativemoduleplugin::importPluginWithQmlFile() QDeclarativeEngine engine; engine.addImportPath(path); - QDeclarativeComponent component(&engine, TEST_FILE("data/pluginWithQmlFile.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("pluginWithQmlFile.qml")); foreach (QDeclarativeError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); @@ -217,7 +239,7 @@ void tst_qdeclarativemoduleplugin::remoteImportWithQuotedUrl() { TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); - server.serveDirectory(SRCDIR "/imports"); + server.serveDirectory(IMPORTSDIR()); QDeclarativeEngine engine; QDeclarativeComponent component(&engine); @@ -238,10 +260,10 @@ void tst_qdeclarativemoduleplugin::remoteImportWithUnquotedUri() { TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); - server.serveDirectory(SRCDIR "/imports"); + server.serveDirectory(IMPORTSDIR()); QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); QDeclarativeComponent component(&engine); component.setData("import com.nokia.PureQmlModule 1.0 \nComponentA { width: 300; ComponentB{} }", QUrl()); @@ -261,10 +283,10 @@ void tst_qdeclarativemoduleplugin::remoteImportWithUnquotedUri() void tst_qdeclarativemoduleplugin::importsMixedQmlCppPlugin() { QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); { - QDeclarativeComponent component(&engine, TEST_FILE("data/importsMixedQmlCppPlugin.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("importsMixedQmlCppPlugin.qml")); QObject *o = component.create(); QVERIFY(o != 0); @@ -273,7 +295,7 @@ void tst_qdeclarativemoduleplugin::importsMixedQmlCppPlugin() } { - QDeclarativeComponent component(&engine, TEST_FILE("data/importsMixedQmlCppPlugin.2.qml")); + QDeclarativeComponent component(&engine, TEST_FILE("importsMixedQmlCppPlugin.2.qml")); QObject *o = component.create(); QVERIFY(o != 0); @@ -290,8 +312,8 @@ void tst_qdeclarativemoduleplugin::versionNotInstalled_data() QTest::addColumn("file"); QTest::addColumn("errorFile"); - QTest::newRow("versionNotInstalled") << "data/versionNotInstalled.qml" << "versionNotInstalled.errors.txt"; - QTest::newRow("versionNotInstalled") << "data/versionNotInstalled.2.qml" << "versionNotInstalled.2.errors.txt"; + QTest::newRow("versionNotInstalled") << "versionNotInstalled.qml" << "versionNotInstalled.errors.txt"; + QTest::newRow("versionNotInstalled") << "versionNotInstalled.2.qml" << "versionNotInstalled.2.errors.txt"; } void tst_qdeclarativemoduleplugin::versionNotInstalled() @@ -300,7 +322,7 @@ void tst_qdeclarativemoduleplugin::versionNotInstalled() QFETCH(QString, errorFile); QDeclarativeEngine engine; - engine.addImportPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("imports")); + engine.addImportPath(IMPORTSDIR()); QDeclarativeComponent component(&engine, TEST_FILE(file)); VERIFY_ERRORS(errorFile.toLatin1().constData()); @@ -326,8 +348,8 @@ void tst_qdeclarativemoduleplugin::implicitQmldir() QFETCH(QString, file); QFETCH(QString, errorFile); - QString importPath = QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("data") + QDir::separator() + directory; - QString fileName = QLatin1String("data") + QDir::separator() + directory + QDir::separator() + file; + QString importPath = TESTDATA(directory); + QString fileName = directory + QDir::separator() + file; QString errorFileName = directory + QDir::separator() + errorFile; QUrl testFileUrl = TEST_FILE(fileName); diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro index 6ae085c..94c0f9d 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro +++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro @@ -6,6 +6,12 @@ SOURCES = tst_qdeclarativemoduleplugin.cpp \ ../shared/testhttpserver.cpp CONFIG -= app_bundle -DEFINES += SRCDIR=\\\"$$PWD\\\" +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +testImportFiles.files = imports +testImportFiles.path = . +DEPLOYMENT += testImportFiles QT += core-private gui-private declarative-private network testlib diff --git a/tests/auto/declarative/qdeclarativesqldatabase/qdeclarativesqldatabase.pro b/tests/auto/declarative/qdeclarativesqldatabase/qdeclarativesqldatabase.pro index 014e8aa..2d0efec 100644 --- a/tests/auto/declarative/qdeclarativesqldatabase/qdeclarativesqldatabase.pro +++ b/tests/auto/declarative/qdeclarativesqldatabase/qdeclarativesqldatabase.pro @@ -4,8 +4,10 @@ macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativesqldatabase.cpp -DEFINES += SRCDIR=\\\"$$PWD\\\" - CONFIG += parallel_test +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + QT += core-private gui-private v8-private declarative-private sql testlib diff --git a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp index a74a7a6..0527427 100644 --- a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp +++ b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp @@ -54,6 +54,7 @@ #include #include #include +#include "../shared/util.h" class tst_qdeclarativesqldatabase : public QObject { @@ -133,22 +134,22 @@ void tst_qdeclarativesqldatabase::testQml_data() QTest::addColumn("jsfile"); // The input file // Each test should use a newly named DB to avoid inter-test dependencies - QTest::newRow("creation") << "data/creation.js"; - QTest::newRow("creation-a") << "data/creation-a.js"; - QTest::newRow("creation") << "data/creation.js"; - QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses above DB - QTest::newRow("changeversion") << "data/changeversion.js"; - QTest::newRow("readonly") << "data/readonly.js"; - QTest::newRow("readonly-error") << "data/readonly-error.js"; - QTest::newRow("selection") << "data/selection.js"; - QTest::newRow("selection-bindnames") << "data/selection-bindnames.js"; - QTest::newRow("iteration") << "data/iteration.js"; - QTest::newRow("iteration-forwardonly") << "data/iteration-forwardonly.js"; - QTest::newRow("error-a") << "data/error-a.js"; - QTest::newRow("error-notransaction") << "data/error-notransaction.js"; - QTest::newRow("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above - QTest::newRow("reopen1") << "data/reopen1.js"; - QTest::newRow("reopen2") << "data/reopen2.js"; // re-uses above DB + QTest::newRow("creation") << "creation.js"; + QTest::newRow("creation-a") << "creation-a.js"; + QTest::newRow("creation") << "creation.js"; + QTest::newRow("error-creation") << "error-creation.js"; // re-uses above DB + QTest::newRow("changeversion") << "changeversion.js"; + QTest::newRow("readonly") << "readonly.js"; + QTest::newRow("readonly-error") << "readonly-error.js"; + QTest::newRow("selection") << "selection.js"; + QTest::newRow("selection-bindnames") << "selection-bindnames.js"; + QTest::newRow("iteration") << "iteration.js"; + QTest::newRow("iteration-forwardonly") << "iteration-forwardonly.js"; + QTest::newRow("error-a") << "error-a.js"; + QTest::newRow("error-notransaction") << "error-notransaction.js"; + QTest::newRow("error-outsidetransaction") << "error-outsidetransaction.js"; // reuse above + QTest::newRow("reopen1") << "reopen1.js"; + QTest::newRow("reopen2") << "reopen2.js"; // re-uses above DB // If you add a test, you should usually use a new database in the // test - in which case increment total_databases_created_by_tests above. @@ -204,7 +205,7 @@ void tst_qdeclarativesqldatabase::testQml() engine->setOfflineStoragePath(dbDir()); QDeclarativeComponent component(engine); - component.setData(qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports + component.setData(qml.toUtf8(), QUrl::fromLocalFile(TESTDATA("empty.qml"))); // just a file for relative local imports QVERIFY(!component.isError()); QSGText *text = qobject_cast(component.create()); QVERIFY(text != 0); @@ -214,9 +215,9 @@ void tst_qdeclarativesqldatabase::testQml() void tst_qdeclarativesqldatabase::testQml_cleanopen_data() { QTest::addColumn("jsfile"); // The input file - QTest::newRow("reopen1") << "data/reopen1.js"; - QTest::newRow("reopen2") << "data/reopen2.js"; - QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses creation DB + QTest::newRow("reopen1") << "reopen1.js"; + QTest::newRow("reopen2") << "reopen2.js"; + QTest::newRow("error-creation") << "error-creation.js"; // re-uses creation DB } void tst_qdeclarativesqldatabase::testQml_cleanopen()