on 73aedc0 help sign in
96 lines 2.6 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 "SessionsModel.h"
19#include <QLightDM/SessionsModel>
20#include <QtCore/QModelIndex>
21#include <QtTest>
22#include <QString>
24class GreeterSessionsModelTest : public QObject
26 Q_OBJECT
28private Q_SLOTS:
30 void init()
31 {
32 model = new SessionsModel();
33 QVERIFY(model);
34 sourceModel = new QLightDM::SessionsModel();
35 QVERIFY(sourceModel);
36 }
38 void cleanup()
39 {
40 delete model;
41 delete sourceModel;
42 }
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
45 {
46 for (int i = 0; i < model->rowCount(QModelIndex()); i++) {
47 if (model->data(model->index(i, 0), QLightDM::SessionsModel::KeyRole).toString() == key)
48 return model->index(i, 0);
49 }
51 return QModelIndex();
52 }
54 void testIconDirectoriesAreValid()
55 {
56 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
57 {
58 QVERIFY(searchDirectory.isValid());
59 }
60 }
62 void testMultipleSessionsCountIsCorrect()
63 {
64 sourceModel->setTestScenario("multipleSessions");
65 QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
66 }
68 void testNoSessionsCountIsCorrect()
69 {
70 sourceModel->setTestScenario("noSessions");
71 QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
72 }
74 void testSingleSessionCountIsCorrect()
75 {
76 sourceModel->setTestScenario("singleSession");
77 QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
78 }
80 void testSessionNameIsCorrect()
81 {
82 // This is testing the lookup, not the correctness of the strings,
83 // so one test should be sufficient
84 sourceModel->setTestScenario("multipleSessions");
85 QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
86 Qt::DisplayRole).toString() == "Ubuntu");
87 }
89private:
90 SessionsModel *model;
91 QLightDM::SessionsModel *sourceModel;
92};
94QTEST_MAIN(GreeterSessionsModelTest)
96#include "sessionsmodel.moc"