on add3e60 help sign in
unity8/tests/plugins/LightDM/usersmodel.cpp
74 lines 2.0 kB history raw
1/*
2 * Copyright (C) 2015 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 <QLightDM/UsersModel>
20#include <QtTest>
22class GreeterUsersModelTest : public QObject
24 Q_OBJECT
26private:
27 static int findName(QAbstractItemModel *model, const QString &name)
28 {
29 for (int i = 0; i < model->rowCount(QModelIndex()); i++) {
30 if (model->data(model->index(i, 0), QLightDM::UsersModel::NameRole).toString() == name) {
31 return i;
32 }
33 }
34 return -1;
35 }
37 static QString getStringValue(QAbstractItemModel *model, const QString &name, int role)
38 {
39 int i = findName(model, name);
40 return model->data(model->index(i, 0), role).toString();
41 }
43private Q_SLOTS:
45 void init()
46 {
47 model = new UsersModel();
48 QVERIFY(model);
49 }
51 void cleanup()
52 {
53 delete model;
54 }
56 void testMangleColor()
57 {
58 auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
59 QCOMPARE(background, QString("data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>"));
60 }
62 void testMangleEmptyName()
63 {
64 auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
65 QCOMPARE(name, QString("empty-name"));
66 }
68private:
69 UsersModel *model;
70};
72QTEST_MAIN(GreeterUsersModelTest)
74#include "usersmodel.moc"