@@ -24,8 +24,14 @@
24#include <QDBusInterface>
24#include <QDBusInterface>
25#include <QDBusReply>
25#include <QDBusReply>
26#include <QDBusVariant>
26#include <QDBusVariant>
28+#include <QDBusObjectPath>
31+#include <sys/types.h>
28#include "dbusunitysessionservice.h"
33#include "dbusunitysessionservice.h"
34+#include "../../AccountsService/AccountsServiceDBusAdaptor.h"
30enum class Action : unsigned
36enum class Action : unsigned
@@ -52,9 +58,10 @@ private Q_SLOTS:
52 QTest::addColumn<QString>("method");
58 QTest::addColumn<QString>("method");
53 QTest::addColumn<QString>("signal");
59 QTest::addColumn<QString>("signal");
55− QTest::newRow("Logout") << "RequestLogout" << "logoutRequested(bool)";
61+ QTest::newRow("Logout") << "RequestLogout" << "LogoutRequested(bool)";
56− QTest::newRow("Reboot") << "RequestReboot" << "rebootRequested(bool)";
62+ QTest::newRow("Reboot") << "RequestReboot" << "RebootRequested(bool)";
57− QTest::newRow("Shutdown") << "RequestShutdown" << "shutdownRequested(bool)";
63+ QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
64+ QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
60 void testUnitySessionLogoutRequested() {
67 void testUnitySessionLogoutRequested() {
@@ -65,7 +72,7 @@ private Q_SLOTS:
65 QCoreApplication::processEvents(); // to let the service register on DBus
72 QCoreApplication::processEvents(); // to let the service register on DBus
67 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
74 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
68− QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
75+ QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
70 QDBusReply<void> reply = dbusUnitySession->call(method);
77 QDBusReply<void> reply = dbusUnitySession->call(method);
71 QCOMPARE(reply.isValid(), true);
78 QCOMPARE(reply.isValid(), true);
@@ -77,9 +84,9 @@ private Q_SLOTS:
77 QTest::addColumn<uint>("method");
84 QTest::addColumn<uint>("method");
78 QTest::addColumn<QString>("signal");
85 QTest::addColumn<QString>("signal");
80− QTest::newRow("Logout") << (uint)Action::LOGOUT << "logoutRequested(bool)";
87+ QTest::newRow("Logout") << (uint)Action::LOGOUT << "LogoutRequested(bool)";
81− QTest::newRow("Shutdown") << (unsigned)Action::SHUTDOWN << "shutdownRequested(bool)";
88+ QTest::newRow("Shutdown") << (unsigned)Action::SHUTDOWN << "ShutdownRequested(bool)";
82− QTest::newRow("Reboot") << (unsigned)Action::REBOOT << "rebootRequested(bool)";
89+ QTest::newRow("Reboot") << (unsigned)Action::REBOOT << "RebootRequested(bool)";
85 void testGnomeSessionWrapper() {
92 void testGnomeSessionWrapper() {
@@ -92,7 +99,7 @@ private Q_SLOTS:
92 // Spy on the given signal on the /com/canonical/Unity/Session object
99 // Spy on the given signal on the /com/canonical/Unity/Session object
93 // as proof we are actually calling the actual method.
100 // as proof we are actually calling the actual method.
94 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
101 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
95− QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
102+ QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
97 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
104 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
98 QCoreApplication::processEvents(); // to let the service register on DBus
105 QCoreApplication::processEvents(); // to let the service register on DBus
@@ -116,6 +123,48 @@ private Q_SLOTS:
116 QCOMPARE(spy.count(), 1);
123 QCOMPARE(spy.count(), 1);
126+ void testUserName() {
127+ DBusUnitySessionService dbusUnitySessionService;
128+ QCoreApplication::processEvents(); // to let the service register on DBus
130+ QCOMPARE(dbusUnitySessionService.UserName(), QString::fromUtf8(qgetenv("USER")));
133+ void testRealName() {
134+ DBusUnitySessionService dbusUnitySessionService;
135+ QCoreApplication::processEvents(); // to let the service register on DBus
137+ QDBusInterface accIface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", QDBusConnection::systemBus());
138+ QVERIFY(accIface.isValid());
139+ QDBusReply<QDBusObjectPath> userPath = accIface.asyncCall("FindUserById", static_cast<qint64>(geteuid()));
140+ if (!userPath.isValid()) {
141+ QFAIL("Could not get user path in Account Service");
144+ QDBusInterface userAccIface("org.freedesktop.Accounts", userPath.value().path(), "org.freedesktop.Accounts.User", QDBusConnection::systemBus());
145+ QCOMPARE(dbusUnitySessionService.RealName(), userAccIface.property("RealName").toString());
148+ void testLogin1Capabilities() {
149+ DBusUnitySessionService dbusUnitySessionService;
150+ QDBusInterface login1face("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus());
151+ QCoreApplication::processEvents(); // to let the services register on DBus
153+ QCOMPARE(dbusUnitySessionService.CanHibernate(), (login1face.call("CanHibernate").arguments().first().toString() != "no"));
154+ QCOMPARE(dbusUnitySessionService.CanSuspend(), (login1face.call("CanSuspend").arguments().first().toString() != "no"));
155+ QCOMPARE(dbusUnitySessionService.CanReboot(), (login1face.call("CanReboot").arguments().first().toString() != "no"));
156+ QCOMPARE(dbusUnitySessionService.CanShutdown(), (login1face.call("CanPowerOff").arguments().first().toString() != "no"));
157+ QCOMPARE(dbusUnitySessionService.CanHybridSleep(), (login1face.call("CanHybridSleep").arguments().first().toString() != "no"));
161+ DBusUnitySessionService dbusUnitySessionService;
162+ QCoreApplication::processEvents(); // to let the service register on DBus
164+ qDebug() << "Locking up...";
165+ dbusUnitySessionService.Lock();
120 QDBusInterface *dbusUnitySession;
169 QDBusInterface *dbusUnitySession;