diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativev4')
15 files changed, 495 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativev4/data/conditionalExpr.qml b/tests/auto/declarative/qdeclarativev4/data/conditionalExpr.qml new file mode 100644 index 0000000000..b74a95a94b --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/conditionalExpr.qml @@ -0,0 +1,6 @@ +import Qt.v4 1.0 + +Result { + property int n: 2 + result: !n ? 100 : 0 +} diff --git a/tests/auto/declarative/qdeclarativev4/data/doubleBoolJump.qml b/tests/auto/declarative/qdeclarativev4/data/doubleBoolJump.qml new file mode 100644 index 0000000000..e7fb82ca36 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/doubleBoolJump.qml @@ -0,0 +1,18 @@ +import QtQuick 1.0 + +Rectangle { + QtObject { + property real output: i1.p1 || i2.p2 == "text" ? 0.7 : 0 + } + + QtObject { + id: i2 + property string p2 + } + + QtObject { + id: i1 + property bool p1: false + } +} + diff --git a/tests/auto/declarative/qdeclarativev4/data/fetchException.qml b/tests/auto/declarative/qdeclarativev4/data/fetchException.qml new file mode 100644 index 0000000000..ece8e73199 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/fetchException.qml @@ -0,0 +1,6 @@ +import QtQuick 1.0 + +Item { + property Item data + property int a: data.x, 1 +} diff --git a/tests/auto/declarative/qdeclarativev4/data/logicalOr.2.qml b/tests/auto/declarative/qdeclarativev4/data/logicalOr.2.qml new file mode 100644 index 0000000000..54fb78b127 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/logicalOr.2.qml @@ -0,0 +1,6 @@ +import Qt.v4 1.0 + +Result { + property string s: "foo" || "bar" + result: s == "foo" +} diff --git a/tests/auto/declarative/qdeclarativev4/data/logicalOr.qml b/tests/auto/declarative/qdeclarativev4/data/logicalOr.qml new file mode 100644 index 0000000000..406a7d83eb --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/logicalOr.qml @@ -0,0 +1,6 @@ +import Qt.v4 1.0 + +Result { + property int a: 10 + result: a == 1 || a == 2 +} diff --git a/tests/auto/declarative/qdeclarativev4/data/nestedObjectAccess.qml b/tests/auto/declarative/qdeclarativev4/data/nestedObjectAccess.qml new file mode 100644 index 0000000000..56cd17e41e --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/nestedObjectAccess.qml @@ -0,0 +1,5 @@ +import Qt.v4 1.0 + +Result { + result: nested.result +} diff --git a/tests/auto/declarative/qdeclarativev4/data/nullQObject.qml b/tests/auto/declarative/qdeclarativev4/data/nullQObject.qml new file mode 100644 index 0000000000..283c1a199b --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/nullQObject.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +Item { + property QtObject obj + property QtObject test + test: obj +} diff --git a/tests/auto/declarative/qdeclarativev4/data/qrealToIntRounding.qml b/tests/auto/declarative/qdeclarativev4/data/qrealToIntRounding.qml new file mode 100644 index 0000000000..f961910f15 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/qrealToIntRounding.qml @@ -0,0 +1,10 @@ +import QtQuick 1.0 + +QtObject { + property int data: 1 + + property int test1: 6.6 + data + property int test2: 6.2 + data + property int test3: 6 + data +} + diff --git a/tests/auto/declarative/qdeclarativev4/data/subscriptionsInConditionalExpressions.qml b/tests/auto/declarative/qdeclarativev4/data/subscriptionsInConditionalExpressions.qml new file mode 100644 index 0000000000..25483b207d --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/subscriptionsInConditionalExpressions.qml @@ -0,0 +1,11 @@ +import QtQuick 1.0 + +Item { + id: thisTest + + property bool cond: true + property real a: 1 + property real result: cond ? a : a + + PropertyAction { running: true; target: thisTest; property: "a"; value: 2; } +} diff --git a/tests/auto/declarative/qdeclarativev4/data/unaryMinus.qml b/tests/auto/declarative/qdeclarativev4/data/unaryMinus.qml new file mode 100644 index 0000000000..3cfa0492c0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/unaryMinus.qml @@ -0,0 +1,18 @@ +import QtQuick 1.0 + +Item { + property real test1: -i1.p2 + property int test2: -i1.p2 + property real test3: -i1.p1 + property int test4: -i1.p1 + property real test5: -i1.p3 + property int test6: -i1.p3 + + QtObject { + id: i1 + property real p1: -3.7 + property int p2: 18 + property real p3: -3.3 + } + } + diff --git a/tests/auto/declarative/qdeclarativev4/data/unnecessaryReeval.qml b/tests/auto/declarative/qdeclarativev4/data/unnecessaryReeval.qml new file mode 100644 index 0000000000..48662d7a2d --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/data/unnecessaryReeval.qml @@ -0,0 +1,7 @@ +import Qt.v4 1.0 + +Result { + property int a: 8 + property int b: 19 + result: (a == 8)?b:7 +} diff --git a/tests/auto/declarative/qdeclarativev4/qdeclarativev4.pro b/tests/auto/declarative/qdeclarativev4/qdeclarativev4.pro new file mode 100644 index 0000000000..0a2005d15d --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/qdeclarativev4.pro @@ -0,0 +1,19 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative script network +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativev4.cpp \ + testtypes.cpp +HEADERS += testtypes.h + +symbian: { + importFiles.files = data + importFiles.path = . + DEPLOYMENT += importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +CONFIG += parallel_test + +QT += core-private gui-private declarative-private script-private diff --git a/tests/auto/declarative/qdeclarativev4/testtypes.cpp b/tests/auto/declarative/qdeclarativev4/testtypes.cpp new file mode 100644 index 0000000000..f4544b6e21 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/testtypes.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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 "testtypes.h" + +#include <QtDeclarative/qdeclarative.h> + +void registerTypes() +{ + qmlRegisterType<ResultObject>("Qt.v4", 1,0, "Result"); + qmlRegisterType<NestedObject>(); +} diff --git a/tests/auto/declarative/qdeclarativev4/testtypes.h b/tests/auto/declarative/qdeclarativev4/testtypes.h new file mode 100644 index 0000000000..0933eff8b7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/testtypes.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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$ +** +****************************************************************************/ +#ifndef TESTTYPES_H +#define TESTTYPES_H + +#include <QtCore/qobject.h> + +class NestedObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int dummy READ dummy); + Q_PROPERTY(int result READ result FINAL CONSTANT); + +public: + int dummy() const { return 7; } + int result() const { return 37; } +}; + +class ResultObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int result READ result WRITE setResult FINAL) + Q_PROPERTY(NestedObject *nested READ nested CONSTANT) +public: + ResultObject() : m_result(0), m_resultCounter(0) {} + + int resultCounter() const { return m_resultCounter; } + void resetResultCounter() { m_resultCounter = 0; } + + int result() const { return m_result; } + void setResult(int result) { m_result = result; m_resultCounter++; } + + NestedObject *nested() { return &m_nested; } + +private: + int m_result; + int m_resultCounter; + + NestedObject m_nested; +}; + +void registerTypes(); + +#endif // TESTTYPES_H + diff --git a/tests/auto/declarative/qdeclarativev4/tst_qdeclarativev4.cpp b/tests/auto/declarative/qdeclarativev4/tst_qdeclarativev4.cpp new file mode 100644 index 0000000000..fb34696ef5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativev4/tst_qdeclarativev4.cpp @@ -0,0 +1,244 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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 <qtest.h> +#include <QtCore/qobject.h> +#include <QtCore/qfileinfo.h> +#include <QtCore/qdir.h> +#include <QtDeclarative/qdeclarativeengine.h> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtCore/qdebug.h> + +#include <private/qdeclarativev4compiler_p.h> + +#include "testtypes.h" + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} + +class tst_qdeclarativev4 : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativev4() {} + +private slots: + void initTestCase(); + + void unnecessaryReeval(); + void logicalOr(); + void conditionalExpr(); + void qtscript(); + void qtscript_data(); + void nestedObjectAccess(); + void subscriptionsInConditionalExpressions(); + +private: + QDeclarativeEngine engine; +}; + +void tst_qdeclarativev4::initTestCase() +{ + registerTypes(); +} + +static int v4ErrorsMsgCount = 0; +static void v4ErrorsMsgHandler(QtMsgType, const char *message) +{ + QByteArray m(message); + if (m.contains("QDeclarativeV4")) + v4ErrorsMsgCount++; +} + +void tst_qdeclarativev4::qtscript() +{ + QFETCH(QString, file); + QDeclarativeV4Compiler::enableBindingsTest(true); + + QDeclarativeComponent component(&engine, TEST_FILE(file)); + + v4ErrorsMsgCount = 0; + QtMsgHandler old = qInstallMsgHandler(v4ErrorsMsgHandler); + + QObject *o = component.create(); + delete o; + + qInstallMsgHandler(old); + + QCOMPARE(v4ErrorsMsgCount, 0); + + QDeclarativeV4Compiler::enableBindingsTest(false); +} + +void tst_qdeclarativev4::qtscript_data() +{ + QTest::addColumn<QString>("file"); + + QTest::newRow("qreal -> int rounding") << "qrealToIntRounding.qml"; + QTest::newRow("exception on fetch") << "fetchException.qml"; + QTest::newRow("logical or") << "logicalOr.qml"; + QTest::newRow("conditional expressions") << "conditionalExpr.qml"; + QTest::newRow("double bool jump") << "doubleBoolJump.qml"; + QTest::newRow("unary minus") << "unaryMinus.qml"; + QTest::newRow("null qobject") << "nullQObject.qml"; +} + +void tst_qdeclarativev4::unnecessaryReeval() +{ + QDeclarativeComponent component(&engine, TEST_FILE("unnecessaryReeval.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + ResultObject *ro = qobject_cast<ResultObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->resultCounter(), 1); + QCOMPARE(ro->result(), 19); + ro->resetResultCounter(); + + ro->setProperty("b", 6); + + QCOMPARE(ro->resultCounter(), 1); + QCOMPARE(ro->result(), 6); + ro->resetResultCounter(); + + ro->setProperty("a", 14); + + QCOMPARE(ro->resultCounter(), 1); + QCOMPARE(ro->result(), 7); + ro->resetResultCounter(); + + ro->setProperty("b", 14); + QCOMPARE(ro->resultCounter(), 0); + QCOMPARE(ro->result(), 7); + + delete o; +} + +void tst_qdeclarativev4::logicalOr() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("logicalOr.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + ResultObject *ro = qobject_cast<ResultObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->result(), 0); + delete o; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("logicalOr.2.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + ResultObject *ro = qobject_cast<ResultObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->result(), 1); + delete o; + } +} + +void tst_qdeclarativev4::conditionalExpr() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("conditionalExpr.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + ResultObject *ro = qobject_cast<ResultObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->result(), 0); + delete o; + } +} + +// This would previously use the metaObject of the root element to result the nested access. +// That is, the index for accessing "result" would have been RootObject::result, instead of +// NestedObject::result. +void tst_qdeclarativev4::nestedObjectAccess() +{ + QDeclarativeComponent component(&engine, TEST_FILE("nestedObjectAccess.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + ResultObject *ro = qobject_cast<ResultObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->result(), 37); + + delete o; +} + +void tst_qdeclarativev4::subscriptionsInConditionalExpressions() +{ + QDeclarativeComponent component(&engine, TEST_FILE("subscriptionsInConditionalExpressions.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QObject *ro = qobject_cast<QObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->property("result").toReal(), qreal(2)); + + delete o; +} + +QTEST_MAIN(tst_qdeclarativev4) + +#include "tst_qdeclarativev4.moc" |