QmlDesigner: Add fetchHasImage to ImageCacheStorage

Change-Id: Ieb148abb02527bb84eda4f00af85a66d98731f03
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2022-01-06 12:00:45 +01:00
parent 6d7578a75b
commit b2e1bcc4e5
6 changed files with 39 additions and 2 deletions

View File

@@ -210,8 +210,6 @@ public:
template<typename ResultType, typename... QueryTypes>
auto value(const QueryTypes &...queryValues)
{
static_assert(!std::is_fundamental_v<ResultType>,
"Use optionalValue(...) instead of value(...) for fundamental types!");
Resetter resetter{this};
ResultType resultValue{};

View File

@@ -165,6 +165,11 @@ public:
return selectModifiedImageTimeStatement.template valueWithTransaction<Sqlite::TimeStamp>(name);
}
bool fetchHasImage(Utils::SmallStringView name) const override
{
return selectHasImageStatement.template valueWithTransaction<int>(name);
}
private:
class Initializer
{
@@ -296,6 +301,8 @@ public:
database};
mutable ReadStatement<1, 1> selectModifiedImageTimeStatement{
"SELECT mtime FROM images WHERE name=?1", database};
mutable ReadStatement<1, 1> selectHasImageStatement{
"SELECT image IS NOT NULL FROM images WHERE name=?1", database};
};
} // namespace QmlDesigner

View File

@@ -53,6 +53,7 @@ public:
virtual void storeIcon(Utils::SmallStringView name, Sqlite::TimeStamp newTimeStamp, const QIcon &icon) = 0;
virtual void walCheckpointFull() = 0;
virtual Sqlite::TimeStamp fetchModifiedImageTime(Utils::SmallStringView name) const = 0;
virtual bool fetchHasImage(Utils::SmallStringView name) const = 0;
protected:
~ImageCacheStorageInterface() = default;

View File

@@ -444,4 +444,31 @@ TEST_F(ImageCacheStorageSlowTest, FetchInvalidModifiedImageTimeForNoEntry)
ASSERT_THAT(timeStamp, Eq(Sqlite::TimeStamp{}));
}
TEST_F(ImageCacheStorageSlowTest, FetchHasImage)
{
storage.storeImage("/path/to/component", {123}, image1, smallImage1);
auto hasImage = storage.fetchHasImage("/path/to/component");
ASSERT_TRUE(hasImage);
}
TEST_F(ImageCacheStorageSlowTest, FetchHasImageForNullImage)
{
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{});
auto hasImage = storage.fetchHasImage("/path/to/component");
ASSERT_FALSE(hasImage);
}
TEST_F(ImageCacheStorageSlowTest, FetchHasImageForNoEntry)
{
storage.storeImage("/path/to/component", {123}, QImage{}, QImage{});
auto hasImage = storage.fetchHasImage("/path/to/component");
ASSERT_FALSE(hasImage);
}
} // namespace

View File

@@ -65,4 +65,5 @@ public:
fetchModifiedImageTime,
(Utils::SmallStringView name),
(const, override));
MOCK_METHOD(bool, fetchHasImage, (Utils::SmallStringView name), (const, override));
};

View File

@@ -98,6 +98,7 @@ public:
(int) );
MOCK_METHOD(Sqlite::TimeStamp, valueWithTransactionReturnsTimeStamp, (Utils::SmallStringView), ());
MOCK_METHOD(int, valueWithTransactionReturnsInt, (Utils::SmallStringView), ());
MOCK_METHOD(QmlDesigner::SourceContextId, valueReturnsSourceContextId, (Utils::SmallStringView), ());
MOCK_METHOD(QmlDesigner::SourceContextId, valueWithTransactionReturnsSourceContextId, (int), ());
@@ -206,6 +207,8 @@ public:
return valueWithTransactionReturnsSourceContextId(queryValues...);
else if constexpr (std::is_same_v<ResultType, Sqlite::TimeStamp>)
return valueWithTransactionReturnsTimeStamp(queryValues...);
else if constexpr (std::is_same_v<ResultType, int>)
return valueWithTransactionReturnsInt(queryValues...);
else
static_assert(!std::is_same_v<ResultType, ResultType>,
"SqliteReadStatementMock::value does not handle result type!");