Added basic support for artist.nfo file parsing, ref #640

This commit is contained in:
emeric
2025-03-22 17:21:08 +01:00
parent 67a6b660be
commit e349e14101
32 changed files with 905 additions and 12 deletions
+112
View File
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2024 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Common.hpp"
#include "database/Artist.hpp"
#include "database/ArtistInfo.hpp"
#include "database/Directory.hpp"
namespace lms::db::tests
{
using ScopedArtistInfo = ScopedEntity<db::ArtistInfo>;
using ScopedDirectory = ScopedEntity<db::Directory>;
TEST_F(DatabaseFixture, ArtistInfo)
{
{
auto transaction{ session.createReadTransaction() };
EXPECT_EQ(ArtistInfo::getCount(session), 0);
}
ScopedArtistInfo artistInfo{ session };
{
auto transaction{ session.createReadTransaction() };
EXPECT_EQ(ArtistInfo::getCount(session), 1);
}
{
auto transaction{ session.createReadTransaction() };
const ArtistInfo::pointer dbArtistInfo{ ArtistInfo::find(session, artistInfo.getId()) };
EXPECT_EQ(dbArtistInfo->getAbsoluteFilePath(), "");
EXPECT_EQ(dbArtistInfo->getLastWriteTime(), Wt::WDateTime{});
EXPECT_EQ(dbArtistInfo->getArtist(), Artist::pointer{});
EXPECT_EQ(dbArtistInfo->getDirectory(), Directory::pointer{});
EXPECT_EQ(dbArtistInfo->getType(), "");
EXPECT_EQ(dbArtistInfo->getGender(), "");
EXPECT_EQ(dbArtistInfo->getDisambiguation(), "");
EXPECT_EQ(dbArtistInfo->getBiography(), "");
}
ScopedArtist artist{ session, "MyArtist" };
ScopedDirectory directory{ session, "/tmp" };
const Wt::WDateTime dateTime{ Wt::WDate{ 2024, 30, 1 }, Wt::WTime{ 12, 58, 29 } };
// Now change some values
{
auto transaction{ session.createWriteTransaction() };
ArtistInfo::pointer dbArtistInfo{ ArtistInfo::find(session, artistInfo.getId()) };
dbArtistInfo.modify()->setAbsoluteFilePath("/tmp/artist.nfo");
dbArtistInfo.modify()->setLastWriteTime(dateTime);
dbArtistInfo.modify()->setArtist(artist.get());
dbArtistInfo.modify()->setDirectory(directory.get());
dbArtistInfo.modify()->setType("MyType");
dbArtistInfo.modify()->setGender("MyGender");
dbArtistInfo.modify()->setDisambiguation("MyDisambiguation");
dbArtistInfo.modify()->setBiography("MyBiography");
}
// Check values are reflected
{
auto transaction{ session.createReadTransaction() };
const ArtistInfo::pointer dbArtistInfo{ ArtistInfo::find(session, artistInfo.getId()) };
EXPECT_EQ(dbArtistInfo->getAbsoluteFilePath(), "/tmp/artist.nfo");
EXPECT_EQ(dbArtistInfo->getLastWriteTime(), dateTime);
EXPECT_EQ(dbArtistInfo->getArtist(), artist.get());
EXPECT_EQ(dbArtistInfo->getDirectory(), directory.get());
EXPECT_EQ(dbArtistInfo->getDirectoryId(), directory.getId());
EXPECT_EQ(dbArtistInfo->getType(), "MyType");
EXPECT_EQ(dbArtistInfo->getGender(), "MyGender");
EXPECT_EQ(dbArtistInfo->getDisambiguation(), "MyDisambiguation");
EXPECT_EQ(dbArtistInfo->getBiography(), "MyBiography");
}
{
auto transaction{ session.createReadTransaction() };
bool visited{};
ArtistInfo::find(session, artist.getId(), [&](const ArtistInfo::pointer& dbArtistInfo) {
ASSERT_NE(dbArtistInfo, ArtistInfo::pointer{});
EXPECT_EQ(dbArtistInfo->getId(), artistInfo.getId());
visited = true;
});
EXPECT_TRUE(visited);
}
}
} // namespace lms::db::tests
+2 -1
View File
@@ -1,7 +1,8 @@
add_executable(test-database
AuthToken.cpp
Artist.cpp
ArtistInfo.cpp
AuthToken.cpp
Cluster.cpp
Common.cpp
DatabaseTest.cpp
+3
View File
@@ -20,6 +20,8 @@
#include "Common.hpp"
#include "core/String.hpp"
#include "database/Artist.hpp"
#include "database/ArtistInfo.hpp"
#include "database/AuthToken.hpp"
#include "database/Db.hpp"
#include "database/Directory.hpp"
@@ -341,6 +343,7 @@ VALUES
auto transaction{ session.createReadTransaction() };
EXPECT_FALSE(Artist::find(session, ArtistId{}));
EXPECT_FALSE(ArtistInfo::find(session, ArtistInfoId{}));
EXPECT_FALSE(AuthToken::find(session, AuthTokenId{}));
EXPECT_FALSE(Country::find(session, CountryId{}));
EXPECT_FALSE(Cluster::find(session, ClusterId{}));