summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-08-13 09:47:43 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-14 08:29:21 +0200
commitb0c4e816e6da2c09593cf8de2f563093947ebdaf (patch)
tree50659e7b5e8689af5d4a6cf4dd55ff75e54ce36b /tests
parentd1cf1cc364463c196dfc99f04328755a67476569 (diff)
downloadqtscript-b0c4e816e6da2c09593cf8de2f563093947ebdaf.tar.gz
Add default conversion for types long and ulong
Such conversion is not guaranteed to be lossless on all platforms, but it's still reasonable to support these types by default. JSC::JSValue already had constructors for them. The type matching / overload resolution in the QObject binding already handled long and ulong, but the value conversion itself was missing, for some reason. Task-number: QTBUG-2124 Change-Id: I14ff29a8e949403234b7659c0aca8b48bcdbda0e Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp34
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp30
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 3be9d62..5cb1f08 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -132,6 +132,7 @@ private slots:
void valueConversion_basic2();
void valueConversion_dateTime();
void valueConversion_regExp();
+ void valueConversion_long();
void qScriptValueFromValue_noEngine();
void importExtension();
void infiniteRecursion();
@@ -2503,6 +2504,39 @@ void tst_QScriptEngine::valueConversion_regExp()
}
}
+void tst_QScriptEngine::valueConversion_long()
+{
+ QScriptEngine eng;
+ {
+ QScriptValue num(&eng, 123);
+ QCOMPARE(qscriptvalue_cast<long>(num), long(123));
+ QCOMPARE(qscriptvalue_cast<ulong>(num), ulong(123));
+ }
+ {
+ QScriptValue num(456);
+ QCOMPARE(qscriptvalue_cast<long>(num), long(456));
+ QCOMPARE(qscriptvalue_cast<ulong>(num), ulong(456));
+ }
+ {
+ QScriptValue str(&eng, "123");
+ QCOMPARE(qscriptvalue_cast<long>(str), long(123));
+ QCOMPARE(qscriptvalue_cast<ulong>(str), ulong(123));
+ }
+ {
+ QScriptValue str("456");
+ QCOMPARE(qscriptvalue_cast<long>(str), long(456));
+ QCOMPARE(qscriptvalue_cast<ulong>(str), ulong(456));
+ }
+ {
+ QScriptValue num = qScriptValueFromValue<long>(&eng, long(123));
+ QCOMPARE(num.toInt32(), 123);
+ }
+ {
+ QScriptValue num = qScriptValueFromValue<ulong>(&eng, ulong(456));
+ QCOMPARE(num.toInt32(), 456);
+ }
+}
+
void tst_QScriptEngine::qScriptValueFromValue_noEngine()
{
QVERIFY(!qScriptValueFromValue(0, 123).isValid());
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index 43e640a..9706901 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -343,6 +343,10 @@ public:
{ m_qtFunctionInvoked = 67; m_actuals << qVariantFromValue(arg); return arg; }
Q_INVOKABLE qulonglong myInvokableWithULonglongArg(qulonglong arg)
{ m_qtFunctionInvoked = 68; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE long myInvokableWithLongArg(long arg)
+ { m_qtFunctionInvoked = 69; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE unsigned long myInvokableWithULongArg(unsigned long arg)
+ { m_qtFunctionInvoked = 70; m_actuals << qVariantFromValue(arg); return arg; }
Q_INVOKABLE QObjectList findObjects() const
{ return findChildren<QObject *>(); }
@@ -1594,6 +1598,32 @@ void tst_QScriptExtQObject::callQtInvokable4()
QCOMPARE(v.userType(), int(QMetaType::ULongLong));
QCOMPARE(qvariant_cast<qulonglong>(v), qulonglong(123));
}
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithLongArg(123)");
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 69);
+ QVERIFY(ret.isNumber());
+ QCOMPARE(long(ret.toInteger()), long(123));
+
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::Long));
+ QCOMPARE(qvariant_cast<long>(v), long(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithULongArg(456)");
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 70);
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ulong(ret.toInteger()), ulong(456));
+
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::ULong));
+ QCOMPARE(qvariant_cast<unsigned long>(v), ulong(456));
+ }
}
void tst_QScriptExtQObject::callQtInvokable5()