37 delete model; |
37 delete model; |
38 } |
38 } |
39 |
39 |
40 void TestCntHistoryModel::testLogsInsertions() |
40 void TestCntHistoryModel::testLogsInsertions() |
41 { |
41 { |
42 QSignalSpy spy( model, SIGNAL(rowsInserted(const QModelIndex &, int, int))); |
42 QSignalSpy spy( model, SIGNAL(modelReset())); |
43 model->d_ptr->logsRowsInserted(QModelIndex(), 0, 0); |
43 model->d_ptr->logsRowsInserted(QModelIndex(), 0, 0); |
44 |
44 |
45 QVERIFY(model->rowCount() == 1); |
45 QVERIFY(model->rowCount() == 1); |
46 QVERIFY(model->d_ptr->m_logsMap.count() == 1); |
46 QVERIFY(model->d_ptr->m_logsMap.count() == 1); |
47 QVERIFY(spy.count() == 1); |
47 QVERIFY(spy.count() == 1); |
84 msg3.setId(333); |
84 msg3.setId(333); |
85 msgs.append(msg1); |
85 msgs.append(msg1); |
86 msgs.append(msg2); |
86 msgs.append(msg2); |
87 msgs.append(msg3); |
87 msgs.append(msg3); |
88 |
88 |
89 QSignalSpy spy( model, SIGNAL(rowsInserted(const QModelIndex &, int, int))); |
89 QSignalSpy spy( model, SIGNAL(modelReset())); |
90 model->d_ptr->messagesReady(msgs); |
90 model->d_ptr->messagesReady(msgs); |
91 |
91 |
92 QVERIFY(model->rowCount() == 3); |
92 QVERIFY(model->rowCount() == 3); |
93 QVERIFY(model->d_ptr->m_msgMap.count() == 3); |
93 QVERIFY(model->d_ptr->m_msgMap.count() == 3); |
94 QVERIFY(model->d_ptr->m_msgMap.contains(111)); |
94 QVERIFY(model->d_ptr->m_msgMap.contains(111)); |
221 |
221 |
222 // BackgroundRole |
222 // BackgroundRole |
223 var = modelIndex.data(Qt::BackgroundRole); |
223 var = modelIndex.data(Qt::BackgroundRole); |
224 QVERIFY(var.type() > (QVariant::UserType - 1)); |
224 QVERIFY(var.type() > (QVariant::UserType - 1)); |
225 |
225 |
|
226 // ConversationRole |
|
227 var = modelIndex.data(CntConverstaionIdRole); |
|
228 QVERIFY(var.type() == QVariant::Int); |
|
229 |
226 // Invalid role |
230 // Invalid role |
227 var = modelIndex.data(-10); |
231 var = modelIndex.data(-10); |
228 QVERIFY(var.type() == QVariant::Invalid); |
232 QVERIFY(var.type() == QVariant::Invalid); |
229 |
233 |
230 // Invalid indices |
234 // Invalid indices |
269 |
273 |
270 model->d_ptr->m_List.append(p); |
274 model->d_ptr->m_List.append(p); |
271 } |
275 } |
272 |
276 |
273 // Sort ascending |
277 // Sort ascending |
274 QSignalSpy spy( model, SIGNAL( rowsInserted(const QModelIndex &, int, int))); |
278 QSignalSpy spy( model, SIGNAL(modelReset())); |
275 model->sortAndRefresh(Qt::AscendingOrder); |
279 model->sortAndRefresh(Qt::AscendingOrder); |
276 |
280 |
277 QVERIFY(spy.count() == 1); |
281 QVERIFY(spy.count() == 1); |
278 HItemPointer current = model->d_ptr->m_List.first(); |
282 HItemPointer current = model->d_ptr->m_List.first(); |
279 for(int i=1; i<model->d_ptr->m_List.count(); i++) { |
283 for(int i=1; i<model->d_ptr->m_List.count(); i++) { |
280 QVERIFY(current.data()->timeStamp <= model->d_ptr->m_List.at(i).data()->timeStamp); |
284 QVERIFY(current.data()->timeStamp <= model->d_ptr->m_List.at(i).data()->timeStamp); |
281 current = model->d_ptr->m_List.at(i); |
285 current = model->d_ptr->m_List.at(i); |
282 } |
286 } |
283 |
287 |
284 // Sort descending |
288 // Sort descending |
285 QSignalSpy spy1( model, SIGNAL( rowsInserted(const QModelIndex &, int, int))); |
289 QSignalSpy spy1( model, SIGNAL( modelReset())); |
286 model->sortAndRefresh(Qt::DescendingOrder); |
290 model->sortAndRefresh(Qt::DescendingOrder); |
287 |
291 |
288 QVERIFY(spy1.count() == 1); |
292 QVERIFY(spy1.count() == 1); |
289 current = model->d_ptr->m_List.last(); |
293 current = model->d_ptr->m_List.last(); |
290 for(int i=model->d_ptr->m_List.count(); i<1; i--) { |
294 for(int i=model->d_ptr->m_List.count(); i<1; i--) { |
305 |
309 |
306 // Clear already empty history view |
310 // Clear already empty history view |
307 QSignalSpy spy1( model, SIGNAL( rowsRemoved(const QModelIndex &, int, int))); |
311 QSignalSpy spy1( model, SIGNAL( rowsRemoved(const QModelIndex &, int, int))); |
308 model->clearHistory(); |
312 model->clearHistory(); |
309 QVERIFY(spy1.count() == 0); |
313 QVERIFY(spy1.count() == 0); |
|
314 |
|
315 // test reset |
|
316 QSignalSpy spy2( model, SIGNAL(modelReset())); |
|
317 model->d_ptr->handleLogsReset(); |
|
318 QVERIFY(spy2.count() == 1); |
310 } |
319 } |
311 |
320 |
312 void TestCntHistoryModel::testMarkSeen() |
321 void TestCntHistoryModel::testMarkSeen() |
313 { |
322 { |
314 // Mark history as seen |
323 // Mark history as seen |