on bionic help sign in
unity8/tests/plugins/SessionBroadcast/sessionbroadcasttest.cpp
111 lines 3.8 kB history raw
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include <QtTest>
18#include <QDBusInterface>
19#include <QSignalSpy>
21#include <glib.h>
23#include "SessionBroadcast.h"
25class SessionBroadcastTest : public QObject
27 Q_OBJECT
29private Q_SLOTS:
31 void initTestCase() {
32 broadcastServer = new QDBusInterface("com.canonical.Unity.Greeter.Broadcast",
33 "/com/canonical/Unity/Greeter/Broadcast",
34 "com.canonical.Unity.Greeter.Broadcast",
35 QDBusConnection::sessionBus(), this);
36 serverStartUrlSpy = new QSignalSpy(broadcastServer,
37 SIGNAL(StartUrl(const QString &, const QString &)));
38 serverShowHomeSpy = new QSignalSpy(broadcastServer,
39 SIGNAL(ShowHome(const QString &)));
40 user = QString(g_get_user_name());
41 otherUser = user + "2";
42 }
44 void init()
45 {
46 serverStartUrlSpy->clear();
47 serverShowHomeSpy->clear();
49 broadcastPlugin = new SessionBroadcast(this);
50 pluginStartUrlSpy = new QSignalSpy(broadcastPlugin,
51 SIGNAL(startUrl(const QString &)));
52 pluginShowHomeSpy = new QSignalSpy(broadcastPlugin,
53 SIGNAL(showHome()));
54 }
56 void cleanup()
57 {
58 delete broadcastPlugin;
59 }
61 void testReceiveUrlStart() {
62 broadcastServer->call("RequestUrlStart", user, "test:");
63 QTRY_COMPARE(serverStartUrlSpy->count(), 1);
64 QCOMPARE(pluginStartUrlSpy->count(), 1);
65 QCOMPARE((*pluginStartUrlSpy)[0][0], QVariant("test:"));
66 }
68 void testReceiveUrlStartOtherUser() {
69 broadcastServer->call("RequestUrlStart", otherUser, "test:");
70 QTRY_COMPARE(serverStartUrlSpy->count(), 1);
71 QCOMPARE(pluginStartUrlSpy->count(), 0);
72 }
74 void testReceiveShowHome() {
75 broadcastServer->call("RequestHomeShown", user);
76 QTRY_COMPARE(serverShowHomeSpy->count(), 1);
77 QCOMPARE(pluginShowHomeSpy->count(), 1);
78 }
80 void testReceiveShowHomeOtherUser() {
81 broadcastServer->call("RequestHomeShown", otherUser);
82 QTRY_COMPARE(serverShowHomeSpy->count(), 1);
83 QCOMPARE(pluginShowHomeSpy->count(), 0);
84 }
86 void testSendUrlStart() {
87 broadcastPlugin->requestUrlStart(otherUser, "test:");
88 QTRY_COMPARE(serverStartUrlSpy->count(), 1);
89 QCOMPARE((*serverStartUrlSpy)[0][0], QVariant(otherUser));
90 QCOMPARE((*serverStartUrlSpy)[0][1], QVariant("test:"));
91 }
93 void testSendShowHome() {
94 broadcastPlugin->requestHomeShown(otherUser);
95 QTRY_COMPARE(serverShowHomeSpy->count(), 1);
96 QCOMPARE((*serverShowHomeSpy)[0][0], QVariant(otherUser));
97 }
99private:
100 QDBusInterface *broadcastServer;
101 SessionBroadcast *broadcastPlugin;
102 QSignalSpy *serverStartUrlSpy;
103 QSignalSpy *serverShowHomeSpy;
104 QSignalSpy *pluginStartUrlSpy;
105 QSignalSpy *pluginShowHomeSpy;
106 QString user;
107 QString otherUser;
108};
110QTEST_GUILESS_MAIN(SessionBroadcastTest)
111#include "sessionbroadcasttest.moc"