diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-08-13 09:47:43 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-14 08:29:21 +0200 |
commit | b0c4e816e6da2c09593cf8de2f563093947ebdaf (patch) | |
tree | 50659e7b5e8689af5d4a6cf4dd55ff75e54ce36b /tests/auto/qscriptengine/tst_qscriptengine.cpp | |
parent | d1cf1cc364463c196dfc99f04328755a67476569 (diff) | |
download | qtscript-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/auto/qscriptengine/tst_qscriptengine.cpp')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 34 |
1 files changed, 34 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()); |