summaryrefslogtreecommitdiff
path: root/tests/auto/webchannel/tst_webchannel.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-01-18 18:04:08 +0100
committerLiang Qi <liang.qi@qt.io>2018-01-18 18:11:34 +0100
commita2b88f9ba0ce2e03ffa73ba26e910e988db5d6c1 (patch)
treea0c539d40f2f165cefb07e231e9763cc795e8c01 /tests/auto/webchannel/tst_webchannel.cpp
parentee70a3dc1dff15f6fc00ea979ae0c169e201acab (diff)
parent97d2deb55b854fd2b97efc0a5b41da28444c6e78 (diff)
downloadqtwebchannel-a2b88f9ba0ce2e03ffa73ba26e910e988db5d6c1.tar.gz
Merge remote-tracking branch 'origin/5.9' into 5.105.10
Conflicts: .qmake.conf Change-Id: Id5d79a1cd456c79ef35a323d1a8713facde2ef91
Diffstat (limited to 'tests/auto/webchannel/tst_webchannel.cpp')
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index a44220f..436a38e 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -814,6 +814,58 @@ void TestWebChannel::testAsyncObject()
thread.wait();
}
+class FunctionWrapper : public QObject
+{
+ Q_OBJECT
+ std::function<void()> m_fun;
+public:
+ FunctionWrapper(std::function<void()> fun) : m_fun(std::move(fun)) {}
+public slots:
+ void invoke()
+ {
+ m_fun();
+ }
+};
+
+void TestWebChannel::testDeletionDuringMethodInvocation_data()
+{
+ QTest::addColumn<bool>("deleteChannel");
+ QTest::addColumn<bool>("deleteTransport");
+ QTest::newRow("delete neither") << false << false;
+ QTest::newRow("delete channel") << true << false;
+ QTest::newRow("delete transport") << false << true;
+ QTest::newRow("delete both") << true << true;
+}
+
+void TestWebChannel::testDeletionDuringMethodInvocation()
+{
+ QFETCH(bool, deleteChannel);
+ QFETCH(bool, deleteTransport);
+
+ QScopedPointer<QWebChannel> channel(new QWebChannel);
+ QScopedPointer<DummyTransport> transport(new DummyTransport(nullptr));
+ FunctionWrapper deleter([&](){
+ if (deleteChannel)
+ channel.reset();
+ if (deleteTransport)
+ transport.reset();
+ });
+ channel->registerObject("deleter", &deleter);
+ channel->connectTo(transport.data());
+
+ transport->emitMessageReceived({
+ {"type", TypeInvokeMethod},
+ {"object", "deleter"},
+ {"method", deleter.metaObject()->indexOfMethod("invoke()")},
+ {"id", 42}
+ });
+
+ QCOMPARE(deleteChannel, !channel);
+ QCOMPARE(deleteTransport, !transport);
+ if (!deleteTransport)
+ QCOMPARE(transport->messagesSent().size(), deleteChannel ? 0 : 1);
+}
+
static QHash<QString, QObject*> createObjects(QObject *parent)
{
const int num = 100;