diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-04-24 18:22:06 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-26 10:30:57 +0200 |
commit | c0f07d5707180856bb2705359d780a836653188c (patch) | |
tree | 064157942515254938c2a47bd587fa26f911d06f /tests | |
parent | 7e9fa5ad9c1786d8be5a422f94a44b2cd836aca6 (diff) |
Specialize for QJson types in the QObject meta-call binding
Avoid falling back to QVariant conversion; make the overload handling
consistent.
Also make the MaxSizeOf template helper class actually compute the
correct size needed for the argument storage.
Change-Id: I04afb378bd89743d542973cc3bb0ceb729b400d9
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 11 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 91 |
2 files changed, 102 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 502c65db38..f39d5d913d 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -54,6 +54,9 @@ #include <QtGui/QFont> #include <QtGui/QPixmap> #include <QtCore/qdatetime.h> +#include <QtCore/qjsonarray.h> +#include <QtCore/qjsonobject.h> +#include <QtCore/qjsonvalue.h> #include <QtQml/qjsvalue.h> #include <QtQml/qqmlscriptstring.h> #include <QtQml/qqmlcomponent.h> @@ -678,6 +681,14 @@ public: Q_INVOKABLE void method_QVariant(QVariant a, QVariant b = QVariant()) { invoke(21); m_actuals << a << b; } + Q_INVOKABLE void method_QJsonObject(const QJsonObject &a) { invoke(22); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_QJsonArray(const QJsonArray &a) { invoke(23); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_QJsonValue(const QJsonValue &a) { invoke(24); m_actuals << QVariant::fromValue(a); } + + Q_INVOKABLE void method_overload(const QJsonObject &a) { invoke(25); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); } + Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); } + private: friend class MyInvokableBaseObject; void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index b66427ef89..4b913ef697 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2607,6 +2607,97 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o.actuals().count(), 2); QCOMPARE(o.actuals().at(0), QVariant(QString("Hello"))); QCOMPARE(o.actuals().at(1), QVariant(QString("World"))); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonObject({foo:123})", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 22); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonObject>(o.actuals().at(0)), QJsonDocument::fromJson("{\"foo\":123}").object()); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonArray([123])", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 23); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonArray>(o.actuals().at(0)), QJsonDocument::fromJson("[123]").array()); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(123)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(123)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(42.35)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(42.35)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue('ciao')", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QStringLiteral("ciao"))); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(true)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(true)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(false)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(false)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(null)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QJsonValue::Null)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(undefined)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 24); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QJsonValue::Undefined)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_overload({foo:123})", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 25); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonObject>(o.actuals().at(0)), QJsonDocument::fromJson("{\"foo\":123}").object()); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_overload([123])", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 26); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonArray>(o.actuals().at(0)), QJsonDocument::fromJson("[123]").array()); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_overload(null)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 27); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QJsonValue::Null)); + + o.reset(); + QVERIFY(EVALUATE_VALUE("object.method_overload(undefined)", v8::Undefined())); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 27); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(qvariant_cast<QJsonValue>(o.actuals().at(0)), QJsonValue(QJsonValue::Undefined)); } // QTBUG-13047 (check that you can pass registered object types as args) |