summaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/imports.pro3
-rw-r--r--src/imports/testlib/TestCase.qml244
-rw-r--r--src/imports/testlib/main.cpp62
-rw-r--r--src/imports/testlib/qmldir2
-rw-r--r--src/imports/testlib/testlib.pro35
-rw-r--r--src/imports/testlib/testlogger.js164
6 files changed, 510 insertions, 0 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
new file mode 100644
index 0000000..8f369d3
--- /dev/null
+++ b/src/imports/imports.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = testlib
+CONFIG += ordered
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
new file mode 100644
index 0000000..61a2ff9
--- /dev/null
+++ b/src/imports/testlib/TestCase.qml
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+import Qt 4.7
+import QtTest 1.0
+import "testlogger.js" as TestLogger
+
+Item {
+ id: testCase
+ visible: false
+
+ // Name of the test case to prefix the function name in messages.
+ property string name
+
+ // Set to true to start the test running.
+ property bool when: true
+
+ // Set to true once the test has completed.
+ property bool completed: false
+
+ // Set to true when the test is running but not yet complete.
+ property bool running: false
+
+ // Set to true if the test doesn't have to run (because some
+ // other test failed which this one depends on).
+ property bool optional: false
+
+ // Internal private state
+ property string currentTestCase
+ property bool expectingFail
+ property string expectFailMsg
+ property bool prevWhen: true
+ property int testId: -1
+
+ TestReport { id: reporter }
+
+ function fail(msg) {
+ if (!msg)
+ msg = "";
+ if (expectingFail) {
+ TestLogger.log_expect_fail(currentTestCase, expectFailMsg, msg)
+ throw new Error("QtTest::expect_fail")
+ } else {
+ TestLogger.log_fail(currentTestCase, msg)
+ throw new Error("QtTest::fail")
+ }
+ }
+
+ function fail2(msg, msg2) {
+ if (msg)
+ fail(msg + ": " + msg2)
+ else
+ fail(msg2)
+ }
+
+ function verify(cond, msg) {
+ if (!cond)
+ fail(msg)
+ }
+
+ function compare(actual, expected, msg) {
+ if (typeof actual == "number" && typeof expected == "number") {
+ // Use a fuzzy compare if the two values are floats
+ if (Math.abs(actual - expected) <= 0.00001)
+ return
+ } else if (typeof actual == "object" && typeof expected == "object") {
+ // Does the expected value look like a vector3d?
+ if ("x" in expected && "y" in expected && "z" in expected) {
+ if (Math.abs(actual.x - expected.x) <= 0.00001 &&
+ Math.abs(actual.y - expected.y) <= 0.00001 &&
+ Math.abs(actual.z - expected.z) <= 0.00001)
+ return
+ fail2(msg, "actual: Qt.vector3d(" +
+ actual.x + ", " + actual.y + ", " + actual.z +
+ "), expected: Qt.vector3d(" +
+ expected.x + ", " + expected.y + ", " + expected.z +
+ ")")
+ return
+ }
+ if (actual == expected)
+ return
+ } else if (actual == expected) {
+ return
+ }
+ fail2(msg, "actual: " + actual + ", expected: " + expected)
+ }
+
+ function skip(msg) {
+ TestLogger.log_skip(currentTestCase, msg)
+ throw new Error("QtTest::skip")
+ }
+
+ function expectFail(msg) {
+ expectingFail = true
+ expectFailMsg = msg
+ }
+
+ property variant testCaseResult
+
+ function runInternal(prop, dataDriven, arg, tag) {
+ currentTestCase = TestLogger.log_prefixed_name(name, prop)
+ if (dataDriven && tag)
+ currentTestCase += " [" + tag + "]"
+ expectingFail = false
+ var success = true
+ try {
+ testCaseResult = testCase[prop](arg)
+ if (expectingFail) {
+ success = false
+ TestLogger.log_expect_fail_pass(currentTestCase)
+ } else if (!dataDriven) {
+ TestLogger.log_pass(currentTestCase)
+ }
+ } catch (e) {
+ testCaseResult = []
+ if (e.message == "QtTest::fail") {
+ success = false
+ } else if (e.message.indexOf("QtTest::") != 0) {
+ // Test threw an unrecognized exception - fail.
+ TestLogger.log_fail(currentTestCase, e.message)
+ success = false
+ }
+ }
+ return success
+ }
+
+ function run() {
+ TestLogger.log_start_test(reporter)
+ var success = true
+ running = true
+ var testList = []
+ for (var prop in testCase) {
+ if (prop.indexOf("test_") != 0)
+ continue
+ var tail = prop.lastIndexOf("_data");
+ if (tail != -1 && tail == (prop.length - 5))
+ continue
+ testList.push(prop)
+ }
+ testList.sort()
+ for (var index in testList) {
+ var prop = testList[index]
+ var datafunc = prop + "_data"
+ if (datafunc in testCase) {
+ if (runInternal(datafunc, true)) {
+ var table = testCaseResult
+ var successThis = true
+ var haveData = false
+ for (var index in table) {
+ haveData = true
+ var row = table[index]
+ if (!runInternal(prop, true, row, row.tag))
+ successThis = false
+ }
+ if (!haveData)
+ TestLogger.log_message("WARNING: no data supplied for " + prop + "() by " + datafunc + "()")
+ if (successThis) {
+ var prefix;
+ if (name)
+ prefix = name + "::"
+ currentTestCase = prefix + prop + "()"
+ TestLogger.log_pass(currentTestCase)
+ } else {
+ success = false
+ }
+ } else {
+ success = false
+ }
+ } else {
+ if (!runInternal(prop, false))
+ success = false
+ }
+ }
+ currentTestCase = ""
+ running = false
+ completed = true
+ TestLogger.log_complete_test(testId, reporter)
+ return success
+ }
+
+ onWhenChanged: {
+ if (when != prevWhen) {
+ prevWhen = when
+ if (when && !completed && !running)
+ run()
+ }
+ }
+
+ onOptionalChanged: {
+ if (!completed) {
+ if (optional)
+ TestLogger.log_optional_test(testId)
+ else
+ TestLogger.log_mandatory_test(testId)
+ }
+ }
+
+ Component.onCompleted: {
+ testId = TestLogger.log_register_test(name)
+ if (optional)
+ TestLogger.log_optional_test(testId)
+ prevWhen = when
+ if (when && !completed && !running)
+ run()
+ }
+}
diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp
new file mode 100644
index 0000000..8a9bb57
--- /dev/null
+++ b/src/imports/testlib/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 <QtDeclarative/qdeclarativeextensionplugin.h>
+#include "qdeclarativetestreport.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTestQmlModule : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ virtual void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("QtTest"));
+ qmlRegisterType<QDeclarativeTestReport>(uri,1,0,"TestReport");
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "main.moc"
+
+Q_EXPORT_PLUGIN2(qmltestplugin, QT_PREPEND_NAMESPACE(QTestQmlModule));
diff --git a/src/imports/testlib/qmldir b/src/imports/testlib/qmldir
new file mode 100644
index 0000000..7df32c0
--- /dev/null
+++ b/src/imports/testlib/qmldir
@@ -0,0 +1,2 @@
+plugin qmltestplugin
+TestCase 1.0 TestCase.qml
diff --git a/src/imports/testlib/testlib.pro b/src/imports/testlib/testlib.pro
new file mode 100644
index 0000000..341d576
--- /dev/null
+++ b/src/imports/testlib/testlib.pro
@@ -0,0 +1,35 @@
+TEMPLATE = lib
+TARGET = qmltestplugin
+CONFIG += qt plugin
+
+symbian {
+ CONFIG += epocallowdlldata
+ contains(QT_EDITION, OpenSource) {
+ TARGET.CAPABILITY = LocalServices NetworkServices ReadUserData UserEnvironment WriteUserData
+ } else {
+ TARGET.CAPABILITY = All -Tcb
+ }
+}
+
+QT += declarative
+
+INCLUDEPATH += $$PWD/../../quicktestlib
+
+SOURCES += main.cpp
+HEADERS +=
+
+qdeclarativesources.files += \
+ qmldir \
+ TestCase.qml \
+ testlogger.js
+
+qdeclarativesources.path += $$[QT_INSTALL_IMPORTS]/QtTest
+target.path += $$[QT_INSTALL_IMPORTS]/QtTest
+INSTALLS += qdeclarativesources target
+
+LIBS += -L../../../lib -L../../../bin
+win32:CONFIG(debug, debug|release) {
+ LIBS += -lQtTestQuick$${QT_LIBINFIX}d
+} else {
+ LIBS += -lQtTestQuick$${QT_LIBINFIX}
+}
diff --git a/src/imports/testlib/testlogger.js b/src/imports/testlib/testlogger.js
new file mode 100644
index 0000000..f556497
--- /dev/null
+++ b/src/imports/testlib/testlogger.js
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+.pragma library
+
+// We need a global place to store the results that can be
+// shared between multiple TestCase instances. Because QML
+// creates a separate scope for every inclusion of this file,
+// we hijack the global "Qt" object to store our data.
+function log_init_results()
+{
+ if (!Qt.testResults) {
+ Qt.testResults = {
+ suiteName: "",
+ reportedStart: false,
+ numPassed: 0,
+ numFailed: 0,
+ numSkipped: 0,
+ nextId: 0,
+ testCases: [],
+ reporter: null
+ }
+ }
+}
+
+function log_fail(testcase, msg)
+{
+ if (!msg)
+ msg = ""
+ Qt.testResults.reporter.log_fail(testcase, msg);
+ ++Qt.testResults.numFailed
+}
+
+function log_expect_fail(testcase, expectmsg, msg)
+{
+ if (!msg)
+ msg = ""
+ if (expectmsg)
+ Qt.testResults.reporter.log_expect_fail(testcase, expectmsg + " " + msg);
+ else
+ Qt.testResults.reporter.log_expect_fail(testcase, msg);
+ ++Qt.testResults.numPassed
+}
+
+function log_expect_fail_pass(testcase)
+{
+ Qt.testResults.reporter.log_expect_fail_pass(testcase);
+ ++Qt.testResults.numFailed
+}
+
+function log_skip(testcase, msg)
+{
+ if (!msg)
+ msg = ""
+ Qt.testResults.reporter.log_skip(testcase, msg);
+ ++Qt.testResults.numSkipped
+}
+
+function log_pass(testcase)
+{
+ Qt.testResults.reporter.log_pass(testcase);
+ ++Qt.testResults.numPassed
+}
+
+function log_message(msg)
+{
+ Qt.testResults.reporter.log_message(msg);
+}
+
+function log_register_test(name)
+{
+ log_init_results()
+ if (name && !Qt.testResults.suiteName)
+ Qt.testResults.suiteName = name
+ var testId = Qt.testResults.nextId++
+ Qt.testResults.testCases.push(testId)
+ return testId
+}
+
+function log_optional_test(testId)
+{
+ log_init_results()
+ var index = Qt.testResults.testCases.indexOf(testId)
+ if (index >= 0)
+ Qt.testResults.testCases.splice(index, 1)
+}
+
+function log_mandatory_test(testId)
+{
+ log_init_results()
+ var index = Qt.testResults.testCases.indexOf(testId)
+ if (index == -1)
+ Qt.testResults.testCases.push(testId)
+}
+
+function log_start_test(reporter)
+{
+ log_init_results()
+ Qt.testResults.reporter = reporter
+ if (Qt.testResults.reportedStart)
+ return
+ Qt.testResults.reportedStart = true
+}
+
+function log_complete_test(testId, reporter)
+{
+ var index = Qt.testResults.testCases.indexOf(testId)
+ if (index >= 0)
+ Qt.testResults.testCases.splice(index, 1)
+ if (!Qt.testResults.testCases.length) {
+ reporter.report(Qt.testResults.numPassed,
+ Qt.testResults.numFailed,
+ Qt.testResults.numSkipped)
+ Qt.quit()
+ }
+}
+
+function log_prefixed_name(name, funcname)
+{
+ if (!name)
+ name = Qt.testResults.suiteName
+ if (name)
+ return name + "::" + funcname + "()"
+ else
+ return funcname + "()"
+}