summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-04-23 03:01:38 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-04-23 03:01:38 +0200
commit583dcc6d31bb44d9d36c6a18dd71d54cbb6d5683 (patch)
tree81ac6b8d539c86258b2cbcdfc6183e95eec9efb0 /tests
parentfc99750865129c3abe9c827dd136ab717a7f4601 (diff)
parent732962319eeae2881890bd146146e7e6f486c9fb (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptable/tst_qscriptable.cpp45
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp2
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp
index 1a0fbe1..b800613 100644
--- a/tests/auto/qscriptable/tst_qscriptable.cpp
+++ b/tests/auto/qscriptable/tst_qscriptable.cpp
@@ -73,6 +73,9 @@ public slots:
QScriptValue getArguments();
int getArgumentCount();
+ QString toString() const;
+ int valueOf() const;
+
signals:
void sig(int);
@@ -172,6 +175,16 @@ bool MyScriptable::isBar()
return str.contains(QLatin1Char('@'));
}
+QString MyScriptable::toString() const
+{
+ return thisObject().property("objectName").toString();
+}
+
+int MyScriptable::valueOf() const
+{
+ return thisObject().property("baz").toInt32();
+}
+
class tst_QScriptable : public QObject
{
Q_OBJECT
@@ -188,6 +201,8 @@ private slots:
void thisObject();
void arguments();
void throwError();
+ void stringConstructor();
+ void numberConstructor();
private:
QScriptEngine m_engine;
@@ -386,5 +401,35 @@ void tst_QScriptable::throwError()
QCOMPARE(ret.toString(), QString("Error: MyScriptable.foo"));
}
+void tst_QScriptable::stringConstructor()
+{
+ m_scriptable.setObjectName("TestObject");
+
+ m_engine.globalObject().setProperty("js_obj", m_engine.newObject());
+ m_engine.evaluate(
+ "js_obj.str = scriptable.toString();"
+ "js_obj.toString = function() { return this.str }");
+
+ QCOMPARE(m_engine.evaluate("String(scriptable)").toString(),
+ m_engine.evaluate("String(js_obj)").toString());
+
+ QCOMPARE(m_engine.evaluate("String(scriptable)").toString(),
+ m_engine.evaluate("scriptable.toString()").toString());
+}
+
+void tst_QScriptable::numberConstructor()
+{
+ m_engine.globalObject().setProperty("js_obj", m_engine.newObject());
+ m_engine.evaluate(
+ "js_obj.num = scriptable.valueOf();"
+ "js_obj.valueOf = function() { return this.num }");
+
+ QCOMPARE(m_engine.evaluate("Number(scriptable)").toInt32(),
+ m_engine.evaluate("Number(js_obj)").toInt32());
+
+ QCOMPARE(m_engine.evaluate("Number(scriptable)").toInt32(),
+ m_engine.evaluate("scriptable.valueOf()").toInt32());
+}
+
QTEST_MAIN(tst_QScriptable)
#include "tst_qscriptable.moc"
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index e199d71..58fee07 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -1354,7 +1354,7 @@ void tst_QScriptExtQObject::callQtInvokable2()
// first time we expect failure because the metatype is not registered
m_myObject->resetQtFunctionInvoked();
- QCOMPARE(QMetaType::type("QVector<CustomType>"), QMetaType::UnknownType); // this type should not be registered yet
+ QCOMPARE(QMetaType::Type(QMetaType::type("QVector<CustomType>")), QMetaType::UnknownType); // this type should not be registered yet
QCOMPARE(m_engine->evaluate("myObject.myInvokableReturningVectorOfCustomType()").isError(), true);
QCOMPARE(m_myObject->qtFunctionInvoked(), -1);