summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2016-07-15 21:24:23 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2016-07-15 21:24:23 +0200
commit3836fd7d12777fc53836a72d6542d2fbf2f20ac9 (patch)
treeffd8a3d1c82fea142d7b50fb42111ceb1fbc2e1a /tests
parentb84f22a3249aa1af46b17e33ac030abb077251bf (diff)
parente35346cf70598c47a456946327927643910aa277 (diff)
downloadqtwebchannel-3836fd7d12777fc53836a72d6542d2fbf2f20ac9.tar.gz
Merge remote-tracking branch 'origin/5.6' into 5.7
Alleged Conflicts: examples/webchannel/chatclient-html/doc/src/chatclient-html.qdoc examples/webchannel/chatclient-qml/doc/src/chatclient-qml.qdoc examples/webchannel/chatserver-cpp/doc/src/chatserver-cpp.qdoc In each case, the two sides agreed byte-for-byte. Not quite sure what git thought the conflict was ! Change-Id: I5da9695b667f4112848c520b630ab1304d61cea3
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/tst_webchannel.qml19
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp205
-rw-r--r--tests/auto/webchannel/tst_webchannel.h51
3 files changed, 270 insertions, 5 deletions
diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml
index 403cc4b..5e28db3 100644
--- a/tests/auto/qml/tst_webchannel.qml
+++ b/tests/auto/qml/tst_webchannel.qml
@@ -46,7 +46,7 @@ TestCase {
id: myObj
property int myProperty: 1
- signal mySignal(var arg)
+ signal mySignal(var arg, QtObject object)
function myMethod(arg)
{
@@ -169,9 +169,11 @@ TestCase {
function test_signal()
{
var signalReceivedArg;
+ var signalReceivedObject;
var channel = client.createChannel(function(channel) {
- channel.objects.myObj.mySignal.connect(function(arg) {
+ channel.objects.myObj.mySignal.connect(function(arg, object) {
signalReceivedArg = arg;
+ signalReceivedObject = object;
});
});
client.awaitInit();
@@ -182,9 +184,16 @@ TestCase {
client.awaitIdle(); // initialization
- myObj.mySignal("test");
+ myObj.mySignal("test", myObj);
compare(signalReceivedArg, "test");
+ compare(signalReceivedObject.__id__, "myObj");
+
+ var newObj = myFactory.create("newObj");
+ myObj.mySignal(newObj, newObj);
+
+ compare(signalReceivedArg.objectName, newObj.objectName);
+ compare(signalReceivedObject.objectName, newObj.objectName);
}
function test_grouping()
@@ -388,14 +397,14 @@ TestCase {
client.awaitIdle();
- myObj.mySignal(42);
+ myObj.mySignal(42, myObj);
compare(signalArg, 42);
msg = client.awaitMessage();
compare(msg.type, JSClient.QWebChannelMessageTypes.disconnectFromSignal);
compare(msg.object, "myObj");
- myObj.mySignal(0);
+ myObj.mySignal(0, myObj);
compare(signalArg, 42);
}
}
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index 7e8e5f5..a8a658f 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -187,6 +187,7 @@ TestWebChannel::TestWebChannel(QObject *parent)
: QObject(parent)
, m_dummyTransport(new DummyTransport(this))
, m_lastInt(0)
+ , m_lastBool(false)
, m_lastDouble(0)
{
}
@@ -196,19 +197,81 @@ TestWebChannel::~TestWebChannel()
}
+int TestWebChannel::readInt() const
+{
+ return m_lastInt;
+}
+
void TestWebChannel::setInt(int i)
{
m_lastInt = i;
+ emit lastIntChanged();
+}
+
+bool TestWebChannel::readBool() const
+{
+ return m_lastBool;
+}
+
+void TestWebChannel::setBool(bool b)
+{
+ m_lastBool = b;
+ emit lastBoolChanged();
+}
+
+double TestWebChannel::readDouble() const
+{
+ return m_lastDouble;
}
void TestWebChannel::setDouble(double d)
{
m_lastDouble = d;
+ emit lastDoubleChanged();
+}
+
+QVariant TestWebChannel::readVariant() const
+{
+ return m_lastVariant;
}
void TestWebChannel::setVariant(const QVariant &v)
{
m_lastVariant = v;
+ emit lastVariantChanged();
+}
+
+QJsonValue TestWebChannel::readJsonValue() const
+{
+ return m_lastJsonValue;
+}
+
+void TestWebChannel::setJsonValue(const QJsonValue& v)
+{
+ m_lastJsonValue = v;
+ emit lastJsonValueChanged();
+}
+
+QJsonObject TestWebChannel::readJsonObject() const
+{
+ return m_lastJsonObject;
+}
+
+void TestWebChannel::setJsonObject(const QJsonObject& v)
+{
+ m_lastJsonObject = v;
+ emit lastJsonObjectChanged();
+}
+
+QJsonArray TestWebChannel::readJsonArray() const
+{
+ return m_lastJsonArray;
+}
+
+void TestWebChannel::setJsonArray(const QJsonArray& v)
+{
+ m_lastJsonArray = v;
+ emit lastJsonArrayChanged();
}
void TestWebChannel::testRegisterObjects()
@@ -290,6 +353,12 @@ void TestWebChannel::testInfoForObject()
}
{
QJsonArray method;
+ method.append(QStringLiteral("setReturnedObject"));
+ method.append(obj.metaObject()->indexOfMethod("setReturnedObject(TestObject*)"));
+ expected.append(method);
+ }
+ {
+ QJsonArray method;
method.append(QStringLiteral("setObjectProperty"));
method.append(obj.metaObject()->indexOfMethod("setObjectProperty(QObject*)"));
expected.append(method);
@@ -391,6 +460,19 @@ void TestWebChannel::testInfoForObject()
property.append(QJsonValue::fromVariant(QVariant::fromValue(obj.objectProperty())));
expected.append(property);
}
+ {
+ QJsonArray property;
+ property.append(obj.metaObject()->indexOfProperty("returnedObject"));
+ property.append(QStringLiteral("returnedObject"));
+ {
+ QJsonArray signal;
+ signal.append(1);
+ signal.append(obj.metaObject()->indexOfMethod("returnedObjectChanged()"));
+ property.append(signal);
+ }
+ property.append(QJsonValue::fromVariant(QVariant::fromValue(obj.returnedObject())));
+ expected.append(property);
+ }
QCOMPARE(info["properties"].toArray(), expected);
}
}
@@ -410,6 +492,14 @@ void TestWebChannel::testInvokeMethodConversion()
QCOMPARE(m_lastInt, args.at(0).toInt());
}
{
+ int method = metaObject()->indexOfMethod("setBool(bool)");
+ QVERIFY(method != -1);
+ QJsonArray args;
+ args.append(QJsonValue(!m_lastBool));
+ channel.d_func()->publisher->invokeMethod(this, method, args);
+ QCOMPARE(m_lastBool, args.at(0).toBool());
+ }
+ {
int method = metaObject()->indexOfMethod("setDouble(double)");
QVERIFY(method != -1);
channel.d_func()->publisher->invokeMethod(this, method, args);
@@ -421,6 +511,90 @@ void TestWebChannel::testInvokeMethodConversion()
channel.d_func()->publisher->invokeMethod(this, method, args);
QCOMPARE(m_lastVariant, args.at(0).toVariant());
}
+ {
+ int method = metaObject()->indexOfMethod("setJsonValue(QJsonValue)");
+ QVERIFY(method != -1);
+ channel.d_func()->publisher->invokeMethod(this, method, args);
+ QCOMPARE(m_lastJsonValue, args.at(0));
+ }
+ {
+ int method = metaObject()->indexOfMethod("setJsonObject(QJsonObject)");
+ QVERIFY(method != -1);
+ QJsonObject object;
+ object["foo"] = QJsonValue(123);
+ object["bar"] = QJsonValue(4.2);
+ args[0] = object;
+ channel.d_func()->publisher->invokeMethod(this, method, args);
+ QCOMPARE(m_lastJsonObject, object);
+ }
+ {
+ int method = metaObject()->indexOfMethod("setJsonArray(QJsonArray)");
+ QVERIFY(method != -1);
+ QJsonArray array;
+ array << QJsonValue(123);
+ array << QJsonValue(4.2);
+ args[0] = array;
+ channel.d_func()->publisher->invokeMethod(this, method, args);
+ QCOMPARE(m_lastJsonArray, array);
+ }
+}
+
+void TestWebChannel::testSetPropertyConversion()
+{
+ QWebChannel channel;
+ channel.connectTo(m_dummyTransport);
+
+ {
+ int property = metaObject()->indexOfProperty("lastInt");
+ QVERIFY(property != -1);
+ channel.d_func()->publisher->setProperty(this, property, QJsonValue(42));
+ QCOMPARE(m_lastInt, 42);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastBool");
+ QVERIFY(property != -1);
+ bool newValue = !m_lastBool;
+ channel.d_func()->publisher->setProperty(this, property, QJsonValue(newValue));
+ QCOMPARE(m_lastBool, newValue);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastDouble");
+ QVERIFY(property != -1);
+ channel.d_func()->publisher->setProperty(this, property, QJsonValue(-4.2));
+ QCOMPARE(m_lastDouble, -4.2);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastVariant");
+ QVERIFY(property != -1);
+ QVariant variant("foo bar asdf");
+ channel.d_func()->publisher->setProperty(this, property, QJsonValue::fromVariant(variant));
+ QCOMPARE(m_lastVariant, variant);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastJsonValue");
+ QVERIFY(property != -1);
+ QJsonValue value("asdf asdf");
+ channel.d_func()->publisher->setProperty(this, property, value);
+ QCOMPARE(m_lastJsonValue, value);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastJsonArray");
+ QVERIFY(property != -1);
+ QJsonArray array;
+ array << QJsonValue(-123);
+ array << QJsonValue(-42);
+ channel.d_func()->publisher->setProperty(this, property, array);
+ QCOMPARE(m_lastJsonArray, array);
+ }
+ {
+ int property = metaObject()->indexOfProperty("lastJsonObject");
+ QVERIFY(property != -1);
+ QJsonObject object;
+ object["foo"] = QJsonValue(-123);
+ object["bar"] = QJsonValue(-4.2);
+ channel.d_func()->publisher->setProperty(this, property, object);
+ QCOMPARE(m_lastJsonObject, object);
+ }
}
void TestWebChannel::testDisconnect()
@@ -455,6 +629,36 @@ void TestWebChannel::testWrapRegisteredObject()
QCOMPARE(obj.objectName(), returnedId);
}
+void TestWebChannel::testPassWrappedObjectBack()
+{
+ QWebChannel channel;
+ TestObject registeredObj;
+ TestObject returnedObjMethod;
+ TestObject returnedObjProperty;
+
+ registeredObj.setObjectName("registeredObject");
+
+ channel.registerObject(registeredObj.objectName(), &registeredObj);
+ channel.connectTo(m_dummyTransport);
+ channel.d_func()->publisher->initializeClient(m_dummyTransport);
+
+ QMetaObjectPublisher *pub = channel.d_func()->publisher;
+ QJsonObject returnedObjMethodInfo = pub->wrapResult(QVariant::fromValue(&returnedObjMethod), m_dummyTransport).toObject();
+ QJsonObject returnedObjPropertyInfo = pub->wrapResult(QVariant::fromValue(&returnedObjProperty), m_dummyTransport).toObject();
+
+ QJsonArray argsMethod;
+ QJsonObject argMethod0;
+ argMethod0["id"] = returnedObjMethodInfo["id"];
+ argsMethod << argMethod0;
+ QJsonObject argProperty;
+ argProperty["id"] = returnedObjPropertyInfo["id"];
+
+ pub->invokeMethod(&registeredObj, registeredObj.metaObject()->indexOfSlot("setReturnedObject(TestObject*)"), argsMethod);
+ QCOMPARE(registeredObj.mReturnedObject, &returnedObjMethod);
+ pub->setProperty(&registeredObj, registeredObj.metaObject()->indexOfProperty("returnedObject"), argProperty);
+ QCOMPARE(registeredObj.mReturnedObject, &returnedObjProperty);
+}
+
void TestWebChannel::testInfiniteRecursion()
{
QWebChannel channel;
@@ -607,6 +811,7 @@ void TestWebChannel::qtbug46548_overriddenProperties()
#endif // WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE
}
+
QTEST_MAIN(TestWebChannel)
#include "tst_webchannel.moc"
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index 98733dc..b46f21b 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -31,6 +31,9 @@
#include <QObject>
#include <QVariant>
+#include <QJsonValue>
+#include <QJsonObject>
+#include <QJsonArray>
#include <QtWebChannel/QWebChannelAbstractTransport>
@@ -65,11 +68,13 @@ class TestObject : public QObject
Q_PROPERTY(int asdf READ asdf NOTIFY asdfChanged)
Q_PROPERTY(QString bar READ bar NOTIFY theBarHasChanged)
Q_PROPERTY(QObject * objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectPropertyChanged)
+ Q_PROPERTY(TestObject * returnedObject READ returnedObject WRITE setReturnedObject NOTIFY returnedObjectChanged)
public:
explicit TestObject(QObject *parent = 0)
: QObject(parent)
, mObjectProperty(0)
+ , mReturnedObject(Q_NULLPTR)
{ }
enum Foo {
@@ -86,6 +91,11 @@ public:
return mObjectProperty;
}
+ TestObject *returnedObject() const
+ {
+ return mReturnedObject;
+ }
+
Q_INVOKABLE void method1() {}
protected:
@@ -100,11 +110,18 @@ signals:
void asdfChanged();
void theBarHasChanged();
void objectPropertyChanged();
+ void returnedObjectChanged();
public slots:
void slot1() {}
void slot2(const QString&) {}
+ void setReturnedObject(TestObject *obj)
+ {
+ mReturnedObject = obj;
+ emit returnedObjectChanged();
+ }
+
void setObjectProperty(QObject *object)
{
mObjectProperty = object;
@@ -119,6 +136,7 @@ private slots:
public:
QObject *mObjectProperty;
+ TestObject *mReturnedObject;
};
class BenchObject : public QObject
@@ -217,21 +235,50 @@ class TestWebChannel : public QObject
{
Q_OBJECT
+ Q_PROPERTY(int lastInt READ readInt WRITE setInt NOTIFY lastIntChanged);
+ Q_PROPERTY(bool lastBool READ readBool WRITE setBool NOTIFY lastBoolChanged);
+ Q_PROPERTY(double lastDouble READ readDouble WRITE setDouble NOTIFY lastDoubleChanged);
+ Q_PROPERTY(QVariant lastVariant READ readVariant WRITE setVariant NOTIFY lastVariantChanged);
+ Q_PROPERTY(QJsonValue lastJsonValue READ readJsonValue WRITE setJsonValue NOTIFY lastJsonValueChanged);
+ Q_PROPERTY(QJsonObject lastJsonObject READ readJsonObject WRITE setJsonObject NOTIFY lastJsonObjectChanged);
+ Q_PROPERTY(QJsonArray lastJsonArray READ readJsonArray WRITE setJsonArray NOTIFY lastJsonArrayChanged);
public:
explicit TestWebChannel(QObject *parent = 0);
virtual ~TestWebChannel();
+ int readInt() const;
Q_INVOKABLE void setInt(int i);
+ bool readBool() const;
+ Q_INVOKABLE void setBool(bool b);
+ double readDouble() const;
Q_INVOKABLE void setDouble(double d);
+ QVariant readVariant() const;
Q_INVOKABLE void setVariant(const QVariant &v);
+ QJsonValue readJsonValue() const;
+ Q_INVOKABLE void setJsonValue(const QJsonValue &v);
+ QJsonObject readJsonObject() const;
+ Q_INVOKABLE void setJsonObject(const QJsonObject &v);
+ QJsonArray readJsonArray() const;
+ Q_INVOKABLE void setJsonArray(const QJsonArray &v);
+
+signals:
+ void lastIntChanged();
+ void lastBoolChanged();
+ void lastDoubleChanged();
+ void lastVariantChanged();
+ void lastJsonValueChanged();
+ void lastJsonObjectChanged();
+ void lastJsonArrayChanged();
private slots:
void testRegisterObjects();
void testDeregisterObjects();
void testInfoForObject();
void testInvokeMethodConversion();
+ void testSetPropertyConversion();
void testDisconnect();
void testWrapRegisteredObject();
+ void testPassWrappedObjectBack();
void testInfiniteRecursion();
void benchClassInfo();
@@ -245,8 +292,12 @@ private:
DummyTransport *m_dummyTransport;
int m_lastInt;
+ bool m_lastBool;
double m_lastDouble;
QVariant m_lastVariant;
+ QJsonValue m_lastJsonValue;
+ QJsonObject m_lastJsonObject;
+ QJsonArray m_lastJsonArray;
};
QT_END_NAMESPACE