on xenial help sign in
Add session key lookup test
57caaccJosh Arenson
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2
@@ -60,6 +60,8 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
60 int row = index.row();
60 int row = index.row();
61
61
62 switch (role) {
62 switch (role) {
63+ case QLightDM::SessionsModel::KeyRole:
64+ return d->sessionItems[row].key;
63 case Qt::DisplayRole:
65 case Qt::DisplayRole:
64 return d->sessionItems[row].name;
66 return d->sessionItems[row].name;
65 default:
67 default:
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+2
@@ -55,6 +55,8 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
55 int row = index.row();
55 int row = index.row();
56
56
57 switch (role) {
57 switch (role) {
58+ case QLightDM::SessionsModel::KeyRole:
59+ return d->sessionItems[row].key;
58 case Qt::DisplayRole:
60 case Qt::DisplayRole:
59 return d->sessionItems[row].name;
61 return d->sessionItems[row].name;
60 default:
62 default:
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+11−4
@@ -46,9 +46,16 @@ void SessionsModelPrivate::resetEntries_multipleSessions()
46{
46{
47 sessionItems =
47 sessionItems =
48 {
48 {
49+ {"ubuntu", "", "Ubuntu", ""},
49− {"", "", "Ubuntu", ""},
50+ {"ubuntu-2d", "", "Ubuntu 2D", ""},
50− {"", "", "GNOME", ""},
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", ""},
51− {"", "", "Plasma", ""},
56+ {"plasma", "", "Plasma", ""},
57+ {"kde", "", "KDE" , ""},
58+ {"xterm", "", "Recovery Console", ""},
52 {"", "", "Unknown?", ""}
59 {"", "", "Unknown?", ""}
53 };
60 };
54}
61}
@@ -60,7 +67,7 @@ void SessionsModelPrivate::resetEntries_noSessions()
60
67
61void SessionsModelPrivate::resetEntries_singleSession()
68void SessionsModelPrivate::resetEntries_singleSession()
62{
69{
63− sessionItems = {{"", "", "Ubuntu", ""}};
70+ sessionItems = {{"ubuntu", "", "Ubuntu", ""}};
64}
71}
65
72
66} // namespace QLightDM
73} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1−1
@@ -28,7 +28,7 @@ class SessionsModel;
28class SessionItem
28class SessionItem
29{
29{
30public:
30public:
31− QString key; // unused
31+ QString key;
32 QString type; // unused
32 QString type; // unused
33 QString name;
33 QString name;
34 QString comment; // unused
34 QString comment; // unused
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+19
@@ -41,6 +41,16 @@ private Q_SLOTS:
41 delete sourceModel;
41 delete sourceModel;
42 }
42 }
43
43
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+
44 void testIconDirectoriesAreValid()
54 void testIconDirectoriesAreValid()
45 {
55 {
46 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
56 Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
@@ -67,6 +77,15 @@ private Q_SLOTS:
67 QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
77 QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
68 }
78 }
69
79
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+
70private:
89private:
71 SessionsModel *model;
90 SessionsModel *model;
72 QLightDM::SessionsModel *sourceModel;
91 QLightDM::SessionsModel *sourceModel;