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 testAsynchornousChangeForDemoEdges()
112 AccountsService session(this, QTest::currentTestFunction());
114 QCOMPARE(session.demoEdges(), false);
115 ASSERT_DBUS_CALL(m_userInterface->call("Set",
116 "com.canonical.unity.AccountsService",
119 QTRY_COMPARE(session.demoEdges(), true);
122 void testAsynchornousChangeForFailedLogins()
124 AccountsService session(this, QTest::currentTestFunction());
126 QCOMPARE(session.failedLogins(), (uint)0);
127 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
128 "com.canonical.unity.AccountsService.Private",
131 QTRY_COMPARE(session.failedLogins(), (uint)5);
134 void testAsynchornousChangeForStatsWelcomeScreen()
136 AccountsService session(this, QTest::currentTestFunction());
138 QCOMPARE(session.statsWelcomeScreen(), true);
139 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
140 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
141 "StatsWelcomeScreen",
142 dbusVariant(false)));
143 QTRY_COMPARE(session.statsWelcomeScreen(), false);
146 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
148 AccountsService session(this, QTest::currentTestFunction());
150 QCOMPARE(session.enableLauncherWhileLocked(), true);
151 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
152 "com.ubuntu.AccountsService.SecurityPrivacy",
153 "EnableLauncherWhileLocked",
154 dbusVariant(false)));
155 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
158 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
160 AccountsService session(this, QTest::currentTestFunction());
162 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
163 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
164 "com.ubuntu.AccountsService.SecurityPrivacy",
165 "EnableIndicatorsWhileLocked",
166 dbusVariant(false)));
167 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
170 void testAsynchornousChangeForStatsPasswordDisplayHint()
172 AccountsService session(this, QTest::currentTestFunction());
174 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
175 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
176 "com.ubuntu.AccountsService.SecurityPrivacy",
177 "PasswordDisplayHint",
178 dbusVariant(AccountsService::Numeric)));
179 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
182 void testAsynchornousChangeForStatsLicenseAccepted()
184 AccountsService session(this, QTest::currentTestFunction());
186 QCOMPARE(session.hereEnabled(), false);
187 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
188 "com.ubuntu.location.providers.here.AccountsService",
191 QTRY_COMPARE(session.hereEnabled(), true);
194 void testAsynchornousChangeForLicenseBasePath()
196 AccountsService session(this, QTest::currentTestFunction());
198 QCOMPARE(session.hereLicensePath(), QString());
199 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
200 "com.ubuntu.location.providers.here.AccountsService",
203 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
206 void testAsynchornousChangeForStatsBackgroundFile()
208 AccountsService session(this, QTest::currentTestFunction());
210 QCOMPARE(session.backgroundFile(), QString());
211 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
212 "org.freedesktop.Accounts.User",
214 dbusVariant("/test/BackgroundFile")));
215 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
219 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
222 QDBusInterface* m_userInterface;
226QTEST_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