on xenial help sign in
Add testScenario to mock sessions model
5030e95Josh Arenson
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txt+1−1
@@ -23,7 +23,7 @@ set(QMLPLUGIN_SRC
23 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
23 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
24 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
24 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
25 MockGreeter.cpp
25 MockGreeter.cpp
26− MockSessionsModel.h
26+ MockSessionsModel.cpp
27 MockUsersModel.cpp
27 MockUsersModel.cpp
28 plugin.cpp
28 plugin.cpp
29 )
29 )
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cppnew file+38
@@ -0,0 +1,38 @@
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+ *
16+ */
17+
18+#include "MockSessionsModel.h"
19+#include <QLightDM/SessionsModel>
20+#include <QSortFilterProxyModel>
21+
22+QString MockSessionsModel::testScenario() const
23+{
24+ QLightDM::SessionsModel* qSessionsModel =
25+ static_cast<QLightDM::SessionsModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
26+
27+ return qSessionsModel->testScenario();
28+}
29+
30+void MockSessionsModel::setTestScenario(QString testScenario)
31+{
32+ QLightDM::SessionsModel* qSessionsModel =
33+ static_cast<QLightDM::SessionsModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
34+
35+ if (qSessionsModel->testScenario() != testScenario) {
36+ qSessionsModel->setTestScenario(testScenario);
37+ }
38+}
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.h+8−4
@@ -19,15 +19,19 @@
19#define MOCK_UNITY_SESSIONSMODEL_H
19#define MOCK_UNITY_SESSIONSMODEL_H
20
20
21#include <SessionsModel.h>
21#include <SessionsModel.h>
22−#include <QLightDM/SessionsModel>
23
22
24−// A wrapper class to preserve naming conventions, thus
25−// enhancing code readability
26class MockSessionsModel : public SessionsModel
23class MockSessionsModel : public SessionsModel
27{
24{
28 Q_OBJECT
25 Q_OBJECT
29
26
30− using SessionsModel::SessionsModel;
27+ Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario)
28+
29+public:
30+ QString testScenario() const;
31+ void setTestScenario(QString testScenario);
32+
33+private:
34+ QString m_testScenario;
31};
35};
32
36
33#endif // MOCK_UNITY_SESSIONSMODEL_H
37#endif // MOCK_UNITY_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+16
@@ -79,4 +79,20 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
79 }
79 }
80}
80}
81
81
82+QString SessionsModel::testScenario() const
83+{
84+ Q_D(const SessionsModel);
85+ return d->testScenario;
86+}
87+
88+void SessionsModel::setTestScenario(QString testScenario)
89+{
90+ Q_D(SessionsModel);
91+
92+ if (d->testScenario != testScenario) {
93+ d->testScenario = testScenario;
94+ d->resetEntries();
95+ }
96+}
97+
82} // namespace QLightDM
98} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h+3
@@ -54,6 +54,9 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
54 int rowCount(const QModelIndex& parent) const override;
54 int rowCount(const QModelIndex& parent) const override;
55 QVariant data(const QModelIndex& index, int role) const override;
55 QVariant data(const QModelIndex& index, int role) const override;
56
56
57+ QString testScenario() const;
58+ void setTestScenario(QString testScenario);
59+
57 protected:
60 protected:
58 SessionsModelPrivate* const d_ptr;
61 SessionsModelPrivate* const d_ptr;
59
62
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+30−8
@@ -21,7 +21,8 @@ namespace QLightDM
21{
21{
22
22
23SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
23SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
24+ : testScenario("multipleSessions")
24− : q_ptr(parent)
25+ , q_ptr(parent)
25{
26{
26 resetEntries();
27 resetEntries();
27}
28}
@@ -31,14 +32,35 @@ void SessionsModelPrivate::resetEntries()
31 Q_Q(SessionsModel);
32 Q_Q(SessionsModel);
32
33
33 q->beginResetModel();
34 q->beginResetModel();
34− sessionItems =
35+ if(testScenario == "multipleSessions") {
35− {
36+ resetEntries_multipleSessions();
36− {"", "", "Ubuntu", ""},
37+ } else if (testScenario == "singleSessions") {
37− {"", "", "GNOME", ""},
38+ resetEntries_singleSession();
38− {"", "", "Plasma", ""},
39+ } else {
39− {"", "", "Unknown?", ""}
40+ resetEntries_noSessions();
40− };
41+ }
41 q->endResetModel();
42 q->endResetModel();
42}
43}
43
44
45+void SessionsModelPrivate::resetEntries_multipleSessions()
46+{
47+ sessionItems =
48+ {
49+ {"", "", "Ubuntu", ""},
50+ {"", "", "GNOME", ""},
51+ {"", "", "Plasma", ""},
52+ {"", "", "Unknown?", ""}
53+ };
54+}
55+
56+void SessionsModelPrivate::resetEntries_noSessions()
57+{
58+ sessionItems = {};
59+}
60+
61+void SessionsModelPrivate::resetEntries_singleSession()
62+{
63+ sessionItems = {{"", "", "Ubuntu", ""}};
64+}
65+
44} // namespace QLightDM
66} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1
@@ -41,6 +41,7 @@ public:
41 virtual ~SessionsModelPrivate() = default;
41 virtual ~SessionsModelPrivate() = default;
42
42
43 QList<SessionItem> sessionItems;
43 QList<SessionItem> sessionItems;
44+ QString testScenario;
44
45
45 void resetEntries();
46 void resetEntries();
46protected:
47protected: