1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* Copyright 2016 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtTest>
#include <QDBusInterface>
#include <QSignalSpy>
#include <glib.h>
#include "SessionBroadcast.h"
class SessionBroadcastTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase() {
broadcastServer = new QDBusInterface("com.lomiri.Shell.Greeter.Broadcast",
"/com/lomiri/Shell/Greeter/Broadcast",
"com.lomiri.Shell.Greeter.Broadcast",
QDBusConnection::sessionBus(), this);
serverStartUrlSpy = new QSignalSpy(broadcastServer,
SIGNAL(StartUrl(const QString &, const QString &)));
serverShowHomeSpy = new QSignalSpy(broadcastServer,
SIGNAL(ShowHome(const QString &)));
user = QString(g_get_user_name());
otherUser = user + "2";
}
void init()
{
serverStartUrlSpy->clear();
serverShowHomeSpy->clear();
broadcastPlugin = new SessionBroadcast(this);
pluginStartUrlSpy = new QSignalSpy(broadcastPlugin,
SIGNAL(startUrl(const QString &)));
pluginShowHomeSpy = new QSignalSpy(broadcastPlugin,
SIGNAL(showHome()));
}
void cleanup()
{
delete broadcastPlugin;
}
void testReceiveUrlStart() {
broadcastServer->call("RequestUrlStart", user, "test:");
QTRY_COMPARE(serverStartUrlSpy->count(), 1);
QCOMPARE(pluginStartUrlSpy->count(), 1);
QCOMPARE((*pluginStartUrlSpy)[0][0], QVariant("test:"));
}
void testReceiveUrlStartOtherUser() {
broadcastServer->call("RequestUrlStart", otherUser, "test:");
QTRY_COMPARE(serverStartUrlSpy->count(), 1);
QCOMPARE(pluginStartUrlSpy->count(), 0);
}
void testReceiveShowHome() {
broadcastServer->call("RequestHomeShown", user);
QTRY_COMPARE(serverShowHomeSpy->count(), 1);
QCOMPARE(pluginShowHomeSpy->count(), 1);
}
void testReceiveShowHomeOtherUser() {
broadcastServer->call("RequestHomeShown", otherUser);
QTRY_COMPARE(serverShowHomeSpy->count(), 1);
QCOMPARE(pluginShowHomeSpy->count(), 0);
}
void testSendUrlStart() {
broadcastPlugin->requestUrlStart(otherUser, "test:");
QTRY_COMPARE(serverStartUrlSpy->count(), 1);
QCOMPARE((*serverStartUrlSpy)[0][0], QVariant(otherUser));
QCOMPARE((*serverStartUrlSpy)[0][1], QVariant("test:"));
}
void testSendShowHome() {
broadcastPlugin->requestHomeShown(otherUser);
QTRY_COMPARE(serverShowHomeSpy->count(), 1);
QCOMPARE((*serverShowHomeSpy)[0][0], QVariant(otherUser));
}
private:
QDBusInterface *broadcastServer;
SessionBroadcast *broadcastPlugin;
QSignalSpy *serverStartUrlSpy;
QSignalSpy *serverShowHomeSpy;
QSignalSpy *pluginStartUrlSpy;
QSignalSpy *pluginShowHomeSpy;
QString user;
QString otherUser;
};
QTEST_GUILESS_MAIN(SessionBroadcastTest)
#include "sessionbroadcasttest.moc"
|