QmlDesigner: Add midSize image to cache

There is now a mid size image in the image cache. It's logical size is
150x150, so it is 300x300 for HighDPI.

Task-number: QDS-8918
Change-Id: I6586b2e82b9e74737f46b67c441201ad4964fca0
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2023-01-25 10:11:18 +01:00
parent aa8b011add
commit d593a5ea9b
47 changed files with 1073 additions and 304 deletions

View File

@@ -24,6 +24,7 @@ protected:
NiceMock<MockTimeStampProvider> mockTimeStampProvider;
QmlDesigner::AsynchronousImageCache cache{mockStorage, mockGenerator, mockTimeStampProvider};
QImage image1{10, 10, QImage::Format_ARGB32};
QImage midSizeImage1{5, 5, QImage::Format_ARGB32};
QImage smallImage1{1, 1, QImage::Format_ARGB32};
};
@@ -105,7 +106,7 @@ TEST_F(AsynchronousImageCache, RequestImageCallsCaptureCallbackWithImageFromGene
{
ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _))
.WillByDefault([&](auto, auto, auto, auto &&callback, auto, auto) {
callback(QImage{image1}, QImage{smallImage1});
callback(QImage{image1}, QImage{midSizeImage1}, QImage{smallImage1});
notification.notify();
});
@@ -133,6 +134,113 @@ TEST_F(AsynchronousImageCache, RequestImageCallsAbortCallbackFromGenerator)
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageFetchesMidSizeImageFromStorage)
{
EXPECT_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _))
.WillRepeatedly([&](Utils::SmallStringView, auto) {
notification.notify();
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{};
});
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageFetchesMidSizeImageFromStorageWithTimeStamp)
{
EXPECT_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillRepeatedly(Return(Sqlite::TimeStamp{123}));
EXPECT_CALL(mockStorage,
fetchMidSizeImage(Eq("/path/to/Component.qml"), Eq(Sqlite::TimeStamp{123})))
.WillRepeatedly([&](Utils::SmallStringView, auto) {
notification.notify();
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{};
});
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageCallsCaptureCallbackWithImageFromStorage)
{
ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _))
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1}));
EXPECT_CALL(mockCaptureCallback, Call(Eq(smallImage1))).WillRepeatedly([&](const QImage &) {
notification.notify();
});
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageCallsAbortCallbackWithoutMidSizeImage)
{
ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _))
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{QImage{}}));
EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed)))
.WillRepeatedly([&](auto) { notification.notify(); });
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageRequestImageFromGenerator)
{
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{123}));
EXPECT_CALL(mockGenerator,
generateImage(Eq("/path/to/Component.qml"), _, Eq(Sqlite::TimeStamp{123}), _, _, _))
.WillRepeatedly([&](auto, auto, auto, auto, auto, auto) { notification.notify(); });
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageCallsCaptureCallbackWithImageFromGenerator)
{
ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _))
.WillByDefault([&](auto, auto, auto, auto &&callback, auto, auto) {
callback(QImage{image1}, QImage{midSizeImage1}, QImage{smallImage1});
notification.notify();
});
EXPECT_CALL(mockCaptureCallback, Call(Eq(midSizeImage1)));
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageCallsAbortCallbackFromGenerator)
{
ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _))
.WillByDefault([&](auto, auto, auto, auto &&, auto &&abortCallback, auto) {
abortCallback(QmlDesigner::ImageCache::AbortReason::Failed);
notification.notify();
});
EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Failed)));
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestSmallImageFetchesSmallImageFromStorage)
{
EXPECT_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component.qml"), _))
@@ -211,7 +319,7 @@ TEST_F(AsynchronousImageCache, RequestSmallImageCallsCaptureCallbackWithImageFro
{
ON_CALL(mockGenerator, generateImage(Eq("/path/to/Component.qml"), _, _, _, _, _))
.WillByDefault([&](auto, auto, auto, auto &&callback, auto, auto) {
callback(QImage{image1}, QImage{smallImage1});
callback(QImage{image1}, QImage{midSizeImage1}, QImage{smallImage1});
notification.notify();
});
@@ -243,7 +351,7 @@ TEST_F(AsynchronousImageCache, CleanRemovesEntries)
{
EXPECT_CALL(mockGenerator, generateImage(_, _, _, _, _, _))
.WillRepeatedly([&](auto, auto, auto, auto &&captureCallback, auto &&, auto) {
captureCallback(QImage{}, QImage{});
captureCallback(QImage{}, QImage{}, QImage{});
waitInThread.wait();
});
cache.requestSmallImage("/path/to/Component1.qml",
@@ -315,6 +423,21 @@ TEST_F(AsynchronousImageCache, RequestImageWithExtraIdFetchesImageFromStorage)
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageWithExtraIdFetchesImageFromStorage)
{
EXPECT_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml+extraId1"), _))
.WillRepeatedly([&](Utils::SmallStringView, auto) {
notification.notify();
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{};
});
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction(),
"extraId1");
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestSmallImageWithExtraIdFetchesImageFromStorage)
{
EXPECT_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component.qml+extraId1"), _))
@@ -347,6 +470,23 @@ TEST_F(AsynchronousImageCache, RequestImageWithExtraIdRequestImageFromGenerator)
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageWithExtraIdRequestImageFromGenerator)
{
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{123}));
EXPECT_CALL(mockGenerator,
generateImage(
Eq("/path/to/Component.qml"), Eq("extraId1"), Eq(Sqlite::TimeStamp{123}), _, _, _))
.WillRepeatedly([&](auto, auto, auto, auto &&, auto, auto) { notification.notify(); });
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction(),
"extraId1");
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestSmallImageWithExtraIdRequestImageFromGenerator)
{
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
@@ -392,6 +532,34 @@ TEST_F(AsynchronousImageCache, RequestImageWithAuxiliaryDataRequestImageFromGene
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestMidSizeImageWithAuxiliaryDataRequestImageFromGenerator)
{
using QmlDesigner::ImageCache::FontCollectorSizesAuxiliaryData;
std::vector<QSize> sizes{{20, 11}};
ON_CALL(mockTimeStampProvider, timeStamp(Eq("/path/to/Component.qml")))
.WillByDefault(Return(Sqlite::TimeStamp{123}));
EXPECT_CALL(mockGenerator,
generateImage(Eq("/path/to/Component.qml"),
Eq("extraId1"),
Eq(Sqlite::TimeStamp{123}),
_,
_,
VariantWith<FontCollectorSizesAuxiliaryData>(
AllOf(Field(&FontCollectorSizesAuxiliaryData::sizes,
ElementsAre(QSize{20, 11})),
Field(&FontCollectorSizesAuxiliaryData::colorName,
Eq(u"color"))))))
.WillRepeatedly([&](auto, auto, auto, auto &&, auto, auto) { notification.notify(); });
cache.requestMidSizeImage("/path/to/Component.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction(),
"extraId1",
FontCollectorSizesAuxiliaryData{sizes, "color", "text"});
notification.wait();
}
TEST_F(AsynchronousImageCache, RequestSmallImageWithAuxiliaryDataRequestImageFromGenerator)
{
using QmlDesigner::ImageCache::FontCollectorSizesAuxiliaryData;