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);
61 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
62 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
66 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
67 "/org/freedesktop/Accounts",
68 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
69 QVERIFY(reply.isValid());
70 QCOMPARE(reply.value(), true);
72 delete m_userInterface;
78 // Test various invalid calls
79 AccountsServiceDBusAdaptor session;
80 QCOMPARE(session.getUserPropertyAsync("NOPE", "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant());
81 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE").value(), QVariant());
84 void testGetSetServiceDBusAdaptor()
86 AccountsServiceDBusAdaptor session;
87 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true)).waitForFinished();
88 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(true));
89 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false)).waitForFinished();
90 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(false));
93 void testGetSetService()
95 AccountsService session(this, QTest::currentTestFunction());
97 QCOMPARE(session.demoEdges(), false);
98 session.setDemoEdges(true);
99 QCOMPARE(session.demoEdges(), true);
101 QCOMPARE(session.failedLogins(), (uint)0);
102 session.setFailedLogins(5);
103 QCOMPARE(session.failedLogins(), (uint)5);
105 QCOMPARE(session.hereEnabled(), false);
106 session.setHereEnabled(true);
107 QCOMPARE(session.hereEnabled(), true);
110 void testMarkDemoEdgeCompleted()
112 AccountsService session(this, QTest::currentTestFunction());
113 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
115 QCOMPARE(changedSpy.count(), 0);
116 QCOMPARE(session.demoEdgesCompleted(), QStringList());
118 session.markDemoEdgeCompleted("testedge");
119 QCOMPARE(changedSpy.count(), 1);
120 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
122 session.markDemoEdgeCompleted("testedge");
123 QCOMPARE(changedSpy.count(), 1);
124 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
126 session.markDemoEdgeCompleted("testedge2");
127 QCOMPARE(changedSpy.count(), 2);
128 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge" << "testedge2");
131 void testAsynchronousChangeForDemoEdgesCompleted()
133 AccountsService session(this, QTest::currentTestFunction());
134 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
136 QCOMPARE(changedSpy.count(), 0);
137 QCOMPARE(session.demoEdgesCompleted(), QStringList());
139 ASSERT_DBUS_CALL(m_userInterface->call("Set",
140 "com.canonical.unity.AccountsService",
141 "DemoEdgesCompleted",
142 dbusVariant(QStringList() << "testedge")));
143 QTRY_COMPARE(changedSpy.count(), 1);
144 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
147 void testAsynchornousChangeForDemoEdges()
149 AccountsService session(this, QTest::currentTestFunction());
151 QCOMPARE(session.demoEdges(), false);
152 ASSERT_DBUS_CALL(m_userInterface->call("Set",
153 "com.canonical.unity.AccountsService",
156 QTRY_COMPARE(session.demoEdges(), true);
159 void testAsynchornousChangeForFailedLogins()
161 AccountsService session(this, QTest::currentTestFunction());
163 QCOMPARE(session.failedLogins(), (uint)0);
164 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
165 "com.canonical.unity.AccountsService.Private",
168 QTRY_COMPARE(session.failedLogins(), (uint)5);
171 void testAsynchornousChangeForStatsWelcomeScreen()
173 AccountsService session(this, QTest::currentTestFunction());
175 QCOMPARE(session.statsWelcomeScreen(), true);
176 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
177 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
178 "StatsWelcomeScreen",
179 dbusVariant(false)));
180 QTRY_COMPARE(session.statsWelcomeScreen(), false);
183 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
185 AccountsService session(this, QTest::currentTestFunction());
187 QCOMPARE(session.enableLauncherWhileLocked(), true);
188 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
189 "com.ubuntu.AccountsService.SecurityPrivacy",
190 "EnableLauncherWhileLocked",
191 dbusVariant(false)));
192 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
195 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
197 AccountsService session(this, QTest::currentTestFunction());
199 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
200 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
201 "com.ubuntu.AccountsService.SecurityPrivacy",
202 "EnableIndicatorsWhileLocked",
203 dbusVariant(false)));
204 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
207 void testAsynchornousChangeForStatsPasswordDisplayHint()
209 AccountsService session(this, QTest::currentTestFunction());
211 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
212 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
213 "com.ubuntu.AccountsService.SecurityPrivacy",
214 "PasswordDisplayHint",
215 dbusVariant(AccountsService::Numeric)));
216 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
219 void testAsynchornousChangeForStatsLicenseAccepted()
221 AccountsService session(this, QTest::currentTestFunction());
223 QCOMPARE(session.hereEnabled(), false);
224 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
225 "com.ubuntu.location.providers.here.AccountsService",
228 QTRY_COMPARE(session.hereEnabled(), true);
231 void testAsynchornousChangeForLicenseBasePath()
233 AccountsService session(this, QTest::currentTestFunction());
235 QCOMPARE(session.hereLicensePath(), QString());
236 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
237 "com.ubuntu.location.providers.here.AccountsService",
240 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
243 void testAsynchornousChangeForStatsBackgroundFile()
245 AccountsService session(this, QTest::currentTestFunction());
247 QCOMPARE(session.backgroundFile(), QString());
248 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
249 "org.freedesktop.Accounts.User",
251 dbusVariant("/test/BackgroundFile")));
252 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
256 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
259 QDBusInterface* m_userInterface;
263QTEST_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