2024-10-18 15:41:57 +02:00
|
|
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
2022-05-28 11:55:48 +02:00
|
|
|
|
2024-10-13 12:38:10 +02:00
|
|
|
#include "common/Literals.hpp"
|
2023-10-13 17:41:23 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
2024-01-27 15:46:11 +01:00
|
|
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
2024-10-13 12:38:10 +02:00
|
|
|
#include "controllers/sound/NullBackend.hpp"
|
|
|
|
#include "lib/Snapshot.hpp"
|
|
|
|
#include "messages/Emote.hpp"
|
|
|
|
#include "messages/Message.hpp"
|
2024-08-24 15:02:08 +02:00
|
|
|
#include "mocks/BaseApplication.hpp"
|
2024-01-19 17:25:52 +01:00
|
|
|
#include "mocks/ChatterinoBadges.hpp"
|
2024-03-01 21:12:02 +01:00
|
|
|
#include "mocks/DisabledStreamerMode.hpp"
|
2024-09-29 14:05:28 +02:00
|
|
|
#include "mocks/Emotes.hpp"
|
2024-10-13 12:38:10 +02:00
|
|
|
#include "mocks/LinkResolver.hpp"
|
2024-09-14 12:17:31 +02:00
|
|
|
#include "mocks/Logging.hpp"
|
2023-10-13 17:41:23 +02:00
|
|
|
#include "mocks/TwitchIrcServer.hpp"
|
2022-11-13 18:21:21 +01:00
|
|
|
#include "mocks/UserData.hpp"
|
2023-10-13 17:41:23 +02:00
|
|
|
#include "providers/ffz/FfzBadges.hpp"
|
|
|
|
#include "providers/seventv/SeventvBadges.hpp"
|
2024-10-13 12:38:10 +02:00
|
|
|
#include "providers/twitch/api/Helix.hpp"
|
|
|
|
#include "providers/twitch/ChannelPointReward.hpp"
|
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2022-05-28 11:55:48 +02:00
|
|
|
#include "providers/twitch/TwitchBadge.hpp"
|
2024-10-13 12:38:10 +02:00
|
|
|
#include "providers/twitch/TwitchBadges.hpp"
|
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "singletons/Emotes.hpp"
|
2024-05-05 15:01:07 +02:00
|
|
|
#include "Test.hpp"
|
2024-08-24 12:18:27 +02:00
|
|
|
#include "util/IrcHelpers.hpp"
|
2024-11-02 13:54:31 +01:00
|
|
|
#include "util/VectorMessageSink.hpp"
|
2022-05-28 11:55:48 +02:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <IrcConnection>
|
2022-05-28 11:55:48 +02:00
|
|
|
#include <QDebug>
|
2024-10-13 12:38:10 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
2022-05-28 11:55:48 +02:00
|
|
|
#include <QString>
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
|
2022-05-28 11:55:48 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace chatterino;
|
2024-10-13 12:38:10 +02:00
|
|
|
using namespace literals;
|
2022-05-28 11:55:48 +02:00
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
namespace {
|
|
|
|
|
2024-10-13 12:38:10 +02:00
|
|
|
/// Controls whether snapshots will be updated (true) or verified (false)
|
|
|
|
///
|
|
|
|
/// In CI, all snapshots must be verified, thus the integrity tests checks for
|
|
|
|
/// this constant.
|
|
|
|
///
|
|
|
|
/// When adding a test, start with `{ "input": "..." }` and set this to `true`
|
|
|
|
/// to generate an initial snapshot. Make sure to verify the output!
|
|
|
|
constexpr bool UPDATE_SNAPSHOTS = false;
|
|
|
|
|
2024-10-18 15:41:57 +02:00
|
|
|
const QString IRC_CATEGORY = u"IrcMessageHandler"_s;
|
2024-10-13 12:38:10 +02:00
|
|
|
|
2024-08-24 15:02:08 +02:00
|
|
|
class MockApplication : public mock::BaseApplication
|
2022-11-05 11:04:35 +01:00
|
|
|
{
|
|
|
|
public:
|
2024-07-21 15:09:59 +02:00
|
|
|
MockApplication()
|
2024-08-24 15:02:08 +02:00
|
|
|
: highlights(this->settings, &this->accounts)
|
2024-07-21 15:09:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-10-13 12:38:10 +02:00
|
|
|
MockApplication(const QString &settingsData)
|
|
|
|
: mock::BaseApplication(settingsData)
|
|
|
|
, highlights(this->settings, &this->accounts)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
IEmotes *getEmotes() override
|
|
|
|
{
|
|
|
|
return &this->emotes;
|
|
|
|
}
|
2023-05-21 12:10:49 +02:00
|
|
|
|
2022-11-13 18:21:21 +01:00
|
|
|
IUserDataController *getUserData() override
|
|
|
|
{
|
|
|
|
return &this->userData;
|
|
|
|
}
|
2022-11-05 11:04:35 +01:00
|
|
|
|
2023-10-13 17:41:23 +02:00
|
|
|
AccountController *getAccounts() override
|
|
|
|
{
|
|
|
|
return &this->accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITwitchIrcServer *getTwitch() override
|
|
|
|
{
|
|
|
|
return &this->twitch;
|
|
|
|
}
|
|
|
|
|
2024-01-19 17:25:52 +01:00
|
|
|
IChatterinoBadges *getChatterinoBadges() override
|
2023-10-13 17:41:23 +02:00
|
|
|
{
|
|
|
|
return &this->chatterinoBadges;
|
|
|
|
}
|
|
|
|
|
|
|
|
FfzBadges *getFfzBadges() override
|
|
|
|
{
|
|
|
|
return &this->ffzBadges;
|
|
|
|
}
|
|
|
|
|
|
|
|
SeventvBadges *getSeventvBadges() override
|
|
|
|
{
|
|
|
|
return &this->seventvBadges;
|
|
|
|
}
|
|
|
|
|
|
|
|
HighlightController *getHighlights() override
|
|
|
|
{
|
|
|
|
return &this->highlights;
|
|
|
|
}
|
|
|
|
|
2024-01-21 14:20:21 +01:00
|
|
|
BttvEmotes *getBttvEmotes() override
|
|
|
|
{
|
|
|
|
return &this->bttvEmotes;
|
|
|
|
}
|
|
|
|
|
|
|
|
FfzEmotes *getFfzEmotes() override
|
|
|
|
{
|
|
|
|
return &this->ffzEmotes;
|
|
|
|
}
|
|
|
|
|
|
|
|
SeventvEmotes *getSeventvEmotes() override
|
|
|
|
{
|
|
|
|
return &this->seventvEmotes;
|
|
|
|
}
|
|
|
|
|
2024-09-14 12:17:31 +02:00
|
|
|
ILogging *getChatLogger() override
|
|
|
|
{
|
|
|
|
return &this->logging;
|
|
|
|
}
|
|
|
|
|
2024-10-13 12:38:10 +02:00
|
|
|
TwitchBadges *getTwitchBadges() override
|
|
|
|
{
|
|
|
|
return &this->twitchBadges;
|
|
|
|
}
|
|
|
|
|
|
|
|
ILinkResolver *getLinkResolver() override
|
|
|
|
{
|
|
|
|
return &this->linkResolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISoundController *getSound() override
|
|
|
|
{
|
|
|
|
return &this->sound;
|
|
|
|
}
|
|
|
|
|
2024-09-14 12:17:31 +02:00
|
|
|
mock::EmptyLogging logging;
|
2023-10-13 17:41:23 +02:00
|
|
|
AccountController accounts;
|
2024-09-29 14:05:28 +02:00
|
|
|
mock::Emotes emotes;
|
2022-11-13 18:21:21 +01:00
|
|
|
mock::UserDataController userData;
|
2023-10-13 17:41:23 +02:00
|
|
|
mock::MockTwitchIrcServer twitch;
|
2024-01-19 17:25:52 +01:00
|
|
|
mock::ChatterinoBadges chatterinoBadges;
|
2023-10-13 17:41:23 +02:00
|
|
|
FfzBadges ffzBadges;
|
|
|
|
SeventvBadges seventvBadges;
|
|
|
|
HighlightController highlights;
|
2024-01-21 14:20:21 +01:00
|
|
|
BttvEmotes bttvEmotes;
|
|
|
|
FfzEmotes ffzEmotes;
|
|
|
|
SeventvEmotes seventvEmotes;
|
2024-10-13 12:38:10 +02:00
|
|
|
TwitchBadges twitchBadges;
|
|
|
|
mock::EmptyLinkResolver linkResolver;
|
|
|
|
NullBackend sound;
|
2022-11-05 11:04:35 +01:00
|
|
|
};
|
|
|
|
|
2024-10-13 12:38:10 +02:00
|
|
|
std::pair<const EmoteName, EmotePtr> makeEmote(Emote &&emote)
|
|
|
|
{
|
|
|
|
auto ptr = std::make_shared<Emote>(std::move(emote));
|
|
|
|
ptr->homePage = {u"https://chatterino.com/" % ptr->name.string};
|
|
|
|
ptr->tooltip = {ptr->name.string % u" Tooltip"_s};
|
|
|
|
ptr->author = {u"Chatterino"_s};
|
|
|
|
ptr->images = {
|
|
|
|
Url{u"https://chatterino.com/" % ptr->name.string % u".png"}};
|
|
|
|
return {ptr->name, ptr};
|
|
|
|
}
|
|
|
|
|
|
|
|
using EmoteMapPtr = std::shared_ptr<const EmoteMap>;
|
|
|
|
|
|
|
|
EmoteMapPtr makeEmotes(auto &&...emotes)
|
|
|
|
{
|
|
|
|
auto map = std::make_shared<EmoteMap>();
|
|
|
|
((map->emplace(makeEmote(std::forward<decltype(emotes)>(emotes)))), ...);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-field-initializers")
|
|
|
|
|
|
|
|
struct MockEmotes {
|
|
|
|
EmoteMapPtr seventv;
|
|
|
|
EmoteMapPtr bttv;
|
|
|
|
EmoteMapPtr ffz;
|
|
|
|
EmoteMapPtr twitchAccount;
|
|
|
|
|
|
|
|
static MockEmotes channel()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
.seventv = makeEmotes(
|
|
|
|
Emote{
|
|
|
|
.name = {u"7TVEmote"_s},
|
|
|
|
.id = {u"1"_s},
|
|
|
|
},
|
|
|
|
Emote{
|
|
|
|
.name = {u"7TVEmote0w"_s},
|
|
|
|
.zeroWidth = true,
|
|
|
|
.id = {u"2"_s},
|
|
|
|
.baseName = EmoteName{u"ZeroWidth"_s},
|
|
|
|
},
|
|
|
|
Emote{
|
|
|
|
.name = {u"PogChamp"_s},
|
|
|
|
.id = {u"3"_s},
|
|
|
|
}),
|
|
|
|
.bttv = makeEmotes(
|
|
|
|
Emote{
|
|
|
|
.name = {u"BTTVEmote"_s},
|
|
|
|
},
|
|
|
|
Emote{
|
|
|
|
.name = {u"Kappa"_s},
|
|
|
|
}),
|
|
|
|
.ffz = makeEmotes(
|
|
|
|
Emote{
|
|
|
|
.name = {u"FFZEmote"_s},
|
|
|
|
},
|
|
|
|
Emote{
|
|
|
|
.name = {u"Keepo"_s},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static MockEmotes twitchdev()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
.seventv = makeEmotes(Emote{
|
|
|
|
.name = {u"7TVTwitchDev"_s},
|
|
|
|
.id = {u"t5"_s},
|
|
|
|
}),
|
|
|
|
.bttv = makeEmotes(Emote{
|
|
|
|
.name = {u"BTTVTwitchDev"_s},
|
|
|
|
}),
|
|
|
|
.ffz = makeEmotes(Emote{
|
|
|
|
.name = {u"FFZTwitchDev"_s},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static MockEmotes global()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
.seventv = makeEmotes(Emote{
|
|
|
|
.name = {u"7TVGlobal"_s},
|
|
|
|
.id = {u"G1"_s},
|
|
|
|
}),
|
|
|
|
.bttv = makeEmotes(Emote{
|
|
|
|
.name = {u"BTTVGlobal"_s},
|
|
|
|
}),
|
|
|
|
.ffz = makeEmotes(Emote{
|
|
|
|
.name = {u"FFZGlobal"_s},
|
|
|
|
}),
|
|
|
|
.twitchAccount = makeEmotes(Emote{
|
|
|
|
.name = {u"MyCoolTwitchEmote"_s},
|
|
|
|
.id = {u"5678"_s},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const QByteArray CHEERMOTE_JSON{R"({
|
|
|
|
"prefix": "Cheer",
|
|
|
|
"tiers": [
|
|
|
|
{
|
|
|
|
"min_bits": 1,
|
|
|
|
"id": "1",
|
|
|
|
"color": "#979797",
|
|
|
|
"images": {
|
|
|
|
"dark": {
|
|
|
|
"animated": {
|
|
|
|
"1": "https://chatterino.com/bits/1.gif",
|
|
|
|
"2": "https://chatterino.com/bits/2.gif",
|
|
|
|
"4": "https://chatterino.com/bits/4.gif"
|
|
|
|
},
|
|
|
|
"static": {
|
|
|
|
"1": "https://chatterino.com/bits/1.png",
|
|
|
|
"2": "https://chatterino.com/bits/2.png",
|
|
|
|
"4": "https://chatterino.com/bits/4.png"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"can_cheer": true,
|
|
|
|
"show_in_bits_card": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"min_bits": 100,
|
|
|
|
"id": "100",
|
|
|
|
"color": "#9c3ee8",
|
|
|
|
"images": {
|
|
|
|
"dark": {
|
|
|
|
"animated": {
|
|
|
|
"1": "https://chatterino.com/bits/1.gif",
|
|
|
|
"2": "https://chatterino.com/bits/2.gif",
|
|
|
|
"4": "https://chatterino.com/bits/4.gif"
|
|
|
|
},
|
|
|
|
"static": {
|
|
|
|
"1": "https://chatterino.com/bits/1.png",
|
|
|
|
"2": "https://chatterino.com/bits/2.png",
|
|
|
|
"4": "https://chatterino.com/bits/4.png"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"can_cheer": true,
|
|
|
|
"show_in_bits_card": true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"type": "global_first_party",
|
|
|
|
"order": 1,
|
|
|
|
"last_updated": "2018-05-22T00:06:04Z",
|
|
|
|
"is_charitable": false
|
|
|
|
})"_ba};
|
|
|
|
|
|
|
|
const QByteArray LOCAL_BADGE_JSON{R"({
|
|
|
|
"data": [
|
|
|
|
{
|
|
|
|
"set_id": "subscriber",
|
|
|
|
"versions": [
|
|
|
|
{
|
|
|
|
"click_url": null,
|
|
|
|
"description": "Subscriber",
|
|
|
|
"id": "3072",
|
|
|
|
"image_url_1x": "https://chatterino.com/tb-1",
|
|
|
|
"image_url_2x": "https://chatterino.com/tb-2",
|
|
|
|
"image_url_4x": "https://chatterino.com/tb-3",
|
|
|
|
"title": "Subscriber"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})"_ba};
|
|
|
|
|
|
|
|
const QByteArray SETTINGS_DEFAULT{"{}"_ba};
|
|
|
|
|
|
|
|
std::shared_ptr<TwitchChannel> makeMockTwitchChannel(
|
|
|
|
const QString &name, const testlib::Snapshot &snapshot)
|
|
|
|
{
|
|
|
|
auto chan = std::make_shared<TwitchChannel>(name);
|
|
|
|
auto mocks = MockEmotes::channel();
|
|
|
|
chan->setSeventvEmotes(std::move(mocks.seventv));
|
|
|
|
chan->setBttvEmotes(std::move(mocks.bttv));
|
|
|
|
chan->setFfzEmotes(std::move(mocks.ffz));
|
|
|
|
|
|
|
|
QJsonObject defaultImage{
|
|
|
|
{u"url_1x"_s, u"https://chatterino.com/reward1x.png"_s},
|
|
|
|
{u"url_2x"_s, u"https://chatterino.com/reward2x.png"_s},
|
|
|
|
{u"url_4x"_s, u"https://chatterino.com/reward4x.png"_s},
|
|
|
|
};
|
|
|
|
chan->addKnownChannelPointReward({{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"id"_s, u"unused"_s},
|
|
|
|
{u"reward"_s,
|
|
|
|
{{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"cost"_s, 1},
|
|
|
|
{u"id"_s, u"31a2344e-0fce-4229-9453-fb2e8b6dd02c"_s},
|
|
|
|
{u"is_user_input_required"_s, true},
|
|
|
|
{u"title"_s, u"my reward"_s},
|
|
|
|
{u"image"_s, defaultImage},
|
|
|
|
}}},
|
|
|
|
}});
|
|
|
|
chan->addKnownChannelPointReward({{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"id"_s, u"unused"_s},
|
|
|
|
{u"reward"_s,
|
|
|
|
{{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"cost"_s, 1},
|
|
|
|
{u"id"_s, u"dc8d1dac-256e-42b9-b7ba-40b32e5294e2"_s},
|
|
|
|
{u"is_user_input_required"_s, false},
|
|
|
|
{u"title"_s, u"test"_s},
|
|
|
|
{u"image"_s, defaultImage},
|
|
|
|
}}},
|
|
|
|
}});
|
|
|
|
chan->addKnownChannelPointReward({{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"id"_s, u"unused"_s},
|
|
|
|
{u"reward"_s,
|
|
|
|
{{
|
|
|
|
{u"channel_id"_s, u"11148817"_s},
|
|
|
|
{u"cost"_s, 1},
|
|
|
|
{u"default_bits_cost"_s, 2},
|
|
|
|
{u"bits_cost"_s, 0},
|
|
|
|
{u"pricing_type"_s, u"BITS"_s},
|
|
|
|
{u"reward_type"_s, u"CELEBRATION"_s},
|
|
|
|
{u"is_user_input_required"_s, false},
|
|
|
|
{u"title"_s, u"BitReward"_s},
|
|
|
|
{u"image"_s, defaultImage},
|
|
|
|
}}},
|
|
|
|
{u"redemption_metadata"_s,
|
|
|
|
QJsonObject{
|
|
|
|
{u"celebration_emote_metadata"_s,
|
|
|
|
QJsonObject{
|
|
|
|
{u"emote"_s,
|
|
|
|
{{
|
|
|
|
{u"id"_s, u"42"_s},
|
|
|
|
{u"token"_s, u"MyBitsEmote"_s},
|
|
|
|
}}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}});
|
|
|
|
|
|
|
|
chan->setUserColor("UserColor", {1, 2, 3, 4});
|
|
|
|
chan->setUserColor("UserColor2", {5, 6, 7, 8});
|
|
|
|
chan->addRecentChatter("UserChatter");
|
|
|
|
chan->addRecentChatter("UserColor");
|
|
|
|
|
|
|
|
chan->setCheerEmoteSets({
|
|
|
|
HelixCheermoteSet{QJsonDocument::fromJson(CHEERMOTE_JSON).object()},
|
|
|
|
});
|
|
|
|
|
|
|
|
chan->setFfzChannelBadges({{u"123456"_s, {3, 4}}});
|
|
|
|
|
|
|
|
chan->addTwitchBadgeSets(HelixChannelBadges{
|
|
|
|
QJsonDocument::fromJson(LOCAL_BADGE_JSON).object(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (snapshot.param("ffzCustomVipBadge").toBool())
|
|
|
|
{
|
|
|
|
chan->setFfzCustomVipBadge(std::make_shared<Emote>(Emote{
|
|
|
|
.name = {},
|
|
|
|
.images = {Url{"https://chatterino.com/ffz-vip1x.png"}},
|
|
|
|
.tooltip = {"VIP"},
|
|
|
|
.homePage = {},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (snapshot.param("ffzCustomModBadge").toBool())
|
|
|
|
{
|
|
|
|
chan->setFfzCustomModBadge(std::make_shared<Emote>(Emote{
|
|
|
|
.name = {},
|
|
|
|
.images = {Url{"https://chatterino.com/ffz-mod1x.png"}},
|
|
|
|
.tooltip = {"Moderator"},
|
|
|
|
.homePage = {},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_WARNING_POP
|
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
} // namespace
|
|
|
|
|
2024-10-18 15:41:57 +02:00
|
|
|
class TestIrcMessageHandlerP : public ::testing::TestWithParam<QString>
|
2024-10-13 12:38:10 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
2024-10-18 15:41:57 +02:00
|
|
|
auto param = TestIrcMessageHandlerP::GetParam();
|
2024-10-13 12:38:10 +02:00
|
|
|
this->snapshot = testlib::Snapshot::read(IRC_CATEGORY, param);
|
|
|
|
|
|
|
|
this->mockApplication =
|
|
|
|
std::make_unique<MockApplication>(QString::fromUtf8(
|
|
|
|
this->snapshot->mergedSettings(SETTINGS_DEFAULT)));
|
|
|
|
auto mocks = MockEmotes::global();
|
|
|
|
this->mockApplication->seventvEmotes.setGlobalEmotes(mocks.seventv);
|
|
|
|
this->mockApplication->bttvEmotes.setEmotes(mocks.bttv);
|
|
|
|
this->mockApplication->ffzEmotes.setEmotes(mocks.ffz);
|
|
|
|
this->mockApplication->getAccounts()->twitch.getCurrent()->setEmotes(
|
|
|
|
mocks.twitchAccount);
|
|
|
|
this->mockApplication->getUserData()->setUserColor(u"117691339"_s,
|
|
|
|
u"#DAA521"_s);
|
|
|
|
|
|
|
|
this->mockApplication->getAccounts()
|
|
|
|
->twitch.getCurrent()
|
|
|
|
->blockUserLocally(u"12345"_s);
|
|
|
|
|
|
|
|
auto makeBadge = [](QStringView platform) {
|
|
|
|
return std::make_shared<Emote>(Emote{
|
|
|
|
.name = {},
|
|
|
|
.images = {Url{u"https://chatterino.com/" % platform %
|
|
|
|
u".png"}},
|
|
|
|
.tooltip = {platform % u" badge"},
|
|
|
|
.homePage = {},
|
|
|
|
.zeroWidth = false,
|
|
|
|
.id = {},
|
|
|
|
.author = {},
|
|
|
|
.baseName = {},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Chatterino
|
|
|
|
this->mockApplication->chatterinoBadges.setBadge(
|
|
|
|
{u"123456"_s}, makeBadge(u"Chatterino"));
|
|
|
|
|
|
|
|
// FFZ
|
|
|
|
this->mockApplication->ffzBadges.registerBadge(
|
|
|
|
1, {.emote = makeBadge(u"FFZ1"), .color = {9, 10, 11, 12}});
|
|
|
|
this->mockApplication->ffzBadges.registerBadge(
|
|
|
|
2, {.emote = makeBadge(u"FFZ2"), .color = {13, 14, 15, 16}});
|
|
|
|
this->mockApplication->ffzBadges.registerBadge(
|
|
|
|
3, {.emote = makeBadge(u"FFZ2"), .color = {17, 18, 19, 20}});
|
|
|
|
this->mockApplication->ffzBadges.registerBadge(
|
|
|
|
4, {.emote = makeBadge(u"FFZ2"), .color = {21, 22, 23, 24}});
|
|
|
|
this->mockApplication->getFfzBadges()->assignBadgeToUser({u"123456"_s},
|
|
|
|
1);
|
|
|
|
this->mockApplication->getFfzBadges()->assignBadgeToUser({u"123456"_s},
|
|
|
|
2);
|
|
|
|
|
|
|
|
// 7TV
|
|
|
|
this->mockApplication->getSeventvBadges()->registerBadge({
|
|
|
|
{u"id"_s, u"1"_s},
|
|
|
|
{u"tooltip"_s, u"7TV badge"_s},
|
|
|
|
{
|
|
|
|
u"host"_s,
|
|
|
|
{{
|
|
|
|
{u"url"_s, u"//chatterino.com/7tv/"_s},
|
|
|
|
{u"files"_s,
|
|
|
|
QJsonArray{
|
|
|
|
{{
|
|
|
|
{u"name"_s, u"1x"_s},
|
|
|
|
{u"format"_s, u"WEBP"_s},
|
|
|
|
{u"width"_s, 16},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this->mockApplication->getSeventvBadges()->assignBadgeToUser(
|
|
|
|
u"1"_s, {u"123456"_s});
|
|
|
|
|
|
|
|
// Twitch
|
|
|
|
this->mockApplication->getTwitchBadges()->loadLocalBadges();
|
|
|
|
|
|
|
|
this->twitchdevChannel = std::make_shared<TwitchChannel>("twitchdev");
|
|
|
|
this->twitchdevChannel->setRoomId("141981764");
|
|
|
|
|
|
|
|
auto tdMocks = MockEmotes::twitchdev();
|
|
|
|
this->twitchdevChannel->setSeventvEmotes(std::move(tdMocks.seventv));
|
|
|
|
this->twitchdevChannel->setBttvEmotes(std::move(tdMocks.bttv));
|
|
|
|
this->twitchdevChannel->setFfzEmotes(std::move(tdMocks.ffz));
|
|
|
|
|
|
|
|
this->mockApplication->twitch.mockChannels.emplace(
|
|
|
|
"twitchdev", this->twitchdevChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override
|
|
|
|
{
|
|
|
|
this->twitchdevChannel.reset();
|
|
|
|
this->mockApplication.reset();
|
|
|
|
this->snapshot.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<TwitchChannel> twitchdevChannel;
|
|
|
|
std::unique_ptr<MockApplication> mockApplication;
|
|
|
|
std::unique_ptr<testlib::Snapshot> snapshot;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This tests the process of parsing IRC messages and emitting `MessagePtr`s.
|
|
|
|
///
|
|
|
|
/// Even though it's in the message builder category, this uses
|
|
|
|
/// `IrcMesssageHandler` to ensure the correct (or: "real") arguments to build
|
|
|
|
/// messages.
|
|
|
|
///
|
2024-10-18 15:41:57 +02:00
|
|
|
/// Tests are contained in `tests/snapshots/IrcMessageHandler`. Fixtures
|
2024-10-13 12:38:10 +02:00
|
|
|
/// consist of an object with the keys `input`, `output`, `settings` (optional),
|
|
|
|
/// and `params` (optional).
|
|
|
|
///
|
|
|
|
/// `UPDATE_SNAPSHOTS` (top) controls whether the `output` will be generated or
|
|
|
|
/// checked.
|
|
|
|
///
|
|
|
|
/// `params` is an optional object with the following keys:
|
|
|
|
/// - `prevMessages`: An array of past messages (used for replies)
|
|
|
|
/// - `findAllUsernames`: A boolean controlling the equally named setting
|
|
|
|
/// (default: false)
|
2024-10-18 15:41:57 +02:00
|
|
|
TEST_P(TestIrcMessageHandlerP, Run)
|
2024-10-13 12:38:10 +02:00
|
|
|
{
|
|
|
|
auto channel = makeMockTwitchChannel(u"pajlada"_s, *snapshot);
|
|
|
|
|
2024-11-02 13:54:31 +01:00
|
|
|
VectorMessageSink sink;
|
2024-10-13 12:38:10 +02:00
|
|
|
|
|
|
|
for (auto prevInput : snapshot->param("prevMessages").toArray())
|
|
|
|
{
|
|
|
|
auto *ircMessage = Communi::IrcMessage::fromData(
|
|
|
|
prevInput.toString().toUtf8(), nullptr);
|
|
|
|
ASSERT_NE(ircMessage, nullptr);
|
2024-11-02 13:54:31 +01:00
|
|
|
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
2024-10-13 12:38:10 +02:00
|
|
|
delete ircMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *ircMessage =
|
|
|
|
Communi::IrcMessage::fromData(snapshot->inputUtf8(), nullptr);
|
|
|
|
ASSERT_NE(ircMessage, nullptr);
|
|
|
|
|
2024-11-02 13:54:31 +01:00
|
|
|
auto firstAddedMsg = sink.messages().size();
|
|
|
|
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
2024-10-13 12:38:10 +02:00
|
|
|
|
|
|
|
QJsonArray got;
|
2024-11-02 13:54:31 +01:00
|
|
|
for (auto i = firstAddedMsg; i < sink.messages().size(); i++)
|
2024-10-13 12:38:10 +02:00
|
|
|
{
|
2024-11-02 13:54:31 +01:00
|
|
|
got.append(sink.messages()[i]->toJson());
|
2024-10-13 12:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
delete ircMessage;
|
|
|
|
|
|
|
|
ASSERT_TRUE(snapshot->run(got, UPDATE_SNAPSHOTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2024-10-18 15:41:57 +02:00
|
|
|
IrcMessage, TestIrcMessageHandlerP,
|
2024-10-13 12:38:10 +02:00
|
|
|
testing::ValuesIn(testlib::Snapshot::discover(IRC_CATEGORY)));
|
|
|
|
|
2024-10-18 15:41:57 +02:00
|
|
|
TEST(TestIrcMessageHandlerP, Integrity)
|
2024-10-13 12:38:10 +02:00
|
|
|
{
|
|
|
|
ASSERT_FALSE(UPDATE_SNAPSHOTS); // make sure fixtures are actually tested
|
|
|
|
}
|