| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							|  |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | ** information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "sqlitedatabasemock.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <imagecachestorage.h>
 | 
					
						
							|  |  |  | #include <sqlitedatabase.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  | MATCHER_P2(IsImageEntry, | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |            image, | 
					
						
							|  |  |  |            hasEntry, | 
					
						
							|  |  |  |            std::string(negation ? "is't" : "is") | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |                + PrintToString(QmlDesigner::ImageCacheStorageInterface::ImageEntry{image, hasEntry})) | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     const QmlDesigner::ImageCacheStorageInterface::ImageEntry &entry = arg; | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     return entry.image == image && entry.hasEntry == hasEntry; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  | MATCHER_P2(IsIconEntry, | 
					
						
							|  |  |  |            icon, | 
					
						
							|  |  |  |            hasEntry, | 
					
						
							|  |  |  |            std::string(negation ? "is't" : "is") | 
					
						
							|  |  |  |                + PrintToString(QmlDesigner::ImageCacheStorageInterface::IconEntry{icon, hasEntry})) | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     const QmlDesigner::ImageCacheStorageInterface::IconEntry &entry = arg; | 
					
						
							|  |  |  |     return entry.icon.availableSizes() == icon.availableSizes() && entry.hasEntry == hasEntry; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  | class ImageCacheStorageTest : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  |     using ReadStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::ReadStatement; | 
					
						
							|  |  |  |     using WriteStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::WriteStatement; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NiceMock<SqliteDatabaseMock> databaseMock; | 
					
						
							|  |  |  |     QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock}; | 
					
						
							|  |  |  |     ReadStatement &selectImageStatement = storage.selectImageStatement; | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ReadStatement &selectSmallImageStatement = storage.selectSmallImageStatement; | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     ReadStatement &selectIconStatement = storage.selectIconStatement; | 
					
						
							|  |  |  |     WriteStatement &upsertImageStatement = storage.upsertImageStatement; | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     WriteStatement &upsertIconStatement = storage.upsertIconStatement; | 
					
						
							|  |  |  |     QImage image1{10, 10, QImage::Format_ARGB32}; | 
					
						
							|  |  |  |     QImage smallImage1{10, 10, QImage::Format_ARGB32}; | 
					
						
							|  |  |  |     QIcon icon1{QPixmap::fromImage(image1)}; | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, Initialize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, exclusiveBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, | 
					
						
							|  |  |  |                 execute(Eq("CREATE TABLE IF NOT EXISTS images(id INTEGER PRIMARY KEY, name TEXT " | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |                            "NOT NULL UNIQUE, mtime INTEGER, image BLOB, smallImage BLOB)"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, | 
					
						
							|  |  |  |                 execute(Eq("CREATE TABLE IF NOT EXISTS icons(id INTEGER PRIMARY KEY, name TEXT " | 
					
						
							|  |  |  |                            "NOT NULL UNIQUE, mtime INTEGER, icon BLOB)"))); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, prepare(Eq(selectImageStatement.sqlStatement))); | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     EXPECT_CALL(databaseMock, prepare(Eq(selectSmallImageStatement.sqlStatement))); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, prepare(Eq(selectIconStatement.sqlStatement))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, prepare(Eq(upsertImageStatement.sqlStatement))); | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     EXPECT_CALL(databaseMock, prepare(Eq(upsertIconStatement.sqlStatement))); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, FetchImageCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchImage("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, FetchImageCallsIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))) | 
					
						
							|  |  |  |         .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchImage("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  | TEST_F(ImageCacheStorageTest, FetchSmallImageCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSmallImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSmallImage("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, FetchSmallImageCallsIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSmallImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))) | 
					
						
							|  |  |  |         .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSmallImageStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSmallImage("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | TEST_F(ImageCacheStorageTest, FetchIconCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectIconStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchIcon("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, FetchIconCallsIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectIconStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))) | 
					
						
							|  |  |  |         .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectIconStatement, | 
					
						
							|  |  |  |                 valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                                 TypedEq<long long>(123))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchIcon("/path/to/component", {123}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreImageCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertImageStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |                       Not(IsEmpty()), | 
					
						
							|  |  |  |                       Not(IsEmpty()))); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreEmptyImageCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertImageStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |                       IsEmpty(), | 
					
						
							|  |  |  |                       IsEmpty())); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreImageCallsIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertImageStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |                       IsEmpty(), | 
					
						
							|  |  |  |                       IsEmpty())); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreIconCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertIconStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							|  |  |  |                       A<Sqlite::BlobView>())); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreEmptyIconCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertIconStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							|  |  |  |                       IsEmpty())); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, QIcon{}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, StoreIconCallsIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, immediateBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(upsertIconStatement, | 
					
						
							|  |  |  |                 write(TypedEq<Utils::SmallStringView>("/path/to/component"), | 
					
						
							|  |  |  |                       TypedEq<long long>(123), | 
					
						
							|  |  |  |                       IsEmpty())); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, QIcon{}); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, CallWalCheckointFull) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, walCheckpointFull()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.walCheckpointFull(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageTest, CallWalCheckointFullIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, walCheckpointFull()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(databaseMock, walCheckpointFull()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.walCheckpointFull(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ImageCacheStorageSlowTest : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     QImage createImage() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QImage image{150, 150, QImage::Format_ARGB32}; | 
					
						
							|  |  |  |         image.fill(QColor{128, 64, 0, 11}); | 
					
						
							|  |  |  |         image.setPixelColor(1, 1, QColor{1, 255, 33, 196}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return image; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; | 
					
						
							|  |  |  |     QmlDesigner::ImageCacheStorage<Sqlite::Database> storage{database}; | 
					
						
							|  |  |  |     QImage image1{createImage()}; | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     QImage smallImage1{image1.scaled(96, 96)}; | 
					
						
							|  |  |  |     QIcon icon1{QPixmap::fromImage(image1)}; | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreImage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), IsImageEntry(image1, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreEmptyImageAfterEntry) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), IsImageEntry(QImage{}, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreEmptyEntry) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), IsImageEntry(QImage{}, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNonExistingImageIsEmpty) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto image = storage.fetchImage("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsImageEntry(QImage{}, false)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchSameTimeImage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchImage("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsImageEntry(image1, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderImage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchImage("/path/to/component", {124}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsImageEntry(QImage{}, false)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNewerImage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchImage("/path/to/component", {122}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsImageEntry(image1, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNonExistingSmallImageIsEmpty) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto image = storage.fetchSmallImage("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(image, IsImageEntry(QImage{}, false)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchSameTimeSmallImage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchSmallImage("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(image, IsImageEntry(smallImage1, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderSmallImage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchSmallImage("/path/to/component", {124}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(image, IsImageEntry(QImage{}, false)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNewerSmallImage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeImage("/path/to/component", {123}, image1, smallImage1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchSmallImage("/path/to/component", {122}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(image, IsImageEntry(smallImage1, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreIcon) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), IsIconEntry(icon1, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreEmptyIconAfterEntry) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, QIcon{}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), IsIconEntry(QIcon{}, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, StoreEmptyIconEntry) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     storage.storeIcon("/path/to/component", {123}, QIcon{}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), IsIconEntry(QIcon{}, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNonExistingIconIsEmpty) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto image = storage.fetchIcon("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsIconEntry(QIcon{}, false)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchSameTimeIcon) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchIcon("/path/to/component", {123}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsIconEntry(icon1, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderIcon) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchIcon("/path/to/component", {124}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsIconEntry(QIcon{}, false)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ImageCacheStorageSlowTest, FetchNewerIcon) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     storage.storeIcon("/path/to/component", {123}, icon1); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto image = storage.fetchIcon("/path/to/component", {122}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 13:23:46 +01:00
										 |  |  |     ASSERT_THAT(image, IsIconEntry(icon1, true)); | 
					
						
							| 
									
										
										
										
											2020-09-16 13:44:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | } // namespace
 |