Fixed unit tests
This commit is contained in:
@@ -30,15 +30,15 @@
|
|||||||
|
|
||||||
namespace lms::db
|
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 } }
|
: _name{ std::string{ name, 0, maxNameLength } }
|
||||||
{
|
{
|
||||||
setPath(p);
|
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)
|
std::size_t MediaLibrary::getCount(Session& session)
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ namespace lms::db
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Session;
|
friend class Session;
|
||||||
MediaLibrary(const std::filesystem::path& p, std::string_view name);
|
MediaLibrary(std::string_view name, const std::filesystem::path& p);
|
||||||
static pointer create(Session& session, const std::filesystem::path& p = {}, std::string_view name = {});
|
static pointer create(Session& session, std::string_view name, const std::filesystem::path& p);
|
||||||
|
|
||||||
std::filesystem::path _path;
|
std::filesystem::path _path;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ namespace lms::db::tests
|
|||||||
ScopedArtist artist1{ session, "MyArtist1" };
|
ScopedArtist artist1{ session, "MyArtist1" };
|
||||||
ScopedArtist artist2{ session, "MyArtist2" };
|
ScopedArtist artist2{ session, "MyArtist2" };
|
||||||
ScopedArtist artist3{ session, "MyArtist3" };
|
ScopedArtist artist3{ session, "MyArtist3" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -306,8 +306,8 @@ namespace lms::db::tests
|
|||||||
{
|
{
|
||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedArtist artist{ session, "MyArtist" };
|
ScopedArtist artist{ session, "MyArtist" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ namespace lms::db::tests
|
|||||||
ScopedDirectory parent2{ session, "/root_1" };
|
ScopedDirectory parent2{ session, "/root_1" };
|
||||||
ScopedDirectory child2{ session, "/root_1/foo" };
|
ScopedDirectory child2{ session, "/root_1/foo" };
|
||||||
|
|
||||||
ScopedMediaLibrary library{ session, "/root" };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createReadTransaction() };
|
auto transaction{ session.createReadTransaction() };
|
||||||
|
|||||||
@@ -343,8 +343,8 @@ namespace lms::db::tests
|
|||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
const Wt::WDateTime dateTime1{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
const Wt::WDateTime dateTime1{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
||||||
ScopedListen listen{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime1 };
|
ScopedListen listen{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime1 };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createReadTransaction() };
|
auto transaction{ session.createReadTransaction() };
|
||||||
@@ -563,8 +563,8 @@ namespace lms::db::tests
|
|||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
||||||
ScopedRelease release{ session, "MyRelease" };
|
ScopedRelease release{ session, "MyRelease" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -809,8 +809,8 @@ namespace lms::db::tests
|
|||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createReadTransaction() };
|
auto transaction{ session.createReadTransaction() };
|
||||||
@@ -1051,8 +1051,8 @@ namespace lms::db::tests
|
|||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
ScopedArtist artist{ session, "MyArtist" };
|
ScopedArtist artist{ session, "MyArtist" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -1325,8 +1325,8 @@ namespace lms::db::tests
|
|||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
ScopedRelease release{ session, "MyRelease" };
|
ScopedRelease release{ session, "MyRelease" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -1410,8 +1410,8 @@ namespace lms::db::tests
|
|||||||
{
|
{
|
||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedUser user{ session, "MyUser" };
|
ScopedUser user{ session, "MyUser" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
const Wt::WDateTime dateTime{ Wt::WDate{ 2000, 1, 2 }, Wt::WTime{ 12, 0, 1 } };
|
||||||
ScopedListen listen1{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime };
|
ScopedListen listen1{ session, user.lockAndGet(), track.lockAndGet(), ScrobblingBackend::Internal, dateTime };
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ namespace lms::db::tests
|
|||||||
ScopedRelease release1{ session, "MyRelease1" };
|
ScopedRelease release1{ session, "MyRelease1" };
|
||||||
ScopedRelease release2{ session, "MyRelease2" };
|
ScopedRelease release2{ session, "MyRelease2" };
|
||||||
ScopedRelease release3{ session, "MyRelease3" };
|
ScopedRelease release3{ session, "MyRelease3" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -233,8 +233,8 @@ namespace lms::db::tests
|
|||||||
{
|
{
|
||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedRelease release{ session, "MyRelease" };
|
ScopedRelease release{ session, "MyRelease" };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ namespace lms::db::tests
|
|||||||
ScopedTrack track1{ session };
|
ScopedTrack track1{ session };
|
||||||
ScopedTrack track2{ session };
|
ScopedTrack track2{ session };
|
||||||
ScopedTrack track3{ session };
|
ScopedTrack track3{ session };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
@@ -148,8 +148,8 @@ namespace lms::db::tests
|
|||||||
TEST_F(DatabaseFixture, Track_MediaLibrary)
|
TEST_F(DatabaseFixture, Track_MediaLibrary)
|
||||||
{
|
{
|
||||||
ScopedTrack track{ session };
|
ScopedTrack track{ session };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
ScopedMediaLibrary otherLibrary{ session };
|
ScopedMediaLibrary otherLibrary{ session, "OtherLibrary", "/otherRoot" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ namespace lms::db::tests
|
|||||||
ScopedTrackList trackList2{ session, "MytrackList2", TrackListType::Playlist, false, user.lockAndGet() };
|
ScopedTrackList trackList2{ session, "MytrackList2", TrackListType::Playlist, false, user.lockAndGet() };
|
||||||
ScopedTrack track1{ session };
|
ScopedTrack track1{ session };
|
||||||
ScopedTrack track2{ session };
|
ScopedTrack track2{ session };
|
||||||
ScopedMediaLibrary library{ session };
|
ScopedMediaLibrary library{ session, "MyLibrary", "/root" };
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction{ session.createWriteTransaction() };
|
auto transaction{ session.createWriteTransaction() };
|
||||||
|
|||||||
@@ -151,14 +151,23 @@ namespace lms::ui
|
|||||||
auto& session{ LmsApp->getDbSession() };
|
auto& session{ LmsApp->getDbSession() };
|
||||||
auto transaction{ LmsApp->getDbSession().createWriteTransaction() };
|
auto transaction{ LmsApp->getDbSession().createWriteTransaction() };
|
||||||
|
|
||||||
|
std::string name{ valueText(NameField).toUTF8() };
|
||||||
|
std::string path{ valueText(DirectoryField).toUTF8() };
|
||||||
|
|
||||||
MediaLibrary::pointer library;
|
MediaLibrary::pointer library;
|
||||||
if (_libraryId.isValid())
|
if (_libraryId.isValid())
|
||||||
|
{
|
||||||
library = MediaLibrary::find(session, _libraryId);
|
library = MediaLibrary::find(session, _libraryId);
|
||||||
|
if (library)
|
||||||
|
{
|
||||||
|
library.modify()->setName(name);
|
||||||
|
library.modify()->setPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
library = session.create<MediaLibrary>();
|
{
|
||||||
|
library = session.create<MediaLibrary>(name, path);
|
||||||
library.modify()->setName(valueText(NameField).toUTF8());
|
}
|
||||||
library.modify()->setPath(valueText(DirectoryField).toUTF8());
|
|
||||||
|
|
||||||
return library->getId();
|
return library->getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ namespace lms
|
|||||||
|
|
||||||
// create some random media libraries
|
// create some random media libraries
|
||||||
for (std::size_t i{}; i < params.mediaLibraryCount; ++i)
|
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
|
// create some random genres/moods
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user