2 * Copyright 2013 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
17 * Authored by: Michael Terry <michael.terry@canonical.com>
20#include "AccountsService.h"
21#include "AccountsServiceDBusAdaptor.h"
28QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
30#define ASSERT_DBUS_CALL(call) \
32 QDBusReply<void> reply = call; \
33 if (!reply.isValid()) QFAIL(reply.error().message().toLatin1()); \
36class AccountsServiceTest : public QObject
41 AccountsServiceTest(QObject* parent = 0)
43 , m_userInterface(nullptr)
44 , m_spy(this, &AccountsServiceTest::propertiesChanged)
51 QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
52 "/org/freedesktop/Accounts",
53 "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
54 QVERIFY(addReply.isValid());
55 QCOMPARE(addReply.value(), true);
57 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
58 QString("/%1").arg(QTest::currentTestFunction()),
59 "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
60 QDBusReply<void> resetReply = m_userInterface->call("Reset");
61 QVERIFY(resetReply.isValid());
63 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
64 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
68 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
69 "/org/freedesktop/Accounts",
70 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
71 QVERIFY(reply.isValid());
72 QCOMPARE(reply.value(), true);
74 delete m_userInterface;
80 // Test various invalid calls
81 AccountsServiceDBusAdaptor session;
82 QCOMPARE(session.getUserProperty("NOPE", "com.canonical.unity.AccountsService", "demo-edges"), QVariant());
83 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE"), QVariant());
86 void testGetSetServiceDBusAdaptor()
88 AccountsServiceDBusAdaptor session;
89 session.setUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true));
90 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges"), QVariant(true));
91 session.setUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false));
92 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges"), QVariant(false));
95 void testGetSetService()
97 AccountsService session;
98 session.setUser(QTest::currentTestFunction());
100 QCOMPARE(session.demoEdges(), false);
101 session.setDemoEdges(true);
102 QCOMPARE(session.demoEdges(), true);
104 QCOMPARE(session.failedLogins(), (uint)0);
105 session.setFailedLogins(5);
106 QCOMPARE(session.failedLogins(), (uint)5);
108 QCOMPARE(session.hereEnabled(), false);
109 session.setHereEnabled(true);
110 QCOMPARE(session.hereEnabled(), true);
113 void testAsynchornousChangeForDemoEdges()
115 AccountsService session;
116 session.setUser(QTest::currentTestFunction());
118 QCOMPARE(session.demoEdges(), false);
119 ASSERT_DBUS_CALL(m_userInterface->call("Set", "com.canonical.unity.AccountsService", "demo-edges", dbusVariant(true)));
120 QTRY_COMPARE(session.demoEdges(), true);
123 void testAsynchornousChangeForFailedLogins()
125 AccountsService session;
126 session.setUser(QTest::currentTestFunction());
128 QCOMPARE(session.failedLogins(), (uint)0);
129 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.canonical.unity.AccountsService.Private", "FailedLogins", dbusVariant(5)));
130 QTRY_COMPARE(session.failedLogins(), (uint)5);
133 void testAsynchornousChangeForStatsWelcomeScreen()
135 AccountsService session;
136 session.setUser(QTest::currentTestFunction());
138 QCOMPARE(session.statsWelcomeScreen(), true);
139 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen", dbusVariant(false)));
140 QTRY_COMPARE(session.statsWelcomeScreen(), false);
143 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
145 AccountsService session;
146 session.setUser(QTest::currentTestFunction());
148 QCOMPARE(session.enableLauncherWhileLocked(), true);
149 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.AccountsService.SecurityPrivacy", "EnableLauncherWhileLocked", dbusVariant(false)));
150 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
153 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
155 AccountsService session;
156 session.setUser(QTest::currentTestFunction());
158 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
159 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.AccountsService.SecurityPrivacy", "EnableIndicatorsWhileLocked", dbusVariant(false)));
160 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
163 void testAsynchornousChangeForStatsPasswordDisplayHint()
165 AccountsService session;
166 session.setUser(QTest::currentTestFunction());
168 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
169 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.AccountsService.SecurityPrivacy", "PasswordDisplayHint", dbusVariant(AccountsService::Numeric)));
170 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
173 void testAsynchornousChangeForStatsLicenseAccepted()
175 AccountsService session;
176 session.setUser(QTest::currentTestFunction());
178 QCOMPARE(session.hereEnabled(), false);
179 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.location.providers.here.AccountsService", "LicenseAccepted", dbusVariant(true)));
180 QTRY_COMPARE(session.hereEnabled(), true);
183 void testAsynchornousChangeForLicenseBasePath()
185 AccountsService session;
186 session.setUser(QTest::currentTestFunction());
188 QCOMPARE(session.hereLicensePath(), QString());
189 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "com.ubuntu.location.providers.here.AccountsService", "LicenseBasePath", dbusVariant("/")));
190 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
193 void testAsynchornousChangeForStatsBackgroundFile()
195 AccountsService session;
196 session.setUser(QTest::currentTestFunction());
198 QCOMPARE(session.backgroundFile(), QString());
199 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set", "org.freedesktop.Accounts.User", "BackgroundFile", dbusVariant("/test/BackgroundFile")));
200 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
204 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
207 QDBusInterface* m_userInterface;
211QTEST_MAIN(AccountsServiceTest)
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