on 28cd643 help sign in
unity8/tests/plugins/Unity/Session/sessionbackendtest.cpp
137 lines 5.1 kB history raw
1/*
2 * Copyright 2013 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 *
16 * Authors:
17 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18 */
20#include <QtTest>
21#include <QDBusConnection>
22#include <QDBusMessage>
23#include <QDBusInterface>
24#include <QDBusReply>
25#include <QDBusVariant>
27#include "dbusunitysessionservice.h"
29enum class Action : unsigned
31 LOGOUT = 0,
32 SHUTDOWN,
33 REBOOT,
34 NONE
35};
37class SessionBackendTest : public QObject
39 Q_OBJECT
41private Q_SLOTS:
43 void initTestCase() {
44 dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
45 "/com/canonical/Unity/Session",
46 "com.canonical.Unity.Session",
47 QDBusConnection::sessionBus());
48 }
50 void testUnitySessionLogoutRequested_data() {
51 QTest::addColumn<QString>("method");
53 QTest::newRow("Logout") << "RequestLogout";
54 }
56 void testUnitySessionLogoutRequested() {
57 QFETCH(QString, method);
59 DBusUnitySessionService dbusUnitySessionService;
60 QCoreApplication::processEvents(); // to let the service register on DBus
62 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
64 QDBusReply<void> reply = dbusUnitySession->call(method);
65 QCOMPARE(reply.isValid(), true);
67 QCOMPARE(spy.count(), 1);
68 }
70 void testGnomeSessionWrapperLogoutRequested() {
71 DBusUnitySessionService dbusUnitySessionService;
72 QCoreApplication::processEvents(); // to let the service register on DBus
74 // Spy on the logoutRequested signal on the /com/canonical/Unity/Session object
75 // as proof we are actually calling the actual method.
76 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
78 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
79 QCoreApplication::processEvents(); // to let the service register on DBus
81 QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
82 "/org/gnome/SessionManager/EndSessionDialog",
83 "org.gnome.SessionManager.EndSessionDialog",
84 QDBusConnection::sessionBus());
86 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
88 // Set the QVariant as a QList<QDBusObjectPath> type
89 QDbusList var;
90 QVariant inhibitors;
91 inhibitors.setValue(var);
93 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::LOGOUT, (unsigned)0, (unsigned)0, inhibitors);
94 QCOMPARE(reply.isValid(), true);
96 // Make sure we see the signal being emitted.
97 QCOMPARE(spy.count(), 1);
98 }
100 void testGnomeSessionWrapperShutdownRequested() {
101 DBusUnitySessionService dbusUnitySessionService;
102 QCoreApplication::processEvents(); // to let the service register on DBus
104 // Spy on the shutdownRequested signal on the /com/canonical/Unity/Session object
105 // as proof we are actually calling the actual method.
106 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(shutdownRequested(bool)));
108 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
109 QCoreApplication::processEvents(); // to let the service register on DBus
111 QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
112 "/org/gnome/SessionManager/EndSessionDialog",
113 "org.gnome.SessionManager.EndSessionDialog",
114 QDBusConnection::sessionBus());
116 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
118 // Set the QVariant as a QList<QDBusObjectPath> type
119 QDbusList var;
120 QVariant inhibitors;
121 inhibitors.setValue(var);
123 // * Reboot action translates to the shutdown signal due to some weird idiosyncracy
124 // in the indicator-session/Unity interaction. *
125 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::REBOOT, (unsigned)0, (unsigned)0, inhibitors);
126 QCOMPARE(reply.isValid(), true);
128 // Make sure we see the signal being emitted.
129 QCOMPARE(spy.count(), 1);
130 }
132private:
133 QDBusInterface *dbusUnitySession;
134};
136QTEST_GUILESS_MAIN(SessionBackendTest)
137#include "sessionbackendtest.moc"