From b0c4e816e6da2c09593cf8de2f563093947ebdaf Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 13 Aug 2012 09:47:43 +0200 Subject: 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 --- .../qscriptextqobject/tst_qscriptextqobject.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp') 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(); } @@ -1594,6 +1598,32 @@ void tst_QScriptExtQObject::callQtInvokable4() QCOMPARE(v.userType(), int(QMetaType::ULongLong)); QCOMPARE(qvariant_cast(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(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(v), ulong(456)); + } } void tst_QScriptExtQObject::callQtInvokable5() -- cgit v1.2.1