diff --git a/tests/unit/tests/unittests/imagecache/asynchronousexplicitimagecache-test.cpp b/tests/unit/tests/unittests/imagecache/asynchronousexplicitimagecache-test.cpp index 15d8f1dd7e5..7c43f96147e 100644 --- a/tests/unit/tests/unittests/imagecache/asynchronousexplicitimagecache-test.cpp +++ b/tests/unit/tests/unittests/imagecache/asynchronousexplicitimagecache-test.cpp @@ -15,11 +15,11 @@ class AsynchronousExplicitImageCache : public testing::Test protected: Notification notification; Notification waitInThread; + NiceMock mockStorage; NiceMock> mockAbortCallback; NiceMock> mockAbortCallback2; NiceMock> mockCaptureCallback; NiceMock> mockCaptureCallback2; - NiceMock mockStorage; QmlDesigner::AsynchronousExplicitImageCache cache{mockStorage}; QImage image1{10, 10, QImage::Format_ARGB32}; QImage midSizeImage1{5, 5, QImage::Format_ARGB32}; @@ -111,7 +111,8 @@ TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_fetches_mid_size_i notification.wait(); } -TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_capture_callback_with_image_from_storage) +TEST_F(AsynchronousExplicitImageCache, + request_mid_size_image_calls_capture_callback_with_image_from_storage) { ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _)) .WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{midSizeImage1})); @@ -140,7 +141,8 @@ TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_abort_callba notification.wait(); } -TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_abort_callback_without_mid_size_image) +TEST_F(AsynchronousExplicitImageCache, + request_mid_size_image_calls_abort_callback_without_mid_size_image) { ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _)) .WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{QImage{}})); @@ -168,7 +170,8 @@ TEST_F(AsynchronousExplicitImageCache, request_small_image_fetches_small_image_f notification.wait(); } -TEST_F(AsynchronousExplicitImageCache, request_small_image_calls_capture_callback_with_image_from_storage) +TEST_F(AsynchronousExplicitImageCache, + request_small_image_calls_capture_callback_with_image_from_storage) { ON_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component.qml"), _)) .WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1})); @@ -211,7 +214,7 @@ TEST_F(AsynchronousExplicitImageCache, request_small_image_calls_abort_callback_ notification.wait(); } -TEST_F(AsynchronousExplicitImageCache, clean_removes_entries) +TEST_F(AsynchronousExplicitImageCache, DISABLED_clean_removes_entries) { ON_CALL(mockStorage, fetchSmallImage(_, _)).WillByDefault([&](Utils::SmallStringView, auto) { return QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1}; @@ -219,8 +222,10 @@ TEST_F(AsynchronousExplicitImageCache, clean_removes_entries) ON_CALL(mockCaptureCallback2, Call(_)).WillByDefault([&](auto) { waitInThread.wait(); }); cache.requestSmallImage("/path/to/Component1.qml", mockCaptureCallback2.AsStdFunction(), - mockAbortCallback.AsStdFunction()); + mockAbortCallback2.AsStdFunction()); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort))) + .WillOnce([&](auto) { notification.notify(); }); EXPECT_CALL(mockCaptureCallback, Call(_)).Times(0); cache.requestSmallImage("/path/to/Component3.qml", @@ -228,26 +233,32 @@ TEST_F(AsynchronousExplicitImageCache, clean_removes_entries) mockAbortCallback.AsStdFunction()); cache.clean(); waitInThread.notify(); + notification.wait(); } TEST_F(AsynchronousExplicitImageCache, clean_calls_abort) { + QmlDesigner::AsynchronousExplicitImageCache cache{mockStorage}; ON_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component1.qml"), _)) .WillByDefault([&](Utils::SmallStringView, auto) { + notification.notify(); waitInThread.wait(); return QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1}; }); cache.requestSmallImage("/path/to/Component1.qml", mockCaptureCallback.AsStdFunction(), mockAbortCallback2.AsStdFunction()); + notification.wait(); cache.requestSmallImage("/path/to/Component2.qml", mockCaptureCallback.AsStdFunction(), mockAbortCallback.AsStdFunction()); - EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort))); + EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort))) + .WillOnce([&](auto) { notification.notify(); }); cache.clean(); waitInThread.notify(); + notification.wait(); } TEST_F(AsynchronousExplicitImageCache, after_clean_new_jobs_works) @@ -268,9 +279,10 @@ TEST_F(AsynchronousExplicitImageCache, after_clean_new_jobs_works) TEST_F(AsynchronousExplicitImageCache, request_image_with_extra_id_fetches_image_from_storage) { + ON_CALL(mockAbortCallback, Call(_)).WillByDefault([&](auto) { notification.notify(); }); + EXPECT_CALL(mockStorage, fetchImage(Eq("/path/to/Component.qml+extraId1"), _)) .WillRepeatedly([&](Utils::SmallStringView, auto) { - notification.notify(); return QmlDesigner::ImageCacheStorageInterface::ImageEntry{}; }); diff --git a/tests/unit/tests/unittests/imagecache/asynchronousimagefactory-test.cpp b/tests/unit/tests/unittests/imagecache/asynchronousimagefactory-test.cpp index e98f0d70e52..b26b4b7c708 100644 --- a/tests/unit/tests/unittests/imagecache/asynchronousimagefactory-test.cpp +++ b/tests/unit/tests/unittests/imagecache/asynchronousimagefactory-test.cpp @@ -124,8 +124,12 @@ TEST_F(AsynchronousImageFactory, request_image_request_image_from_collector_if_f TEST_F(AsynchronousImageFactory, clean_removes_entries) { EXPECT_CALL(collectorMock, start(Eq("/path/to/Component1.qml"), _, _, _, _)) - .WillRepeatedly([&](auto, auto, auto, auto, auto) { waitInThread.wait(); }); + .WillRepeatedly([&](auto, auto, auto, auto, auto) { + notification.notify(); + waitInThread.wait(); + }); factory.generate("/path/to/Component1.qml"); + notification.wait(); EXPECT_CALL(collectorMock, start(Eq("/path/to/Component3.qml"), _, _, _, _)).Times(0);