on xenial help sign in
fix crashes in the mock model
commit5b58aba08cb357ac592af2ac648df4208bcca1c6 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 7 Apr 2016, 21:03 (11 years ago) parent2d2a022
2 files changed+7−12
CMakeLists.txt+1−1 tests/mocks/Unity/Notifications/MockNotificationModel.cpp+6−11
CMakeLists.txt+1−1
@@ -57,7 +57,7 @@ find_package(Qt5DBus 5.4 REQUIRED)
5757find_package(Qt5Concurrent 5.4 REQUIRED)
5858find_package(Qt5Sql 5.4 REQUIRED)
5959
60−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application>=14)
60+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=14)
6161pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
6262pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
6363pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
tests/mocks/Unity/Notifications/MockNotificationModel.cpp+6−11
@@ -90,6 +90,7 @@ QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
9090}
9191
9292void MockNotificationModel::append(MockNotification* n) {
93+ QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
9394 int location = m_queue.size();
9495 QModelIndex insertionPoint = QModelIndex();
9596 beginInsertRows(insertionPoint, location, location);
@@ -98,9 +99,10 @@ void MockNotificationModel::append(MockNotification* n) {
9899}
99100
100101MockNotification* MockNotificationModel::getNotification(int id) const {
101− for(int i=0; i < m_queue.size(); i++) {
102− if(m_queue[i]->getID() == id) {
103− return m_queue[i];
102+ for(int i = 0; i < m_queue.size(); i++) {
103+ MockNotification* n = m_queue.at(i);
104+ if(n && n->getID() == id) {
105+ return n;
104106 }
105107 }
106108
@@ -130,14 +132,7 @@ void MockNotificationModel::removeInternal(int loc) {
130132}
131133
132134MockNotification* MockNotificationModel::getRaw(const int notificationId) const {
133− for(int i = 0; i < m_queue.size(); i++) {
134− if(m_queue[i]->getID() == notificationId) {
135− MockNotification* n = m_queue[i];
136− return n;
137− }
138− }
139−
140− return nullptr;
135+ return getNotification(notificationId);
141136}
142137
143138int MockNotificationModel::queued() const {