on xenial help sign in
Implement private class members for testing sessions model
commitf8b28865455c93d9e34cede8ba6c3f08e21c163d authorJosh Arenson <joshua.arenson@canonical.com> dateWed 18 Nov 2015, 16:51 (11 years ago) parent4132cd5
4 files changed+25−1
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+16 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h+6 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+2−1 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+16
@@ -79,4 +79,20 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
7979 }
8080}
8181
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+
8298} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h+6
@@ -31,6 +31,9 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
3131
3232 Q_ENUMS(SessionModelRoles SessionType)
3333
34+ // Mock-only API for testing purposes
35+ Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario)
36+
3437 public:
3538
3639 enum SessionModelRoles {
@@ -54,6 +57,9 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
5457 int rowCount(const QModelIndex& parent) const override;
5558 QVariant data(const QModelIndex& index, int role) const override;
5659
60+ QString testScenario() const;
61+ void setTestScenario(QString testScenario);
62+
5763 protected:
5864 SessionsModelPrivate* const d_ptr;
5965
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+2−1
@@ -21,7 +21,8 @@ namespace QLightDM
2121{
2222
2323SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
24− : q_ptr(parent)
24+ : testScenario("singleSession")
25+ , q_ptr(parent)
2526{
2627 resetEntries();
2728}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+1
@@ -41,6 +41,7 @@ public:
4141 virtual ~SessionsModelPrivate() = default;
4242
4343 QList<SessionItem> sessionItems;
44+ QString testScenario;
4445
4546 void resetEntries();
4647protected: