diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index fc31ec84a72..e953f5e9629 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -182,6 +182,10 @@ public: "DELETE FROM newUsedMacros", database }; + WriteStatement insertFileInformations{ + "INSERT OR REPLACE INTO fileInformations(sourceId, size, lastModified) VALUES (?,?,?)", + database + }; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index ed54e5c5f1e..fa22cc2eb2d 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -108,6 +108,16 @@ public: insertStatement.write(projectPartId, sourceFilePathId.filePathId); } + void insertFileInformations(const FileInformations &fileInformations) + { + WriteStatement &statement = m_statementFactory.insertFileInformations; + + for (const FileInformation &fileInformation : fileInformations) + statement.write(fileInformation.filePathId.filePathId, + fileInformation.size, + fileInformation.lastModified); + } + static Utils::SmallString toJson(const Utils::SmallStringVector &strings) { QJsonDocument document; diff --git a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h index 870290d6ece..7cc1a89200c 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h @@ -25,6 +25,7 @@ #pragma once +#include "fileinformation.h" #include "projectpartentry.h" #include "sourcelocationentry.h" #include "symbolentry.h" @@ -50,6 +51,7 @@ public: virtual void updateProjectPartSources(Utils::SmallStringView projectPartName, const FilePathIds &sourceFilePathIds) = 0; virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0; + virtual void insertFileInformations(const FileInformations &fileInformations) = 0; }; } // namespace ClangBackEnd diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h index b7802ee237d..736a18ba7ef 100644 --- a/tests/unit/unittest/mocksqlitewritestatement.h +++ b/tests/unit/unittest/mocksqlitewritestatement.h @@ -73,5 +73,8 @@ public: MOCK_METHOD2(write, void (int, int)); + MOCK_METHOD3(write, + void (uint, uint, uint)); + Utils::SmallString sqlStatement; }; diff --git a/tests/unit/unittest/mocksymbolstorage.h b/tests/unit/unittest/mocksymbolstorage.h index 4cb7bb918d6..dc6ef3377f9 100644 --- a/tests/unit/unittest/mocksymbolstorage.h +++ b/tests/unit/unittest/mocksymbolstorage.h @@ -46,4 +46,6 @@ public: const ClangBackEnd::FilePathIds &sourceFilePathIds)); MOCK_METHOD1(insertOrUpdateUsedMacros, void (const ClangBackEnd::UsedMacros &usedMacros)); + MOCK_METHOD1(insertFileInformations, + void (const ClangBackEnd::FileInformations &fileInformations)); }; diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp index d0b832e00d6..b798db3a230 100644 --- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp @@ -213,4 +213,10 @@ TEST_F(StorageSqliteStatementFactory, DeleteAllInNewUnusedMacros) ASSERT_THAT(factory.deleteNewUsedMacrosTableStatement.sqlStatement, Eq("DELETE FROM newUsedMacros")); } + +TEST_F(StorageSqliteStatementFactory, InsertFileInformations) +{ + ASSERT_THAT(factory.insertFileInformations.sqlStatement, + Eq("INSERT OR REPLACE INTO fileInformations(sourceId, size, lastModified) VALUES (?,?,?)")); +} } diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp index 87a3b211f14..15ec994a054 100644 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ b/tests/unit/unittest/symbolstorage-test.cpp @@ -78,6 +78,7 @@ protected: MockSqliteWriteStatement &syncNewUsedMacrosStatement = statementFactory.syncNewUsedMacrosStatement; MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = statementFactory.deleteOutdatedUsedMacrosStatement; MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = statementFactory.deleteNewUsedMacrosTableStatement; + MockSqliteWriteStatement &insertFileInformations = statementFactory.insertFileInformations; SymbolEntries symbolEntries{{1, {"functionUSR", "function"}}, {2, {"function2USR", "function2"}}}; SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SymbolType::Declaration}, @@ -148,7 +149,7 @@ TEST_F(SymbolStorage, AddSymbolsAndSourceLocationsCallsWrite) { InSequence sequence; - EXPECT_CALL(insertSymbolsToNewSymbolsStatement, write(An(), _, _)).Times(2); + EXPECT_CALL(insertSymbolsToNewSymbolsStatement, write(An(), An(), _)).Times(2); EXPECT_CALL(insertLocationsToNewLocationsStatement, write(1, 42, 23, 3)); EXPECT_CALL(insertLocationsToNewLocationsStatement, write(2, 7, 11, 4)); EXPECT_CALL(addNewSymbolsToSymbolsStatement, execute()); @@ -230,5 +231,13 @@ TEST_F(SymbolStorage, InsertOrUpdateUsedMacros) storage.insertOrUpdateUsedMacros({{"FOO", {1, 42}}, {"BAR", {1, 43}}}); } +TEST_F(SymbolStorage, InsertFileInformations) +{ + EXPECT_CALL(insertFileInformations, write(TypedEq(42), TypedEq(1), TypedEq(2))); + EXPECT_CALL(insertFileInformations, write(TypedEq(43), TypedEq(4), TypedEq(5))); + + storage.insertFileInformations({{{1, 42}, 1, 2}, {{1, 43}, 4, 5}}); +} + }