Commit 3632bf05 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add test for recent thumbnail cache freeze issue

parent 5bbd0e6e
Pipeline #170550 canceled with stage
in 3 minutes and 16 seconds
......@@ -71,6 +71,19 @@ public:
m_cache.clear();
m_currentCost = 0;
}
bool checkIntegrity() const
{
if (m_data.size() != m_cache.size()) {
// Cache is corrupted
return false;
}
for (const auto &d : m_data) {
if (!contains(d.first)) {
return false;
}
}
return true;
}
protected:
int m_maxCost;
......@@ -215,6 +228,11 @@ void ThumbnailCache::storeThumbnail(const QString &binId, int pos, const QImage
m_volatileCache->insert(key, img, (int)img.sizeInBytes());
}
bool ThumbnailCache::checkIntegrity() const
{
return m_volatileCache->checkIntegrity();
}
void ThumbnailCache::saveCachedThumbs(const std::unordered_map<QString, std::vector<int>> &keys)
{
bool ok;
......
......@@ -64,6 +64,9 @@ public:
/** @brief Reset cache (discarding all thumbs stored in memory) */
void clearCache();
/** @brief Ensure the cache is not corrupted */
bool checkIntegrity() const;
protected:
// Constructor is protected because class is a Singleton
ThumbnailCache();
......
......@@ -17,6 +17,7 @@ add_executable(runTests
timewarptest.cpp
treetest.cpp
trimmingtest.cpp
cachetest.cpp
)
set_property(TARGET runTests PROPERTY CXX_STANDARD 14)
target_link_libraries(runTests kdenliveLib)
......
#include "catch.hpp"
#include "doc/docundostack.hpp"
#include "test_utils.hpp"
#include <QString>
#include <cmath>
#include <iostream>
#include <tuple>
#include <unordered_set>
#include "definitions.h"
#define private public
#define protected public
#include "core.h"
#include "utils/thumbnailcache.hpp"
Mlt::Profile profile_cache;
TEST_CASE("Cache insert-remove", "[Cache]")
{
// Create timeline
auto binModel = pCore->projectItemModel();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
std::shared_ptr<MarkerListModel> guideModel = std::make_shared<MarkerListModel>(undoStack);
// Here we do some trickery to enable testing.
// We mock the project class so that the undoStack function returns our undoStack
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_cache, undoStack);
Mock<TimelineItemModel> timMock(tim);
auto timeline = std::shared_ptr<TimelineItemModel>(&timMock.get(), [](...) {});
TimelineItemModel::finishConstruct(timeline, guideModel);
// Create a track
int tid1;
REQUIRE(timeline->requestTrackInsertion(-1, tid1));
// Create bin clip
QString binId = createProducer(profile_cache, "red", binModel);
std::shared_ptr<ProjectClip> clip = binModel->getClipByBinID(binId);
SECTION("Insert and remove thumbnail")
{
QImage img(100, 100, QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::red);
ThumbnailCache::get()->storeThumbnail(binId, 0, img, false);
REQUIRE(ThumbnailCache::get()->checkIntegrity());
ThumbnailCache::get()->storeThumbnail(binId, 0, img, false);
REQUIRE(ThumbnailCache::get()->checkIntegrity());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment