43 int main(int argc, char *argv[]) |
43 int main(int argc, char *argv[]) |
44 { |
44 { |
45 HbApplication app(argc, argv); |
45 HbApplication app(argc, argv); |
46 TestMpCollectionDataModel tv; |
46 TestMpCollectionDataModel tv; |
47 |
47 |
48 char *pass[3]; |
48 if ( argc > 1 ) { |
49 pass[0] = argv[0]; |
49 return QTest::qExec( &tv, argc, argv); |
50 pass[1] = "-o"; |
50 } |
51 pass[2] = "c:\\data\\unittest_mpcollectiondatamodel.txt"; |
51 else { |
52 |
52 char *pass[3]; |
53 int res = QTest::qExec(&tv, 3, pass); |
53 pass[0] = argv[0]; |
54 |
54 pass[1] = "-o"; |
55 return res; |
55 pass[2] = "c:\\data\\unittest_mpcollectiondatamodel.txt"; |
|
56 |
|
57 return QTest::qExec(&tv, 3, pass); |
|
58 } |
56 } |
59 } |
57 |
60 |
58 TestMpCollectionDataModel::TestMpCollectionDataModel() |
61 TestMpCollectionDataModel::TestMpCollectionDataModel() |
59 : mTest(0), |
62 : mTest(0), |
60 mHelper(0), |
63 mHelper(0), |
87 if ( translatorLoaded ) { |
90 if ( translatorLoaded ) { |
88 qApp->installTranslator(mMpTranslator); |
91 qApp->installTranslator(mMpTranslator); |
89 } |
92 } |
90 |
93 |
91 mStubData = new MpMpxCollectionData(); |
94 mStubData = new MpMpxCollectionData(); |
92 mStubPlaybackData = new MpPlaybackData(this); |
95 mStubPlaybackData = new MpPlaybackData(); |
93 mHelper = new TestHelper(); |
96 mHelper = new TestHelper(); |
94 } |
97 } |
95 |
98 |
96 /*! |
99 /*! |
97 Called after the last testfunction was executed. |
100 Called after the last testfunction was executed. |
230 |
233 |
231 // Qt::DisplayRole |
234 // Qt::DisplayRole |
232 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
235 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
233 QCOMPARE(data.canConvert(QVariant::StringList), true); |
236 QCOMPARE(data.canConvert(QVariant::StringList), true); |
234 QStringList dataList = data.toStringList(); |
237 QStringList dataList = data.toStringList(); |
235 QCOMPARE(dataList.count(), 2); |
238 QCOMPARE(dataList.count(), 1); |
236 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
239 QCOMPARE(dataList.at(0), hbTrId("txt_mus_dblist_val_unknown")); |
237 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown3")); |
|
238 |
240 |
239 // Qt::DecorationRole |
241 // Qt::DecorationRole |
240 data = mTest->data(modelIndex, Qt::DecorationRole); |
242 data = mTest->data(modelIndex, Qt::DecorationRole); |
241 QCOMPARE(data.isNull(), true); |
243 QCOMPARE(data.isNull(), true); |
242 |
244 |
318 QStringList dataList = data.toStringList(); |
320 QStringList dataList = data.toStringList(); |
319 QCOMPARE(dataList.count(), 1); |
321 QCOMPARE(dataList.count(), 1); |
320 QCOMPARE(dataList.at(0), QString("Title1")); |
322 QCOMPARE(dataList.at(0), QString("Title1")); |
321 |
323 |
322 // Qt::DecorationRole |
324 // Qt::DecorationRole |
323 data = mTest->data(modelIndex, Qt::DecorationRole); |
325 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
324 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
326 QVERIFY(iconData.isValid()); |
325 |
327 |
326 // Hb::IndexFeedbackRole |
328 // Hb::IndexFeedbackRole |
327 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
329 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
328 QCOMPARE(data.toString(), QString("Title1")); |
330 QCOMPARE(data.toString(), QString("Title1")); |
329 } |
331 } |
347 QCOMPARE(dataList.count(), 1); |
349 QCOMPARE(dataList.count(), 1); |
348 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
350 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
349 |
351 |
350 |
352 |
351 // Qt::DecorationRole |
353 // Qt::DecorationRole |
352 data = mTest->data(modelIndex, Qt::DecorationRole); |
354 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
353 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
355 QVERIFY(iconData.isValid()); |
354 |
356 |
355 // Hb::IndexFeedbackRole |
357 // Hb::IndexFeedbackRole |
356 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
358 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
357 QCOMPARE(data.toString(), QString("")); |
359 QCOMPARE(data.toString(), QString("")); |
358 } |
360 } |
375 QCOMPARE(dataList.count(), 2); |
377 QCOMPARE(dataList.count(), 2); |
376 QCOMPARE(dataList.at(0), QString("Title1")); |
378 QCOMPARE(dataList.at(0), QString("Title1")); |
377 QCOMPARE(dataList.at(1), QString("CollectionTitle")); |
379 QCOMPARE(dataList.at(1), QString("CollectionTitle")); |
378 |
380 |
379 // Qt::DecorationRole |
381 // Qt::DecorationRole |
380 data = mTest->data(modelIndex, Qt::DecorationRole); |
382 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
381 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
383 QVERIFY(iconData.isValid()); |
382 } |
384 } |
383 |
385 |
384 /*! |
386 /*! |
385 Tests data() request for ArtistAlbumsTBone context with no data available. |
387 Tests data() request for ArtistAlbumsTBone context with no data available. |
386 */ |
388 */ |
397 // Qt::DisplayRole |
399 // Qt::DisplayRole |
398 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
400 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
399 QCOMPARE(data.canConvert(QVariant::StringList), true); |
401 QCOMPARE(data.canConvert(QVariant::StringList), true); |
400 QStringList dataList = data.toStringList(); |
402 QStringList dataList = data.toStringList(); |
401 QCOMPARE(dataList.count(), 2); |
403 QCOMPARE(dataList.count(), 2); |
402 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
404 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown8")); |
403 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown3")); |
405 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown5")); |
404 |
406 |
405 // Qt::DecorationRole |
407 // Qt::DecorationRole |
406 data = mTest->data(modelIndex, Qt::DecorationRole); |
408 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
407 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
409 QVERIFY(iconData.isValid()); |
408 } |
410 } |
409 |
411 |
410 /*! |
412 /*! |
411 Tests data() request for ArtistAllSongs context. |
413 Tests data() request for ArtistAllSongs context. |
412 */ |
414 */ |
449 |
451 |
450 // Qt::DisplayRole |
452 // Qt::DisplayRole |
451 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
453 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
452 QCOMPARE(data.canConvert(QVariant::StringList), true); |
454 QCOMPARE(data.canConvert(QVariant::StringList), true); |
453 QStringList dataList = data.toStringList(); |
455 QStringList dataList = data.toStringList(); |
454 QCOMPARE(dataList.count(), 2); |
456 QCOMPARE(dataList.count(), 1); |
455 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
457 QCOMPARE(dataList.at(0), hbTrId("txt_mus_dblist_val_unknown3")); |
456 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown3")); |
|
457 |
458 |
458 |
459 |
459 // Qt::DecorationRole |
460 // Qt::DecorationRole |
460 data = mTest->data(modelIndex, Qt::DecorationRole); |
461 data = mTest->data(modelIndex, Qt::DecorationRole); |
461 QCOMPARE(data.isNull(), true); |
462 QCOMPARE(data.isNull(), true); |
483 QCOMPARE(dataList.count(), 2); |
484 QCOMPARE(dataList.count(), 2); |
484 QCOMPARE(dataList.at(0), QString("Title1")); |
485 QCOMPARE(dataList.at(0), QString("Title1")); |
485 QCOMPARE(dataList.at(1), QString("Artist1")); |
486 QCOMPARE(dataList.at(1), QString("Artist1")); |
486 |
487 |
487 // Qt::DecorationRole |
488 // Qt::DecorationRole |
488 data = mTest->data(modelIndex, Qt::DecorationRole); |
489 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
489 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
490 QVERIFY(iconData.isValid()); |
490 |
491 |
491 // Hb::IndexFeedbackRole |
492 // Hb::IndexFeedbackRole |
492 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
493 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
493 QCOMPARE(data.toString(), QString("Title1")); |
494 QCOMPARE(data.toString(), QString("Title1")); |
494 } |
495 } |
508 // Qt::DisplayRole |
509 // Qt::DisplayRole |
509 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
510 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
510 QCOMPARE(data.canConvert(QVariant::StringList), true); |
511 QCOMPARE(data.canConvert(QVariant::StringList), true); |
511 QStringList dataList = data.toStringList(); |
512 QStringList dataList = data.toStringList(); |
512 QCOMPARE(dataList.count(), 2); |
513 QCOMPARE(dataList.count(), 2); |
513 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
514 QCOMPARE(dataList.at(0), hbTrId("txt_mus_dblist_unknown")); |
514 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown3")); |
515 QCOMPARE(dataList.at(1), hbTrId("txt_mus_dblist_val_unknown2")); |
515 |
516 |
516 // Qt::DecorationRole |
517 // Qt::DecorationRole |
517 data = mTest->data(modelIndex, Qt::DecorationRole); |
518 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
518 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
519 QVERIFY(iconData.isValid()); |
519 |
520 |
520 // Hb::IndexFeedbackRole |
521 // Hb::IndexFeedbackRole |
521 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
522 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
522 QCOMPARE(data.toString(), QString("")); |
523 QCOMPARE(data.toString(), QString("")); |
523 } |
524 } |
540 QCOMPARE(dataList.count(), 2); |
541 QCOMPARE(dataList.count(), 2); |
541 QCOMPARE(dataList.at(0), QString("Title1")); |
542 QCOMPARE(dataList.at(0), QString("Title1")); |
542 QCOMPARE(dataList.at(1), QString("Artist1")); |
543 QCOMPARE(dataList.at(1), QString("Artist1")); |
543 |
544 |
544 // Qt::DecorationRole |
545 // Qt::DecorationRole |
545 data = mTest->data(modelIndex, Qt::DecorationRole); |
546 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
546 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
547 QVERIFY(iconData.isValid()); |
547 |
548 |
548 // Hb::IndexFeedbackRole |
549 // Hb::IndexFeedbackRole |
549 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
550 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
550 QCOMPARE(data.toString(), QString("Title1")); |
551 QCOMPARE(data.toString(), QString("Title1")); |
551 } |
552 } |
565 // Qt::DisplayRole |
566 // Qt::DisplayRole |
566 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
567 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
567 QCOMPARE(data.canConvert(QVariant::StringList), true); |
568 QCOMPARE(data.canConvert(QVariant::StringList), true); |
568 QStringList dataList = data.toStringList(); |
569 QStringList dataList = data.toStringList(); |
569 QCOMPARE(dataList.count(), 2); |
570 QCOMPARE(dataList.count(), 2); |
570 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
571 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown8")); |
571 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown3")); |
572 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown5")); |
572 |
573 |
573 // Qt::DecorationRole |
574 // Qt::DecorationRole |
574 data = mTest->data(modelIndex, Qt::DecorationRole); |
575 QVariant iconData = mTest->data(modelIndex, Qt::DecorationRole); |
575 QCOMPARE(data.userType(), QMetaType::type("QIcon")); |
576 QVERIFY(iconData.isValid()); |
576 |
577 |
577 // Hb::IndexFeedbackRole |
578 // Hb::IndexFeedbackRole |
578 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
579 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
579 QCOMPARE(data.toString(), QString("")); |
580 QCOMPARE(data.toString(), QString("")); |
580 } |
581 } |
620 |
621 |
621 // Qt::DisplayRole |
622 // Qt::DisplayRole |
622 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
623 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
623 QCOMPARE(data.canConvert(QVariant::StringList), true); |
624 QCOMPARE(data.canConvert(QVariant::StringList), true); |
624 QStringList dataList = data.toStringList(); |
625 QStringList dataList = data.toStringList(); |
625 QCOMPARE(dataList.count(), 1); |
626 QCOMPARE(dataList.count(), 0); |
626 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
|
627 |
627 |
628 // Hb::IndexFeedbackRole |
628 // Hb::IndexFeedbackRole |
629 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
629 data = mTest->data(modelIndex, Hb::IndexFeedbackRole); |
630 QCOMPARE(data.toString(), QString("")); |
630 QCOMPARE(data.toString(), QString("")); |
631 } |
631 } |
672 |
672 |
673 // Qt::DisplayRole |
673 // Qt::DisplayRole |
674 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
674 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
675 QCOMPARE(data.canConvert(QVariant::StringList), true); |
675 QCOMPARE(data.canConvert(QVariant::StringList), true); |
676 QStringList dataList = data.toStringList(); |
676 QStringList dataList = data.toStringList(); |
677 QCOMPARE(dataList.count(), 2); |
677 QCOMPARE(dataList.count(), 1); |
678 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
678 QCOMPARE(dataList.at(0), hbTrId("txt_mus_dblist_val_unknown")); |
679 QCOMPARE(dataList.at(1), hbTrId("txt_mus_other_unknown3")); |
|
680 |
679 |
681 // Qt::DecorationRole |
680 // Qt::DecorationRole |
682 data = mTest->data(modelIndex, Qt::DecorationRole); |
681 data = mTest->data(modelIndex, Qt::DecorationRole); |
683 QCOMPARE(data.isNull(), true); |
682 QCOMPARE(data.isNull(), true); |
684 |
683 |
975 /*! |
974 /*! |
976 Tests fileCorrupted() |
975 Tests fileCorrupted() |
977 */ |
976 */ |
978 void TestMpCollectionDataModel::testFileCorrupted() |
977 void TestMpCollectionDataModel::testFileCorrupted() |
979 { |
978 { |
|
979 QSignalSpy spy(mTest, SIGNAL(dataChanged( QModelIndex, QModelIndex ))); |
|
980 mTest->mRowCount = 4; |
|
981 mTest->fileCorrupted(1); |
|
982 QCOMPARE(mStubData->mCorruptedIndex.value(0), 1); |
|
983 QCOMPARE(mStubData->mCorruptedIndex.value(1), 3); |
|
984 QCOMPARE(spy.count(), 2); |
980 |
985 |
981 |
986 } |
|
987 |
|
988 /*! |
|
989 Tests setLayout() |
|
990 */ |
|
991 void TestMpCollectionDataModel::testSetLayout() |
|
992 { |
|
993 QCOMPARE(mTest->mCollectionLayout, ECollectionListView); |
|
994 mTest->setLayout(ECollectionSelectionDialog); |
|
995 QCOMPARE(mTest->mCollectionLayout, ECollectionSelectionDialog); |
|
996 mTest->setLayout(ECollectionArrangeSongsDialog); |
|
997 QCOMPARE(mTest->mCollectionLayout, ECollectionArrangeSongsDialog); |
|
998 mTest->setLayout(ECollectionListView); |
|
999 QCOMPARE(mTest->mCollectionLayout, ECollectionListView); |
982 } |
1000 } |
983 |
1001 |
984 // End of file |
1002 // End of file |