diff options
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 65 |
3 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml index 4fc2dab943..676593096c 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml @@ -15,4 +15,6 @@ 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) + + onQjsValueEmittingSignal: {} } 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..8c0b0601fc 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); @@ -1410,6 +1412,7 @@ void tst_qqmlecmascript::signalParameterTypes() QVERIFY(object != 0); emit object->basicSignal(); + emit object->qjsValueEmittingSignal(QJSValue()); QCOMPARE(object->property("intProperty").toInt(), 10); QCOMPARE(object->property("realProperty").toReal(), 19.2); @@ -8113,6 +8116,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" |