on xenial help sign in
Add session key lookup test
commit57caaccbbcc1ca50526ebe6ff8dcbb83e7c2c303 authorJosh Arenson <joshua.arenson@canonical.com> dateWed 15 Jun 2016, 08:29 (10 years ago) parentf9c534e
5 files changed+35−5
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+11−4 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1−1 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+19
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2
@@ -60,6 +60,8 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
6060 int row = index.row();
6161
6262 switch (role) {
63+ case QLightDM::SessionsModel::KeyRole:
64+ return d->sessionItems[row].key;
6365 case Qt::DisplayRole:
6466 return d->sessionItems[row].name;
6567 default:
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2
@@ -55,6 +55,8 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
5555 int row = index.row();
5656
5757 switch (role) {
58+ case QLightDM::SessionsModel::KeyRole:
59+ return d->sessionItems[row].key;
5860 case Qt::DisplayRole:
5961 return d->sessionItems[row].name;
6062 default:
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+11−4
@@ -46,9 +46,16 @@ void SessionsModelPrivate::resetEntries_multipleSessions()
4646{
4747 sessionItems =
4848 {
49− {"", "", "Ubuntu", ""},
50− {"", "", "GNOME", ""},
51− {"", "", "Plasma", ""},
49+ {"ubuntu", "", "Ubuntu", ""},
50+ {"ubuntu-2d", "", "Ubuntu 2D", ""},
51+ {"gnome", "", "GNOME", ""},
52+ {"gnome-classic", "", "GNOME Classic", ""},
53+ {"gnome-flashback-compiz", "", "GNOME Flashback (Compiz)", ""},
54+ {"gnome-flashback-metacity", "", "GNOME Flashback (Metacity)", ""},
55+ {"gnome-wayland", "", "GNOME on Wayland", ""},
56+ {"plasma", "", "Plasma", ""},
57+ {"kde", "", "KDE" , ""},
58+ {"xterm", "", "Recovery Console", ""},
5259 {"", "", "Unknown?", ""}
5360 };
5461}
@@ -60,7 +67,7 @@ void SessionsModelPrivate::resetEntries_noSessions()
6067
6168void SessionsModelPrivate::resetEntries_singleSession()
6269{
63− sessionItems = {{"", "", "Ubuntu", ""}};
70+ sessionItems = {{"ubuntu", "", "Ubuntu", ""}};
6471}
6572
6673} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1−1
@@ -28,7 +28,7 @@ class SessionsModel;
2828class SessionItem
2929{
3030public:
31− QString key; // unused
31+ QString key;
3232 QString type; // unused
3333 QString name;
3434 QString comment; // unused
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+19
@@ -41,6 +41,16 @@ private Q_SLOTS:
4141 delete sourceModel;
4242 }
4343
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+ }
50+
51+ return QModelIndex();
52+ }
53+
4454 void testIconDirectoriesAreValid()
4555 {
4656 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
@@ -67,6 +77,15 @@ private Q_SLOTS:
6777 QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
6878 }
6979
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+ }
88+
7089private:
7190 SessionsModel *model;
7291 QLightDM::SessionsModel *sourceModel;