Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epoupon committed Nov 15, 2024
1 parent 7b47910 commit 0a320a8
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/libs/database/impl/MediaLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

namespace lms::db
{
MediaLibrary::MediaLibrary(const std::filesystem::path& p, std::string_view name)
MediaLibrary::MediaLibrary(std::string_view name, const std::filesystem::path& p)
: _name{ std::string{ name, 0, maxNameLength } }
{
setPath(p);
}

MediaLibrary::pointer MediaLibrary::create(Session& session, const std::filesystem::path& p, std::string_view name)
MediaLibrary::pointer MediaLibrary::create(Session& session, std::string_view name, const std::filesystem::path& p)
{
return session.getDboSession()->add(std::unique_ptr<MediaLibrary>{ new MediaLibrary{ p, name } });
return session.getDboSession()->add(std::unique_ptr<MediaLibrary>{ new MediaLibrary{ name, p } });
}

std::size_t MediaLibrary::getCount(Session& session)
Expand Down
4 changes: 2 additions & 2 deletions src/libs/database/include/database/MediaLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ namespace lms::db

private:
friend class Session;
MediaLibrary(const std::filesystem::path& p, std::string_view name);
static pointer create(Session& session, const std::filesystem::path& p = {}, std::string_view name = {});
MediaLibrary(std::string_view name, const std::filesystem::path& p);
static pointer create(Session& session, std::string_view name, const std::filesystem::path& p);

std::filesystem::path _path;
std::string _name;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/database/test/Artist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace lms::db::tests
ScopedArtist artist1{ session, "MyArtist1" };
ScopedArtist artist2{ session, "MyArtist2" };
ScopedArtist artist3{ session, "MyArtist3" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -306,8 +306,8 @@ namespace lms::db::tests
{
ScopedTrack track{ session };
ScopedArtist artist{ session, "MyArtist" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down
2 changes: 1 addition & 1 deletion src/libs/database/test/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ namespace lms::db::tests
ScopedDirectory parent2{ session, "/root_1" };
ScopedDirectory child2{ session, "/root_1/foo" };

ScopedMediaLibrary library{ session, "/root" };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };

{
auto transaction{ session.createReadTransaction() };
Expand Down
24 changes: 12 additions & 12 deletions src/libs/database/test/Listen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ namespace lms::db::tests
ScopedUser user{ session, "MyUser" };
const Wt::WDateTime dateTime1{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
ScopedListen listen{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime1 };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createReadTransaction() };
Expand Down Expand Up @@ -563,8 +563,8 @@ namespace lms::db::tests
ScopedUser user{ session, "MyUser" };
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
ScopedRelease release{ session, "MyRelease" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -809,8 +809,8 @@ namespace lms::db::tests
ScopedTrack track{ session };
ScopedUser user{ session, "MyUser" };
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createReadTransaction() };
Expand Down Expand Up @@ -1051,8 +1051,8 @@ namespace lms::db::tests
ScopedTrack track{ session };
ScopedUser user{ session, "MyUser" };
ScopedArtist artist{ session, "MyArtist" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -1325,8 +1325,8 @@ namespace lms::db::tests
ScopedTrack track{ session };
ScopedUser user{ session, "MyUser" };
ScopedRelease release{ session, "MyRelease" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -1410,8 +1410,8 @@ namespace lms::db::tests
{
ScopedTrack track{ session };
ScopedUser user{ session, "MyUser" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
ScopedListen listen1{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime };
Expand Down
8 changes: 4 additions & 4 deletions src/libs/database/test/Release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ namespace lms::db::tests
ScopedRelease release1{ session, "MyRelease1" };
ScopedRelease release2{ session, "MyRelease2" };
ScopedRelease release3{ session, "MyRelease3" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -233,8 +233,8 @@ namespace lms::db::tests
{
ScopedTrack track{ session };
ScopedRelease release{ session, "MyRelease" };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down
8 changes: 4 additions & 4 deletions src/libs/database/test/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace lms::db::tests
ScopedTrack track1{ session };
ScopedTrack track2{ session };
ScopedTrack track3{ session };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down Expand Up @@ -148,8 +148,8 @@ namespace lms::db::tests
TEST_F(DatabaseFixture, Track_MediaLibrary)
{
ScopedTrack track{ session };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary otherLibrary{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down
2 changes: 1 addition & 1 deletion src/libs/database/test/TrackList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace lms::db::tests
ScopedTrackList trackList2{ session, "MytrackList2", TrackListType::Playlist, false, user.lockAndGet() };
ScopedTrack track1{ session };
ScopedTrack track2{ session };
ScopedMediaLibrary library{ session };
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };

{
auto transaction{ session.createWriteTransaction() };
Expand Down
17 changes: 13 additions & 4 deletions src/lms/ui/admin/MediaLibraryModal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,23 @@ namespace lms::ui
auto& session{ LmsApp->getDbSession() };
auto transaction{ LmsApp->getDbSession().createWriteTransaction() };

std::string name{ valueText(NameField).toUTF8() };
std::string path{ valueText(DirectoryField).toUTF8() };

MediaLibrary::pointer library;
if (_libraryId.isValid())
{
library = MediaLibrary::find(session, _libraryId);
if (library)
{
library.modify()->setName(name);
library.modify()->setPath(path);
}
}
else
library = session.create<MediaLibrary>();

library.modify()->setName(valueText(NameField).toUTF8());
library.modify()->setPath(valueText(DirectoryField).toUTF8());
{
library = session.create<MediaLibrary>(name, path);
}

return library->getId();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/db-generator/LmsDbGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace lms

// create some random media libraries
for (std::size_t i{}; i < params.mediaLibraryCount; ++i)
context.mediaLibraries.push_back(context.session.create<db::MediaLibrary>());
context.mediaLibraries.push_back(context.session.create<db::MediaLibrary>("Library" + std::to_string(i), "/root" + std::to_string(i)));

// create some random genres/moods
{
Expand Down

0 comments on commit 0a320a8

Please sign in to comment.