on xenial help sign in
Expose size of mocked notification-model as count for the qmltest.
25c5617Mirco Müller
tests/mocks/Unity/Notifications/MockNotificationModel.cpp+5−4
@@ -42,8 +42,11 @@ int MockNotificationModel::rowCount(const QModelIndex &parent) const {
42 return m_queue.size();
42 return m_queue.size();
43}
43}
44
44
45+int MockNotificationModel::getCount() const {
46+ return m_queue.size();
47+}
48+
45QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
49QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
46− qDebug() << "::data()";
47 if (!index.isValid())
50 if (!index.isValid())
48 return QVariant();
51 return QVariant();
49
52
@@ -89,7 +92,6 @@ void MockNotificationModel::append(MockNotification* n) {
89 beginInsertRows(insertionPoint, location, location);
92 beginInsertRows(insertionPoint, location, location);
90 m_queue.insert(location, n);
93 m_queue.insert(location, n);
91 endInsertRows();
94 endInsertRows();
92− qDebug() << "queue-size:" << m_queue.size();
93}
95}
94
96
95MockNotification* MockNotificationModel::getNotification(unsigned int id) const {
97MockNotification* MockNotificationModel::getNotification(unsigned int id) const {
@@ -116,7 +118,7 @@ bool MockNotificationModel::hasNotification(unsigned int id) const {
116 return !(getNotification(id) != nullptr);
118 return !(getNotification(id) != nullptr);
117}
119}
118
120
119−void MockNotificationModel::removeNotification(const unsigned int id) {
121+void MockNotificationModel::remove(const unsigned int id) {
120 for(int i = 0; i < m_queue.size(); i++) {
122 for(int i = 0; i < m_queue.size(); i++) {
121 if(m_queue[i]->getID() == id) {
123 if(m_queue[i]->getID() == id) {
122 deleteFromVisible(i);
124 deleteFromVisible(i);
@@ -140,7 +142,6 @@ void MockNotificationModel::deleteFromVisible(int loc) {
140}
142}
141
143
142MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
144MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
143− qDebug() << "::getRaw()";
144 for(int i = 0; i < m_queue.size(); i++) {
145 for(int i = 0; i < m_queue.size(); i++) {
145 if(m_queue[i]->getID() == notificationId) {
146 if(m_queue[i]->getID() == notificationId) {
146 MockNotification* n = m_queue[i];
147 MockNotification* n = m_queue[i];
tests/mocks/Unity/Notifications/MockNotificationModel.h+4−1
@@ -29,6 +29,7 @@ class MockNotification;
29
29
30class MockNotificationModel : public QAbstractListModel {
30class MockNotificationModel : public QAbstractListModel {
31 Q_OBJECT
31 Q_OBJECT
32+ Q_PROPERTY(int count READ getCount)
32
33
33public:
34public:
34 MockNotificationModel(QObject *parent=nullptr);
35 MockNotificationModel(QObject *parent=nullptr);
@@ -48,7 +49,9 @@ public:
48 Q_INVOKABLE MockNotification* getRaw(const unsigned int notificationId) const;
49 Q_INVOKABLE MockNotification* getRaw(const unsigned int notificationId) const;
49
50
50 Q_INVOKABLE int queued() const;
51 Q_INVOKABLE int queued() const;
51− Q_INVOKABLE void removeNotification(const unsigned int id);
52+ Q_INVOKABLE void remove(const unsigned int id);
53+
54+ int getCount() const;
52
55
53private Q_SLOTS:
56private Q_SLOTS:
54 void onDataChanged(unsigned int id);
57 void onDataChanged(unsigned int id);
tests/qmltests/Notifications/tst_Notifications.qml+3−3
@@ -125,7 +125,7 @@ Item {
125
125
126 // add the default/PlaceHolder notification to the model
126 // add the default/PlaceHolder notification to the model
127 Component.onCompleted: {
127 Component.onCompleted: {
128− //append(mockList[0])
128+ append(mockList[0])
129 }
129 }
130 }
130 }
131
131
@@ -164,8 +164,9 @@ Item {
164 }
164 }
165
165
166 function remove1stNotification() {
166 function remove1stNotification() {
167− if (mockModel.count > 1)
167+ if (mockModel.count > 1) {
168 mockModel.remove(1)
168 mockModel.remove(1)
169+ }
169 }
170 }
170
171
171 Rectangle {
172 Rectangle {
@@ -187,7 +188,6 @@ Item {
187
188
188 anchors.fill: parent
189 anchors.fill: parent
189 model: mockModel
190 model: mockModel
190− //model: mockList
191 }
191 }
192 }
192 }
193
193