on bionic help sign in
88 lines 3.0 kB history raw
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "UsersModel.h"
19#include <glib.h>
20#include <QDBusInterface>
21#include <QDBusReply>
22#include <QtTest>
24class GreeterIntegratedTest : public QObject
26 Q_OBJECT
28private Q_SLOTS:
30 void init()
31 {
32 m_accounts = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
33 QStringLiteral("/org/freedesktop/Accounts"),
34 QStringLiteral("org.freedesktop.Accounts"),
35 QDBusConnection::sessionBus());
36 QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("AddUser"),
37 g_get_user_name());
38 QVERIFY(addReply.isValid());
39 QCOMPARE(addReply.value(), true);
41 m_user = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
42 QStringLiteral("/%1").arg(g_get_user_name()),
43 QStringLiteral("org.freedesktop.DBus.Properties"),
44 QDBusConnection::sessionBus());
46 m_model = new QLightDM::UsersModel();
47 QVERIFY(m_model);
48 }
50 void cleanup()
51 {
52 QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("RemoveUser"),
53 g_get_user_name());
54 QVERIFY(addReply.isValid());
55 QCOMPARE(addReply.value(), true);
57 delete m_model;
58 delete m_accounts;
59 delete m_user;
60 }
62 void testWatchRealName()
63 {
64 auto index = m_model->index(0, 0);
66 QCOMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
67 QStringLiteral(""));
69 QDBusInterface accountsIface(m_user->service(),
70 m_user->path(),
71 "org.freedesktop.Accounts.User");
72 QDBusReply<void> reply = accountsIface.call(QStringLiteral("SetRealName"),
73 QStringLiteral("Test User"));
74 QVERIFY(reply.isValid());
76 QTRY_COMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
77 QStringLiteral("Test User"));
78 }
80private:
81 QLightDM::UsersModel *m_model;
82 QDBusInterface *m_accounts;
83 QDBusInterface *m_user;
84};
86QTEST_MAIN(GreeterIntegratedTest)
88#include "integrated.moc"