diff --git a/core/device.h b/core/device.h index 15fd73ea8..699a8b06b 100644 --- a/core/device.h +++ b/core/device.h @@ -87,7 +87,7 @@ public: Q_SCRIPTABLE bool isTrusted() const; Q_SCRIPTABLE QStringList availableLinks() const; - bool isReachable() const; + virtual bool isReachable() const; Q_SCRIPTABLE QStringList loadedPlugins() const; Q_SCRIPTABLE bool hasPlugin(const QString& name) const; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 87dfd755f..cf3852231 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,7 @@ ecm_add_test(kdeconnectconfigtest.cpp TEST_NAME kdeconnectconfigtest LINK_LIBRAR ecm_add_test(lanlinkprovidertest.cpp TEST_NAME lanlinkprovidertest LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(devicetest.cpp TEST_NAME devicetest LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(testnotificationlistener.cpp + testdevice.cpp ../plugins/sendnotifications/sendnotificationsplugin.cpp ../plugins/sendnotifications/notificationslistener.cpp ../plugins/sendnotifications/notifyingapplication.cpp diff --git a/tests/testdevice.cpp b/tests/testdevice.cpp new file mode 100644 index 000000000..5aab05e22 --- /dev/null +++ b/tests/testdevice.cpp @@ -0,0 +1,52 @@ +/** + * Copyright 2015 Holger Kaelberer + * Copyright 2019 Simon Redman + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "testdevice.h" + +TestDevice::TestDevice(QObject* parent, const QString& id) + : Device (parent, id) + , sentPackets(0) + , lastPacket(nullptr) +{} + +TestDevice::~TestDevice() +{ + delete lastPacket; +} + +bool TestDevice::isReachable() const +{ + return true; +} + +bool TestDevice::sendPacket(NetworkPacket& np) +{ + ++sentPackets; + // copy packet manually to allow for inspection (can't use copy-constructor) + deleteLastPacket(); + lastPacket = new NetworkPacket(np.type()); + Q_ASSERT(lastPacket); + for (QVariantMap::ConstIterator iter = np.body().constBegin(); + iter != np.body().constEnd(); iter++) + lastPacket->set(iter.key(), iter.value()); + lastPacket->setPayload(np.payload(), np.payloadSize()); + return true; +} diff --git a/tests/testdevice.h b/tests/testdevice.h new file mode 100644 index 000000000..ebdd525d3 --- /dev/null +++ b/tests/testdevice.h @@ -0,0 +1,60 @@ +/** + * Copyright 2015 Holger Kaelberer + * Copyright 2019 Simon Redman + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "core/device.h" + +// Tweaked Device for testing: +class TestDevice: public Device +{ + Q_OBJECT +private: + int sentPackets; + NetworkPacket* lastPacket; + +public: + explicit TestDevice(QObject* parent, const QString& id); + + ~TestDevice() override; + + bool isReachable() const override; + + int getSentPackets() const + { + return sentPackets; + } + + NetworkPacket* getLastPacket() + { + return lastPacket; + } + +private: + void deleteLastPacket() + { + delete lastPacket; + lastPacket = nullptr; + } + +public Q_SLOTS: + bool sendPacket(NetworkPacket& np) override; + +}; diff --git a/tests/testnotificationlistener.cpp b/tests/testnotificationlistener.cpp index 211a39234..4897df6a8 100644 --- a/tests/testnotificationlistener.cpp +++ b/tests/testnotificationlistener.cpp @@ -31,6 +31,7 @@ #include "core/daemon.h" #include "core/device.h" +#include "testdevice.h" #include "core/kdeconnectplugin.h" #include "kdeconnect-version.h" #include "plugins/sendnotifications/sendnotificationsplugin.h" @@ -62,58 +63,6 @@ public: }; -// Tweaked Device for testing: -class TestDevice: public Device -{ - Q_OBJECT -private: - int sentPackets; - NetworkPacket* lastPacket; - -public: - explicit TestDevice(QObject* parent, const QString& id) - : Device (parent, id) - , sentPackets(0) - , lastPacket(nullptr) - {} - - ~TestDevice() override - { - delete lastPacket; - } - - int getSentPackets() const - { - return sentPackets; - } - - NetworkPacket* getLastPacket() - { - return lastPacket; - } - - void deleteLastPacket() - { - delete lastPacket; - lastPacket = nullptr; - } - -public Q_SLOTS: - bool sendPacket(NetworkPacket& np) override - { - ++sentPackets; - // copy packet manually to allow for inspection (can't use copy-constructor) - deleteLastPacket(); - lastPacket = new NetworkPacket(np.type()); - Q_ASSERT(lastPacket); - for (QVariantMap::ConstIterator iter = np.body().constBegin(); - iter != np.body().constEnd(); iter++) - lastPacket->set(iter.key(), iter.value()); - lastPacket->setPayload(np.payload(), np.payloadSize()); - return true; - } -}; - // Tweaked NotificationsListener for testing: class TestedNotificationsListener: public NotificationsListener {