Refactoring
This commit is contained in:
@@ -28,13 +28,13 @@
|
||||
#include <QThread>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/scoped_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "core/database.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "core/memorydatabase.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "collection/collection.h"
|
||||
#include "collection/collectionlibrary.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using std::make_unique;
|
||||
@@ -49,7 +49,7 @@ class CollectionBackendTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
database_ = make_shared<MemoryDatabase>(nullptr);
|
||||
backend_ = make_unique<CollectionBackend>();
|
||||
backend_->Init(database_, nullptr, Song::Source::Collection, QLatin1String(SCollection::kSongsTable), QLatin1String(SCollection::kDirsTable), QLatin1String(SCollection::kSubdirsTable));
|
||||
backend_->Init(database_, nullptr, Song::Source::Collection, QLatin1String(CollectionLibrary::kSongsTable), QLatin1String(CollectionLibrary::kDirsTable), QLatin1String(CollectionLibrary::kSubdirsTable));
|
||||
}
|
||||
|
||||
static Song MakeDummySong(int directory_id) {
|
||||
@@ -417,7 +417,7 @@ TEST_F(TestUrls, TestUrls) {
|
||||
|
||||
QSqlDatabase db(database_->Connect());
|
||||
QSqlQuery q(db);
|
||||
q.prepare(QStringLiteral("SELECT url FROM %1 WHERE url = :url").arg(QLatin1String(SCollection::kSongsTable)));
|
||||
q.prepare(QStringLiteral("SELECT url FROM %1 WHERE url = :url").arg(QLatin1String(CollectionLibrary::kSongsTable)));
|
||||
|
||||
q.bindValue(u":url"_s, url.toString(QUrl::FullyEncoded));
|
||||
EXPECT_TRUE(q.exec());
|
||||
@@ -495,7 +495,7 @@ TEST_F(UpdateSongsBySongID, UpdateSongsBySongID) {
|
||||
SongMap songs;
|
||||
{
|
||||
QSqlDatabase db(database_->Connect());
|
||||
CollectionQuery query(db, QLatin1String(SCollection::kSongsTable));
|
||||
CollectionQuery query(db, QLatin1String(CollectionLibrary::kSongsTable));
|
||||
EXPECT_TRUE(backend_->ExecCollectionQuery(&query, songs));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
#include <QSignalSpy>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "includes/scoped_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/database.h"
|
||||
#include "collection/collection.h"
|
||||
#include "core/memorydatabase.h"
|
||||
#include "collection/collectionlibrary.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "collection/collectionmodel.h"
|
||||
#include "collection/collectionfilter.h"
|
||||
@@ -55,7 +55,7 @@ class CollectionModelTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
database_ = make_shared<MemoryDatabase>(nullptr);
|
||||
backend_ = make_shared<CollectionBackend>();
|
||||
backend_->Init(database_, nullptr, Song::Source::Collection, QLatin1String(SCollection::kSongsTable), QLatin1String(SCollection::kDirsTable), QLatin1String(SCollection::kSubdirsTable));
|
||||
backend_->Init(database_, nullptr, Song::Source::Collection, QLatin1String(CollectionLibrary::kSongsTable), QLatin1String(CollectionLibrary::kDirsTable), QLatin1String(CollectionLibrary::kSubdirsTable));
|
||||
model_ = make_unique<CollectionModel>(backend_, nullptr);
|
||||
collection_filter_ = model_->filter();
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "organize/organizeformat.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "core/song.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/song.h"
|
||||
#include "organize/organizeformat.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
@@ -44,16 +44,14 @@ namespace {
|
||||
class PlaylistTest : public ::testing::Test {
|
||||
protected:
|
||||
PlaylistTest()
|
||||
: playlist_(nullptr, nullptr, nullptr, 1),
|
||||
sequence_(nullptr, new DummySettingsProvider)
|
||||
{
|
||||
}
|
||||
: playlist_(nullptr, nullptr, nullptr, nullptr, nullptr, 1),
|
||||
sequence_(nullptr, new DummySettingsProvider) {}
|
||||
|
||||
void SetUp() override {
|
||||
playlist_.set_sequence(&sequence_);
|
||||
}
|
||||
|
||||
MockPlaylistItem* MakeMockItem(const QString &title, const QString &artist = QString(), const QString &album = QString(), int length = 123) const {
|
||||
MockPlaylistItem *MakeMockItem(const QString &title, const QString &artist = QString(), const QString &album = QString(), int length = 123) const {
|
||||
Song metadata;
|
||||
metadata.Init(title, artist, album, length);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "includes/scoped_ptr.h"
|
||||
#include "playlist/songplaylistitem.h"
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <QThread>
|
||||
#include <QEventLoop>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/song.h"
|
||||
#include "tagreader/tagreaderclient.h"
|
||||
|
||||
@@ -44,11 +45,18 @@ namespace {
|
||||
class TagReaderTest : public ::testing::Test {
|
||||
protected:
|
||||
|
||||
~TagReaderTest() {
|
||||
tagreader_client_thread_->exit();
|
||||
tagreader_client_thread_->wait(5000);
|
||||
tagreader_client_->deleteLater();
|
||||
tagreader_client_thread_->deleteLater();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
tagread_client_thread_ = new QThread();
|
||||
tagreader_client_ = make_shared<TagReaderClient>();
|
||||
tagreader_client_->moveToThread(tagread_client_thread_);
|
||||
tagread_client_thread_->start();
|
||||
tagreader_client_ = new TagReaderClient();
|
||||
tagreader_client_thread_ = new QThread();
|
||||
tagreader_client_->moveToThread(tagreader_client_thread_);
|
||||
tagreader_client_thread_->start();
|
||||
}
|
||||
|
||||
static void SetUpTestCase() {
|
||||
@@ -56,9 +64,9 @@ class TagReaderTest : public ::testing::Test {
|
||||
testing::DefaultValue<TagLib::String>::Set("foobarbaz");
|
||||
}
|
||||
|
||||
static Song ReadSongFromFile(const QString &filename) {
|
||||
Song ReadSongFromFile(const QString &filename) const {
|
||||
|
||||
TagReaderReadFileReplyPtr reply = TagReaderClient::Instance()->ReadFileAsync(filename);
|
||||
TagReaderReadFileReplyPtr reply = tagreader_client_->ReadFileAsync(filename);
|
||||
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderReadFileReply::Finished, &loop, &QEventLoop::quit);
|
||||
@@ -68,9 +76,9 @@ class TagReaderTest : public ::testing::Test {
|
||||
|
||||
}
|
||||
|
||||
static void WriteSongToFile(const Song &song, const QString &filename) {
|
||||
void WriteSongToFile(const Song &song, const QString &filename) const {
|
||||
|
||||
TagReaderReplyPtr reply = TagReaderClient::Instance()->WriteFileAsync(filename, song, SaveTagsOption::Tags, SaveTagCoverData());
|
||||
TagReaderReplyPtr reply = tagreader_client_->WriteFileAsync(filename, song, SaveTagsOption::Tags, SaveTagCoverData());
|
||||
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderReply::Finished, &loop, &QEventLoop::quit);
|
||||
@@ -95,27 +103,27 @@ class TagReaderTest : public ::testing::Test {
|
||||
return QString();
|
||||
}
|
||||
|
||||
static void WriteSongPlaycountToFile(const Song &song, const QString &filename) {
|
||||
void WriteSongPlaycountToFile(const Song &song, const QString &filename) const {
|
||||
|
||||
TagReaderReplyPtr reply = TagReaderClient::Instance()->SaveSongPlaycountAsync(filename, song.playcount());
|
||||
TagReaderReplyPtr reply = tagreader_client_->SaveSongPlaycountAsync(filename, song.playcount());
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderReply::Finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
}
|
||||
|
||||
static void WriteSongRatingToFile(const Song &song, const QString &filename) {
|
||||
void WriteSongRatingToFile(const Song &song, const QString &filename) const {
|
||||
|
||||
TagReaderReplyPtr reply = TagReaderClient::Instance()->SaveSongRatingAsync(filename, song.rating());
|
||||
TagReaderReplyPtr reply = tagreader_client_->SaveSongRatingAsync(filename, song.rating());
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderReply::Finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
}
|
||||
|
||||
static QImage ReadCoverFromFile(const QString &filename) {
|
||||
QImage ReadCoverFromFile(const QString &filename) const {
|
||||
|
||||
TagReaderLoadCoverImageReplyPtr reply = TagReaderClient::Instance()->LoadCoverImageAsync(filename);
|
||||
TagReaderLoadCoverImageReplyPtr reply = tagreader_client_->LoadCoverImageAsync(filename);
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderLoadCoverImageReply::Finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
@@ -124,9 +132,9 @@ class TagReaderTest : public ::testing::Test {
|
||||
|
||||
}
|
||||
|
||||
static TagReaderResult WriteCoverToFile(const QString &filename, const SaveTagCoverData &save_tag_cover_data) {
|
||||
TagReaderResult WriteCoverToFile(const QString &filename, const SaveTagCoverData &save_tag_cover_data) const {
|
||||
|
||||
TagReaderReplyPtr reply = TagReaderClient::Instance()->SaveCoverAsync(filename, save_tag_cover_data);
|
||||
TagReaderReplyPtr reply = tagreader_client_->SaveCoverAsync(filename, save_tag_cover_data);
|
||||
QEventLoop loop;
|
||||
QObject::connect(&*reply, &TagReaderReply::Finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
@@ -135,8 +143,8 @@ class TagReaderTest : public ::testing::Test {
|
||||
|
||||
}
|
||||
|
||||
QThread *tagread_client_thread_ = nullptr;
|
||||
SharedPtr<TagReaderClient> tagreader_client_;
|
||||
QThread *tagreader_client_thread_ = nullptr;
|
||||
TagReaderClient *tagreader_client_ = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user