pluginloadtest.cpp 3.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
 * Copyright 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 * 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
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 20 21
 */

#include <QSocketNotifier>
22
#include <QCoreApplication>
23 24 25 26 27 28 29 30 31
#include <QNetworkAccessManager>
#include <QTest>
#include <QTemporaryFile>
#include <QSignalSpy>
#include <QStandardPaths>

#include "core/daemon.h"
#include "core/device.h"
#include "core/kdeconnectplugin.h"
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
32
#include <backends/pairinghandler.h>
33
#include "kdeconnect-version.h"
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
34
#include "testdaemon.h"
35 36 37 38 39

class PluginLoadTest : public QObject
{
    Q_OBJECT
    public:
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40
        PluginLoadTest() {
41
            QStandardPaths::setTestModeEnabled(true);
42
            m_daemon = new TestDaemon;
43 44 45 46
        }

    private Q_SLOTS:
        void testPlugins() {
Simon Redman's avatar
Simon Redman committed
47 48 49 50
            if (!(m_daemon->getLinkProviders().size() > 0)) {
                QFAIL("No links available, but loopback should have been provided by the test");
            }

51
            Device* d = nullptr;
52 53
            m_daemon->acquireDiscoveryMode(QStringLiteral("plugintest"));
            const QList<Device*> devicesList = m_daemon->devicesList();
54
            for (Device* id : devicesList) {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
55
                if (id->isReachable()) {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
56 57
                    if (!id->isTrusted())
                        id->requestPair();
58
                    d = id;
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
59
                    break;
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
60
                }
61
            }
Simon Redman's avatar
Simon Redman committed
62 63 64
            if (d == nullptr) {
                QFAIL("Unable to determine device");
            }
65
            m_daemon->releaseDiscoveryMode(QStringLiteral("plugintest"));
66

67
            if (!d->loadedPlugins().contains(QStringLiteral("kdeconnect_remotecontrol"))) {
68 69 70
                QSKIP("kdeconnect_remotecontrol is required for this test");
            }

71
            QVERIFY(d);
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
72
            QVERIFY(d->isTrusted());
73 74
            QVERIFY(d->isReachable());

75
            d->setPluginEnabled(QStringLiteral("kdeconnect_mousepad"), false);
76 77
            QCOMPARE(d->isPluginEnabled(QStringLiteral("kdeconnect_mousepad")), false);
            QVERIFY(d->supportedPlugins().contains(QStringLiteral("kdeconnect_remotecontrol")));
78

79
            d->setPluginEnabled(QStringLiteral("kdeconnect_mousepad"), true);
80 81
            QCOMPARE(d->isPluginEnabled(QStringLiteral("kdeconnect_mousepad")), true);
            QVERIFY(d->supportedPlugins().contains(QStringLiteral("kdeconnect_remotecontrol")));
82 83 84
        }

    private:
85
        TestDaemon* m_daemon;
86 87 88 89 90
};

QTEST_MAIN(PluginLoadTest);

#include "pluginloadtest.moc"