Commit 28588557 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

add media play list for restoring local track from files not db

parent 595f5ca6
......@@ -2430,6 +2430,111 @@ void MediaPlayListTest::restoreTrackWithoutAlbum()
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DurationRole).toTime().msecsSinceStartOfDay(), 29);
}
void MediaPlayListTest::restoreLocalTrack()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "restoreLocalTrack" << databaseFile.fileName();
MediaPlayList myPlayList;
QAbstractItemModelTester testModel(&myPlayList);
DatabaseInterface myDatabaseContent;
TracksListener myListener(&myDatabaseContent);
QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved);
QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved);
QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted);
QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved);
QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved);
QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted);
QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged);
QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList);
QSignalSpy newEntryInListSpy(&myPlayList, &MediaPlayList::newEntryInList);
QSignalSpy newUrlInListSpy(&myPlayList, &MediaPlayList::newUrlInList);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 0);
myDatabaseContent.init(QStringLiteral("restoreTrackWithoutAlbum"), databaseFile.fileName());
connect(&myListener, &TracksListener::trackHasChanged,
&myPlayList, &MediaPlayList::trackChanged,
Qt::QueuedConnection);
connect(&myListener, &TracksListener::tracksListAdded,
&myPlayList, &MediaPlayList::tracksListAdded,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newTrackByNameInList,
&myListener, &TracksListener::trackByNameInList,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newEntryInList,
&myListener, &TracksListener::newEntryInList,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newUrlInList,
&myListener, &TracksListener::newUrlInList,
Qt::QueuedConnection);
connect(&myDatabaseContent, &DatabaseInterface::tracksAdded,
&myListener, &TracksListener::tracksAdded);
myDatabaseContent.insertTracksList(mNewTracks, mNewCovers);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueueRestoredEntries(QVariantList({QStringList({{},
QStringLiteral("Title"),
QStringLiteral("Artist"),
QStringLiteral("Test"),
{},
{},
QString::number(ElisaUtils::PlayListEntryType::Unknown),
QUrl::fromLocalFile(QStringLiteral(MEDIAPLAYLIST_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/test.ogg")).toString()})}));
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(dataChangedSpy.wait(), true);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("Title"));
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("Test"));
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("Artist"));
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1);
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1);
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DurationRole).toTime().msecsSinceStartOfDay(), 1000);
QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::IsValidRole).toBool(), true);
}
void MediaPlayListTest::testHasHeaderAlbumWithSameTitle()
{
MediaPlayList myPlayList;
......
......@@ -63,6 +63,8 @@ private Q_SLOTS:
void restoreTrackWithoutAlbum();
void restoreLocalTrack();
void testHasHeaderAlbumWithSameTitle();
void testHasHeaderMoveFirstLikeQml();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment