on daa5708 help sign in
unity8/tests/plugins/LightDM/usersmodel.cpp
84 lines 2.4 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 sourceModel = new QLightDM::UsersModel();
50 QVERIFY(sourceModel);
51 }
53 void cleanup()
54 {
55 delete model;
56 delete sourceModel;
57 }
59 void testMangleColor()
60 {
61 QString background = getStringValue(sourceModel, "color-background", QLightDM::UsersModel::BackgroundPathRole);
62 QVERIFY(background == "#dd4814");
64 background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
65 QVERIFY(background == "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#dd4814'/></svg>");
66 }
68 void testMangleEmptyName()
69 {
70 QString name = getStringValue(sourceModel, "empty-name", QLightDM::UsersModel::RealNameRole);
71 QVERIFY(name == "");
73 name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
74 QVERIFY(name == "empty-name");
75 }
77private:
78 UsersModel *model;
79 QLightDM::UsersModel *sourceModel;
80};
82QTEST_MAIN(GreeterUsersModelTest)
84#include "usersmodel.moc"