2 * Copyright 2013-2015 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>
18 * Lukáš Tinkl <lukas.tinkl@canonical.com>
22#include <QDBusConnection>
23#include <QDBusMessage>
24#include <QDBusInterface>
26#include <QDBusVariant>
28#include <QDBusObjectPath>
33#include "dbusunitysessionservice.h"
35enum class Action : unsigned
43class SessionBackendTest : public QObject
50 dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
51 "/com/canonical/Unity/Session",
52 "com.canonical.Unity.Session",
53 QDBusConnection::sessionBus());
56 void testUnitySessionLogoutRequested_data() {
57 QTest::addColumn<QString>("method");
58 QTest::addColumn<QString>("signal");
60 QTest::newRow("Logout") << "RequestLogout" << "LogoutRequested(bool)";
61 QTest::newRow("Reboot") << "RequestReboot" << "RebootRequested(bool)";
62 QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
63 QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
64 QTest::newRow("Lock") << "Lock" << "LockRequested()";
65 QTest::newRow("LockLightDM") << "Lock" << "Locked()"; // happens when we lock LightDM, only for Lock()
68 void testUnitySessionLogoutRequested() {
69 QFETCH(QString, method);
70 QFETCH(QString, signal);
72 DBusUnitySessionService dbusUnitySessionService;
73 QCoreApplication::processEvents(); // to let the service register on DBus
75 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
76 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
78 QDBusReply<void> reply = dbusUnitySession->call(method);
79 QCOMPARE(reply.isValid(), true);
81 QTRY_COMPARE(spy.count(), 1);
84 void testGnomeSessionWrapper_data() {
85 QTest::addColumn<uint>("method");
86 QTest::addColumn<QString>("signal");
88 QTest::newRow("Logout") << (uint)Action::LOGOUT << "LogoutRequested(bool)";
89 QTest::newRow("Shutdown") << (uint)Action::SHUTDOWN << "ShutdownRequested(bool)";
90 QTest::newRow("Reboot") << (uint)Action::REBOOT << "RebootRequested(bool)";
93 void testGnomeSessionWrapper() {
95 QFETCH(QString, signal);
97 DBusUnitySessionService dbusUnitySessionService;
98 QCoreApplication::processEvents(); // to let the service register on DBus
100 // Spy on the given signal on the /com/canonical/Unity/Session object
101 // as proof we are actually calling the actual method.
102 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
103 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
105 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
106 QCoreApplication::processEvents(); // to let the service register on DBus
108 QDBusInterface dbusGnomeSessionWrapper("com.canonical.Unity",
109 "/org/gnome/SessionManager/EndSessionDialog",
110 "org.gnome.SessionManager.EndSessionDialog",
111 QDBusConnection::sessionBus());
113 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
115 // Set the QVariant as a QList<QDBusObjectPath> type
118 inhibitors.setValue(var);
120 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", method, (unsigned)0, (unsigned)0, inhibitors);
121 QCOMPARE(reply.isValid(), true);
123 // Make sure we see the signal being emitted.
124 QCOMPARE(spy.count(), 1);
127 void testUnlockFromLogind() {
128 DBusUnitySessionService dbusUnitySessionService;
129 QCoreApplication::processEvents(); // to let the service register on DBus
131 QDBusInterface iface("org.freedesktop.login1", "/logindsession", "org.freedesktop.login1.Session");
132 QVERIFY(iface.isValid());
134 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(Unlocked()));
135 QCOMPARE(iface.call("MockEmitUnlock").errorMessage(), QString());
136 QTRY_COMPARE(spy.count(), 1);
139 void testUserName() {
140 DBusUnitySessionService dbusUnitySessionService;
141 QCoreApplication::processEvents(); // to let the service register on DBus
143 QProcess * proc = new QProcess(this);
144 proc->start("id -un", QProcess::ReadOnly);
145 proc->waitForFinished();
146 const QByteArray out = proc->readAll().trimmed();
148 QCOMPARE(dbusUnitySessionService.UserName(), QString::fromUtf8(out));
151 void testRealName() {
152 DBusUnitySessionService dbusUnitySessionService;
153 QCoreApplication::processEvents(); // to let the service register on DBus
155 QDBusInterface accIface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", QDBusConnection::systemBus());
156 if (accIface.isValid()) {
157 QDBusReply<QDBusObjectPath> userPath = accIface.asyncCall("FindUserById", static_cast<qint64>(geteuid()));
158 if (userPath.isValid()) {
159 QDBusInterface userAccIface("org.freedesktop.Accounts", userPath.value().path(), "org.freedesktop.Accounts.User", QDBusConnection::systemBus());
160 QCOMPARE(dbusUnitySessionService.RealName(), userAccIface.property("RealName").toString());
166 QDBusInterface *dbusUnitySession;
169QTEST_GUILESS_MAIN(SessionBackendTest)
170#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