diff options
author | Daniel Pope <daniel.pope@nokia.com> | 2010-12-10 11:54:28 +1000 |
---|---|---|
committer | Daniel Pope <daniel.pope@nokia.com> | 2010-12-10 11:54:28 +1000 |
commit | b55b2570ab79108d1774cc37826ae23360ab4a6f (patch) | |
tree | b43f6782f5d443348c05d27a02f404cd64760658 | |
parent | 0959997cfa97b21d19c0ba806ece14f649fd4789 (diff) | |
parent | 2bd706c898383a7dae051d0d119c05b0f5a671cd (diff) |
Merge branch 'master' of scm.dev.nokia.troll.no:research/qtest-qml
-rw-r--r-- | doc/testcases.txt | 6 | ||||
-rw-r--r-- | features/qmltestcase.prf | 7 | ||||
-rw-r--r-- | src/qmltestrunner/main.cpp | 75 | ||||
-rw-r--r-- | src/qmltestrunner/qmltestrunner.pro | 12 | ||||
-rw-r--r-- | src/quicktestlib/quicktest.cpp | 39 | ||||
-rw-r--r-- | src/src.pro | 2 |
6 files changed, 139 insertions, 2 deletions
diff --git a/doc/testcases.txt b/doc/testcases.txt index 3ba44bc..5c6282a 100644 --- a/doc/testcases.txt +++ b/doc/testcases.txt @@ -73,6 +73,12 @@ See "tests/qmlexample" for an example of creating a test harness that uses resources and "tests/qmlauto" for an example that uses the QUICK_TEST_SOURCE_DIR macro. +If your test case needs QML imports, then you can add them as +"-import" options to the the test program command-line by adding +the following line to your .pro file: + + IMPORTPATH += $$PWD/../imports/my_module1 $$PWD/../imports/my_module2 + Basic test cases ================ diff --git a/features/qmltestcase.prf b/features/qmltestcase.prf index d5cbedc..de3c641 100644 --- a/features/qmltestcase.prf +++ b/features/qmltestcase.prf @@ -15,3 +15,10 @@ win32:CONFIG(debug, debug|release) { } else { LIBS += -lQtQuickTest$${QT_LIBINFIX} } + +# If the .pro file specified an IMPORTPATH, then add that to +# the command-line when the test is run. +!isEmpty(IMPORTPATH) { + load(testcase) + for(import, IMPORTPATH): check.commands += -import \"$$import\" +} diff --git a/src/qmltestrunner/main.cpp b/src/qmltestrunner/main.cpp new file mode 100644 index 0000000..47f34ee --- /dev/null +++ b/src/qmltestrunner/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQuickTest/quicktest.h> +#include <QtCore/qstring.h> +#ifdef QT_OPENGL_LIB +#include <QtOpenGL/qgl.h> +#endif + +#ifdef QT_OPENGL_LIB + +static QWidget *qmltestrunner_create_gl_viewport() +{ + return new QGLWidget(); +} + +#endif + +int main(int argc, char **argv) +{ +#ifdef QT_OPENGL_LIB + bool isOpenGL = false; + for (int index = 1; index < argc; ++index) { + if (strcmp(argv[index], "-opengl") == 0) { + isOpenGL = true; + break; + } + } + if (isOpenGL) { + return quick_test_main(argc, argv, "qmltestrunner", + qmltestrunner_create_gl_viewport, "."); + } else +#endif + { + return quick_test_main(argc, argv, "qmltestrunner", 0, "."); + } +} diff --git a/src/qmltestrunner/qmltestrunner.pro b/src/qmltestrunner/qmltestrunner.pro new file mode 100644 index 0000000..e954754 --- /dev/null +++ b/src/qmltestrunner/qmltestrunner.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = qmltestrunner +CONFIG += warn_on +SOURCES += main.cpp +include(../quicktestlib/quicktestlib_dep.pri) + +contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) { + QT += opengl +} + +target.path = $$[QT_INSTALL_BINS] +INSTALLS += target diff --git a/src/quicktestlib/quicktest.cpp b/src/quicktestlib/quicktest.cpp index d4e9fe3..ce00cde 100644 --- a/src/quicktestlib/quicktest.cpp +++ b/src/quicktestlib/quicktest.cpp @@ -96,13 +96,48 @@ private: bool m_windowShown; }; +static inline QString stripQuotes(const QString &s) +{ + if (s.length() >= 2 && s.startsWith(QLatin1Char('"')) && s.endsWith(QLatin1Char('"'))) + return s.mid(1, s.length() - 2); + else + return s; +} + int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport_create createViewport, const char *sourceDir) { QApplication app(argc, argv); + // Look for QML-specific command-line options. + // -import dir Specify an import directory. + // -input dir Specify the input directory for test cases. + QStringList imports; + QString testPath; + int outargc = 1; + int index = 1; + while (index < argc) { + if (strcmp(argv[index], "-import") == 0 && (index + 1) < argc) { + imports += stripQuotes(QString::fromLocal8Bit(argv[index + 1])); + index += 2; + } else if (strcmp(argv[index], "-input") == 0 && (index + 1) < argc) { + testPath = stripQuotes(QString::fromLocal8Bit(argv[index + 1])); + index += 2; + } else if (strcmp(argv[index], "-opengl") == 0) { + ++index; + } else if (outargc != index) { + argv[outargc++] = argv[index++]; + } else { + ++outargc; + ++index; + } + } + argv[outargc] = 0; + argc = outargc; + // Determine where to look for the test data. If QUICK_TEST_SOURCE_DIR // is set, then use that. Otherwise scan the application's resources. - QString testPath = QString::fromLocal8Bit(qgetenv("QUICK_TEST_SOURCE_DIR")); + if (testPath.isEmpty()) + testPath = QString::fromLocal8Bit(qgetenv("QUICK_TEST_SOURCE_DIR")); if (testPath.isEmpty() && sourceDir) testPath = QString::fromLocal8Bit(sourceDir); if (testPath.isEmpty()) @@ -154,6 +189,8 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport = engine->globalObject().property(QLatin1String("Qt")); qtObject.setProperty (QLatin1String("qtest_wrapper"), engine->newVariant(true)); + foreach (QString path, imports) + view.engine()->addImportPath(path); QString path = fi.absoluteFilePath(); if (path.startsWith(QLatin1String(":/"))) view.setSource(QUrl(QLatin1String("qrc:") + path.mid(2))); diff --git a/src/src.pro b/src/src.pro index e323dcf..45c5c6c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -SUBDIRS = quicktestlib imports +SUBDIRS = quicktestlib imports qmltestrunner CONFIG += ordered |