diff --git a/CMakeLists.txt b/CMakeLists.txt index 05a132b7117..cb07d3c535f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,17 @@ set(chatterino_SOURCES src/common/UsernameSet.cpp src/controllers/highlights/HighlightPhrase.cpp + + + src/providers/emoji/Emojis.cpp + + src/messages/Emote.cpp + src/messages/Image.cpp + src/messages/ImageSet.cpp + src/util/RapidjsonHelpers.cpp + + ${CMAKE_CURRENT_LIST_DIR}/resources/resources.qrc + ${CMAKE_CURRENT_LIST_DIR}/resources/resources_autogenerated.qrc ) find_package(Qt5 5.9.0 REQUIRED COMPONENTS @@ -28,8 +39,7 @@ find_package(Qt5 5.9.0 REQUIRED COMPONENTS ) set(CMAKE_AUTOMOC ON) - -# set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) if (BUILD_TESTS) set(BUILD_TESTS OFF) @@ -41,12 +51,13 @@ if (BUILD_TESTS) ${chatterino_SOURCES} tests/src/main.cpp + tests/src/Emojis.cpp tests/src/NetworkRequest.cpp tests/src/UsernameSet.cpp tests/src/HighlightPhrase.cpp ) - target_compile_definitions(chatterino-test PRIVATE CHATTERINO_GIT_HASH="test" AB_CUSTOM_SETTINGS) + target_compile_definitions(chatterino-test PRIVATE CHATTERINO_GIT_HASH="test" AB_CUSTOM_SETTINGS CHATTERINO_TEST) target_link_libraries(chatterino-test Qt5::Core Qt5::Widgets Qt5::Network Qt5::Concurrent) diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 9a29d159683..91e3bc6e239 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -15,11 +15,16 @@ #include "common/QLogging.hpp" #include "debug/AssertInGuiThread.hpp" #include "debug/Benchmark.hpp" -#include "singletons/Emotes.hpp" +#ifndef CHATTERINO_TEST +# include "singletons/Emotes.hpp" +#endif #include "singletons/WindowManager.hpp" +#include "singletons/helper/GifTimer.hpp" #include "util/DebugCount.hpp" #include "util/PostToThread.hpp" +#include + namespace chatterino { namespace detail { // Frames @@ -38,10 +43,12 @@ namespace detail { { DebugCount::increase("animated images"); +#ifndef CHATTERINO_TEST this->gifTimerConnection_ = getApp()->emotes->gifTimer.signal.connect([this] { this->advance(); }); +#endif } auto totalLength = @@ -56,9 +63,11 @@ namespace detail { } else { +#ifndef CHATTERINO_TEST this->durationOffset_ = std::min( int(getApp()->emotes->gifTimer.position() % totalLength), 60000); +#endif } this->processOffset(); } @@ -182,7 +191,9 @@ namespace detail { } } +#ifndef CHATTERINO_TEST getApp()->windows->forceLayoutChannelViews(); +#endif loadedEventQueued = false; } diff --git a/src/messages/ImageSet.cpp b/src/messages/ImageSet.cpp index 8d950a3f799..1dccf10e90f 100644 --- a/src/messages/ImageSet.cpp +++ b/src/messages/ImageSet.cpp @@ -60,7 +60,9 @@ const ImagePtr &ImageSet::getImage3() const const std::shared_ptr &getImagePriv(const ImageSet &set, float scale) { +#ifndef CHATTERINO_TEST scale *= getSettings()->emoteScale; +#endif int quality = 1; diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index dae8ee28fd3..23b575a5def 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -260,7 +260,11 @@ void Emojis::sortEmojis() void Emojis::loadEmojiSet() { +#ifndef CHATTERINO_TEST getSettings()->emojiSet.connect([=](const auto &emojiSet) { +#else + const QString emojiSet = "twitter"; +#endif this->emojis.each([=](const auto &name, std::shared_ptr &emoji) { QString emojiSetToUse = emojiSet; @@ -318,7 +322,9 @@ void Emojis::loadEmojiSet() EmoteName{emoji->value}, ImageSet{Image::fromUrl({url}, 0.35)}, Tooltip{":" + emoji->shortCodes[0] + ":
Emoji"}, Url{}}); }); +#ifndef CHATTERINO_TEST }); +#endif } std::vector> Emojis::parse( @@ -345,6 +351,12 @@ std::vector> Emojis::parse( const auto &possibleEmojis = it.value(); + for (const auto &p : possibleEmojis) + { + printf("xd\n"); + qDebug() << "possible emoji:" << p->value; + } + int remainingCharacters = text.length() - i - 1; std::shared_ptr matchedEmoji; @@ -436,11 +448,15 @@ QString Emojis::replaceShortCodes(const QString &text) if (emojiIt == this->emojiShortCodeToEmoji_.constEnd()) { + printf("No match for %s\n", matchString.toStdString().c_str()); continue; } auto emojiData = emojiIt.value(); + printf("Found match for %s: '%s'\n", qUtf8Printable(matchString), + qUtf8Printable(emojiData->unifiedCode)); + ret.replace(offset + match.capturedStart(), match.capturedLength(), emojiData->value); diff --git a/tests/src/Emojis.cpp b/tests/src/Emojis.cpp new file mode 100644 index 00000000000..13c6fa2b0cc --- /dev/null +++ b/tests/src/Emojis.cpp @@ -0,0 +1,42 @@ +#include "providers/emoji/Emojis.hpp" + +#include +#include +#include + +using namespace chatterino; + +TEST(Emojis, ShortcodeParsing) +{ + Emojis emojis; + + emojis.load(); + + struct TestCase { + QString input; + QString expectedOutput; + }; + + std::vector tests{ + { + .input = "foo :penguin: bar", + .expectedOutput = "foo 🐧 bar", + }, + { + .input = "foo :nonexistantcode: bar", + .expectedOutput = "foo :nonexistantcode: bar", + }, + { + .input = ":male-doctor:", + .expectedOutput = "👨‍⚕️", + }, + }; + + for (const auto &test : tests) + { + auto output = emojis.replaceShortCodes(test.input); + + EXPECT_EQ(output, test.expectedOutput) + << "Input " << test.input.toStdString() << " failed"; + } +} diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 9a55758bf58..779c864174c 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -22,33 +22,6 @@ using namespace chatterino; -void xd() -{ - std::mutex mut; - bool requestDone = false; - std::condition_variable requestDoneCondition; - - EXPECT_TRUE(NetworkManager::workerThread.isRunning()); - - using namespace std::chrono_literals; - - auto url = "http://localhost:8000/status/200"; - NetworkRequest(url) - .onSuccess([&](NetworkResult result) -> Outcome { - qDebug() << "ON SUCCESS"; - qDebug() << url; - return Success; - }) - .onError([&](NetworkResult result) { - qDebug() << "ON ERROR"; - }) - .execute(); - - EXPECT_TRUE(NetworkManager::workerThread.isRunning()); - - EXPECT_TRUE(true); -} - int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv);