summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-03-26 14:02:20 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-03-26 14:10:36 (GMT)
commit9ffc533ffbba156ff69dc1bd3a9a4a2cb53b68af (patch)
treec9bfe6a9e5fbe3d1393f0ff4ceba51f4904a01bf /tests/auto/qscriptengine
parentc7627129e0ab3133ea0a95e93cd8643b5a97e189 (diff)
downloadQt-9ffc533ffbba156ff69dc1bd3a9a4a2cb53b68af.zip
Qt-9ffc533ffbba156ff69dc1bd3a9a4a2cb53b68af.tar.gz
Qt-9ffc533ffbba156ff69dc1bd3a9a4a2cb53b68af.tar.bz2
Fix regression in qscriptvalue_cast (primitive-->complex type cast)
qscriptvalue_cast implementation was changed from 4.4 to 4.5 because of the introduction of QScriptValue constructors that don't take an engine pointer. However, when the old constructors are used, the behavior of qscriptvalue_cast should be as before, which this patch ensures. In short: If we have an engine pointer, use it. Task-number: 248802 Reviewed-by: Ariya Hidayat
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 9995b46..5339fb4 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -1187,6 +1187,16 @@ static void fooFromScriptValue(const QScriptValue &value, Foo &foo)
foo.y = value.property("y").toInt32();
}
+static QScriptValue fooToScriptValueV2(QScriptEngine *eng, const Foo &foo)
+{
+ return QScriptValue(eng, foo.x);
+}
+
+static void fooFromScriptValueV2(const QScriptValue &value, Foo &foo)
+{
+ foo.x = value.toInt32();
+}
+
Q_DECLARE_METATYPE(QLinkedList<QString>)
Q_DECLARE_METATYPE(QList<Foo>)
Q_DECLARE_METATYPE(QVector<QChar>)
@@ -1427,6 +1437,24 @@ void tst_QScriptEngine::valueConversion()
QVERIFY(val.isVariant());
QCOMPARE(val.toVariant(), var);
}
+
+ // task 248802
+ qScriptRegisterMetaType<Foo>(&eng, fooToScriptValueV2, fooFromScriptValueV2);
+ {
+ QScriptValue num(&eng, 123);
+ Foo foo = qScriptValueToValue<Foo>(num);
+ QCOMPARE(foo.x, 123);
+ }
+ {
+ QScriptValue num(123);
+ Foo foo = qScriptValueToValue<Foo>(num);
+ QCOMPARE(foo.x, -1);
+ }
+ {
+ QScriptValue str(&eng, "123");
+ Foo foo = qScriptValueToValue<Foo>(str);
+ QCOMPARE(foo.x, 123);
+ }
}
static QScriptValue __import__(QScriptContext *ctx, QScriptEngine *eng)