Commit 85ca893d authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

fix browsing albums from an artist and a genre but without album artist

Summary:
null album artist case needs to be handled to extract all albums from artist and genre

BUG: 411300

Test Plan: new automatic test is KO without patch and OK with it

Reviewers: #elisa, astippich, ngraham

Reviewed By: #elisa, ngraham

Differential Revision: https://phabricator.kde.org/D23720
parent 1a74cda7
......@@ -5175,6 +5175,75 @@ private Q_SLOTS:
QCOMPARE(oneAlbum.artist(), QStringLiteral("Various Artists"));
QCOMPARE(oneAlbum[DatabaseInterface::ColumnsRoles::SecondaryTextRole], QStringLiteral("Various Artists"));
}
void testAlbumFromGenreAndArtistWithoutAlbumArtist()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "testAlbumFromGenreAndArtistWithoutAlbumArtist" << databaseFile.fileName();
DatabaseInterface musicDb;
musicDb.init(QStringLiteral("testDb"), databaseFile.fileName());
QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded);
QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded);
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved);
QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved);
QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved);
QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QCOMPARE(musicDb.allAlbumsData().count(), 0);
QCOMPARE(musicDb.allArtistsData().count(), 0);
QCOMPARE(musicDb.allTracksData().count(), 0);
QCOMPARE(musicDbArtistAddedSpy.count(), 0);
QCOMPARE(musicDbAlbumAddedSpy.count(), 0);
QCOMPARE(musicDbTrackAddedSpy.count(), 0);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto newTracks = QList<MusicAudioTrack>{
{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);
musicDbTrackAddedSpy.wait(300);
QCOMPARE(musicDb.allAlbumsData().count(), 1);
QCOMPARE(musicDb.allArtistsData().count(), 1);
QCOMPARE(musicDb.allTracksData().count(), 1);
QCOMPARE(musicDbArtistAddedSpy.count(), 1);
QCOMPARE(musicDbAlbumAddedSpy.count(), 1);
QCOMPARE(musicDbTrackAddedSpy.count(), 1);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto albumFromGenreAndArtist = musicDb.allAlbumsDataByGenreAndArtist(QStringLiteral("genre1"), QStringLiteral("artist2"));
QCOMPARE(albumFromGenreAndArtist.size(), 1);
}
};
QTEST_GUILESS_MAIN(DatabaseInterfaceTests)
......
......@@ -3289,7 +3289,11 @@ void DatabaseInterface::initRequest()
" `Genre` genre2 "
" WHERE "
" tracks2.`AlbumTitle` = album.`Title` AND "
" tracks2.`AlbumArtistName` = album.`ArtistName` AND "
" (tracks2.`AlbumArtistName` = album.`ArtistName` OR "
" (tracks2.`AlbumArtistName` IS NULL AND "
" album.`ArtistName` IS NULL"
" )"
" ) AND "
" tracks2.`Genre` = genre2.`Name` AND "
" genre2.`Name` = :genreFilter AND "
" (tracks2.`ArtistName` = :artistFilter OR tracks2.`AlbumArtistName` = :artistFilter) "
......
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