Verified Commit 3fbb202c authored by Sven Marquardt's avatar Sven Marquardt
Browse files

Fix Radio streams



Adding Radio stream was broken before this. The issue was a check
against the databaseId for new Radiostreams. The check was against a
predefined value for ulong that was not correct anymore. This change
fixes the assumption about the value of not initialized long values by
using hasDatabaseid. Also introduces some tests so this can not
happen again. Hopefully.
Signed-off-by: Sven Marquardt's avatarSven Marquardt <dev@mail.smarquardt.space>
parent 422afda6
Pipeline #47589 canceled with stage
......@@ -55,6 +55,7 @@ private Q_SLOTS:
qRegisterMetaType<DataTypes::AlbumDataType>("AlbumDataType");
qRegisterMetaType<DataTypes::ArtistDataType>("ArtistDataType");
qRegisterMetaType<DataTypes::GenreDataType>("GenreDataType");
qRegisterMetaType<DataTypes::ListRadioDataType>("ListRadioDataType");
}
void avoidCrashInTrackIdFromTitleAlbumArtist()
......@@ -73,6 +74,90 @@ private Q_SLOTS:
{
DatabaseInterface musicDb;
musicDb.allAlbumsData();
}
void avoidCrashInAllRadios(){
DatabaseInterface musicDb;
musicDb.allRadiosData();
}
void addOneRadio()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "addOneRadio" << databaseFile.fileName();
DatabaseInterface musicDb;
musicDb.init(QStringLiteral("testDb"),databaseFile.fileName());
QSignalSpy musicDbRadioAddedSpy(&musicDb,&DatabaseInterface::radioAdded);
//9 because elisa inits the radio table with 9 radio streams
QCOMPARE(musicDb.allRadiosData().count(),9);
auto newRadio = DataTypes::TrackDataType();
newRadio[DataTypes::CommentRole]=QStringLiteral("Test Comment");
newRadio[DataTypes::ResourceRole]=QUrl::fromEncoded("http://ice2.somafm.com/defcon-128-aac");
newRadio[DataTypes::TitleRole]=QStringLiteral("Test Radio");
newRadio[DataTypes::RatingRole]=9;
newRadio[DataTypes::ImageUrlRole]=QUrl::fromEncoded("https://somafm.com/img3/defcon400.png");
newRadio[DataTypes::ElementTypeRole]=ElisaUtils::Radio;
auto newRadios = DataTypes::ListRadioDataType();
newRadios.push_back(newRadio);
//Covers are ignored for radios.
musicDb.insertTracksList(newRadios,mNewCovers);
musicDbRadioAddedSpy.wait(300);
QCOMPARE(musicDb.allRadiosData().count(),10);
QCOMPARE(musicDbRadioAddedSpy.count(),1);
databaseFile.close();
}
void modifyOneRadio(){
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "addOneRadio" << databaseFile.fileName();
DatabaseInterface musicDb;
musicDb.init(QStringLiteral("testDb"),databaseFile.fileName());
QSignalSpy musicDbRadioAddedSpy(&musicDb,&DatabaseInterface::radioAdded);
QSignalSpy musicDbRadioModifiedSpy(&musicDb,&DatabaseInterface::radioModified);
QCOMPARE(musicDb.allRadiosData().count(),9);
auto newRadio = DataTypes::TrackDataType();
newRadio[DataTypes::CommentRole]=QStringLiteral("Test Comment");
newRadio[DataTypes::ResourceRole]=QUrl::fromEncoded("http://ice2.somafm.com/defcon-128-aac");
newRadio[DataTypes::TitleRole]=QStringLiteral("Test Radio");
newRadio[DataTypes::RatingRole]=9;
newRadio[DataTypes::ImageUrlRole]=QUrl::fromEncoded("https://somafm.com/img3/defcon400.png");
newRadio[DataTypes::ElementTypeRole]=ElisaUtils::Radio;
auto newRadios = DataTypes::ListRadioDataType();
newRadios.push_back(newRadio);
//Covers are ignored for radios.
musicDb.insertTracksList(newRadios,mNewCovers);
musicDbRadioAddedSpy.wait(300);
QCOMPARE(musicDb.allRadiosData().count(),10);
QCOMPARE(musicDbRadioAddedSpy.count(),1);
newRadios.clear();
auto radioId = musicDb.radioIdFromFileName(QUrl::fromEncoded("http://ice2.somafm.com/defcon-128-aac"));
auto modifiedRadio = musicDb.radioDataFromDatabaseId(radioId);
modifiedRadio[DataTypes::CommentRole]=QStringLiteral("News Test Comment");
newRadios.push_back(modifiedRadio);
musicDb.insertTracksList(newRadios,mNewCovers);
QCOMPARE(musicDb.allRadiosData().count(),10);
QCOMPARE(musicDbRadioAddedSpy.count(),1);
QCOMPARE(musicDbRadioModifiedSpy.count(),1);
databaseFile.close();
}
void addOneTrackWithoutAlbumArtist()
......
......@@ -3492,7 +3492,7 @@ void DatabaseInterface::internalInsertOneRadio(const DataTypes::TrackDataType &o
{
QSqlQuery query = d->mUpdateRadioQuery;
if (oneTrack.databaseId() == -1ull) {
if (!oneTrack.hasDatabaseId()) {
query = d->mInsertRadioQuery;
}
......@@ -3512,7 +3512,7 @@ void DatabaseInterface::internalInsertOneRadio(const DataTypes::TrackDataType &o
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::insertTracksList" << query.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::insertTracksList" << query.lastError();
} else {
if (oneTrack[DataTypes::TrackDataType::key_type::DatabaseIdRole] == -1) {
if (!oneTrack.hasDatabaseId()) {
auto radio = internalOneRadioPartialData(internalRadioIdFromHttpAddress(oneTrack.resourceURI().toString()));
Q_EMIT radioAdded(radio);
......
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