From c8e1741e47767f182e6f304b782212d63362791a Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 9 Apr 2023 12:18:56 +0200 Subject: [PATCH] Remove CHATTERINO_TEST definition (#4526) --- CHANGELOG.md | 1 + CMakeLists.txt | 4 ---- benchmarks/CMakeLists.txt | 4 ---- src/messages/Image.cpp | 24 +++++++++--------------- src/messages/Image.hpp | 10 +--------- src/messages/ImageSet.cpp | 2 -- src/providers/emoji/Emojis.cpp | 6 ------ tests/CMakeLists.txt | 4 ---- 8 files changed, 11 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d7bf915..287b09632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Dev: Add scripting capabilities with Lua (#4341, #4504) - Dev: Conan 2.0 is now used instead of Conan 1.0. (#4417) - Dev: Added tests and benchmarks for `LinkParser`. (#4436) +- Dev: Removed `CHATTERINO_TEST` definitions. (#4526) ## 2.4.2 diff --git a/CMakeLists.txt b/CMakeLists.txt index bc3844e60..74fab03e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,10 +169,6 @@ endif() set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (BUILD_TESTS OR BUILD_BENCHMARKS) - add_definitions(-DCHATTERINO_TEST) -endif () - # Generate resource files include(cmake/resources/generate_resources.cmake) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b655b7f84..344258516 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -18,10 +18,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-lib) target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark) -target_compile_definitions(${PROJECT_NAME} PRIVATE - CHATTERINO_TEST - ) - set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 952b61465..2e8616b19 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -8,6 +8,11 @@ #include "common/QLogging.hpp" #include "debug/AssertInGuiThread.hpp" #include "debug/Benchmark.hpp" +#include "singletons/Emotes.hpp" +#include "singletons/helper/GifTimer.hpp" +#include "singletons/WindowManager.hpp" +#include "util/DebugCount.hpp" +#include "util/PostToThread.hpp" #include #include @@ -20,13 +25,6 @@ #include #include #include -#ifndef CHATTERINO_TEST -# include "singletons/Emotes.hpp" -#endif -#include "singletons/helper/GifTimer.hpp" -#include "singletons/WindowManager.hpp" -#include "util/DebugCount.hpp" -#include "util/PostToThread.hpp" // Duration between each check of every Image instance const auto IMAGE_POOL_CLEANUP_INTERVAL = std::chrono::minutes(1); @@ -55,12 +53,10 @@ namespace detail { { DebugCount::increase("animated images"); -#ifndef CHATTERINO_TEST this->gifTimerConnection_ = getApp()->emotes->gifTimer.signal.connect([this] { this->advance(); }); -#endif } auto totalLength = @@ -75,11 +71,9 @@ namespace detail { } else { -#ifndef CHATTERINO_TEST this->durationOffset_ = std::min( int(getApp()->emotes->gifTimer.position() % totalLength), 60000); -#endif } this->processOffset(); } @@ -228,9 +222,8 @@ namespace detail { } } -#ifndef CHATTERINO_TEST getApp()->windows->forceLayoutChannelViews(); -#endif + loadedEventQueued = false; } @@ -558,8 +551,9 @@ void Image::expireFrames() #ifndef DISABLE_IMAGE_EXPIRATION_POOL ImageExpirationPool::ImageExpirationPool() + : freeTimer_(new QTimer) { - QObject::connect(&this->freeTimer_, &QTimer::timeout, [this] { + QObject::connect(this->freeTimer_, &QTimer::timeout, [this] { if (isGuiThread()) { this->freeOld(); @@ -572,7 +566,7 @@ ImageExpirationPool::ImageExpirationPool() } }); - this->freeTimer_.start( + this->freeTimer_->start( std::chrono::duration_cast( IMAGE_POOL_CLEANUP_INTERVAL)); } diff --git a/src/messages/Image.hpp b/src/messages/Image.hpp index 5ac7fafe5..90159a442 100644 --- a/src/messages/Image.hpp +++ b/src/messages/Image.hpp @@ -19,14 +19,6 @@ #include #include -#ifdef CHATTERINO_TEST -// When running tests, the ImageExpirationPool destructor can be called before -// all images are deleted, leading to a use-after-free of its mutex. This -// happens despite the lifetime of the ImageExpirationPool being (apparently) -// static. Therefore, just disable it during testing. -# define DISABLE_IMAGE_EXPIRATION_POOL -#endif - namespace chatterino { namespace detail { template @@ -136,7 +128,7 @@ private: private: // Timer to periodically run freeOld() - QTimer freeTimer_; + QTimer *freeTimer_; std::map> allImages_; std::mutex mutex_; }; diff --git a/src/messages/ImageSet.cpp b/src/messages/ImageSet.cpp index 09294f766..b4fa4a857 100644 --- a/src/messages/ImageSet.cpp +++ b/src/messages/ImageSet.cpp @@ -61,9 +61,7 @@ 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 1727f0bf3..72c429837 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -216,11 +216,7 @@ void Emojis::sortEmojis() void Emojis::loadEmojiSet() { -#ifndef CHATTERINO_TEST getSettings()->emojiSet.connect([this](const auto &emojiSet) { -#else - const QString emojiSet = "twitter"; -#endif this->emojis.each([=](const auto &name, std::shared_ptr &emoji) { QString emojiSetToUse = emojiSet; @@ -265,9 +261,7 @@ 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( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e57515d7b..7c9afa29d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,10 +35,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-lib) target_link_libraries(${PROJECT_NAME} PRIVATE gtest gmock) -target_compile_definitions(${PROJECT_NAME} PRIVATE - CHATTERINO_TEST - ) - set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"