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"
23class GreeterSessionsModelTest : public QObject
31 model = new SessionsModel();
40 // mock will be a singleton, doesn't need to be cleaned
43 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
45 for (int i = 0; i < model->rowCount(QModelIndex()); i++) {
46 if (model->data(model->index(i, 0), QLightDM::SessionsModel::KeyRole).toString() == key)
47 return model->index(i, 0);
53 void testIconDirectoriesAreValid()
55 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
57 QVERIFY(searchDirectory.isValid());
61 void testIconLookupLogic()
63 const QString data[][2] = {
64 //{SESSION KEY, ICON NAME}
65 {"gnome-classic", "gnome_badge.png"},
66 {"gnome-flashback-compiz", "gnome_badge.png"},
67 {"gnome-flashback-metacity", "gnome_badge.png"},
68 {"gnome-shell", "gnome_badge.png"},
69 {"gnome-wayland", "gnome_badge.png"},
70 {"gnome", "gnome_badge.png"},
71 {"kde", "kde_badge.png"},
72 {"plasma", "kde_badge.png"},
73 {"recovery_console", "recovery_console_badge.png"},
74 {"ubuntu","ubuntu_badge.png"},
75 {"ubuntu-2d", "ubuntu_badge.png"},
76 {"xterm", "recovery_console_badge.png"},
77 {"made up session", "unknown_badge.png"},
78 {"", "unknown_badge.png"}
81 const short length = sizeof(data) / sizeof(data[0]);
82 for (int i = 0; i < length; i++) {
83 std::string key = data[i][0].toStdString();
84 std::string icon = data[i][1].toStdString();
85 std::string url = model->iconUrl(data[i][0]).toString().toStdString();
86 std::string errorMessage = "Session icon url for " + key +
87 " should contain " + icon + " but " + url + " was returned";
88 QVERIFY2(model->iconUrl(data[i][0]).toString().contains(data[i][1]),
89 errorMessage.c_str());
93 void testMultipleSessionsCountIsCorrect()
95 mock->setProperty("sessionMode", "full");
96 QVERIFY(model->rowCount(QModelIndex()) > 1);
99 void testNoSessionsCountIsCorrect()
101 mock->setProperty("sessionMode", "none");
102 QVERIFY(model->rowCount(QModelIndex()) == 0);
105 void testSingleSessionCountIsCorrect()
107 mock->setProperty("sessionMode", "single");
108 QVERIFY(model->rowCount(QModelIndex()) == 1);
111 void testSessionNameIsCorrect()
113 // This is testing the lookup, not the correctness of the strings,
114 // so one test should be sufficient
115 mock->setProperty("sessionMode", "full");
116 QVERIFY(model->data(findByKey(model, "ubuntu"),
117 Qt::DisplayRole).toString() == "Ubuntu");
121 SessionsModel *model;
125QTEST_MAIN(GreeterSessionsModelTest)
127#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