aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h1
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp70
3 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml
index 4fc2dab943..54d29dfc94 100644
--- a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml
+++ b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml
@@ -15,4 +15,12 @@ MyQmlObject
onMySignal: { intProperty = a; realProperty = b; colorProperty = c; variantProperty = d; enumProperty = e; qtEnumProperty = f; }
onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1), MyQmlObject.EnumValue3, Qt.LeftButton)
+
+ property bool emittedQjsValueWasUndefined
+ property int emittedQjsValueAsInt
+
+ onQjsValueEmittingSignal: {
+ emittedQjsValueWasUndefined = value === undefined;
+ emittedQjsValueAsInt = value
+ }
}
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 47fb2a56e7..1f7f3344ef 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -244,6 +244,7 @@ signals:
void signalWithGlobalName(int parseInt);
void intChanged();
void qjsvalueChanged();
+ void qjsValueEmittingSignal(QJSValue value);
public slots:
void deleteMe() { delete this; }
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 88a8886ecb..89dac33671 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -331,6 +331,8 @@ private slots:
void qtbug_54589();
void qtbug_54687();
void stringify_qtbug_50592();
+ void instanceof_data();
+ void instanceof();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -1418,6 +1420,12 @@ void tst_qqmlecmascript::signalParameterTypes()
QVERIFY(object->property("enumProperty") == MyQmlObject::EnumValue3);
QVERIFY(object->property("qtEnumProperty") == Qt::LeftButton);
+ emit object->qjsValueEmittingSignal(QJSValue());
+ QVERIFY(object->property("emittedQjsValueWasUndefined").toBool());
+ emit object->qjsValueEmittingSignal(QJSValue(42));
+ QVERIFY(!object->property("emittedQjsValueWasUndefined").toBool());
+ QCOMPARE(object->property("emittedQjsValueAsInt").value<int>(), 42);
+
delete object;
}
@@ -8113,6 +8121,68 @@ void tst_qqmlecmascript::stringify_qtbug_50592()
QCOMPARE(obj->property("source").toString(), QString::fromLatin1("http://example.org/some_nonexistant_image.png"));
}
+void tst_qqmlecmascript::instanceof_data()
+{
+ QTest::addColumn<QString>("setupCode");
+ QTest::addColumn<QVariant>("expectedValue");
+
+ // so the way this works is that the name of the test tag defines the test
+ // to run. the code in setupCode defines code run before the actual test
+ // (e.g. to create vars).
+ //
+ // the expectedValue is either a boolean true or false for whether the two
+ // operands are indeed an instanceof each other, or a string for the
+ // expected error message.
+ QTest::newRow("String instanceof String")
+ << ""
+ << QVariant(false);
+ QTest::newRow("s instanceof String")
+ << "var s = \"hello\""
+ << QVariant(false);
+ QTest::newRow("objectString instanceof String")
+ << "var objectString = new String(\"hello\")"
+ << QVariant(true);
+ QTest::newRow("o instanceof Object")
+ << "var o = new Object()"
+ << QVariant(true);
+ QTest::newRow("o instanceof String")
+ << "var o = new Object()"
+ << QVariant(false);
+ QTest::newRow("true instanceof true")
+ << ""
+ << QVariant("TypeError: Type error");
+ QTest::newRow("1 instanceof Math")
+ << ""
+ << QVariant("TypeError: Type error");
+ QTest::newRow("date instanceof Date")
+ << "var date = new Date"
+ << QVariant(true);
+ QTest::newRow("date instanceof Object")
+ << "var date = new Date"
+ << QVariant(true);
+ QTest::newRow("date instanceof String")
+ << "var date = new Date"
+ << QVariant(false);
+}
+
+void tst_qqmlecmascript::instanceof()
+{
+ QFETCH(QString, setupCode);
+ QFETCH(QVariant, expectedValue);
+
+ QJSEngine engine;
+ QJSValue ret = engine.evaluate(setupCode + ";\n" + QTest::currentDataTag());
+
+ if (expectedValue.type() == QMetaType::Bool) {
+ bool returnValue = ret.toBool();
+ QVERIFY2(!ret.isError(), qPrintable(ret.toString()));
+ QCOMPARE(returnValue, expectedValue.toBool());
+ } else {
+ QVERIFY2(ret.isError(), qPrintable(ret.toString()));
+ QCOMPARE(ret.toString(), expectedValue.toString());
+ }
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"