tests: better test initializing allowing for better printing (#5379)
Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
@@ -4,12 +4,12 @@
|
||||
#include "providers/twitch/pubsubmessages/AutoMod.hpp"
|
||||
#include "providers/twitch/pubsubmessages/Whisper.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "TestHelpers.hpp"
|
||||
#include "Test.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <QString>
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
using namespace chatterino;
|
||||
@@ -33,6 +33,47 @@ using namespace std::chrono_literals;
|
||||
|
||||
#ifdef RUN_PUBSUB_TESTS
|
||||
|
||||
template <typename T>
|
||||
class ReceivedMessage
|
||||
{
|
||||
mutable std::mutex mutex;
|
||||
|
||||
bool isSet{false};
|
||||
T t;
|
||||
|
||||
public:
|
||||
ReceivedMessage() = default;
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
return this->isSet;
|
||||
}
|
||||
|
||||
ReceivedMessage &operator=(const T &newT)
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
this->isSet = true;
|
||||
this->t = newT;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const T &otherT) const
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
return this->t == otherT;
|
||||
}
|
||||
|
||||
const T *operator->() const
|
||||
{
|
||||
return &this->t;
|
||||
}
|
||||
};
|
||||
|
||||
class FTest : public PubSub
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user