2 * Copyright (C) 2015 Canonical, Ltd.
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.
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.
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/>.
17#include "SessionsModel.h"
19#include <QLightDM/SessionsModel>
20#include <QtCore/QModelIndex>
24class GreeterSessionsModelTest : public QObject
32 model = new SessionsModel();
34 sourceModel = new QLightDM::SessionsModel();
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
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);
54 void testIconDirectoriesAreValid()
56 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
58 QVERIFY(searchDirectory.isValid());
62 void testIconLookupLogic()
64 const QString data[][2] = {
65 //{SESSION KEY, ICON NAME}
66 {"gnome-classic", "gnome_badge.png"},
67 {"gnome-flashback-compiz", "gnome_badge.png"},
68 {"gnome-flashback-metacity", "gnome_badge.png"},
69 {"gnome-shell", "gnome_badge.png"},
70 {"gnome-wayland", "gnome_badge.png"},
71 {"gnome", "gnome_badge.png"},
72 {"kde", "kde_badge.png"},
73 {"plasma", "kde_badge.png"},
74 {"recovery_console", "recovery_console_badge.png"},
75 {"ubuntu","ubuntu_badge.png"},
76 {"ubuntu-2d", "ubuntu_badge.png"},
77 {"xterm", "recovery_console_badge.png"},
78 {"made up session", "unknown_badge.png"},
79 {"", "unknown_badge.png"}
82 const short length = sizeof(data) / sizeof(data[0]);
83 for (int i = 0; i < length; i++) {
84 std::string key = data[i][0].toStdString();
85 std::string icon = data[i][1].toStdString();
86 std::string url = model->iconUrl(data[i][0]).toString().toStdString();
87 std::string errorMessage = "Session icon url for " + key +
88 " should contain " + icon + " but " + url + " was returned";
89 QVERIFY2(model->iconUrl(data[i][0]).toString().contains(data[i][1]),
90 errorMessage.c_str());
94 void testMultipleSessionsCountIsCorrect()
96 sourceModel->setTestScenario("multipleSessions");
97 QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
100 void testNoSessionsCountIsCorrect()
102 sourceModel->setTestScenario("noSessions");
103 QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
106 void testSingleSessionCountIsCorrect()
108 sourceModel->setTestScenario("singleSession");
109 QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
112 void testSessionNameIsCorrect()
114 // This is testing the lookup, not the correctness of the strings,
115 // so one test should be sufficient
116 sourceModel->setTestScenario("multipleSessions");
117 QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
118 Qt::DisplayRole).toString() == "Ubuntu");
122 SessionsModel *model;
123 QLightDM::SessionsModel *sourceModel;
126QTEST_MAIN(GreeterSessionsModelTest)
128#include "sessionsmodel.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list