diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryiconimageprovider.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryiconimageprovider.cpp index 818dda087a9..e7dbbee0857 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryiconimageprovider.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryiconimageprovider.cpp @@ -77,12 +77,19 @@ QQuickImageResponse *ItemLibraryIconImageProvider::requestImageResponse(const QS }, Qt::QueuedConnection); }, - [response = QPointer(response.get())] { + [response = QPointer(response.get())](ImageCache::AbortReason abortReason) { QMetaObject::invokeMethod( response, - [response] { - if (response) - response->abort(); + [response, abortReason] { + switch (abortReason) { + case ImageCache::AbortReason::Failed: + if (response) + response->abort(); + break; + case ImageCache::AbortReason::Abort: + response->cancel(); + break; + } }, Qt::QueuedConnection); }); diff --git a/src/plugins/qmldesigner/components/previewtooltip/previewtooltipbackend.cpp b/src/plugins/qmldesigner/components/previewtooltip/previewtooltipbackend.cpp index a5872c7c639..475e4ac17d0 100644 --- a/src/plugins/qmldesigner/components/previewtooltip/previewtooltipbackend.cpp +++ b/src/plugins/qmldesigner/components/previewtooltip/previewtooltipbackend.cpp @@ -63,7 +63,7 @@ void PreviewTooltipBackend::showTooltip() } }); }, - [] {}, + [](auto) {}, m_extraId, m_auxiliaryData); diff --git a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp index f1d4f4cfb6d..027d6b3098a 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp @@ -68,8 +68,8 @@ AsynchronousImageCache::~AsynchronousImageCache() void AsynchronousImageCache::request(Utils::SmallStringView name, Utils::SmallStringView extraId, AsynchronousImageCache::RequestType requestType, - AsynchronousImageCache::CaptureImageCallback captureCallback, - AsynchronousImageCache::AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, ImageCache::AuxiliaryData auxiliaryData, ImageCacheStorageInterface &storage, ImageCacheGeneratorInterface &generator, @@ -83,7 +83,7 @@ void AsynchronousImageCache::request(Utils::SmallStringView name, if (entry.hasEntry) { if (entry.image.isNull()) - abortCallback(); + abortCallback(ImageCache::AbortReason::Failed); else captureCallback(entry.image); } else { @@ -109,8 +109,8 @@ void AsynchronousImageCache::wait() } void AsynchronousImageCache::requestImage(Utils::PathString name, - AsynchronousImageCache::CaptureImageCallback captureCallback, - AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId, ImageCache::AuxiliaryData auxiliaryData) { @@ -124,8 +124,8 @@ void AsynchronousImageCache::requestImage(Utils::PathString name, } void AsynchronousImageCache::requestSmallImage(Utils::PathString name, - AsynchronousImageCache::CaptureImageCallback captureCallback, - AsynchronousImageCache::AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId, ImageCache::AuxiliaryData auxiliaryData) { @@ -166,8 +166,8 @@ std::tuple AsynchronousImageCache::getEntry void AsynchronousImageCache::addEntry(Utils::PathString &&name, Utils::SmallString &&extraId, - AsynchronousImageCache::CaptureImageCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData, RequestType requestType) { @@ -185,7 +185,7 @@ void AsynchronousImageCache::clearEntries() { std::unique_lock lock{m_mutex}; for (Entry &entry : m_entries) - entry.abortCallback(); + entry.abortCallback(ImageCache::AbortReason::Abort); m_entries.clear(); } diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollector.cpp b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollector.cpp index b9b99d8a9a5..49e6e4325a6 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollector.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollector.cpp @@ -68,12 +68,10 @@ ImageCacheCollector::~ImageCacheCollector() = default; void ImageCacheCollector::start(Utils::SmallStringView name, Utils::SmallStringView state, - const ImageCache::AuxiliaryData &auxiliaryData, + const ImageCache::AuxiliaryData &, CaptureCallback captureCallback, AbortCallback abortCallback) { - Q_UNUSED(auxiliaryData) - RewriterView rewriterView{RewriterView::Amend, nullptr}; NodeInstanceView nodeInstanceView{m_connectionManager}; @@ -91,7 +89,7 @@ void ImageCacheCollector::start(Utils::SmallStringView name, model->setRewriterView(&rewriterView); if (rewriterView.inErrorState() || !rewriterView.rootModelNode().metaInfo().isGraphicalItem()) { - abortCallback(); + abortCallback(ImageCache::AbortReason::Failed); return; } @@ -100,18 +98,18 @@ void ImageCacheCollector::start(Utils::SmallStringView name, if (stateNode.isValid()) rewriterView.setCurrentStateNode(stateNode); - auto callback = [captureCallback = std::move(captureCallback)](QImage &&image) { + auto callback = [captureCallback = std::move(captureCallback)](const QImage &image) { QSize smallImageSize = image.size().scaled(QSize{96, 96}.boundedTo(image.size()), Qt::KeepAspectRatio); QImage smallImage = image.isNull() ? QImage{} : image.scaled(smallImageSize); - captureCallback(std::move(image), std::move(smallImage)); + captureCallback(image, smallImage); }; m_connectionManager.setCallback(std::move(callback)); nodeInstanceView.setTarget(m_target.data()); - nodeInstanceView.setCrashCallback(abortCallback); + nodeInstanceView.setCrashCallback([=] { abortCallback(ImageCache::AbortReason::Failed); }); model->setNodeInstanceView(&nodeInstanceView); bool capturedDataArrived = m_connectionManager.waitForCapturedData(); @@ -123,7 +121,7 @@ void ImageCacheCollector::start(Utils::SmallStringView name, model->setRewriterView({}); if (!capturedDataArrived) - abortCallback(); + abortCallback(ImageCache::AbortReason::Failed); } std::pair ImageCacheCollector::createImage(Utils::SmallStringView filePath, diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h index 4ac288c6f86..cad68450c8e 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h @@ -36,8 +36,8 @@ namespace QmlDesigner { class ImageCacheCollectorInterface { public: - using CaptureCallback = std::function; - using AbortCallback = std::function; + using CaptureCallback = ImageCache::CaptureImageWithSmallImageCallback; + using AbortCallback = ImageCache::AbortCallback; using ImagePair = std::pair; virtual void start(Utils::SmallStringView filePath, diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecacheconnectionmanager.h b/src/plugins/qmldesigner/designercore/imagecache/imagecacheconnectionmanager.h index 5788f6f31d2..2eef8b9a932 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecacheconnectionmanager.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecacheconnectionmanager.h @@ -26,7 +26,7 @@ class CapturedDataCommand; class ImageCacheConnectionManager : public ConnectionManager { public: - using Callback = std::function; + using Callback = std::function; ImageCacheConnectionManager(); diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachefontcollector.cpp b/src/plugins/qmldesigner/designercore/imagecache/imagecachefontcollector.cpp index ebe85a45234..57d254e7787 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachefontcollector.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachefontcollector.cpp @@ -140,7 +140,7 @@ void ImageCacheFontCollector::start(Utils::SmallStringView name, return; } } - abortCallback(); + abortCallback(ImageCache::AbortReason::Failed); } std::pair ImageCacheFontCollector::createImage( diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp index 13e1a141c78..c3b4a379af8 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp @@ -50,8 +50,8 @@ ImageCacheGenerator::~ImageCacheGenerator() void ImageCacheGenerator::generateImage(Utils::SmallStringView name, Utils::SmallStringView extraId, Sqlite::TimeStamp timeStamp, - ImageCacheGeneratorInterface::CaptureCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageWithSmallImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData) { { @@ -96,7 +96,7 @@ void ImageCacheGenerator::clean() { std::lock_guard lock{m_mutex}; for (Task &task : m_tasks) - callCallbacks(task.abortCallbacks); + callCallbacks(task.abortCallbacks, ImageCache::AbortReason::Abort); m_tasks.clear(); } @@ -133,9 +133,9 @@ void ImageCacheGenerator::startGeneration() task.filePath, task.extraId, std::move(task.auxiliaryData), - [this, task](QImage &&image, QImage &&smallImage) { + [this, task](const QImage &image, const QImage &smallImage) { if (image.isNull()) - callCallbacks(task.abortCallbacks); + callCallbacks(task.abortCallbacks, ImageCache::AbortReason::Failed); else callCallbacks(task.captureCallbacks, image, smallImage); @@ -144,9 +144,10 @@ void ImageCacheGenerator::startGeneration() image, smallImage); }, - [this, task] { - callCallbacks(task.abortCallbacks); - m_storage.storeImage(createId(task.filePath, task.extraId), task.timeStamp, {}, {}); + [this, task](ImageCache::AbortReason abortReason) { + callCallbacks(task.abortCallbacks, abortReason); + if (abortReason != ImageCache::AbortReason::Abort) + m_storage.storeImage(createId(task.filePath, task.extraId), task.timeStamp, {}, {}); }); std::lock_guard lock{m_mutex}; diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h index 78b7c96c937..dd1adc39fc8 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h @@ -55,8 +55,8 @@ public: void generateImage(Utils::SmallStringView filePath, Utils::SmallStringView extraId, Sqlite::TimeStamp timeStamp, - CaptureCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageWithSmallImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData) override; void clean() override; @@ -70,8 +70,8 @@ private: Utils::SmallStringView extraId, ImageCache::AuxiliaryData &&auxiliaryData, Sqlite::TimeStamp timeStamp, - CaptureCallback &&captureCallback, - AbortCallback &&abortCallback) + ImageCache::CaptureImageWithSmallImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback) : filePath(filePath) , extraId(std::move(extraId)) , auxiliaryData(std::move(auxiliaryData)) @@ -83,8 +83,8 @@ private: Utils::PathString filePath; Utils::SmallString extraId; ImageCache::AuxiliaryData auxiliaryData; - std::vector captureCallbacks; - std::vector abortCallbacks; + std::vector captureCallbacks; + std::vector abortCallbacks; Sqlite::TimeStamp timeStamp; }; diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h index 49ab963863b..4bf0915d80a 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h @@ -36,14 +36,11 @@ namespace QmlDesigner { class ImageCacheGeneratorInterface { public: - using CaptureCallback = std::function; - using AbortCallback = std::function; - virtual void generateImage(Utils::SmallStringView name, Utils::SmallStringView extraId, Sqlite::TimeStamp timeStamp, - CaptureCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageWithSmallImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData) = 0; diff --git a/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h b/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h index 271dac16203..f1356c64a03 100644 --- a/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h +++ b/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h @@ -43,8 +43,6 @@ class ImageCacheCollectorInterface; class AsynchronousImageCache final : public AsynchronousImageCacheInterface { public: - using CaptureImageCallback = std::function; - using AbortCallback = std::function; ~AsynchronousImageCache(); @@ -53,13 +51,13 @@ public: TimeStampProviderInterface &timeStampProvider); void requestImage(Utils::PathString name, - CaptureImageCallback captureCallback, - AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId = {}, ImageCache::AuxiliaryData auxiliaryData = {}) override; void requestSmallImage(Utils::PathString name, - CaptureImageCallback captureCallback, - AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId = {}, ImageCache::AuxiliaryData auxiliaryData = {}) override; @@ -73,8 +71,8 @@ private: Entry() = default; Entry(Utils::PathString name, Utils::SmallString extraId, - CaptureImageCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData, RequestType requestType) : name{std::move(name)} @@ -87,8 +85,8 @@ private: Utils::PathString name; Utils::SmallString extraId; - CaptureImageCallback captureCallback; - AbortCallback abortCallback; + ImageCache::CaptureImageCallback captureCallback; + ImageCache::AbortCallback abortCallback; ImageCache::AuxiliaryData auxiliaryData; RequestType requestType = RequestType::Image; }; @@ -96,8 +94,8 @@ private: std::tuple getEntry(); void addEntry(Utils::PathString &&name, Utils::SmallString &&extraId, - CaptureImageCallback &&captureCallback, - AbortCallback &&abortCallback, + ImageCache::CaptureImageCallback &&captureCallback, + ImageCache::AbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData, RequestType requestType); void clearEntries(); @@ -107,8 +105,8 @@ private: static void request(Utils::SmallStringView name, Utils::SmallStringView extraId, AsynchronousImageCache::RequestType requestType, - AsynchronousImageCache::CaptureImageCallback captureCallback, - AsynchronousImageCache::AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, ImageCache::AuxiliaryData auxiliaryData, ImageCacheStorageInterface &storage, ImageCacheGeneratorInterface &generator, diff --git a/src/plugins/qmldesigner/designercore/include/asynchronousimagecacheinterface.h b/src/plugins/qmldesigner/designercore/include/asynchronousimagecacheinterface.h index 51a722e7fc5..052c527049d 100644 --- a/src/plugins/qmldesigner/designercore/include/asynchronousimagecacheinterface.h +++ b/src/plugins/qmldesigner/designercore/include/asynchronousimagecacheinterface.h @@ -36,18 +36,15 @@ namespace QmlDesigner { class AsynchronousImageCacheInterface { public: - using CaptureCallback = std::function; - using AbortCallback = std::function; - virtual void requestImage(Utils::PathString name, - CaptureCallback captureCallback, - AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId = {}, ImageCache::AuxiliaryData auxiliaryData = {}) = 0; virtual void requestSmallImage(Utils::PathString name, - CaptureCallback captureCallback, - AbortCallback abortCallback, + ImageCache::CaptureImageCallback captureCallback, + ImageCache::AbortCallback abortCallback, Utils::SmallString extraId = {}, ImageCache::AuxiliaryData auxiliaryData = {}) = 0; diff --git a/src/plugins/qmldesigner/designercore/include/imagecacheauxiliarydata.h b/src/plugins/qmldesigner/designercore/include/imagecacheauxiliarydata.h index 688ead81831..c8c4d115878 100644 --- a/src/plugins/qmldesigner/designercore/include/imagecacheauxiliarydata.h +++ b/src/plugins/qmldesigner/designercore/include/imagecacheauxiliarydata.h @@ -28,9 +28,12 @@ #include #include +#include #include #include +#include + namespace QmlDesigner { namespace ImageCache { @@ -56,6 +59,11 @@ public: using AuxiliaryData = Utils::variant; +enum class AbortReason : char { Abort, Failed }; + +using CaptureImageCallback = std::function; +using CaptureImageWithSmallImageCallback = std::function; +using AbortCallback = std::function; } // namespace ImageCache } // namespace QmlDesigner diff --git a/tests/unit/unittest/asynchronousimagecache-test.cpp b/tests/unit/unittest/asynchronousimagecache-test.cpp index bd73d5f77de..d179c51b918 100644 --- a/tests/unit/unittest/asynchronousimagecache-test.cpp +++ b/tests/unit/unittest/asynchronousimagecache-test.cpp @@ -39,7 +39,7 @@ class AsynchronousImageCache : public testing::Test protected: Notification notification; Notification waitInThread; - NiceMock> mockAbortCallback; + NiceMock> mockAbortCallback; NiceMock> mockCaptureCallback; NiceMock mockStorage; NiceMock mockGenerator; @@ -99,7 +99,8 @@ TEST_F(AsynchronousImageCache, RequestImageCallsAbortCallbackWithoutImage) ON_CALL(mockStorage, fetchImage(Eq("/path/to/Component.qml"), _)) .WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{QImage{}, true})); - EXPECT_CALL(mockAbortCallback, Call()).WillRepeatedly([&] { notification.notify(); }); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))) + .WillRepeatedly([&](auto) { notification.notify(); }); cache.requestImage("/path/to/Component.qml", mockCaptureCallback.AsStdFunction(), @@ -142,11 +143,11 @@ TEST_F(AsynchronousImageCache, RequestImageCallsAbortCallbackFromGenerator) { ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _)) .WillByDefault([&](auto, auto, auto, auto &&, auto &&abortCallback, auto) { - abortCallback(); + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); notification.notify(); }); - EXPECT_CALL(mockAbortCallback, Call()); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))); cache.requestImage("/path/to/Component.qml", mockCaptureCallback.AsStdFunction(), @@ -204,7 +205,8 @@ TEST_F(AsynchronousImageCache, RequestSmallImageCallsAbortCallbackWithoutSmallIm ON_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component.qml"), _)) .WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{QImage{}, true})); - EXPECT_CALL(mockAbortCallback, Call()).WillRepeatedly([&] { notification.notify(); }); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))) + .WillRepeatedly([&](auto) { notification.notify(); }); cache.requestSmallImage("/path/to/Component.qml", mockCaptureCallback.AsStdFunction(), @@ -247,11 +249,11 @@ TEST_F(AsynchronousImageCache, RequestSmallImageCallsAbortCallbackFromGenerator) { ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _)) .WillByDefault([&](auto, auto, auto, auto &&, auto &&abortCallback, auto) { - abortCallback(); + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); notification.notify(); }); - EXPECT_CALL(mockAbortCallback, Call()); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))); cache.requestSmallImage("/path/to/Component.qml", mockCaptureCallback.AsStdFunction(), @@ -292,7 +294,8 @@ TEST_F(AsynchronousImageCache, CleanCallsAbort) mockCaptureCallback.AsStdFunction(), mockAbortCallback.AsStdFunction()); - EXPECT_CALL(mockAbortCallback, Call()).Times(AtLeast(2)); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort))) + .Times(AtLeast(2)); cache.requestSmallImage("/path/to/Component3.qml", mockCaptureCallback.AsStdFunction(), diff --git a/tests/unit/unittest/imagecachegenerator-test.cpp b/tests/unit/unittest/imagecachegenerator-test.cpp index 898b3d90579..dd8bd4297da 100644 --- a/tests/unit/unittest/imagecachegenerator-test.cpp +++ b/tests/unit/unittest/imagecachegenerator-test.cpp @@ -56,7 +56,7 @@ protected: QImage image1{10, 10, QImage::Format_ARGB32}; QImage smallImage1{1, 1, QImage::Format_ARGB32}; NiceMock> imageCallbackMock; - NiceMock> abortCallbackMock; + NiceMock> abortCallbackMock; NiceMock collectorMock; NiceMock storageMock; QmlDesigner::ImageCacheGenerator generator{collectorMock, storageMock}; @@ -196,12 +196,15 @@ TEST_F(ImageCacheGenerator, AbortCallback) captureCallback(QImage{image1}, QImage{smallImage1}); }); ON_CALL(collectorMock, start(Eq("name2"), _, _, _, _)) - .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { abortCallback(); }); + .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); + }); EXPECT_CALL(imageCallbackMock, Call(_, _)).WillOnce([&](const QImage &, const QImage &) { notification.notify(); }); - EXPECT_CALL(abortCallbackMock, Call()).WillOnce([&]() { notification.notify(); }); + EXPECT_CALL(abortCallbackMock, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))) + .WillOnce([&](auto) { notification.notify(); }); generator.generateImage( "name", {}, {}, imageCallbackMock.AsStdFunction(), abortCallbackMock.AsStdFunction(), {}); @@ -210,10 +213,29 @@ TEST_F(ImageCacheGenerator, AbortCallback) notification.wait(2); } -TEST_F(ImageCacheGenerator, StoreNullImageForAbortCallback) +TEST_F(ImageCacheGenerator, StoreNullImageForAbortCallbackAbort) +{ + ON_CALL(collectorMock, start(Eq("name"), _, _, _, _)) + .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { + abortCallback(QmlDesigner::ImageCache::AbortReason::Abort); + }); + ON_CALL(collectorMock, start(Eq("dummyNotify"), _, _, _, _)) + .WillByDefault([&](auto, auto, auto, auto, auto) { notification.notify(); }); + + EXPECT_CALL(storageMock, storeImage(Eq("name"), _, _, _)).Times(0); + + generator.generateImage( + "name", {}, {11}, imageCallbackMock.AsStdFunction(), abortCallbackMock.AsStdFunction(), {}); + generator.generateImage("dummyNotify", {}, {}, {}, {}, {}); + notification.wait(); +} + +TEST_F(ImageCacheGenerator, DontStoreNullImageForAbortCallbackFailed) { ON_CALL(collectorMock, start(_, _, _, _, _)) - .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { abortCallback(); }); + .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); + }); EXPECT_CALL(storageMock, storeImage(Eq("name"), Eq(Sqlite::TimeStamp{11}), Eq(QImage{}), Eq(QImage{}))) @@ -231,7 +253,8 @@ TEST_F(ImageCacheGenerator, AbortForEmptyImage) captureCallback(QImage{}, QImage{}); }); - EXPECT_CALL(abortCallbackMock, Call()).WillOnce([&]() { notification.notify(); }); + EXPECT_CALL(abortCallbackMock, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))) + .WillOnce([&](auto) { notification.notify(); }); generator.generateImage( "name", {}, {}, imageCallbackMock.AsStdFunction(), abortCallbackMock.AsStdFunction(), {}); @@ -264,7 +287,8 @@ TEST_F(ImageCacheGenerator, CleanIsCallingAbortCallback) generator.generateImage( "name2", {}, {11}, imageCallbackMock.AsStdFunction(), abortCallbackMock.AsStdFunction(), {}); - EXPECT_CALL(abortCallbackMock, Call()).Times(AtLeast(1)); + EXPECT_CALL(abortCallbackMock, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort))) + .Times(AtLeast(1)); generator.clean(); waitInThread.notify(); @@ -401,9 +425,11 @@ TEST_F(ImageCacheGenerator, UseLastTimeStampIfTasksAreMerged) ON_CALL(collectorMock, start(Eq("notificationDummy"), _, _, _, _)) .WillByDefault([&](auto, auto, auto, auto, auto) { notification.notify(); }); ON_CALL(collectorMock, start(Eq("name"), _, _, _, _)) - .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { abortCallback(); }); + .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); + }); - EXPECT_CALL(storageMock, storeImage(Eq("name"), _, _, _)); + EXPECT_CALL(storageMock, storeImage(Eq("name"), Eq(Sqlite::TimeStamp{4}), _, _)); generator.generateImage("waitDummy", {}, {}, {}, {}, {}); generator.generateImage("name", {}, {3}, {}, abortCallbackMock.AsStdFunction(), {}); @@ -438,16 +464,18 @@ TEST_F(ImageCacheGenerator, MergeCaptureCallbackIfTasksAreMerged) TEST_F(ImageCacheGenerator, MergeAbortCallbackIfTasksAreMerged) { - NiceMock> newerAbortCallbackMock; + NiceMock> newerAbortCallbackMock; ON_CALL(collectorMock, start(Eq("waitDummy"), _, _, _, _)) .WillByDefault([&](auto, auto, auto, auto, auto) { waitInThread.wait(); }); ON_CALL(collectorMock, start(Eq("notificationDummy"), _, _, _, _)) .WillByDefault([&](auto, auto, auto, auto, auto) { notification.notify(); }); ON_CALL(collectorMock, start(Eq("name"), _, _, _, _)) - .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { abortCallback(); }); + .WillByDefault([&](auto, auto, auto, auto, auto abortCallback) { + abortCallback(QmlDesigner::ImageCache::AbortReason::Failed); + }); - EXPECT_CALL(abortCallbackMock, Call()); - EXPECT_CALL(newerAbortCallbackMock, Call()); + EXPECT_CALL(abortCallbackMock, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))); + EXPECT_CALL(newerAbortCallbackMock, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed))); generator.generateImage("waitDummy", {}, {}, {}, {}, {}); generator.generateImage("name", {}, {}, {}, abortCallbackMock.AsStdFunction(), {}); diff --git a/tests/unit/unittest/mockimagecachegenerator.h b/tests/unit/unittest/mockimagecachegenerator.h index b576683cb09..b2b0fc63d69 100644 --- a/tests/unit/unittest/mockimagecachegenerator.h +++ b/tests/unit/unittest/mockimagecachegenerator.h @@ -37,8 +37,8 @@ public: (Utils::SmallStringView name, Utils::SmallStringView state, Sqlite::TimeStamp timeStamp, - CaptureCallback &&captureCallback, - AbortCallback &&abortCallback, + QmlDesigner::ImageCache::CaptureImageWithSmallImageCallback &&captureCallback, + QmlDesigner::ImageCache::AbortCallback &&abortCallback, QmlDesigner::ImageCache::AuxiliaryData &&auxiliaryData), (override)); MOCK_METHOD(void, clean, (), (override));