Commit 9453e640 authored by Simon Redman's avatar Simon Redman

Refactor testdevice

parent 673c3ced
Pipeline #4049 passed with stage
in 29 minutes and 7 seconds
......@@ -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;
......
......@@ -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
......
/**
* Copyright 2015 Holger Kaelberer <holger.k@elberer.de>
* Copyright 2019 Simon Redman <simon@ergotech.com>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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;
}
/**
* Copyright 2015 Holger Kaelberer <holger.k@elberer.de>
* Copyright 2019 Simon Redman <simon@ergotech.com>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include <QtCore>
#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;
};
......@@ -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
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment