2022-06-05 17:40:57 +02:00
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
2022-11-13 18:21:21 +01:00
|
|
|
|
2022-06-05 17:40:57 +02:00
|
|
|
#include "BaseSettings.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2023-02-18 13:02:12 +01:00
|
|
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
2022-11-13 18:21:21 +01:00
|
|
|
#include "messages/MessageBuilder.hpp" // for MessageParseArgs
|
2023-05-20 12:54:50 +02:00
|
|
|
#include "mocks/EmptyApplication.hpp"
|
|
|
|
#include "mocks/Helix.hpp"
|
2022-11-13 18:21:21 +01:00
|
|
|
#include "mocks/UserData.hpp"
|
2022-06-05 17:40:57 +02:00
|
|
|
#include "providers/twitch/api/Helix.hpp"
|
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 "providers/twitch/TwitchBadge.hpp" // for Badge
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "singletons/Paths.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2022-06-05 17:40:57 +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 <boost/optional/optional_io.hpp>
|
2022-06-05 17:40:57 +02:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
using ::testing::Exactly;
|
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-05-20 12:54:50 +02:00
|
|
|
class MockApplication : mock::EmptyApplication
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
AccountController *getAccounts() override
|
|
|
|
{
|
|
|
|
return &this->accounts;
|
|
|
|
}
|
2023-05-20 12:54:50 +02:00
|
|
|
|
2022-06-09 16:37:52 +02:00
|
|
|
HighlightController *getHighlights() override
|
|
|
|
{
|
|
|
|
return &this->highlights;
|
|
|
|
}
|
2023-05-20 12:54:50 +02:00
|
|
|
|
2022-11-13 18:21:21 +01:00
|
|
|
IUserDataController *getUserData() override
|
|
|
|
{
|
|
|
|
return &this->userData;
|
|
|
|
}
|
2022-06-05 17:40:57 +02:00
|
|
|
|
|
|
|
AccountController accounts;
|
2022-06-09 16:37:52 +02:00
|
|
|
HighlightController highlights;
|
2022-11-13 18:21:21 +01:00
|
|
|
mock::UserDataController userData;
|
2022-06-05 17:40:57 +02:00
|
|
|
// TODO: Figure this out
|
|
|
|
};
|
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
} // namespace
|
|
|
|
|
2022-06-05 17:40:57 +02:00
|
|
|
static QString DEFAULT_SETTINGS = R"!(
|
|
|
|
{
|
|
|
|
"accounts": {
|
|
|
|
"uid117166826": {
|
|
|
|
"username": "testaccount_420",
|
|
|
|
"userID": "117166826",
|
|
|
|
"clientID": "abc",
|
|
|
|
"oauthToken": "def"
|
|
|
|
},
|
|
|
|
"current": "testaccount_420"
|
|
|
|
},
|
|
|
|
"highlighting": {
|
|
|
|
"selfHighlight": {
|
|
|
|
"enableSound": true
|
|
|
|
},
|
|
|
|
"blacklist": [
|
|
|
|
{
|
|
|
|
"pattern": "zenix",
|
|
|
|
"regex": false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"users": [
|
|
|
|
{
|
|
|
|
"pattern": "pajlada",
|
|
|
|
"showInMentions": false,
|
|
|
|
"alert": false,
|
|
|
|
"sound": false,
|
|
|
|
"regex": false,
|
|
|
|
"case": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7fffffff"
|
|
|
|
},
|
2022-06-26 12:43:34 +02:00
|
|
|
{
|
|
|
|
"pattern": "testaccount_420",
|
|
|
|
"showInMentions": false,
|
|
|
|
"alert": false,
|
|
|
|
"sound": false,
|
|
|
|
"regex": false,
|
|
|
|
"case": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#6fffffff"
|
|
|
|
},
|
2022-06-05 17:40:57 +02:00
|
|
|
{
|
|
|
|
"pattern": "gempir",
|
|
|
|
"showInMentions": true,
|
|
|
|
"alert": true,
|
|
|
|
"sound": false,
|
|
|
|
"regex": false,
|
|
|
|
"case": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7ff19900"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"alwaysPlaySound": true,
|
|
|
|
"highlights": [
|
|
|
|
{
|
|
|
|
"pattern": "!testmanxd",
|
|
|
|
"showInMentions": true,
|
|
|
|
"alert": true,
|
|
|
|
"sound": true,
|
|
|
|
"regex": false,
|
|
|
|
"case": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7f7f3f49"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"badges": [
|
|
|
|
{
|
|
|
|
"name": "broadcaster",
|
|
|
|
"displayName": "Broadcaster",
|
|
|
|
"alert": false,
|
|
|
|
"sound": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7f427f00"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "subscriber",
|
|
|
|
"displayName": "Subscriber",
|
|
|
|
"alert": false,
|
|
|
|
"sound": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7f7f3f49"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "founder",
|
|
|
|
"displayName": "Founder",
|
|
|
|
"alert": true,
|
|
|
|
"sound": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7fe8b7eb"
|
2022-10-02 13:25:10 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "vip",
|
|
|
|
"displayName": "VIP",
|
|
|
|
"showInMentions": true,
|
|
|
|
"alert": false,
|
|
|
|
"sound": false,
|
|
|
|
"soundUrl": "",
|
|
|
|
"color": "#7fe8b7ec"
|
2022-06-05 17:40:57 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"subHighlightColor": "#64ffd641"
|
|
|
|
}
|
|
|
|
})!";
|
|
|
|
|
|
|
|
struct TestCase {
|
|
|
|
// TODO: create one of these from a raw irc message? hmm xD
|
|
|
|
struct {
|
|
|
|
MessageParseArgs args;
|
|
|
|
std::vector<Badge> badges;
|
|
|
|
QString senderName;
|
|
|
|
QString originalMessage;
|
2022-10-08 16:25:32 +02:00
|
|
|
MessageFlags flags;
|
2022-06-05 17:40:57 +02:00
|
|
|
} input;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
bool state;
|
|
|
|
HighlightResult result;
|
|
|
|
} expected;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HighlightControllerTest : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
2023-04-01 13:23:18 +02:00
|
|
|
// Write default settings to the mock settings json file
|
|
|
|
ASSERT_TRUE(QDir().mkpath("/tmp/c2-tests"));
|
|
|
|
|
|
|
|
QFile settingsFile("/tmp/c2-tests/settings.json");
|
|
|
|
ASSERT_TRUE(settingsFile.open(QIODevice::WriteOnly | QIODevice::Text));
|
|
|
|
ASSERT_GT(settingsFile.write(DEFAULT_SETTINGS.toUtf8()), 0);
|
|
|
|
ASSERT_TRUE(settingsFile.flush());
|
|
|
|
settingsFile.close();
|
2022-06-05 17:40:57 +02:00
|
|
|
|
2023-05-20 12:54:50 +02:00
|
|
|
this->mockHelix = new mock::Helix;
|
2022-06-05 17:40:57 +02:00
|
|
|
|
|
|
|
initializeHelix(this->mockHelix);
|
|
|
|
|
|
|
|
EXPECT_CALL(*this->mockHelix, loadBlocks).Times(Exactly(1));
|
|
|
|
EXPECT_CALL(*this->mockHelix, update).Times(Exactly(1));
|
|
|
|
|
|
|
|
this->mockApplication = std::make_unique<MockApplication>();
|
|
|
|
this->settings = std::make_unique<Settings>("/tmp/c2-tests");
|
|
|
|
this->paths = std::make_unique<Paths>();
|
|
|
|
|
|
|
|
this->controller = std::make_unique<HighlightController>();
|
|
|
|
|
|
|
|
this->mockApplication->accounts.initialize(*this->settings,
|
|
|
|
*this->paths);
|
|
|
|
this->controller->initialize(*this->settings, *this->paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override
|
|
|
|
{
|
2023-04-01 13:23:18 +02:00
|
|
|
ASSERT_TRUE(QDir("/tmp/c2-tests").removeRecursively());
|
2022-06-05 17:40:57 +02:00
|
|
|
this->mockApplication.reset();
|
|
|
|
this->settings.reset();
|
|
|
|
this->paths.reset();
|
|
|
|
|
|
|
|
this->controller.reset();
|
|
|
|
|
|
|
|
delete this->mockHelix;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<MockApplication> mockApplication;
|
|
|
|
std::unique_ptr<Settings> settings;
|
|
|
|
std::unique_ptr<Paths> paths;
|
|
|
|
|
|
|
|
std::unique_ptr<HighlightController> controller;
|
|
|
|
|
2023-05-20 12:54:50 +02:00
|
|
|
mock::Helix *mockHelix;
|
2022-06-05 17:40:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(HighlightControllerTest, A)
|
|
|
|
{
|
|
|
|
auto currentUser =
|
|
|
|
this->mockApplication->getAccounts()->twitch.getCurrent();
|
|
|
|
std::vector<TestCase> tests{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{}, // no badges
|
|
|
|
"pajlada", // sender name
|
|
|
|
"hello!", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
false, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7fffffff"), // color
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{}, // no badges
|
|
|
|
"pajlada2", // sender name
|
|
|
|
"hello!", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
false, // state
|
|
|
|
HighlightResult::emptyResult(), // result
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"founder",
|
|
|
|
"0",
|
|
|
|
}, // founder badge
|
|
|
|
},
|
|
|
|
"pajlada22", // sender name
|
|
|
|
"hello!", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
true, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7fe8b7eb"), // color
|
|
|
|
false, //showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"founder",
|
|
|
|
"0",
|
|
|
|
}, // founder badge
|
|
|
|
},
|
|
|
|
"pajlada", // sender name
|
|
|
|
"hello!", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
true, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7fffffff"), // color
|
|
|
|
false, //showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-02 13:25:10 +02:00
|
|
|
{
|
|
|
|
// Badge highlight with showInMentions only
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"vip",
|
|
|
|
"0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"badge", // sender name
|
|
|
|
"show in mentions only", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
false, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7fe8b7ec"), // color
|
|
|
|
true, // showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-06 15:36:53 +02:00
|
|
|
{
|
|
|
|
// User mention with showInMentions
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{}, // no badges
|
|
|
|
"gempir", // sender name
|
|
|
|
"a", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
true, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7ff19900"), // color
|
|
|
|
true, // showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{}, // no badges
|
|
|
|
"a", // sender name
|
|
|
|
"!testmanxd", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
true, // alert
|
|
|
|
true, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7f7f3f49"), // color
|
|
|
|
true, // showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-26 12:43:34 +02:00
|
|
|
{
|
|
|
|
// TEST CASE: Message phrase from sender should be ignored (so showInMentions false), but since it's a user highlight, it should set a color
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
MessageParseArgs{}, // no special args
|
|
|
|
{}, // no badges
|
|
|
|
"testaccount_420", // sender name
|
|
|
|
"!testmanxd", // original message
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
true, // state
|
|
|
|
{
|
|
|
|
false, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#6fffffff"), // color
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-18 13:02:12 +01:00
|
|
|
{
|
|
|
|
// TEST CASE: Whispers that do not hit a highlight phrase should not be added to /mentions
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
.args =
|
|
|
|
MessageParseArgs{
|
|
|
|
.isReceivedWhisper = true,
|
|
|
|
},
|
|
|
|
.senderName = "forsen",
|
|
|
|
.originalMessage = "Hello NymN!",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
.state = true, // state
|
|
|
|
.result =
|
|
|
|
{
|
|
|
|
false, // alert
|
|
|
|
false, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>(
|
|
|
|
HighlightPhrase::
|
|
|
|
FALLBACK_HIGHLIGHT_COLOR), // color
|
|
|
|
false, // showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// TEST CASE: Whispers that do hit a highlight phrase should be added to /mentions
|
|
|
|
{
|
|
|
|
// input
|
|
|
|
.args =
|
|
|
|
MessageParseArgs{
|
|
|
|
.isReceivedWhisper = true,
|
|
|
|
},
|
|
|
|
.senderName = "forsen",
|
|
|
|
.originalMessage = "!testmanxd",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// expected
|
|
|
|
.state = true, // state
|
|
|
|
.result =
|
|
|
|
{
|
|
|
|
true, // alert
|
|
|
|
true, // playsound
|
|
|
|
boost::none, // custom sound url
|
|
|
|
std::make_shared<QColor>("#7f7f3f49"), // color
|
|
|
|
true, // showInMentions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-05 17:40:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &[input, expected] : tests)
|
|
|
|
{
|
2022-10-08 16:25:32 +02:00
|
|
|
auto [isMatch, matchResult] =
|
|
|
|
this->controller->check(input.args, input.badges, input.senderName,
|
|
|
|
input.originalMessage, input.flags);
|
2022-06-05 17:40:57 +02:00
|
|
|
|
2022-06-26 12:43:34 +02:00
|
|
|
EXPECT_EQ(isMatch, expected.state)
|
|
|
|
<< qUtf8Printable(input.senderName) << ": "
|
|
|
|
<< qUtf8Printable(input.originalMessage);
|
2022-10-02 13:25:10 +02:00
|
|
|
EXPECT_EQ(matchResult, expected.result)
|
|
|
|
<< qUtf8Printable(input.senderName) << ": "
|
|
|
|
<< qUtf8Printable(input.originalMessage);
|
2022-06-05 17:40:57 +02:00
|
|
|
}
|
|
|
|
}
|