2 * Copyright 2013 Canonical Ltd.
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.
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.
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/>.
17 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
21#include <QDBusConnection>
22#include <QDBusMessage>
23#include <QDBusInterface>
25#include <QDBusVariant>
27#include "dbusunitysessionservice.h"
29enum class Action : unsigned
37class SessionBackendTest : public QObject
44 dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
45 "/com/canonical/Unity/Session",
46 "com.canonical.Unity.Session",
47 QDBusConnection::sessionBus());
50 void testUnitySessionLogoutRequested_data() {
51 QTest::addColumn<QString>("method");
53 QTest::newRow("Logout") << "RequestLogout";
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);
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
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);
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
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);
133 QDBusInterface *dbusUnitySession;
136QTEST_GUILESS_MAIN(SessionBackendTest)
137#include "sessionbackendtest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list