diff --git a/CMakeLists.txt b/CMakeLists.txt index 560f6ba71..0714104ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,10 @@ include(cmake/resources/generate_resources.cmake) add_subdirectory(src) +if (BUILD_TESTS OR BUILD_BENCHMARKS) + add_subdirectory(mocks) +endif () + if (BUILD_TESTS) enable_testing() add_subdirectory(tests) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 344258516..84ac8aa19 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(${PROJECT_NAME} ${benchmark_SOURCES}) add_sanitizers(${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-lib) +target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-mocks) target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark) diff --git a/benchmarks/src/Highlights.cpp b/benchmarks/src/Highlights.cpp index c35a0847f..303cb6612 100644 --- a/benchmarks/src/Highlights.cpp +++ b/benchmarks/src/Highlights.cpp @@ -1,11 +1,12 @@ #include "Application.hpp" -#include "singletons/Settings.hpp" #include "common/Channel.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightController.hpp" #include "controllers/highlights/HighlightPhrase.hpp" #include "messages/Message.hpp" #include "messages/SharedMessageBuilder.hpp" +#include "mocks/EmptyApplication.hpp" +#include "singletons/Settings.hpp" #include "util/Helpers.hpp" #include @@ -45,65 +46,17 @@ public: } }; -class MockApplication : IApplication +class MockApplication : mock::EmptyApplication { public: - Theme *getThemes() override - { - return nullptr; - } - Fonts *getFonts() override - { - return nullptr; - } - IEmotes *getEmotes() override - { - return nullptr; - } AccountController *getAccounts() override { return &this->accounts; } - HotkeyController *getHotkeys() override - { - return nullptr; - } - WindowManager *getWindows() override - { - return nullptr; - } - Toasts *getToasts() override - { - return nullptr; - } - CommandController *getCommands() override - { - return nullptr; - } - NotificationController *getNotifications() override - { - return nullptr; - } HighlightController *getHighlights() override { return &this->highlights; } - TwitchIrcServer *getTwitch() override - { - return nullptr; - } - ChatterinoBadges *getChatterinoBadges() override - { - return nullptr; - } - FfzBadges *getFfzBadges() override - { - return nullptr; - } - IUserDataController *getUserData() override - { - return nullptr; - } AccountController accounts; HighlightController highlights; diff --git a/benchmarks/src/main.cpp b/benchmarks/src/main.cpp index 501b3aa51..cc4491f22 100644 --- a/benchmarks/src/main.cpp +++ b/benchmarks/src/main.cpp @@ -1,13 +1,20 @@ +#include "singletons/Settings.hpp" + #include #include #include +using namespace chatterino; + int main(int argc, char **argv) { QApplication app(argc, argv); ::benchmark::Initialize(&argc, argv); + // Ensure settings are initialized before any tests are run + chatterino::Settings settings("/tmp/c2-empty-test"); + QtConcurrent::run([&app] { ::benchmark::RunSpecifiedBenchmarks(); diff --git a/mocks/.clang-format b/mocks/.clang-format new file mode 100644 index 000000000..7bae09f2c --- /dev/null +++ b/mocks/.clang-format @@ -0,0 +1,55 @@ +Language: Cpp + +AccessModifierOffset: -4 +AlignEscapedNewlinesLeft: true +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakBeforeMultilineStrings: false +BasedOnStyle: Google +BraceWrapping: + AfterClass: "true" + AfterControlStatement: "true" + AfterFunction: "true" + AfterNamespace: "false" + BeforeCatch: "true" + BeforeElse: "true" +BreakBeforeBraces: Custom +BreakConstructorInitializersBeforeComma: true +ColumnLimit: 80 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +DerivePointerBinding: false +FixNamespaceComments: true +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +IndentPPDirectives: AfterHash +SortIncludes: CaseInsensitive +IncludeBlocks: Regroup +IncludeCategories: + # Project includes + - Regex: '^"[a-zA-Z\._-]+(/[a-zA-Z0-9\._-]+)*"$' + Priority: 1 + # Third party library includes + - Regex: '<[[:alnum:].]+/[a-zA-Z0-9\._\/-]+>' + Priority: 3 + # Qt includes + - Regex: '^$' + Priority: 3 + CaseSensitive: true + # LibCommuni includes + - Regex: "^$" + Priority: 3 + # Misc libraries + - Regex: '^<[a-zA-Z_0-9]+\.h(pp)?>$' + Priority: 3 + # Standard library includes + - Regex: "^<[a-zA-Z_]+>$" + Priority: 4 +NamespaceIndentation: Inner +PointerBindsToType: false +SpacesBeforeTrailingComments: 2 +Standard: Auto +ReflowComments: false diff --git a/mocks/CMakeLists.txt b/mocks/CMakeLists.txt new file mode 100644 index 000000000..47abd0ef4 --- /dev/null +++ b/mocks/CMakeLists.txt @@ -0,0 +1,7 @@ +project(chatterino-mocks) + +add_library(chatterino-mocks INTERFACE) + +target_include_directories(chatterino-mocks INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) + +target_link_libraries(${PROJECT_NAME} INTERFACE gmock) diff --git a/mocks/include/mocks/EmptyApplication.hpp b/mocks/include/mocks/EmptyApplication.hpp new file mode 100644 index 000000000..846fd0aaa --- /dev/null +++ b/mocks/include/mocks/EmptyApplication.hpp @@ -0,0 +1,81 @@ +#pragma once + +#include "Application.hpp" + +namespace chatterino::mock { + +class EmptyApplication : public IApplication +{ +public: + Theme *getThemes() override + { + return nullptr; + } + + Fonts *getFonts() override + { + return nullptr; + } + + IEmotes *getEmotes() override + { + return nullptr; + } + + AccountController *getAccounts() override + { + return nullptr; + } + + HotkeyController *getHotkeys() override + { + return nullptr; + } + + WindowManager *getWindows() override + { + return nullptr; + } + + Toasts *getToasts() override + { + return nullptr; + } + + CommandController *getCommands() override + { + return nullptr; + } + + NotificationController *getNotifications() override + { + return nullptr; + } + + HighlightController *getHighlights() override + { + return nullptr; + } + + TwitchIrcServer *getTwitch() override + { + return nullptr; + } + + ChatterinoBadges *getChatterinoBadges() override + { + return nullptr; + } + + FfzBadges *getFfzBadges() override + { + return nullptr; + } + + IUserDataController *getUserData() override + { + return nullptr; + } +}; + +} // namespace chatterino::mock diff --git a/mocks/include/mocks/Helix.hpp b/mocks/include/mocks/Helix.hpp new file mode 100644 index 000000000..792094fbf --- /dev/null +++ b/mocks/include/mocks/Helix.hpp @@ -0,0 +1,396 @@ +#pragma once + +#include "providers/twitch/api/Helix.hpp" + +#include +#include +#include + +#include + +namespace chatterino::mock { + +class Helix : public IHelix +{ +public: + virtual ~Helix() = default; + + MOCK_METHOD(void, fetchUsers, + (QStringList userIds, QStringList userLogins, + ResultCallback> successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, getUserByName, + (QString userName, ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + MOCK_METHOD(void, getUserById, + (QString userId, ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, fetchUsersFollows, + (QString fromId, QString toId, + ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, getUserFollowers, + (QString userId, + ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, fetchStreams, + (QStringList userIds, QStringList userLogins, + ResultCallback> successCallback, + HelixFailureCallback failureCallback, + std::function finallyCallback), + (override)); + + MOCK_METHOD(void, getStreamById, + (QString userId, + (ResultCallback successCallback), + HelixFailureCallback failureCallback, + std::function finallyCallback), + (override)); + + MOCK_METHOD(void, getStreamByName, + (QString userName, + (ResultCallback successCallback), + HelixFailureCallback failureCallback, + std::function finallyCallback), + (override)); + + MOCK_METHOD(void, fetchGames, + (QStringList gameIds, QStringList gameNames, + (ResultCallback> successCallback), + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, searchGames, + (QString gameName, + ResultCallback> successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, getGameById, + (QString gameId, ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, createClip, + (QString channelId, ResultCallback successCallback, + std::function failureCallback, + std::function finallyCallback), + (override)); + + MOCK_METHOD(void, getChannel, + (QString broadcasterId, + ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, createStreamMarker, + (QString broadcasterId, QString description, + ResultCallback successCallback, + std::function failureCallback), + (override)); + + MOCK_METHOD(void, loadBlocks, + (QString userId, + ResultCallback> successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, blockUser, + (QString targetUserId, std::function successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, unblockUser, + (QString targetUserId, std::function successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, updateChannel, + (QString broadcasterId, QString gameId, QString language, + QString title, + std::function successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, manageAutoModMessages, + (QString userID, QString msgID, QString action, + std::function successCallback, + std::function failureCallback), + (override)); + + MOCK_METHOD(void, getCheermotes, + (QString broadcasterId, + ResultCallback> successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, getEmoteSetData, + (QString emoteSetId, + ResultCallback successCallback, + HelixFailureCallback failureCallback), + (override)); + + MOCK_METHOD(void, getChannelEmotes, + (QString broadcasterId, + ResultCallback> successCallback, + HelixFailureCallback failureCallback), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, getGlobalBadges, + (ResultCallback successCallback, + (FailureCallback failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, getChannelBadges, + (QString broadcasterID, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateUserChatColor, + (QString userID, QString color, + ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, deleteChatMessages, + (QString broadcasterID, QString moderatorID, QString messageID, + ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, addChannelModerator, + (QString broadcasterID, QString userID, + ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, removeChannelModerator, + (QString broadcasterID, QString userID, + ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, sendChatAnnouncement, + (QString broadcasterID, QString moderatorID, QString message, + HelixAnnouncementColor color, ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, addChannelVIP, + (QString broadcasterID, QString userID, + ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, removeChannelVIP, + (QString broadcasterID, QString userID, + ResultCallback<> successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, unbanUser, + (QString broadcasterID, QString moderatorID, QString userID, + ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( // /raid + void, startRaid, + (QString fromBroadcasterID, QString toBroadcasterId, + ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); // /raid + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( // /unraid + void, cancelRaid, + (QString broadcasterID, ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); // /unraid + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateEmoteMode, + (QString broadcasterID, QString moderatorID, bool emoteMode, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateFollowerMode, + (QString broadcasterID, QString moderatorID, + boost::optional followerModeDuration, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateNonModeratorChatDelay, + (QString broadcasterID, QString moderatorID, + boost::optional nonModeratorChatDelayDuration, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateSlowMode, + (QString broadcasterID, QString moderatorID, + boost::optional slowModeWaitTime, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateSubscriberMode, + (QString broadcasterID, QString moderatorID, + bool subscriberMode, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateUniqueChatMode, + (QString broadcasterID, QString moderatorID, + bool uniqueChatMode, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + // update chat settings + + // /timeout, /ban + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, banUser, + (QString broadcasterID, QString moderatorID, QString userID, + boost::optional duration, QString reason, + ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); // /timeout, /ban + + // /w + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, sendWhisper, + (QString fromUserID, QString toUserID, QString message, + ResultCallback<> successCallback, + (FailureCallback failureCallback)), + (override)); // /w + + // getChatters + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, getChatters, + (QString broadcasterID, QString moderatorID, int maxChattersToFetch, + ResultCallback successCallback, + (FailureCallback failureCallback)), + (override)); // getChatters + + // /vips + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, getChannelVIPs, + (QString broadcasterID, + ResultCallback> successCallback, + (FailureCallback failureCallback)), + (override)); // /vips + + // /commercial + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, startCommercial, + (QString broadcasterID, int length, + ResultCallback successCallback, + (FailureCallback failureCallback)), + (override)); // /commercial + + // /mods + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD( + void, getModerators, + (QString broadcasterID, int maxModeratorsToFetch, + ResultCallback> successCallback, + (FailureCallback failureCallback)), + (override)); // /mods + + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateShieldMode, + (QString broadcasterID, QString moderatorID, bool isActive, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); + + MOCK_METHOD(void, update, (QString clientId, QString oauthToken), + (override)); + +protected: + // The extra parenthesis around the failure callback is because its type + // contains a comma + MOCK_METHOD(void, updateChatSettings, + (QString broadcasterID, QString moderatorID, QJsonObject json, + ResultCallback successCallback, + (FailureCallback + failureCallback)), + (override)); +}; + +} // namespace chatterino::mock diff --git a/tests/src/mocks/UserData.hpp b/mocks/include/mocks/UserData.hpp similarity index 100% rename from tests/src/mocks/UserData.hpp rename to mocks/include/mocks/UserData.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a3cb5ef0e..4f4cd2292 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(${PROJECT_NAME} ${test_SOURCES}) add_sanitizers(${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-lib) +target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-mocks) target_link_libraries(${PROJECT_NAME} PRIVATE gtest gmock) diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index f5609ed45..b2f89e7a5 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -5,6 +5,8 @@ #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightPhrase.hpp" #include "messages/MessageBuilder.hpp" // for MessageParseArgs +#include "mocks/EmptyApplication.hpp" +#include "mocks/Helix.hpp" #include "mocks/UserData.hpp" #include "providers/twitch/api/Helix.hpp" #include "providers/twitch/TwitchBadge.hpp" // for Badge @@ -24,61 +26,19 @@ using ::testing::Exactly; namespace { -class MockApplication : IApplication +class MockApplication : mock::EmptyApplication { public: - Theme *getThemes() override - { - return nullptr; - } - Fonts *getFonts() override - { - return nullptr; - } - IEmotes *getEmotes() override - { - return nullptr; - } AccountController *getAccounts() override { return &this->accounts; } - HotkeyController *getHotkeys() override - { - return nullptr; - } - WindowManager *getWindows() override - { - return nullptr; - } - Toasts *getToasts() override - { - return nullptr; - } - CommandController *getCommands() override - { - return nullptr; - } - NotificationController *getNotifications() override - { - return nullptr; - } + HighlightController *getHighlights() override { return &this->highlights; } - TwitchIrcServer *getTwitch() override - { - return nullptr; - } - ChatterinoBadges *getChatterinoBadges() override - { - return nullptr; - } - FfzBadges *getFfzBadges() override - { - return nullptr; - } + IUserDataController *getUserData() override { return &this->userData; @@ -92,361 +52,6 @@ public: } // namespace -class MockHelix : public IHelix -{ -public: - MOCK_METHOD(void, fetchUsers, - (QStringList userIds, QStringList userLogins, - ResultCallback> successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, getUserByName, - (QString userName, ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - MOCK_METHOD(void, getUserById, - (QString userId, ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, fetchUsersFollows, - (QString fromId, QString toId, - ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, getUserFollowers, - (QString userId, - ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, fetchStreams, - (QStringList userIds, QStringList userLogins, - ResultCallback> successCallback, - HelixFailureCallback failureCallback, - std::function finallyCallback), - (override)); - - MOCK_METHOD(void, getStreamById, - (QString userId, - (ResultCallback successCallback), - HelixFailureCallback failureCallback, - std::function finallyCallback), - (override)); - - MOCK_METHOD(void, getStreamByName, - (QString userName, - (ResultCallback successCallback), - HelixFailureCallback failureCallback, - std::function finallyCallback), - (override)); - - MOCK_METHOD(void, fetchGames, - (QStringList gameIds, QStringList gameNames, - (ResultCallback> successCallback), - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, searchGames, - (QString gameName, - ResultCallback> successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, getGameById, - (QString gameId, ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, createClip, - (QString channelId, ResultCallback successCallback, - std::function failureCallback, - std::function finallyCallback), - (override)); - - MOCK_METHOD(void, getChannel, - (QString broadcasterId, - ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, createStreamMarker, - (QString broadcasterId, QString description, - ResultCallback successCallback, - std::function failureCallback), - (override)); - - MOCK_METHOD(void, loadBlocks, - (QString userId, - ResultCallback> successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, blockUser, - (QString targetUserId, std::function successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, unblockUser, - (QString targetUserId, std::function successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, updateChannel, - (QString broadcasterId, QString gameId, QString language, - QString title, - std::function successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, manageAutoModMessages, - (QString userID, QString msgID, QString action, - std::function successCallback, - std::function failureCallback), - (override)); - - MOCK_METHOD(void, getCheermotes, - (QString broadcasterId, - ResultCallback> successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, getEmoteSetData, - (QString emoteSetId, - ResultCallback successCallback, - HelixFailureCallback failureCallback), - (override)); - - MOCK_METHOD(void, getChannelEmotes, - (QString broadcasterId, - ResultCallback> successCallback, - HelixFailureCallback failureCallback), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, getGlobalBadges, - (ResultCallback successCallback, - (FailureCallback failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, getChannelBadges, - (QString broadcasterID, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateUserChatColor, - (QString userID, QString color, - ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, deleteChatMessages, - (QString broadcasterID, QString moderatorID, QString messageID, - ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, addChannelModerator, - (QString broadcasterID, QString userID, - ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, removeChannelModerator, - (QString broadcasterID, QString userID, - ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, sendChatAnnouncement, - (QString broadcasterID, QString moderatorID, QString message, - HelixAnnouncementColor color, ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, addChannelVIP, - (QString broadcasterID, QString userID, - ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, removeChannelVIP, - (QString broadcasterID, QString userID, - ResultCallback<> successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, unbanUser, - (QString broadcasterID, QString moderatorID, QString userID, - ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( // /raid - void, startRaid, - (QString fromBroadcasterID, QString toBroadcasterId, - ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); // /raid - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( // /unraid - void, cancelRaid, - (QString broadcasterID, ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); // /unraid - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateEmoteMode, - (QString broadcasterID, QString moderatorID, bool emoteMode, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateFollowerMode, - (QString broadcasterID, QString moderatorID, - boost::optional followerModeDuration, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateNonModeratorChatDelay, - (QString broadcasterID, QString moderatorID, - boost::optional nonModeratorChatDelayDuration, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateSlowMode, - (QString broadcasterID, QString moderatorID, - boost::optional slowModeWaitTime, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateSubscriberMode, - (QString broadcasterID, QString moderatorID, - bool subscriberMode, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateUniqueChatMode, - (QString broadcasterID, QString moderatorID, - bool uniqueChatMode, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - // update chat settings - - // /timeout, /ban - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, banUser, - (QString broadcasterID, QString moderatorID, QString userID, - boost::optional duration, QString reason, - ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); // /timeout, /ban - - // /w - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, sendWhisper, - (QString fromUserID, QString toUserID, QString message, - ResultCallback<> successCallback, - (FailureCallback failureCallback)), - (override)); // /w - - // getChatters - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, getChatters, - (QString broadcasterID, QString moderatorID, int maxChattersToFetch, - ResultCallback successCallback, - (FailureCallback failureCallback)), - (override)); // getChatters - - // /vips - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, getChannelVIPs, - (QString broadcasterID, - ResultCallback> successCallback, - (FailureCallback failureCallback)), - (override)); // /vips - - // /commercial - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, startCommercial, - (QString broadcasterID, int length, - ResultCallback successCallback, - (FailureCallback failureCallback)), - (override)); // /commercial - - // /mods - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD( - void, getModerators, - (QString broadcasterID, int maxModeratorsToFetch, - ResultCallback> successCallback, - (FailureCallback failureCallback)), - (override)); // /mods - - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateShieldMode, - (QString broadcasterID, QString moderatorID, bool isActive, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); - - MOCK_METHOD(void, update, (QString clientId, QString oauthToken), - (override)); - -protected: - // The extra parenthesis around the failure callback is because its type contains a comma - MOCK_METHOD(void, updateChatSettings, - (QString broadcasterID, QString moderatorID, QJsonObject json, - ResultCallback successCallback, - (FailureCallback - failureCallback)), - (override)); -}; - static QString DEFAULT_SETTINGS = R"!( { "accounts": { @@ -582,7 +187,7 @@ protected: ASSERT_TRUE(settingsFile.flush()); settingsFile.close(); - this->mockHelix = new MockHelix; + this->mockHelix = new mock::Helix; initializeHelix(this->mockHelix); @@ -618,7 +223,7 @@ protected: std::unique_ptr controller; - MockHelix *mockHelix; + mock::Helix *mockHelix; }; TEST_F(HighlightControllerTest, A) diff --git a/tests/src/TwitchMessageBuilder.cpp b/tests/src/TwitchMessageBuilder.cpp index b1ce38eb9..e167a7773 100644 --- a/tests/src/TwitchMessageBuilder.cpp +++ b/tests/src/TwitchMessageBuilder.cpp @@ -3,6 +3,7 @@ #include "Application.hpp" #include "common/Channel.hpp" #include "messages/MessageBuilder.hpp" +#include "mocks/EmptyApplication.hpp" #include "mocks/UserData.hpp" #include "providers/twitch/TwitchBadge.hpp" #include "singletons/Emotes.hpp" @@ -19,61 +20,13 @@ using namespace chatterino; namespace { -class MockApplication : IApplication +class MockApplication : mock::EmptyApplication { public: - Theme *getThemes() override - { - return nullptr; - } - Fonts *getFonts() override - { - return nullptr; - } IEmotes *getEmotes() override { return &this->emotes; } - AccountController *getAccounts() override - { - return nullptr; - } - HotkeyController *getHotkeys() override - { - return nullptr; - } - WindowManager *getWindows() override - { - return nullptr; - } - Toasts *getToasts() override - { - return nullptr; - } - CommandController *getCommands() override - { - return nullptr; - } - NotificationController *getNotifications() override - { - return nullptr; - } - HighlightController *getHighlights() override - { - return nullptr; - } - TwitchIrcServer *getTwitch() override - { - return nullptr; - } - ChatterinoBadges *getChatterinoBadges() override - { - return nullptr; - } - FfzBadges *getFfzBadges() override - { - return nullptr; - } IUserDataController *getUserData() override { return &this->userData;