2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-09-16 13:44:43 +02:00
|
|
|
|
|
|
|
|
#include "googletest.h"
|
|
|
|
|
|
|
|
|
|
#include "sqlitedatabasemock.h"
|
|
|
|
|
|
|
|
|
|
#include <imagecachestorage.h>
|
|
|
|
|
#include <sqlitedatabase.h>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
MATCHER_P(IsIcon, icon, std::string(negation ? "is't" : "is") + PrintToString(icon))
|
2020-09-16 13:44:43 +02:00
|
|
|
{
|
2021-12-28 15:03:31 +01:00
|
|
|
return arg.availableSizes() == icon.availableSizes();
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
2023-01-25 10:11:18 +01:00
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, CheckVersionIfDatabaseIsAlreadyInitialized)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(true));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, version());
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, AddColumnMidSizeIfVersionIsZero)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(true));
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(_)).Times(AnyNumber());
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(Eq("ALTER TABLE images ADD COLUMN midSizeImage")));
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, DeleteAllRowsBeforeAddingMidSizeColumn)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(true));
|
|
|
|
|
InSequence s;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(Eq("DELETE FROM images")));
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(Eq("ALTER TABLE images ADD COLUMN midSizeImage")));
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, DontCallAddColumnMidSizeIfDatabaseWasNotAlreadyInitialized)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(false));
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(_)).Times(2);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, execute(Eq("ALTER TABLE images ADD COLUMN midSizeImage"))).Times(0);
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, SetVersionToOneIfVersionIsZero)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(true));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, setVersion(Eq(1)));
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, DontSetVersionIfVersionIsOne)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(true));
|
|
|
|
|
ON_CALL(databaseMock, version()).WillByDefault(Return(1));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, setVersion(_)).Times(0);
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ImageCacheStorageUpdateTest, SetVersionToOneForInitialization)
|
|
|
|
|
{
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
ON_CALL(databaseMock, isInitialized()).WillByDefault(Return(false));
|
|
|
|
|
ON_CALL(databaseMock, version()).WillByDefault(Return(1));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, setVersion(Eq(1)));
|
|
|
|
|
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 13:23:46 +01:00
|
|
|
class ImageCacheStorageTest : public testing::Test
|
|
|
|
|
{
|
2020-09-16 13:44:43 +02:00
|
|
|
protected:
|
2021-12-07 17:28:38 +01:00
|
|
|
template<int ResultCount, int BindParameterCount = 0>
|
|
|
|
|
using ReadStatement = QmlDesigner::ImageCacheStorage<
|
|
|
|
|
SqliteDatabaseMock>::ReadStatement<ResultCount, BindParameterCount>;
|
|
|
|
|
template<int BindParameterCount>
|
|
|
|
|
using WriteStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::WriteStatement<BindParameterCount>;
|
2020-09-16 13:44:43 +02:00
|
|
|
|
|
|
|
|
NiceMock<SqliteDatabaseMock> databaseMock;
|
|
|
|
|
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
|
2021-12-07 17:28:38 +01:00
|
|
|
ReadStatement<1, 2> &selectImageStatement = storage.selectImageStatement;
|
2023-01-25 10:11:18 +01:00
|
|
|
ReadStatement<1, 2> &selectMidSizeImageStatement = storage.selectMidSizeImageStatement;
|
2021-12-07 17:28:38 +01:00
|
|
|
ReadStatement<1, 2> &selectSmallImageStatement = storage.selectSmallImageStatement;
|
|
|
|
|
ReadStatement<1, 2> &selectIconStatement = storage.selectIconStatement;
|
2023-01-25 10:11:18 +01:00
|
|
|
WriteStatement<5> &upsertImageStatement = storage.upsertImageStatement;
|
2021-12-07 17:28:38 +01:00
|
|
|
WriteStatement<3> &upsertIconStatement = storage.upsertIconStatement;
|
2021-01-13 13:23:46 +01:00
|
|
|
QImage image1{10, 10, QImage::Format_ARGB32};
|
2023-01-25 10:11:18 +01:00
|
|
|
QImage midSizeImage1{5, 5, QImage::Format_ARGB32};
|
|
|
|
|
QImage smallImage1{1, 1, QImage::Format_ARGB32};
|
2021-01-13 13:23:46 +01:00
|
|
|
QIcon icon1{QPixmap::fromImage(image1)};
|
2020-09-16 13:44:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
TEST_F(ImageCacheStorageTest, FetchMidSizeImageCalls)
|
|
|
|
|
{
|
|
|
|
|
InSequence s;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, deferredBegin());
|
|
|
|
|
EXPECT_CALL(selectMidSizeImageStatement,
|
|
|
|
|
valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"),
|
|
|
|
|
TypedEq<long long>(123)));
|
|
|
|
|
EXPECT_CALL(databaseMock, commit());
|
|
|
|
|
|
|
|
|
|
storage.fetchMidSizeImage("/path/to/component", {123});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageTest, FetchMidSizeImageCallsIsBusy)
|
|
|
|
|
{
|
|
|
|
|
InSequence s;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(databaseMock, deferredBegin());
|
|
|
|
|
EXPECT_CALL(selectMidSizeImageStatement,
|
|
|
|
|
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(selectMidSizeImageStatement,
|
|
|
|
|
valueReturnBlob(TypedEq<Utils::SmallStringView>("/path/to/component"),
|
|
|
|
|
TypedEq<long long>(123)));
|
|
|
|
|
EXPECT_CALL(databaseMock, commit());
|
|
|
|
|
|
|
|
|
|
storage.fetchMidSizeImage("/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()),
|
2023-01-25 10:11:18 +01:00
|
|
|
Not(IsEmpty()),
|
2021-01-13 13:23:46 +01:00
|
|
|
Not(IsEmpty())));
|
2020-09-16 13:44:43 +02:00
|
|
|
EXPECT_CALL(databaseMock, commit());
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, 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(),
|
2023-01-25 10:11:18 +01:00
|
|
|
IsEmpty(),
|
2021-01-13 13:23:46 +01:00
|
|
|
IsEmpty()));
|
2020-09-16 13:44:43 +02:00
|
|
|
EXPECT_CALL(databaseMock, commit());
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, 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(),
|
2023-01-25 10:11:18 +01:00
|
|
|
IsEmpty(),
|
2021-01-13 13:23:46 +01:00
|
|
|
IsEmpty()));
|
|
|
|
|
EXPECT_CALL(databaseMock, commit());
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}, QImage{});
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()};
|
2023-01-25 10:11:18 +01:00
|
|
|
QImage midSizeImage1{image1.scaled(96, 96)};
|
|
|
|
|
QImage smallImage1{image1.scaled(48, 48)};
|
2021-01-13 13:23:46 +01:00
|
|
|
QIcon icon1{QPixmap::fromImage(image1)};
|
2020-09-16 13:44:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, QImage{}, QImage{});
|
2020-09-16 13:44:43 +02:00
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), Optional(image1));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptyImageAfterEntry)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2020-09-16 13:44:43 +02:00
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, midSizeImage1, smallImage1);
|
2020-09-16 13:44:43 +02:00
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), Optional(QImage{}));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreMidSizeImage)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, midSizeImage1, QImage{});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(storage.fetchMidSizeImage("/path/to/component", {123}), Optional(midSizeImage1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptyMidSizeImageAfterEntry)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
|
|
|
|
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, QImage{}, smallImage1);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(storage.fetchMidSizeImage("/path/to/component", {123}), Optional(QImage{}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreSmallImage)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}, smallImage1);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(storage.fetchSmallImage("/path/to/component", {123}), Optional(smallImage1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptySmallImageAfterEntry)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
|
|
|
|
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, QImage{});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(storage.fetchSmallImage("/path/to/component", {123}), Optional(QImage{}));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 13:44:43 +02:00
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptyEntry)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}, QImage{});
|
2020-09-16 13:44:43 +02:00
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchImage("/path/to/component", {123}), Optional(QImage{}));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNonExistingImageIsEmpty)
|
|
|
|
|
{
|
|
|
|
|
auto image = storage.fetchImage("/path/to/component", {123});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchSameTimeImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2020-09-16 13:44:43 +02:00
|
|
|
|
|
|
|
|
auto image = storage.fetchImage("/path/to/component", {123});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(image1));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2020-09-16 13:44:43 +02:00
|
|
|
|
|
|
|
|
auto image = storage.fetchImage("/path/to/component", {124});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNewerImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2020-09-16 13:44:43 +02:00
|
|
|
|
|
|
|
|
auto image = storage.fetchImage("/path/to/component", {122});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(image1));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 10:11:18 +01:00
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNonExistingMidSizeImageIsEmpty)
|
|
|
|
|
{
|
|
|
|
|
auto image = storage.fetchMidSizeImage("/path/to/component", {123});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchSameTimeMidSizeImage)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
|
|
|
|
|
|
|
|
|
auto image = storage.fetchMidSizeImage("/path/to/component", {123});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(image, Optional(midSizeImage1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderMidSizeImage)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
|
|
|
|
|
|
|
|
|
auto image = storage.fetchMidSizeImage("/path/to/component", {124});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNewerMidSizeImage)
|
|
|
|
|
{
|
|
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
|
|
|
|
|
|
|
|
|
auto image = storage.fetchMidSizeImage("/path/to/component", {122});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(image, Optional(midSizeImage1));
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 13:23:46 +01:00
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNonExistingSmallImageIsEmpty)
|
|
|
|
|
{
|
|
|
|
|
auto image = storage.fetchSmallImage("/path/to/component", {123});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchSameTimeSmallImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2021-01-13 13:23:46 +01:00
|
|
|
|
|
|
|
|
auto image = storage.fetchSmallImage("/path/to/component", {123});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(smallImage1));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, DoNotFetchOlderSmallImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2021-01-13 13:23:46 +01:00
|
|
|
|
|
|
|
|
auto image = storage.fetchSmallImage("/path/to/component", {124});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNewerSmallImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2021-01-13 13:23:46 +01:00
|
|
|
|
|
|
|
|
auto image = storage.fetchSmallImage("/path/to/component", {122});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(smallImage1));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreIcon)
|
|
|
|
|
{
|
|
|
|
|
storage.storeIcon("/path/to/component", {123}, icon1);
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), Optional(IsIcon(icon1)));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptyIconAfterEntry)
|
|
|
|
|
{
|
|
|
|
|
storage.storeIcon("/path/to/component", {123}, icon1);
|
|
|
|
|
|
|
|
|
|
storage.storeIcon("/path/to/component", {123}, QIcon{});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), Optional(IsIcon(QIcon{})));
|
2021-01-13 13:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, StoreEmptyIconEntry)
|
|
|
|
|
{
|
|
|
|
|
storage.storeIcon("/path/to/component", {123}, QIcon{});
|
|
|
|
|
|
2021-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(storage.fetchIcon("/path/to/component", {123}), Optional(IsIcon(QIcon{})));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchNonExistingIconIsEmpty)
|
|
|
|
|
{
|
|
|
|
|
auto image = storage.fetchIcon("/path/to/component", {123});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
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-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(IsIcon(icon1)));
|
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});
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
ASSERT_THAT(image, Eq(std::nullopt));
|
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-12-28 15:03:31 +01:00
|
|
|
ASSERT_THAT(image, Optional(IsIcon(icon1)));
|
2020-09-16 13:44:43 +02:00
|
|
|
}
|
2021-12-28 11:32:47 +01:00
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchModifiedImageTime)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2021-12-28 11:32:47 +01:00
|
|
|
|
|
|
|
|
auto timeStamp = storage.fetchModifiedImageTime("/path/to/component");
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(timeStamp, Eq(Sqlite::TimeStamp{123}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchInvalidModifiedImageTimeForNoEntry)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component2", {123}, image1, midSizeImage1, smallImage1);
|
2021-12-28 11:32:47 +01:00
|
|
|
|
|
|
|
|
auto timeStamp = storage.fetchModifiedImageTime("/path/to/component");
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(timeStamp, Eq(Sqlite::TimeStamp{}));
|
|
|
|
|
}
|
2022-01-06 12:00:45 +01:00
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchHasImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, image1, midSizeImage1, smallImage1);
|
2022-01-06 12:00:45 +01:00
|
|
|
|
|
|
|
|
auto hasImage = storage.fetchHasImage("/path/to/component");
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(hasImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchHasImageForNullImage)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}, QImage{});
|
2022-01-06 12:00:45 +01:00
|
|
|
|
|
|
|
|
auto hasImage = storage.fetchHasImage("/path/to/component");
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(hasImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ImageCacheStorageSlowTest, FetchHasImageForNoEntry)
|
|
|
|
|
{
|
2023-01-25 10:11:18 +01:00
|
|
|
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{}, QImage{});
|
2022-01-06 12:00:45 +01:00
|
|
|
|
|
|
|
|
auto hasImage = storage.fetchHasImage("/path/to/component");
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(hasImage);
|
|
|
|
|
}
|
2020-09-16 13:44:43 +02:00
|
|
|
} // namespace
|