Skip to content

Commit

Permalink
chore: remove Singleton & replace getIApp with getApp (#5514)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Jul 21, 2024
1 parent 21186df commit 5deec1f
Show file tree
Hide file tree
Showing 145 changed files with 805 additions and 859 deletions.
10 changes: 7 additions & 3 deletions benchmarks/src/Highlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "controllers/highlights/HighlightPhrase.hpp"
#include "messages/Message.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include "mocks/EmptyApplication.hpp"
#include "mocks/BaseApplication.hpp"
#include "singletons/Settings.hpp"
#include "util/Helpers.hpp"

Expand Down Expand Up @@ -47,9 +47,14 @@ class BenchmarkMessageBuilder : public SharedMessageBuilder
}
};

class MockApplication : mock::EmptyApplication
class MockApplication : public mock::BaseApplication
{
public:
MockApplication()
: highlights(this->settings, &this->accounts)
{
}

AccountController *getAccounts() override
{
return &this->accounts;
Expand All @@ -61,7 +66,6 @@ class MockApplication : mock::EmptyApplication

AccountController accounts;
HighlightController highlights;
// TODO: Figure this out
};

static void BM_HighlightTest(benchmark::State &state)
Expand Down
9 changes: 7 additions & 2 deletions benchmarks/src/RecentMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "messages/Emote.hpp"
#include "mocks/BaseApplication.hpp"
#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "mocks/LinkResolver.hpp"
#include "mocks/TwitchIrcServer.hpp"
#include "mocks/UserData.hpp"
Expand Down Expand Up @@ -32,9 +32,14 @@ using namespace literals;

namespace {

class MockApplication : mock::EmptyApplication
class MockApplication : public mock::BaseApplication
{
public:
MockApplication()
: highlights(this->settings, &this->accounts)
{
}

IEmotes *getEmotes() override
{
return &this->emotes;
Expand Down
37 changes: 37 additions & 0 deletions mocks/include/mocks/BaseApplication.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "singletons/Settings.hpp"

#include <QString>

namespace chatterino::mock {

/**
* BaseApplication intends to be a mock application with a few more sane defaults, but with less configurability
*/
class BaseApplication : public EmptyApplication
{
public:
BaseApplication()
: settings(this->settingsDir.filePath("settings.json"))
{
}

explicit BaseApplication(const QString &settingsData)
: EmptyApplication(settingsData)
, settings(this->settingsDir.filePath("settings.json"))
{
}

IStreamerMode *getStreamerMode() override
{
return &this->streamerMode;
}

Settings settings;
DisabledStreamerMode streamerMode;
};

} // namespace chatterino::mock
13 changes: 11 additions & 2 deletions mocks/include/mocks/EmptyApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ class EmptyApplication : public IApplication
{
}

virtual ~EmptyApplication() = default;
explicit EmptyApplication(const QString &settingsData)
: EmptyApplication()
{
QFile settingsFile(this->settingsDir.filePath("settings.json"));
settingsFile.open(QIODevice::WriteOnly | QIODevice::Text);
settingsFile.write(settingsData.toUtf8());
settingsFile.flush();
settingsFile.close();
}

~EmptyApplication() override = default;

bool isTest() const override
{
Expand Down Expand Up @@ -249,7 +259,6 @@ class EmptyApplication : public IApplication
return nullptr;
}

protected:
QTemporaryDir settingsDir;
Paths paths_;
Args args_;
Expand Down
Loading

0 comments on commit 5deec1f

Please sign in to comment.