forked from qt-creator/qt-creator
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:
@@ -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{};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -65,4 +65,5 @@ public:
|
||||
fetchModifiedImageTime,
|
||||
(Utils::SmallStringView name),
|
||||
(const, override));
|
||||
MOCK_METHOD(bool, fetchHasImage, (Utils::SmallStringView name), (const, override));
|
||||
};
|
||||
|
||||
@@ -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!");
|
||||
|
||||
Reference in New Issue
Block a user