From 24ab6d15cfc22b4354c7f1992d124cd17d322035 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Sun, 2 Jun 2019 21:26:47 +0000 Subject: [PATCH] ## Summary pluginloadtest and sendfiletest are crashing. This patch fixes that by allowing Daemon::init() to be called from TestDaemon ## Test Plan ### Before: Both tests are crashing because it is not able to find any devices. It is not able to find any devices because the LanLinkProvider is not being added because Daemon::init() is not being called. ### After: pluginloadtest and sendfiletest pass --- core/daemon.cpp | 5 +++++ core/daemon.h | 2 ++ tests/pluginloadtest.cpp | 7 +++++++ tests/sendfiletest.cpp | 8 +++++++- tests/testdaemon.h | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/daemon.cpp b/core/daemon.cpp index 2ecf1526a..3d631801b 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -179,6 +179,11 @@ Device*Daemon::getDevice(const QString& deviceId) return nullptr; } +const QSet& Daemon::getLinkProviders() const +{ + return d->m_linkProviders; +} + QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const { QStringList ret; diff --git a/core/daemon.h b/core/daemon.h index c498d3cbc..83b3fa5db 100644 --- a/core/daemon.h +++ b/core/daemon.h @@ -56,6 +56,8 @@ public: Device* getDevice(const QString& deviceId); + const QSet& getLinkProviders() const; + QStringList pairingRequests() const; Q_SCRIPTABLE QString selfId() const; diff --git a/tests/pluginloadtest.cpp b/tests/pluginloadtest.cpp index 3375980e5..98f9cd896 100644 --- a/tests/pluginloadtest.cpp +++ b/tests/pluginloadtest.cpp @@ -46,6 +46,10 @@ class PluginLoadTest : public QObject private Q_SLOTS: void testPlugins() { + if (!(m_daemon->getLinkProviders().size() > 0)) { + QFAIL("No links available, but loopback should have been provided by the test"); + } + Device* d = nullptr; m_daemon->acquireDiscoveryMode(QStringLiteral("plugintest")); const QList devicesList = m_daemon->devicesList(); @@ -57,6 +61,9 @@ class PluginLoadTest : public QObject break; } } + if (d == nullptr) { + QFAIL("Unable to determine device"); + } m_daemon->releaseDiscoveryMode(QStringLiteral("plugintest")); if (!d->loadedPlugins().contains(QStringLiteral("kdeconnect_remotecontrol"))) { diff --git a/tests/sendfiletest.cpp b/tests/sendfiletest.cpp index 28373391b..892adc7c4 100644 --- a/tests/sendfiletest.cpp +++ b/tests/sendfiletest.cpp @@ -51,6 +51,10 @@ class TestSendFile : public QObject private Q_SLOTS: void testSend() { + if (!(m_daemon->getLinkProviders().size() > 0)) { + QFAIL("No links available, but loopback should have been provided by the test"); + } + m_daemon->acquireDiscoveryMode(QStringLiteral("test")); Device* d = nullptr; const QList devicesList = m_daemon->devicesList(); @@ -61,8 +65,10 @@ class TestSendFile : public QObject d = id; } } + if (d == nullptr) { + QFAIL("Unable to determine device"); + } m_daemon->releaseDiscoveryMode(QStringLiteral("test")); - QVERIFY(d); QCOMPARE(d->isReachable(), true); QCOMPARE(d->isTrusted(), true); diff --git a/tests/testdaemon.h b/tests/testdaemon.h index 3144c6011..dd64d1058 100644 --- a/tests/testdaemon.h +++ b/tests/testdaemon.h @@ -31,6 +31,9 @@ public: : Daemon(parent, true) , m_nam(nullptr) { + // Necessary to force the event loop to run because the test harness seems to behave differently + // and we need the QTimer::SingleShot in Daemon's constructor to fire + QCoreApplication::processEvents(); } void addDevice(Device* device) {