~mterry/unity8/oobe-revert-geonames

« back to all changes in this revision

Viewing changes to tests/plugins/IntegratedLightDM/integrated.cpp

  • Committer: Michael Terry
  • Date: 2016-03-11 17:51:18 UTC
  • mfrom: (1821.227.75 unity8)
  • Revision ID: michael.terry@canonical.com-20160311175118-6za2cj41c21d88ha
Merge silo 64 (soon to be trunk)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
16
 
 
17
#include "UsersModel.h"
 
18
 
 
19
#include <glib.h>
 
20
#include <QDBusInterface>
 
21
#include <QDBusReply>
 
22
#include <QtTest>
 
23
 
 
24
class GreeterIntegratedTest : public QObject
 
25
{
 
26
    Q_OBJECT
 
27
 
 
28
private Q_SLOTS:
 
29
 
 
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);
 
40
 
 
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());
 
45
 
 
46
        m_model = new QLightDM::UsersModel();
 
47
        QVERIFY(m_model);
 
48
    }
 
49
 
 
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);
 
56
 
 
57
        delete m_model;
 
58
        delete m_accounts;
 
59
        delete m_user;
 
60
    }
 
61
 
 
62
    void testWatchRealName()
 
63
    {
 
64
        auto index = m_model->index(0, 0);
 
65
 
 
66
        QCOMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
 
67
                 QStringLiteral(""));
 
68
 
 
69
        // The real AccountsService doesn't let you set via dbus properties. You
 
70
        // have to call SetRealName instead (so that they can protect the call
 
71
        // via policykit). But our test server does let us.
 
72
        QVariant wrapped = QVariant::fromValue(QDBusVariant(QStringLiteral("Test User")));
 
73
        QDBusReply<void> reply = m_user->call(QStringLiteral("Set"),
 
74
                                              QStringLiteral("org.freedesktop.Accounts.User"),
 
75
                                              QStringLiteral("RealName"),
 
76
                                              wrapped);
 
77
        QVERIFY(reply.isValid());
 
78
 
 
79
        QTRY_COMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
 
80
                     QStringLiteral("Test User"));
 
81
    }
 
82
 
 
83
private:
 
84
    QLightDM::UsersModel *m_model;
 
85
    QDBusInterface *m_accounts;
 
86
    QDBusInterface *m_user;
 
87
};
 
88
 
 
89
QTEST_MAIN(GreeterIntegratedTest)
 
90
 
 
91
#include "integrated.moc"