Commit 025e822a authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

add more tests for the database: removal of metadata

test removal of track number

test removal of disc number
parent 936d1897
......@@ -5307,6 +5307,142 @@ private Q_SLOTS:
QCOMPARE(allTracks[2].resourceURI(), QUrl::fromLocalFile(QStringLiteral("/test/$25")));
QCOMPARE(allTracks[2].fileModificationTime(), QDateTime::fromMSecsSinceEpoch(25));
}
void removeTrackNumber()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "removeTrackNumber" << databaseFile.fileName();
DatabaseInterface musicDb;
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
musicDb.init(QStringLiteral("testDb"), databaseFile.fileName());
musicDb.insertTracksList(mNewTracks, mNewCovers);
musicDbTrackAddedSpy.wait(300);
QCOMPARE(musicDb.allAlbumsData().count(), 5);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto newTracks = DataTypes::ListTrackDataType{
{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"),
QStringLiteral("artist2"), QStringLiteral("album3"), {},
6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/test/$23"))},
QDateTime::fromMSecsSinceEpoch(23),
QUrl::fromLocalFile(QStringLiteral("album3")), 5, true,
QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1"), false}};
auto newCovers = mNewCovers;
newCovers[QStringLiteral("/test/$23")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$24")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$25")] = QUrl::fromLocalFile(QStringLiteral("album3"));
musicDb.insertTracksList(newTracks, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto trackIdFirstVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
auto firstTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdFirstVersion);
auto newTrackData = firstTrackDataVersion;
newTrackData.remove(DataTypes::TrackNumberRole);
musicDb.insertTracksList({newTrackData}, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
auto trackIdSecondVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
QCOMPARE(trackIdFirstVersion, trackIdSecondVersion);
auto secondTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdSecondVersion);
auto modifiedTrack = musicDbTrackModifiedSpy.at(0).at(0).value<DataTypes::TrackDataType>();
auto trackIdIterator = secondTrackDataVersion.find(DataTypes::TrackNumberRole);
QCOMPARE(trackIdIterator, secondTrackDataVersion.end());
QCOMPARE(secondTrackDataVersion, modifiedTrack);
}
void removeDiscNumber()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "removeTrackNumber" << databaseFile.fileName();
DatabaseInterface musicDb;
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
musicDb.init(QStringLiteral("testDb"), databaseFile.fileName());
musicDb.insertTracksList(mNewTracks, mNewCovers);
musicDbTrackAddedSpy.wait(300);
QCOMPARE(musicDb.allAlbumsData().count(), 5);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto newTracks = DataTypes::ListTrackDataType{
{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"),
QStringLiteral("artist2"), QStringLiteral("album3"), {},
6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/test/$23"))},
QDateTime::fromMSecsSinceEpoch(23),
QUrl::fromLocalFile(QStringLiteral("album3")), 5, true,
QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1"), false}};
auto newCovers = mNewCovers;
newCovers[QStringLiteral("/test/$23")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$24")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$25")] = QUrl::fromLocalFile(QStringLiteral("album3"));
musicDb.insertTracksList(newTracks, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto trackIdFirstVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
auto firstTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdFirstVersion);
auto newTrackData = firstTrackDataVersion;
newTrackData.remove(DataTypes::DiscNumberRole);
musicDb.insertTracksList({newTrackData}, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
auto trackIdSecondVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
QCOMPARE(trackIdFirstVersion, trackIdSecondVersion);
auto secondTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdSecondVersion);
auto modifiedTrack = musicDbTrackModifiedSpy.at(0).at(0).value<DataTypes::TrackDataType>();
auto trackIdIterator = secondTrackDataVersion.find(DataTypes::DiscNumberRole);
QCOMPARE(trackIdIterator, secondTrackDataVersion.end());
QCOMPARE(secondTrackDataVersion, modifiedTrack);
qDebug() << trackIdFirstVersion << secondTrackDataVersion;
}
};
QTEST_GUILESS_MAIN(DatabaseInterfaceTests)
......
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