22 #include "logsdetailsmodel.h" |
22 #include "logsdetailsmodel.h" |
23 #include "logsmessage.h" |
23 #include "logsmessage.h" |
24 #include "logseventdata.h" |
24 #include "logseventdata.h" |
25 #include "logsdbconnector.h" |
25 #include "logsdbconnector.h" |
26 #include "logsdbconnector_stub_helper.h" |
26 #include "logsdbconnector_stub_helper.h" |
|
27 #include "logscommondata.h" |
|
28 #include "logsconfigurationparams.h" |
27 |
29 |
28 #include <hbicon.h> |
30 #include <hbicon.h> |
29 #include <QtTest/QtTest> |
31 #include <QtTest/QtTest> |
|
32 #include <hbfontspec.h> |
30 |
33 |
31 Q_DECLARE_METATYPE(LogsEvent *) |
34 Q_DECLARE_METATYPE(LogsEvent *) |
32 Q_DECLARE_METATYPE(LogsCall *) |
35 Q_DECLARE_METATYPE(LogsCall *) |
33 Q_DECLARE_METATYPE(LogsDetailsModel *) |
36 Q_DECLARE_METATYPE(LogsDetailsModel *) |
34 Q_DECLARE_METATYPE(LogsMessage *) |
37 Q_DECLARE_METATYPE(LogsMessage *) |
156 QVERIFY( !contact ); |
160 QVERIFY( !contact ); |
157 } |
161 } |
158 |
162 |
159 void UT_LogsModel::testDataAdded() |
163 void UT_LogsModel::testDataAdded() |
160 { |
164 { |
|
165 QList<int> addedIndexes; |
|
166 QSignalSpy spy(mModel, SIGNAL(rowsInserted(const QModelIndex &, int, int))); |
|
167 |
|
168 // Empty list |
|
169 mModel->dataAdded(addedIndexes); |
|
170 QVERIFY( spy.count() == 0 ); |
|
171 |
161 // One event added |
172 // One event added |
162 LogsEvent* event = new LogsEvent(); |
173 LogsEvent* event = new LogsEvent(); |
163 mModel->mEvents.append(event); |
174 mModel->mEvents.append(event); |
164 QList<int> addedIndexes; |
|
165 addedIndexes.append( 0 ); |
175 addedIndexes.append( 0 ); |
166 QSignalSpy spy(mModel, SIGNAL(rowsInserted(const QModelIndex &, int, int))); |
176 |
167 mModel->dataAdded(addedIndexes); |
177 mModel->dataAdded(addedIndexes); |
168 QVERIFY( spy.count() == 1 ); |
178 QVERIFY( spy.count() == 1 ); |
169 |
179 |
170 // Two more sequnetial events added |
180 // Two more sequnetial events added |
171 LogsEvent* event2 = new LogsEvent(); |
181 LogsEvent* event2 = new LogsEvent(); |
193 QVERIFY( spy.count() == 4 ); // +two addition sequences |
203 QVERIFY( spy.count() == 4 ); // +two addition sequences |
194 } |
204 } |
195 |
205 |
196 void UT_LogsModel::testDataUpdated() |
206 void UT_LogsModel::testDataUpdated() |
197 { |
207 { |
|
208 QList<int> updatedIndexes; |
|
209 QSignalSpy spy(mModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); |
|
210 |
|
211 // Empty list |
|
212 mModel->dataUpdated(updatedIndexes); |
|
213 QVERIFY( spy.count() == 0 ); |
|
214 |
|
215 // Something updated |
198 LogsEvent* event = new LogsEvent(); |
216 LogsEvent* event = new LogsEvent(); |
199 mModel->mEvents.append(event); |
217 mModel->mEvents.append(event); |
200 QList<int> updatedIndexes; |
218 |
201 updatedIndexes.append( 0 ); |
219 updatedIndexes.append( 0 ); |
202 QSignalSpy spy(mModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); |
220 |
203 mModel->dataUpdated(updatedIndexes); |
221 mModel->dataUpdated(updatedIndexes); |
204 QVERIFY( spy.count() == 1 ); |
222 QVERIFY( spy.count() == 1 ); |
205 } |
223 } |
206 |
224 |
207 void UT_LogsModel::testDataRemoved() |
225 void UT_LogsModel::testDataRemoved() |
208 { |
226 { |
209 QList<int> removedIndexes; |
227 QList<int> removedIndexes; |
210 removedIndexes.append( 0 ); |
|
211 QSignalSpy spy(mModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int))); |
228 QSignalSpy spy(mModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int))); |
|
229 mModel->dataRemoved(removedIndexes); |
|
230 QVERIFY( spy.count() == 0 ); |
|
231 |
|
232 removedIndexes.append( 0 ); |
212 mModel->dataRemoved(removedIndexes); |
233 mModel->dataRemoved(removedIndexes); |
213 QVERIFY( spy.count() == 1 ); |
234 QVERIFY( spy.count() == 1 ); |
214 } |
235 } |
215 |
236 |
216 void UT_LogsModel::testGetDecorationData() |
237 void UT_LogsModel::testGetDecorationData() |
380 |
401 |
381 } |
402 } |
382 |
403 |
383 void UT_LogsModel::testGetCallerId() |
404 void UT_LogsModel::testGetCallerId() |
384 { |
405 { |
|
406 //add private and unknown |
385 // No name or number |
407 // No name or number |
386 LogsEvent event; |
408 LogsEvent event; |
387 QVERIFY( mModel->getCallerId(event) == QString("No number") ); |
409 QVERIFY( mModel->getCallerId(event) == QString("") ); |
388 |
410 |
389 // No name |
411 // No name |
390 QString num("+12345555"); |
412 QString num("+12345555"); |
391 event.setNumber(num); |
413 event.setNumber(num); |
392 QVERIFY( mModel->getCallerId(event) == num ); |
414 QVERIFY( mModel->getCallerId(event) == num ); |
414 QVERIFY( mModel->getCallerId(event) == "test@1.2.3.4(4)" ); |
436 QVERIFY( mModel->getCallerId(event) == "test@1.2.3.4(4)" ); |
415 |
437 |
416 // Duplicates for already read event |
438 // Duplicates for already read event |
417 event.setIsRead(true); |
439 event.setIsRead(true); |
418 QVERIFY( mModel->getCallerId(event) == "test@1.2.3.4" ); |
440 QVERIFY( mModel->getCallerId(event) == "test@1.2.3.4" ); |
|
441 } |
|
442 |
|
443 void UT_LogsModel::testSqueezedString() |
|
444 { |
|
445 QFontMetricsF fontMetrics(HbFontSpec(HbFontSpec::Primary).font()); |
|
446 qreal maxwidth = LogsCommonData::getInstance().currentConfiguration().listItemTextWidth(); |
|
447 QString baseString = "4124"; |
|
448 QString secondaryString = "(3)"; |
|
449 qreal stringWidth = fontMetrics.width(baseString+secondaryString); |
|
450 |
|
451 //test with string that fits |
|
452 QVERIFY (mModel->SqueezedString(baseString,secondaryString,stringWidth + 10) == "4124(3)"); |
|
453 |
|
454 //test with string that needs to be cutted |
|
455 QString squeezed = mModel->SqueezedString(baseString,secondaryString,stringWidth - 10); |
|
456 QVERIFY (squeezed.endsWith("...(3)")); |
|
457 |
|
458 //test with empty basestring |
|
459 QVERIFY (mModel->SqueezedString("",secondaryString,stringWidth) == "(3)"); |
|
460 |
|
461 //test with empty secondarystring |
|
462 QVERIFY (mModel->SqueezedString(baseString,"",stringWidth) == "4124"); |
419 } |
463 } |
420 |
464 |
421 void UT_LogsModel::testClearList() |
465 void UT_LogsModel::testClearList() |
422 { |
466 { |
423 mModel->clearList(LogsModel::TypeLogsClearAll); |
467 mModel->clearList(LogsModel::TypeLogsClearAll); |
494 { |
538 { |
495 LogsDbConnectorStubHelper::setPredictiveSearch(2); |
539 LogsDbConnectorStubHelper::setPredictiveSearch(2); |
496 QVERIFY( mModel->setPredictiveSearch(true) == 0 ); |
540 QVERIFY( mModel->setPredictiveSearch(true) == 0 ); |
497 QVERIFY( LogsDbConnectorStubHelper::lastCalledFunction() == "setPredictiveSearch" ); |
541 QVERIFY( LogsDbConnectorStubHelper::lastCalledFunction() == "setPredictiveSearch" ); |
498 } |
542 } |
|
543 |
|
544 void UT_LogsModel::testUpdateConfiguration() |
|
545 { |
|
546 QSignalSpy spy(mModel, SIGNAL(modelReset())); |
|
547 |
|
548 // No previous config, reset not signaled |
|
549 LogsConfigurationParams params; |
|
550 params.setListItemTextWidth(200); |
|
551 mModel->updateConfiguration(params); |
|
552 QVERIFY( spy.count() == 0 ); |
|
553 |
|
554 // Previous config but no change, reset not signaled |
|
555 mModel->updateConfiguration(params); |
|
556 QVERIFY( spy.count() == 0 ); |
|
557 |
|
558 // Config changed but no unseen events, reset not signaled |
|
559 params.setListItemTextWidth(400); |
|
560 mModel->updateConfiguration(params); |
|
561 QVERIFY( spy.count() == 0 ); |
|
562 |
|
563 // Config changed and unseen events, reset signaled |
|
564 LOGS_TEST_CREATE_EVENT(event, 1, LogsEvent::EventAdded ); |
|
565 event->setDirection(LogsEvent::DirMissed); |
|
566 event->setDuplicates(10); |
|
567 params.setListItemTextWidth(300); |
|
568 mModel->updateConfiguration(params); |
|
569 QVERIFY( spy.count() == 1 ); |
|
570 |
|
571 } |