@@ -26,6 +26,14 @@
2626
2727#include "dbusunitysessionservice.h"
2828
29+enum class Action : unsigned
30+{
31+ LOGOUT = 0,
32+ SHUTDOWN,
33+ REBOOT,
34+ NONE
35+};
36+
2937class SessionBackendTest : public QObject
3038{
3139 Q_OBJECT
@@ -33,32 +41,96 @@ class SessionBackendTest : public QObject
3341private Q_SLOTS:
3442
3543 void initTestCase() {
44+ dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
45+ "/com/canonical/Unity/Session",
46+ "com.canonical.Unity.Session",
47+ QDBusConnection::sessionBus());
3648 }
3749
38− void testDbusIfaceMethods_data() {
50+ void testUnitySessionLogoutRequested_data() {
3951 QTest::addColumn<QString>("method");
4052
4153 QTest::newRow("Logout") << "RequestLogout";
4254 }
4355
44− void testDbusIfaceMethods() {
56+ void testUnitySessionLogoutRequested() {
4557 QFETCH(QString, method);
4658
4759 DBusUnitySessionService dbusUnitySessionService;
4860 QCoreApplication::processEvents(); // to let the service register on DBus
4961
50− QDBusConnection con = QDBusConnection::sessionBus();
51− QDBusInterface interface ("com.canonical.Unity",
52− "/com/canonical/Unity/Session",
53− "com.canonical.Unity.Session",
54− con);
55− QDBusReply<void> reply;
62+ QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
63+
64+ QDBusReply<void> reply = dbusUnitySession->call(method);
65+ QCOMPARE(reply.isValid(), true);
66+
67+ QCOMPARE(spy.count(), 1);
68+ }
69+
70+ void testGnomeSessionWrapperLogoutRequested() {
71+ DBusUnitySessionService dbusUnitySessionService;
72+ QCoreApplication::processEvents(); // to let the service register on DBus
73+
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)));
77+
78+ DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
79+ QCoreApplication::processEvents(); // to let the service register on DBus
80+
81+ QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
82+ "/org/gnome/SessionManager/EndSessionDialog",
83+ "org.gnome.SessionManager.EndSessionDialog",
84+ QDBusConnection::sessionBus());
85+
86+ QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
87+
88+ // Set the QVariant as a QList<QDBusObjectPath> type
89+ QDbusList var;
90+ QVariant inhibitors;
91+ inhibitors.setValue(var);
92+
93+ QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::LOGOUT, (unsigned)0, (unsigned)0, inhibitors);
94+ QCOMPARE(reply.isValid(), true);
95+
96+ // Make sure we see the signal being emitted.
97+ QCOMPARE(spy.count(), 1);
98+ }
99+
100+ void testGnomeSessionWrapperShutdownRequested() {
101+ DBusUnitySessionService dbusUnitySessionService;
102+ QCoreApplication::processEvents(); // to let the service register on DBus
103+
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)));
107+
108+ DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
109+ QCoreApplication::processEvents(); // to let the service register on DBus
110+
111+ QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
112+ "/org/gnome/SessionManager/EndSessionDialog",
113+ "org.gnome.SessionManager.EndSessionDialog",
114+ QDBusConnection::sessionBus());
56115
57− QCOMPARE(interface.isValid(), true);
58− reply = interface.call(method);
116+ QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
117+
118+ // Set the QVariant as a QList<QDBusObjectPath> type
119+ QDbusList var;
120+ QVariant inhibitors;
121+ inhibitors.setValue(var);
122+
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);
59126 QCOMPARE(reply.isValid(), true);
60127
128+ // Make sure we see the signal being emitted.
129+ QCOMPARE(spy.count(), 1);
61130 }
131+
132+private:
133+ QDBusInterface *dbusUnitySession;
62134};
63135
64136QTEST_GUILESS_MAIN(SessionBackendTest)