summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-07-12 12:35:27 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-07-12 12:35:27 (GMT)
commit55ff179342bfb67b6f2592d7b1df66e1f3c6a350 (patch)
tree266b6e82ae4de9c1eb2f0c2d2c2310f774a55089 /tests/auto/declarative/qdeclarativeecmascript
parent0713442baa4120050e85c13998797415bb40efce (diff)
parente4f5a81869e75a998278c19134f2772fefd998fe (diff)
downloadQt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.zip
Qt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.tar.gz
Qt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.2.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/eval.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/function.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml4
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp87
11 files changed, 103 insertions, 35 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.2.qml
index db7f2b5..2c79729 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.2.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.2.qml
@@ -7,7 +7,7 @@ MyTypeObject {
uintProperty: if(1) 10
intProperty: if(1) -19
realProperty: if(1) 23.2
- doubleProperty: if(1) -19.7
+ doubleProperty: if(1) -19.75
floatProperty: if(1) 8.5
colorProperty: if(1) "red"
dateProperty: if(1) "1982-11-25"
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.qml
index 72ae865..1cd78a5 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignBasicTypes.qml
@@ -9,7 +9,7 @@ MyTypeObject {
uintProperty = 10
intProperty = -19
realProperty = 23.2
- doubleProperty = -19.7
+ doubleProperty = -19.75
floatProperty = 8.5
colorProperty = "red"
dateProperty = "1982-11-25"
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
index bc2df98..aab39be 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
@@ -16,7 +16,11 @@ QtObject {
test1 = (eval("a") == 7);
test2 = (eval("b") == 9);
- test3 = (eval("c") == undefined);
+ try {
+ eval("c");
+ } catch(e) {
+ test3 = true;
+ }
test4 = (eval("console") == console);
test5 = (eval("Qt") == Qt);
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
index b435f58..80d6ef4 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
@@ -14,6 +14,10 @@ QtObject {
test1 = (func1(4) == 11);
test2 = (func2("Hello World!") == Qt.atob("Hello World!"));
- test3 = (func3() == undefined);
+ try {
+ func3();
+ } catch(e) {
+ test3 = true;
+ }
}
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js
new file mode 100644
index 0000000..092bc2b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js
@@ -0,0 +1 @@
+;
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml
new file mode 100644
index 0000000..56e7885
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml
@@ -0,0 +1,8 @@
+import Qt 4.7
+import "qtbug_11600.js" as Test
+
+QtObject {
+ id: goo
+
+ property bool test: undefined == goo.Test.foo
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml
new file mode 100644
index 0000000..6efb9c1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml
@@ -0,0 +1,12 @@
+import Qt 4.7
+
+QtObject {
+ property bool test: false
+ Component.onCompleted: {
+ try {
+ console.log(sorryNoSuchProperty);
+ } catch (e) {
+ test = true;
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml
index 4395ba3..2548005 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml
@@ -1,10 +1,10 @@
import Qt 4.7
+import Qt.test 1.0
-Item {
+MyQmlObject {
id: root
property int foo: 12
- property int console: 11
property bool test1: foo == 12
property bool test2: console != 11
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
index e8f7b62..f601f49 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
@@ -4,7 +4,7 @@ import "scriptErrors.js" as Script
MyQmlObject {
property int t: a.value
property int w: Script.getValue();
- property int x: undefinedObject
+ property int x: undefined
property int y: (a.value, undefinedObject)
onBasicSignal: { console.log(a.value); }
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index 7bb8a8e..19bfd37 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -86,6 +86,7 @@ class MyQmlObject : public QObject
Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT)
Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT)
Q_PROPERTY(int value READ value WRITE setValue)
+ Q_PROPERTY(int console READ console CONSTANT)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged)
Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
@@ -142,6 +143,7 @@ public:
QRegExp regExp() { return m_regExp; }
void setRegExp(const QRegExp &regExp) { m_regExp = regExp; }
+ int console() const { return 11; }
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c);
@@ -555,7 +557,9 @@ Q_DECLARE_METATYPE(QScriptValue);
class MyInvokableObject : public QObject
{
Q_OBJECT
+ Q_ENUMS(TestEnum)
public:
+ enum TestEnum { EnumValue1, EnumValue2 };
MyInvokableObject() { reset(); }
int invoked() const { return m_invoked; }
@@ -568,7 +572,7 @@ public:
Q_INVOKABLE void method_NoArgs() { invoke(0); }
Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; }
- Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.7; }
+ Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.75; }
Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); }
Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; }
Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; }
@@ -587,6 +591,8 @@ public:
Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
+ Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(18); m_actuals << (int)e; }
+
private:
void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
int m_invoked;
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 16e7ec5..a6d2dac 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -155,6 +155,8 @@ private slots:
void eval();
void function();
void qtbug_10696();
+ void qtbug_11606();
+ void qtbug_11600();
void include();
@@ -177,7 +179,7 @@ void tst_qdeclarativeecmascript::assignBasicTypes()
QCOMPARE(object->uintProperty(), uint(10));
QCOMPARE(object->intProperty(), -19);
QCOMPARE((float)object->realProperty(), float(23.2));
- QCOMPARE((float)object->doubleProperty(), float(-19.7));
+ QCOMPARE((float)object->doubleProperty(), float(-19.75));
QCOMPARE((float)object->floatProperty(), float(8.5));
QCOMPARE(object->colorProperty(), QColor("red"));
QCOMPARE(object->dateProperty(), QDate(1982, 11, 25));
@@ -205,7 +207,7 @@ void tst_qdeclarativeecmascript::assignBasicTypes()
QCOMPARE(object->uintProperty(), uint(10));
QCOMPARE(object->intProperty(), -19);
QCOMPARE((float)object->realProperty(), float(23.2));
- QCOMPARE((float)object->doubleProperty(), float(-19.7));
+ QCOMPARE((float)object->doubleProperty(), float(-19.75));
QCOMPARE((float)object->floatProperty(), float(8.5));
QCOMPARE(object->colorProperty(), QColor("red"));
QCOMPARE(object->dateProperty(), QDate(1982, 11, 25));
@@ -278,8 +280,8 @@ void tst_qdeclarativeecmascript::signalAssignment()
MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->string(), QString());
- emit object->argumentSignal(19, "Hello world!", 10.3);
- QCOMPARE(object->string(), QString("pass 19 Hello world! 10.3"));
+ emit object->argumentSignal(19, "Hello world!", 10.25);
+ QCOMPARE(object->string(), QString("pass 19 Hello world! 10.25"));
}
}
@@ -1002,10 +1004,10 @@ void tst_qdeclarativeecmascript::scriptErrors()
QString url = component.url().toString();
QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\"";
- QString warning2 = url + ":5: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning2 = url + ":5: ReferenceError: Can't find variable: a";
QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\"";
- QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object.";
- QString warning5 = url + ":8: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning4 = url + ":10: ReferenceError: Can't find variable: a";
+ QString warning5 = url + ":8: ReferenceError: Can't find variable: a";
QString warning6 = url + ":7: Unable to assign [undefined] to int x";
QString warning7 = url + ":12: Error: Cannot assign to read-only property \"trueProperty\"";
QString warning8 = url + ":13: Error: Cannot assign to non-existent property \"fakeProperty\"";
@@ -1322,7 +1324,12 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QDeclarativeEngine qmlengine;
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine);
QScriptEngine *engine = &ep->scriptEngine;
- ep->globalClass->explicitSetProperty("object", ep->objectClass->newQObject(&o));
+
+ QStringList names; QList<QScriptValue> values;
+ names << QLatin1String("object"); values << ep->objectClass->newQObject(&o);
+ names << QLatin1String("undefined"); values << engine->undefinedValue();
+
+ ep->globalClass->explicitSetProperty(names, values);
// Non-existent methods
o.reset();
@@ -1380,7 +1387,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QVERIFY(engine->evaluate("object.method_NoArgs_real()").strictlyEquals(QScriptValue(engine, 19.7)));
+ QVERIFY(engine->evaluate("object.method_NoArgs_real()").strictlyEquals(QScriptValue(engine, 19.75)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 2);
QCOMPARE(o.actuals().count(), 0);
@@ -1714,6 +1721,13 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().count(), 2);
QCOMPARE(o.actuals().at(0), QVariant(10));
QCOMPARE(o.actuals().at(1), QVariant(11));
+
+ o.reset();
+ QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true);
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), 18);
+ QCOMPARE(o.actuals().count(), 1);
+ QCOMPARE(o.actuals().at(0), QVariant(9));
}
// QTBUG-5675
@@ -1804,7 +1818,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toBool(), false);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toBool(), true);
delete object;
@@ -1817,7 +1831,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toBool(), false);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toBool(), true);
delete object;
@@ -1830,7 +1844,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toBool(), false);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toBool(), true);
delete object;
@@ -1843,7 +1857,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->methodCalled(), false);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->methodCalled(), true);
delete object;
@@ -1856,7 +1870,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->methodCalled(), false);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->methodCalled(), true);
delete object;
@@ -1869,7 +1883,7 @@ void tst_qdeclarativeecmascript::scriptConnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 0);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
delete object;
@@ -1885,13 +1899,13 @@ void tst_qdeclarativeecmascript::scriptDisconnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 0);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 1);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
emit object->basicSignal();
QCOMPARE(object->property("test").toInt(), 2);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
delete object;
@@ -1904,13 +1918,13 @@ void tst_qdeclarativeecmascript::scriptDisconnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 0);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 1);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
emit object->basicSignal();
QCOMPARE(object->property("test").toInt(), 2);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
delete object;
@@ -1923,13 +1937,13 @@ void tst_qdeclarativeecmascript::scriptDisconnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 0);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 1);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
emit object->basicSignal();
QCOMPARE(object->property("test").toInt(), 2);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 3);
delete object;
@@ -1941,13 +1955,13 @@ void tst_qdeclarativeecmascript::scriptDisconnect()
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 0);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 1);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 2);
emit object->basicSignal();
QCOMPARE(object->property("test").toInt(), 2);
- emit object->argumentSignal(19, "Hello world!", 10.3);
+ emit object->argumentSignal(19, "Hello world!", 10.25);
QCOMPARE(object->property("test").toInt(), 3);
delete object;
@@ -2498,6 +2512,25 @@ void tst_qdeclarativeecmascript::qtbug_10696()
delete o;
}
+void tst_qdeclarativeecmascript::qtbug_11606()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11606.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+ QCOMPARE(o->property("test").toBool(), true);
+ delete o;
+}
+
+void tst_qdeclarativeecmascript::qtbug_11600()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11600.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+ QCOMPARE(o->property("test").toBool(), true);
+ delete o;
+}
+
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"