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()";
67 void testUnitySessionLogoutRequested() {
68 QFETCH(QString, method);
69 QFETCH(QString, signal);
71 DBusUnitySessionService dbusUnitySessionService;
72 QCoreApplication::processEvents(); // to let the service register on DBus
74 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
75 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
77 QDBusReply<void> reply = dbusUnitySession->call(method);
78 QCOMPARE(reply.isValid(), true);
80 QTRY_COMPARE(spy.count(), 1);
83 void testGnomeSessionWrapper_data() {
84 QTest::addColumn<uint>("method");
85 QTest::addColumn<QString>("signal");
87 QTest::newRow("Logout") << (uint)Action::LOGOUT << "LogoutRequested(bool)";
88 QTest::newRow("Shutdown") << (uint)Action::SHUTDOWN << "ShutdownRequested(bool)";
89 QTest::newRow("Reboot") << (uint)Action::REBOOT << "RebootRequested(bool)";
92 void testGnomeSessionWrapper() {
94 QFETCH(QString, signal);
96 DBusUnitySessionService dbusUnitySessionService;
97 QCoreApplication::processEvents(); // to let the service register on DBus
99 // Spy on the given signal on the /com/canonical/Unity/Session object
100 // as proof we are actually calling the actual method.
101 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
102 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
104 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
105 QCoreApplication::processEvents(); // to let the service register on DBus
107 QDBusInterface dbusGnomeSessionWrapper("com.canonical.Unity",
108 "/org/gnome/SessionManager/EndSessionDialog",
109 "org.gnome.SessionManager.EndSessionDialog",
110 QDBusConnection::sessionBus());
112 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
114 // Set the QVariant as a QList<QDBusObjectPath> type
117 inhibitors.setValue(var);
119 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", method, (unsigned)0, (unsigned)0, inhibitors);
120 QCOMPARE(reply.isValid(), true);
122 // Make sure we see the signal being emitted.
123 QCOMPARE(spy.count(), 1);
126 void testUnlockFromLogind() {
127 DBusUnitySessionService dbusUnitySessionService;
128 QCoreApplication::processEvents(); // to let the service register on DBus
130 QDBusInterface iface("org.freedesktop.login1", "/logindsession", "org.freedesktop.login1.Session");
131 QVERIFY(iface.isValid());
133 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(Unlocked()));
134 QCOMPARE(iface.call("MockEmitUnlock").errorMessage(), QString());
135 QTRY_COMPARE(spy.count(), 1);
138 void testUserName() {
139 DBusUnitySessionService dbusUnitySessionService;
140 QCoreApplication::processEvents(); // to let the service register on DBus
142 QProcess * proc = new QProcess(this);
143 proc->start("id -un", QProcess::ReadOnly);
144 proc->waitForFinished();
145 const QByteArray out = proc->readAll().trimmed();
147 QCOMPARE(dbusUnitySessionService.UserName(), QString::fromUtf8(out));
150 void testRealName() {
151 DBusUnitySessionService dbusUnitySessionService;
152 QCoreApplication::processEvents(); // to let the service register on DBus
154 QDBusInterface accIface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", QDBusConnection::systemBus());
155 if (accIface.isValid()) {
156 QDBusReply<QDBusObjectPath> userPath = accIface.asyncCall("FindUserById", static_cast<qint64>(geteuid()));
157 if (userPath.isValid()) {
158 QDBusInterface userAccIface("org.freedesktop.Accounts", userPath.value().path(), "org.freedesktop.Accounts.User", QDBusConnection::systemBus());
159 QCOMPARE(dbusUnitySessionService.RealName(), userAccIface.property("RealName").toString());
165 QDBusInterface *dbusUnitySession;
168QTEST_GUILESS_MAIN(SessionBackendTest)
169#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