pluginloadtest.cpp 3.18 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 22 23 24 25 26 27 28 29 30 31 32 33
 */

#include <QSocketNotifier>
#include <QApplication>
#include <QNetworkAccessManager>
#include <QTest>
#include <QTemporaryFile>
#include <QSignalSpy>
#include <QStandardPaths>

#include <KIO/AccessManager>

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

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

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

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

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

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

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

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

    private:
87
        TestDaemon* m_daemon;
88 89 90 91 92
};

QTEST_MAIN(PluginLoadTest);

#include "pluginloadtest.moc"