Put all directories and images in database, use the info to associate an image to each artist
This commit is contained in:
@@ -4,6 +4,7 @@ add_executable(test-database
|
||||
Cluster.cpp
|
||||
Common.cpp
|
||||
DatabaseTest.cpp
|
||||
Directory.cpp
|
||||
Image.cpp
|
||||
Listen.cpp
|
||||
Migration.cpp
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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/Directory.hpp"
|
||||
|
||||
namespace lms::db::tests
|
||||
{
|
||||
using ScopedDirectory = ScopedEntity<db::Directory>;
|
||||
|
||||
TEST_F(DatabaseFixture, Directory)
|
||||
{
|
||||
ScopedDirectory directory{ session, "/path/to/dir/" };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(Directory::getCount(session), 1);
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getAbsolutePath(), "/path/to/dir");
|
||||
EXPECT_EQ(dir->getName(), "dir");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
dir.modify()->setAbsolutePath("/path/to/another/dir2");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getAbsolutePath(), "/path/to/another/dir2");
|
||||
EXPECT_EQ(dir->getName(), "dir2");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
dir.modify()->setAbsolutePath("/foo/");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getAbsolutePath(), "/foo");
|
||||
EXPECT_EQ(dir->getName(), "foo");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
dir.modify()->setAbsolutePath("/");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, directory.getId()) };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getAbsolutePath(), "/");
|
||||
EXPECT_EQ(dir->getName(), "");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
Directory::pointer dir{ Directory::find(session, "/") };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getId(), directory.getId());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DatabaseFixture, parent)
|
||||
{
|
||||
ScopedDirectory parent{ session, "/path/to/dir/" };
|
||||
ScopedDirectory child{ session, "/path/to/dir/child" };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
auto dir{ child->getParent() };
|
||||
EXPECT_EQ(dir, Directory::pointer{});
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
|
||||
child.get().modify()->setParent(parent.lockAndGet());
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
auto dir{ child->getParent() };
|
||||
ASSERT_NE(dir, Directory::pointer{});
|
||||
EXPECT_EQ(dir->getId(), parent.getId());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DatabaseFixture, Directory_orphaned)
|
||||
{
|
||||
ScopedDirectory parent{ session, "/path/to/dir/" };
|
||||
ScopedDirectory child{ session, "/path/to/dir/child" };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
const auto directories{ Directory::findOrphanIds(session).results };
|
||||
EXPECT_EQ(directories.size(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
|
||||
child.get().modify()->setParent(parent.lockAndGet());
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
const auto directories{ Directory::findOrphanIds(session).results };
|
||||
ASSERT_EQ(directories.size(), 1);
|
||||
EXPECT_EQ(directories.front(), child.getId());
|
||||
}
|
||||
}
|
||||
} // namespace lms::db::tests
|
||||
@@ -19,10 +19,12 @@
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
#include "database/Directory.hpp"
|
||||
#include "database/Image.hpp"
|
||||
|
||||
namespace lms::db::tests
|
||||
{
|
||||
using ScopedDirectory = ScopedEntity<db::Directory>;
|
||||
using ScopedImage = ScopedEntity<db::Image>;
|
||||
|
||||
TEST_F(DatabaseFixture, Image)
|
||||
@@ -35,7 +37,8 @@ namespace lms::db::tests
|
||||
|
||||
Image::pointer img{ Image::find(session, image.getId()) };
|
||||
ASSERT_NE(img, Image::pointer{});
|
||||
EXPECT_EQ(img->getPath(), "/path/to/image");
|
||||
EXPECT_EQ(img->getAbsoluteFilePath(), "/path/to/image");
|
||||
EXPECT_EQ(img->getFileStem(), "image");
|
||||
EXPECT_EQ(img->getWidth(), 0);
|
||||
EXPECT_EQ(img->getHeight(), 0);
|
||||
EXPECT_EQ(img->getFileSize(), 0);
|
||||
@@ -46,7 +49,7 @@ namespace lms::db::tests
|
||||
|
||||
Image::pointer img{ Image::find(session, image.getId()) };
|
||||
ASSERT_NE(img, Image::pointer{});
|
||||
img.modify()->setPath("/path/to/another/image");
|
||||
img.modify()->setAbsoluteFilePath("/path/to/another/image2");
|
||||
img.modify()->setWidth(640);
|
||||
img.modify()->setHeight(480);
|
||||
img.modify()->setFileSize(1024 * 1024);
|
||||
@@ -57,10 +60,42 @@ namespace lms::db::tests
|
||||
|
||||
Image::pointer img{ Image::find(session, image.getId()) };
|
||||
ASSERT_NE(img, Image::pointer{});
|
||||
EXPECT_EQ(img->getPath(), "/path/to/another/image");
|
||||
EXPECT_EQ(img->getAbsoluteFilePath(), "/path/to/another/image2");
|
||||
EXPECT_EQ(img->getFileStem(), "image2");
|
||||
EXPECT_EQ(img->getWidth(), 640);
|
||||
EXPECT_EQ(img->getHeight(), 480);
|
||||
EXPECT_EQ(img->getFileSize(), 1024 * 1024);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
Image::pointer img{ Image::find(session, "/path/to/another/image2") };
|
||||
ASSERT_NE(img, Image::pointer{});
|
||||
EXPECT_EQ(img->getId(), image->getId());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DatabaseFixture, Image_inDirectory)
|
||||
{
|
||||
ScopedImage image{ session, "/path/to/image" };
|
||||
ScopedDirectory directory{ session, "/path/to" };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(Image::find(session, Image::FindParameters{}.setDirectory(directory.getId())).results.size(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
image.get().modify()->setDirectory(directory.get());
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
const auto results{ Image::find(session, Image::FindParameters{}.setDirectory(directory.getId())).results };
|
||||
ASSERT_EQ(results.size(), 1);
|
||||
EXPECT_EQ(results.front()->getId(), image.getId());
|
||||
}
|
||||
}
|
||||
} // namespace lms::db::tests
|
||||
@@ -18,8 +18,14 @@
|
||||
*/
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
#include "core/String.hpp"
|
||||
#include "database/Db.hpp"
|
||||
#include "database/Directory.hpp"
|
||||
#include "database/Image.hpp"
|
||||
#include "database/StarredArtist.hpp"
|
||||
#include "database/StarredRelease.hpp"
|
||||
#include "database/StarredTrack.hpp"
|
||||
|
||||
namespace lms::db::tests
|
||||
{
|
||||
@@ -318,5 +324,24 @@ VALUES
|
||||
|
||||
// Now perform full migration
|
||||
db.getTLSSession().migrateSchemaIfNeeded();
|
||||
|
||||
// Now perform some dummy finds to ensure all fields are correctly mapped
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
EXPECT_FALSE(Artist::find(session, ArtistId{}));
|
||||
EXPECT_FALSE(Cluster::find(session, ClusterId{}));
|
||||
EXPECT_FALSE(ClusterType::find(session, ClusterTypeId{}));
|
||||
EXPECT_FALSE(Directory::find(session, DirectoryId{}));
|
||||
EXPECT_FALSE(Image::find(session, ImageId{}));
|
||||
EXPECT_FALSE(Listen::find(session, ListenId{}));
|
||||
EXPECT_FALSE(Release::find(session, ReleaseId{}));
|
||||
EXPECT_FALSE(StarredArtist::find(session, StarredArtistId{}));
|
||||
EXPECT_FALSE(StarredRelease::find(session, StarredReleaseId{}));
|
||||
EXPECT_FALSE(StarredTrack::find(session, StarredTrackId{}));
|
||||
EXPECT_FALSE(Track::find(session, TrackId{}));
|
||||
EXPECT_FALSE(TrackList::find(session, TrackListId{}));
|
||||
EXPECT_FALSE(User::find(session, UserId{}));
|
||||
}
|
||||
}
|
||||
} // namespace lms::db::tests
|
||||
Reference in New Issue
Block a user