diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-11-07 17:48:25 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-11-08 14:34:02 +0000 |
commit | 9b1e7e440a217f70d2cbd6df3582efcfc3e4d341 (patch) | |
tree | fc8b798801365115be4ef6d6907969ab8345eb3d | |
parent | 0e5c7f51fa88f8df0061ae6c8e43a7a0e143d552 (diff) | |
download | qt-creator-9b1e7e440a217f70d2cbd6df3582efcfc3e4d341.tar.gz |
Clang: Add BuildDependenciesStorage
Task-number: QTCREATORBUG-21378
Change-Id: Ibcb90239d240653b21f12a7b96a7775e5b0b4319
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
21 files changed, 242 insertions, 187 deletions
diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index 0b212c3a58..653397b317 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -95,7 +95,6 @@ public: table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); const Sqlite::Column &directoryIdColumn = table.addColumn("directoryId", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceNameColumn = table.addColumn("sourceName", Sqlite::ColumnType::Text); - table.addColumn("sourceType", Sqlite::ColumnType::Integer); table.addUniqueIndex({directoryIdColumn, sourceNameColumn}); table.initialize(database); @@ -135,6 +134,7 @@ public: table.setName("projectPartsSources"); const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + table.addColumn("sourceType", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, projectPartIdColumn}); table.addIndex({projectPartIdColumn}); @@ -163,6 +163,7 @@ public: table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); table.addColumn("size", Sqlite::ColumnType::Integer); table.addColumn("lastModified", Sqlite::ColumnType::Integer); + table.addColumn("buildDependencyTimeStamp", Sqlite::ColumnType::Integer); table.addColumn("isInPrecompiledHeader", Sqlite::ColumnType::Integer); table.initialize(database); } diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp index 5044f9e294..f10b6494d8 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp @@ -53,7 +53,8 @@ OutputContainer setUnion(InputContainer1 &&input1, BuildDependency BuildDependenciesProvider::create(const V2::ProjectPartContainer &projectPart) const { - SourceEntries includes = createSourceEntriesFromStorage(projectPart.sourcePathIds); + SourceEntries includes = createSourceEntriesFromStorage(projectPart.sourcePathIds, + projectPart.projectPartId); if (!m_modifiedTimeChecker.isUpToDate(includes)) return m_buildDependenciesGenerator.create(projectPart); @@ -89,12 +90,13 @@ UsedMacros BuildDependenciesProvider::createUsedMacrosFromStorage(const SourceEn } SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( - const FilePathIds &sourcePathIds) const + const FilePathIds &sourcePathIds, Utils::SmallStringView projectPartId) const { SourceEntries includes; for (FilePathId sourcePathId : sourcePathIds) { - SourceEntries entries = m_buildDependenciesStorage.fetchDependSources(sourcePathId); + SourceEntries entries = m_buildDependenciesStorage.fetchDependSources(sourcePathId, + projectPartId); SourceEntries mergedEntries = setUnion<SourceEntries>(includes, entries); includes = std::move(mergedEntries); diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h index c9aab60de4..00d4101b16 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h @@ -50,7 +50,8 @@ public: private: BuildDependency createBuildDependencyFromStorage(SourceEntries &&includes) const; UsedMacros createUsedMacrosFromStorage(const SourceEntries &includes) const; - SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds) const; + SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds, + Utils::SmallStringView projectPartId) const; private: BuildDependenciesStorageInterface &m_buildDependenciesStorage; diff --git a/src/tools/clangpchmanagerbackend/source/usedmacroandsourcestorage.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h index ed45465c68..ecb2d7cc7d 100644 --- a/src/tools/clangpchmanagerbackend/source/usedmacroandsourcestorage.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h @@ -25,7 +25,7 @@ #pragma once -#include "usedmacroandsourcestorageinterface.h" +#include "builddependenciesstorageinterface.h" #include <compilermacro.h> #include <sqliteexception.h> @@ -41,21 +41,31 @@ namespace ClangBackEnd { template<typename Database=Sqlite::Database> -class UsedMacroAndSourceStorage final : public UsedMacroAndSourceStorageInterface +class BuildDependenciesStorage final : public BuildDependenciesStorageInterface { using ReadStatement = typename Database::ReadStatement; using WriteStatement = typename Database::WriteStatement; public: - UsedMacroAndSourceStorage(Database &database) + BuildDependenciesStorage(Database &database) : m_transaction(database), m_database(database) { m_transaction.commit(); } + void updateSources(const SourceEntries &sourceEntries) override + { + for (const SourceEntry &entry : sourceEntries) { + m_updateBuildDependencyTimeStampStatement.write(static_cast<long long>(entry.lastModified), + entry.sourceId.filePathId); + m_updateSourceTypeStatement.write(static_cast<uchar>(entry.sourceType), + entry.sourceId.filePathId); + } + } + void insertFileStatuses(const FileStatuses &fileStatuses) override { - WriteStatement &statement = m_insertFileStatuses; + WriteStatement &statement = m_insertFileStatusesStatement; for (const FileStatus &fileStatus : fileStatuses) statement.write(fileStatus.filePathId.filePathId, @@ -94,6 +104,25 @@ public: m_deleteNewSourceDependenciesStatement.execute(); } + SourceEntries fetchDependSources(FilePathId sourceId, + Utils::SmallStringView projectPartName) const override + { + auto projectPartId = m_fetchProjectPartIdStatement.template value<int>(projectPartName); + + if (projectPartId) { + return m_fetchSourceDependenciesStatement.template values<SourceEntry, 3>( + 300, + sourceId.filePathId, + projectPartId.value()); + } + return {}; + } + + UsedMacros fetchUsedMacros(FilePathId sourceId) const override + { + return m_fetchUsedMacrosStatement.template values<UsedMacro, 2>(128, sourceId.filePathId); + } + static Utils::SmallString toJson(const Utils::SmallStringVector &strings) { QJsonDocument document; @@ -178,7 +207,7 @@ public: "INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)", m_database }; - WriteStatement m_insertFileStatuses{ + WriteStatement m_insertFileStatusesStatement{ "INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)", m_database }; @@ -194,5 +223,25 @@ public: "DELETE FROM newSourceDependencies", m_database }; + WriteStatement m_updateBuildDependencyTimeStampStatement{ + "UPDATE fileStatuses SET buildDependencyTimeStamp = ? WHERE sourceId == ?", + m_database + }; + WriteStatement m_updateSourceTypeStatement{ + "UPDATE projectPartsSources SET sourceType = ? WHERE sourceId == ?", + m_database + }; + mutable ReadStatement m_fetchSourceDependenciesStatement{ + "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, collectedDependencies WHERE sourceDependencies.sourceId == collectedDependencies.sourceId) SELECT sourceId, buildDependencyTimeStamp, sourceType FROM collectedDependencies NATURAL JOIN projectPartsSources NATURAL JOIN fileStatuses WHERE projectPartId = ?", + m_database + }; + mutable ReadStatement m_fetchProjectPartIdStatement{ + "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", + m_database + }; + mutable ReadStatement m_fetchUsedMacrosStatement{ + "SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ?", + m_database + }; }; } diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h index 265065b0d0..445afa052f 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h @@ -25,6 +25,8 @@ #pragma once +#include "sourceentry.h" + #include <builddependency.h> #include <filepathid.h> #include <filestatus.h> @@ -45,7 +47,7 @@ public: virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0; virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0; virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0; - virtual SourceEntries fetchDependSources(FilePathId sourceId) const = 0; + virtual SourceEntries fetchDependSources(FilePathId sourceId, Utils::SmallStringView projectPartId) const = 0; virtual UsedMacros fetchUsedMacros(FilePathId sourceId) const = 0; protected: diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index 4b5ac43a7e..abdebd22f0 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -24,8 +24,6 @@ HEADERS += \ $$PWD/taskschedulerinterface.h \ $$PWD/precompiledheaderstorage.h \ $$PWD/precompiledheaderstorageinterface.h \ - $$PWD/usedmacroandsourcestorageinterface.h \ - $$PWD/usedmacroandsourcestorage.h \ $$PWD/pchtaskgenerator.h \ $$PWD/pchtask.h \ $$PWD/builddependenciesproviderinterface.h \ @@ -34,7 +32,8 @@ HEADERS += \ $$PWD/builddependency.h \ $$PWD/modifiedtimecheckerinterface.h \ $$PWD/sourceentry.h \ - $$PWD/builddependenciesgeneratorinterface.h + $$PWD/builddependenciesgeneratorinterface.h \ + $$PWD/builddependenciesstorage.h !isEmpty(LIBTOOLING_LIBS) { SOURCES += \ diff --git a/src/tools/clangpchmanagerbackend/source/usedmacroandsourcestorageinterface.h b/src/tools/clangpchmanagerbackend/source/usedmacroandsourcestorageinterface.h deleted file mode 100644 index 2cbb9f84b5..0000000000 --- a/src/tools/clangpchmanagerbackend/source/usedmacroandsourcestorageinterface.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#pragma once - -#include "filestatus.h" -#include "sourcedependency.h" -#include "usedmacro.h" - -namespace ClangBackEnd { - -class UsedMacroAndSourceStorageInterface -{ -public: - UsedMacroAndSourceStorageInterface() = default; - UsedMacroAndSourceStorageInterface(const UsedMacroAndSourceStorageInterface &) = delete; - UsedMacroAndSourceStorageInterface &operator=(const UsedMacroAndSourceStorageInterface &) = delete; - - virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0; - virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0; - virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0; - virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0; - - -protected: - ~UsedMacroAndSourceStorageInterface() = default; -}; - -} // namespace ClangBackEnd - diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 02a2fd14a0..47a02e9fa3 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -58,7 +58,7 @@ private: SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue, SymbolStorageInterface &symbolStorage, - UsedMacroAndSourceStorageInterface &usedMacroAndSourceStorage, + BuildDependenciesStorageInterface &usedMacroAndSourceStorage, ClangPathWatcherInterface &pathWatcher, FilePathCachingInterface &filePathCache, FileStatusCache &fileStatusCache, diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h index 6e96e2fee5..d9070005ce 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.h @@ -28,7 +28,7 @@ #include "filestatuscache.h" #include "symbolindexertaskqueueinterface.h" #include "symbolstorageinterface.h" -#include "usedmacroandsourcestorageinterface.h" +#include "builddependenciesstorageinterface.h" #include "clangpathwatcher.h" #include <projectpartcontainerv2.h> @@ -43,7 +43,7 @@ class SymbolIndexer final : public ClangPathWatcherNotifier public: SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue, SymbolStorageInterface &symbolStorage, - UsedMacroAndSourceStorageInterface &usedMacroAndSourceStorage, + BuildDependenciesStorageInterface &usedMacroAndSourceStorage, ClangPathWatcherInterface &pathWatcher, FilePathCachingInterface &filePathCache, FileStatusCache &fileStatusCache, @@ -73,7 +73,7 @@ public: private: SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue; SymbolStorageInterface &m_symbolStorage; - UsedMacroAndSourceStorageInterface &m_usedMacroAndSourceStorage; + BuildDependenciesStorageInterface &m_usedMacroAndSourceStorage; ClangPathWatcherInterface &m_pathWatcher; FilePathCachingInterface &m_filePathCache; FileStatusCache &m_fileStatusCache; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h index 9b4950b176..8a8a156fb6 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h @@ -34,7 +34,7 @@ #include "taskscheduler.h" #include "symbolstorage.h" -#include <usedmacroandsourcestorage.h> +#include <builddependenciesstorage.h> #include <refactoringdatabaseinitializer.h> #include <filepathcachingfwd.h> @@ -74,7 +74,7 @@ private: class SymbolIndexing final : public SymbolIndexingInterface { public: - using UsedMacroAndSourceStorage = ClangBackEnd::UsedMacroAndSourceStorage<Sqlite::Database>; + using BuildDependenciesStorage = ClangBackEnd::BuildDependenciesStorage<Sqlite::Database>; using SymbolStorage = ClangBackEnd::SymbolStorage<Sqlite::Database>; SymbolIndexing(Sqlite::Database &database, FilePathCachingInterface &filePathCache, @@ -111,7 +111,7 @@ public: private: using SymbolIndexerTaskScheduler = TaskScheduler<SymbolsCollectorManager, SymbolIndexerTask::Callable>; FilePathCachingInterface &m_filePathCache; - UsedMacroAndSourceStorage m_usedMacroAndSourceStorage; + BuildDependenciesStorage m_usedMacroAndSourceStorage; SymbolStorage m_symbolStorage; ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache}; FileStatusCache m_fileStatusCache{m_filePathCache}; diff --git a/src/tools/clangrefactoringbackend/source/usedmacro.h b/src/tools/clangrefactoringbackend/source/usedmacro.h index 2c3588da7e..a7312b6376 100644 --- a/src/tools/clangrefactoringbackend/source/usedmacro.h +++ b/src/tools/clangrefactoringbackend/source/usedmacro.h @@ -42,6 +42,11 @@ public: filePathId(filePathId) {} + UsedMacro(Utils::SmallStringView macroName, int filePathId) + : macroName(macroName), + filePathId(filePathId) + {} + friend bool operator<(const UsedMacro &first, const UsedMacro &second) { return std::tie(first.filePathId, first.macroName) diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp index 4f27ecb8c4..24d4b10465 100644 --- a/tests/unit/unittest/builddependenciesprovider-test.cpp +++ b/tests/unit/unittest/builddependenciesprovider-test.cpp @@ -25,7 +25,7 @@ #include "googletest.h" -#include "mockbuilddependencystorage.h" +#include "mockbuilddependenciesstorage.h" #include "mockmodifiedtimechecker.h" #include "mockbuilddependenciesgenerator.h" @@ -83,7 +83,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime { InSequence s; - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).Times(0); @@ -92,9 +92,9 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3})).WillByDefault(Return(secondSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4})).WillByDefault(Return(thirdSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(secondSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(thirdSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); auto buildDependency = provider.create(projectPart2); @@ -106,7 +106,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi { InSequence s; - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)); @@ -115,7 +115,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false)); ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency)); @@ -128,7 +128,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta { InSequence s; - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})); EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})); @@ -139,7 +139,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillByDefault(Return(true)); ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})).WillByDefault(Return(firstUsedMacros)); ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})).WillByDefault(Return(secondUsedMacros)); diff --git a/tests/unit/unittest/usedmacroandsourcestorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp index 3db5423b54..05d3d70887 100644 --- a/tests/unit/unittest/usedmacroandsourcestorage-test.cpp +++ b/tests/unit/unittest/builddependenciesstorage-test.cpp @@ -29,7 +29,7 @@ #include "mocksqlitedatabase.h" #include <sqlitedatabase.h> -#include <usedmacroandsourcestorage.h> +#include <builddependenciesstorage.h> #include <utils/optional.h> @@ -38,12 +38,15 @@ namespace { using Utils::PathString; using ClangBackEnd::FilePathId; using ClangBackEnd::FilePathCachingInterface; +using ClangBackEnd::SourceEntries; +using ClangBackEnd::SourceType; +using ClangBackEnd::UsedMacro; using Sqlite::Database; using Sqlite::Table; -using Storage = ClangBackEnd::UsedMacroAndSourceStorage<MockSqliteDatabase>; +using Storage = ClangBackEnd::BuildDependenciesStorage<MockSqliteDatabase>; -class UsedMacroAndSourceStorage : public testing::Test +class BuildDependenciesStorage : public testing::Test { protected: NiceMock<MockSqliteDatabase> mockDatabase; @@ -52,15 +55,20 @@ protected: MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.m_syncNewUsedMacrosStatement; MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.m_deleteOutdatedUsedMacrosStatement; MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.m_deleteNewUsedMacrosTableStatement; - MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatuses; + MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatusesStatement; MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.m_insertIntoNewSourceDependenciesStatement; MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.m_syncNewSourceDependenciesStatement; MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.m_deleteOutdatedSourceDependenciesStatement; MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.m_deleteNewSourceDependenciesStatement; MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.m_getLowestLastModifiedTimeOfDependencies; + MockSqliteWriteStatement &updateBuildDependencyTimeStampStatement = storage.m_updateBuildDependencyTimeStampStatement; + MockSqliteWriteStatement &updateSourceTypeStatement = storage.m_updateSourceTypeStatement; + MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.m_fetchSourceDependenciesStatement; + MockSqliteReadStatement &fetchProjectPartIdStatement = storage.m_fetchProjectPartIdStatement; + MockSqliteReadStatement &fetchUsedMacrosStatement = storage.m_fetchUsedMacrosStatement; }; -TEST_F(UsedMacroAndSourceStorage, ConvertStringsToJson) +TEST_F(BuildDependenciesStorage, ConvertStringsToJson) { Utils::SmallStringVector strings{"foo", "bar", "foo"}; @@ -69,7 +77,7 @@ TEST_F(UsedMacroAndSourceStorage, ConvertStringsToJson) ASSERT_THAT(jsonText, Eq("[\"foo\",\"bar\",\"foo\"]")); } -TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateUsedMacros) +TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros) { InSequence sequence; @@ -82,7 +90,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateUsedMacros) storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}}); } -TEST_F(UsedMacroAndSourceStorage, InsertFileStatuses) +TEST_F(BuildDependenciesStorage, InsertFileStatuses) { EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(42), TypedEq<off_t>(1), TypedEq<time_t>(2), TypedEq<bool>(false))); EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(43), TypedEq<off_t>(4), TypedEq<time_t>(5), TypedEq<bool>(true))); @@ -90,7 +98,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertFileStatuses) storage.insertFileStatuses({{42, 1, 2, false}, {43, 4, 5, true}}); } -TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies) +TEST_F(BuildDependenciesStorage, InsertOrUpdateSourceDependencies) { InSequence sequence; @@ -103,7 +111,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies) storage.insertOrUpdateSourceDependencies({{42, 1}, {42, 2}}); } -TEST_F(UsedMacroAndSourceStorage, AddTablesInConstructor) +TEST_F(BuildDependenciesStorage, AddTablesInConstructor) { InSequence s; @@ -118,7 +126,7 @@ TEST_F(UsedMacroAndSourceStorage, AddTablesInConstructor) } -TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) +TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) { EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1))); @@ -127,7 +135,7 @@ TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTimeIfNoModificationTim ASSERT_THAT(lowestLastModified, Eq(0)); } -TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTime) +TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTime) { EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21))) .WillRepeatedly(Return(12)); @@ -137,7 +145,7 @@ TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTime) ASSERT_THAT(lowestLastModified, Eq(12)); } -TEST_F(UsedMacroAndSourceStorage, AddNewUsedMacroTable) +TEST_F(BuildDependenciesStorage, AddNewUsedMacroTable) { InSequence s; @@ -147,7 +155,7 @@ TEST_F(UsedMacroAndSourceStorage, AddNewUsedMacroTable) storage.createNewUsedMacrosTable(); } -TEST_F(UsedMacroAndSourceStorage, AddNewSourceDependenciesTable) +TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable) { InSequence s; @@ -157,5 +165,71 @@ TEST_F(UsedMacroAndSourceStorage, AddNewSourceDependenciesTable) storage.createNewSourceDependenciesTable(); } +TEST_F(BuildDependenciesStorage, UpdateSources) +{ + InSequence s; + SourceEntries entries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; + + EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1))); + EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(1), TypedEq<int>(1))); + EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(20), TypedEq<int>(2))); + EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(2), TypedEq<int>(2))); + + storage.updateSources(entries); +} + +TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithNonExistingProjectPartDontFetchesSourceDependencies) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, _, _)).Times(0); + + storage.fetchDependSources(22, "test"); +} + +TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithExistingProjectPartFetchesSourceDependencies) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)); + + storage.fetchDependSources(22, "test"); +} + +TEST_F(BuildDependenciesStorage, FetchDependSourcesWithNonExistingProjectPartReturnsEmptySourceEntries) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{})); + + auto entries = storage.fetchDependSources(22, "test"); + + ASSERT_THAT(entries, IsEmpty()); +} + +TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries) +{ + SourceEntries sourceEntries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries)); + + auto entries = storage.fetchDependSources(22, "test"); + + ASSERT_THAT(entries, sourceEntries); +} + +TEST_F(BuildDependenciesStorage, CallsFetchUsedMacros) +{ + EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)); + + storage.fetchUsedMacros(22); +} + +TEST_F(BuildDependenciesStorage, FetchUsedMacros) +{ + ClangBackEnd::UsedMacros result{UsedMacro{"YI", 1}, UsedMacro{"ER", 2}}; + EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)).WillOnce(Return(result)); + + auto usedMacros = storage.fetchUsedMacros(22); + + ASSERT_THAT(usedMacros, result); +} + } diff --git a/tests/unit/unittest/mockbuilddependencystorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h index 9a043880d8..a654579a83 100644 --- a/tests/unit/unittest/mockbuilddependencystorage.h +++ b/tests/unit/unittest/mockbuilddependenciesstorage.h @@ -42,8 +42,8 @@ public: void (const ClangBackEnd::SourceDependencies &sourceDependencies)); MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, long long (ClangBackEnd::FilePathId sourceId)); - MOCK_CONST_METHOD1(fetchDependSources, - ClangBackEnd::SourceEntries (ClangBackEnd::FilePathId sourceId)); + MOCK_CONST_METHOD2(fetchDependSources, + ClangBackEnd::SourceEntries (ClangBackEnd::FilePathId sourceId, Utils::SmallStringView)); MOCK_CONST_METHOD1(fetchUsedMacros, ClangBackEnd::UsedMacros (ClangBackEnd::FilePathId sourceId)); }; diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp index a002fea177..66406f09fa 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.cpp +++ b/tests/unit/unittest/mocksqlitereadstatement.cpp @@ -82,6 +82,15 @@ MockSqliteReadStatement::values<Symbol, 3>( } template <> +UsedMacros +MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>( + std::size_t reserveSize, + const int &sourceId) +{ + return valuesReturnUsedMacros(reserveSize, sourceId); +} + +template <> std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize) { return valuesReturnStdVectorDirectory(reserveSize); diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h index 2d2b3320c4..e5926d2d17 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.h +++ b/tests/unit/unittest/mocksqlitereadstatement.h @@ -34,6 +34,7 @@ #include <projectpartartefact.h> #include <projectpartpch.h> #include <sourceentry.h> +#include <usedmacro.h> #include <symbol.h> #include <cpptools/usages.h> @@ -53,6 +54,7 @@ using ClangRefactoring::SourceLocations; namespace Sources = ClangBackEnd::Sources; using ClangRefactoring::Symbol; using ClangRefactoring::Symbols; +using ClangBackEnd::UsedMacros; class MockSqliteDatabase; @@ -79,6 +81,9 @@ public: MOCK_METHOD3(valuesReturnSourceEntries, SourceEntries(std::size_t, int, int)); + MOCK_METHOD2(valuesReturnUsedMacros, + UsedMacros (std::size_t, int)); + MOCK_METHOD1(valueReturnInt32, Utils::optional<int>(Utils::SmallStringView)); @@ -185,6 +190,12 @@ MockSqliteReadStatement::values<Symbol, 3>( const Utils::SmallStringView&); template <> +UsedMacros +MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>( + std::size_t reserveSize, + const int &sourceId); + +template <> std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize); template <> diff --git a/tests/unit/unittest/mockusedmacroandsourcestorage.h b/tests/unit/unittest/mockusedmacroandsourcestorage.h deleted file mode 100644 index 6fba12c26c..0000000000 --- a/tests/unit/unittest/mockusedmacroandsourcestorage.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#pragma once - -#include "googletest.h" - -#include "mocksqlitedatabase.h" - -#include <usedmacroandsourcestorageinterface.h> - -class MockUsedMacroAndSourceStorage : public ClangBackEnd::UsedMacroAndSourceStorageInterface -{ -public: - MOCK_METHOD1(insertOrUpdateUsedMacros, - void (const ClangBackEnd::UsedMacros &usedMacros)); - MOCK_METHOD1(insertFileStatuses, - void (const ClangBackEnd::FileStatuses &fileStatuses)); - MOCK_METHOD1(insertOrUpdateSourceDependencies, - void (const ClangBackEnd::SourceDependencies &sourceDependencies)); - MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, - long long (ClangBackEnd::FilePathId sourceId)); -}; diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index 6b9257facf..449c722d86 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -68,7 +68,7 @@ TEST_F(RefactoringDatabaseInitializer, AddSourcesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); initializer.createSourcesTable(); @@ -98,7 +98,7 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); @@ -120,7 +120,7 @@ TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); initializer.createFileStatusesTable(); } @@ -155,19 +155,19 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, compilerMacros TEXT, includeSearchPaths TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))); diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 8b5e3e91c1..fef72b47e4 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -29,7 +29,7 @@ #include "mocksymbolstorage.h" #include "mockfilepathcaching.h" #include "mocksqlitetransactionbackend.h" -#include "mockusedmacroandsourcestorage.h" +#include "mockbuilddependenciesstorage.h" #include <filepathcaching.h> #include <filestatuscache.h> @@ -112,7 +112,7 @@ protected: ON_CALL(mockCollector, fileStatuses()).WillByDefault(ReturnRef(fileStatus)); ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies)); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(A<FilePathId>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1)); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1)); mockCollector.setIsUsed(false); @@ -197,7 +197,7 @@ protected: ClangBackEnd::ProjectPartPch projectPartPch{"/path/to/pch", 4}; NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend; NiceMock<MockSymbolStorage> mockSymbolStorage; - NiceMock<MockUsedMacroAndSourceStorage> mockUsedMacroAndSourceStorage; + NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage; NiceMock<MockClangPathWatcher> mockPathWatcher; ClangBackEnd::FileStatusCache fileStatusCache{filePathCache}; ClangBackEnd::GeneratedFiles generatedFiles; @@ -206,7 +206,7 @@ protected: SymbolIndexerTaskQueue indexerQueue{indexerScheduler}; ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, - mockUsedMacroAndSourceStorage, + mockBuildDependenciesStorage, mockPathWatcher, filePathCache, fileStatusCache, @@ -345,7 +345,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArti TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))) + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -353,7 +353,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))) + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -361,7 +361,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses) TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateSourceDependencies) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -383,16 +383,16 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillOnce(Return(nullArtefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(12)); EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(12))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(main1PathId, projectPart1.arguments)); EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.updateProjectParts({projectPart1}); @@ -406,16 +406,16 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(-1)); EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1)); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), Eq(projectPart1.arguments))); EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(artefact.projectPartId), Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.updateProjectParts({projectPart1}); @@ -425,7 +425,7 @@ TEST_F(SymbolIndexer, CallSetNotifier) { EXPECT_CALL(mockPathWatcher, setNotifier(_)); - ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockUsedMacroAndSourceStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend}; + ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockBuildDependenciesStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend}; } TEST_F(SymbolIndexer, PathChangedCallsFetchProjectPartArtefactInStorage) @@ -449,9 +449,9 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.pathsChanged({sourceFileIds[0]}); @@ -470,9 +470,9 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath) EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); indexer.pathsChanged({sourceFileIds[0]}); @@ -548,21 +548,21 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent) TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame) { InSequence s; - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch())); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); EXPECT_CALL(mockCollector, collectSymbols()).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); indexer.updateProjectPart(std::move(projectPart1)); @@ -600,7 +600,7 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent) TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame) { ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -611,7 +611,7 @@ TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds) { indexer.pathsChanged({main1PathId}); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(0)); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -623,7 +623,7 @@ TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds) { indexer.pathsChanged({main1PathId}); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -636,7 +636,7 @@ TEST_F(SymbolIndexer, OutdatedFilesAreParsedInUpdateProjectParts) indexer.pathsChanged({main1PathId}); indexerScheduler.syncTasks(); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(0)); EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), _)); @@ -649,7 +649,7 @@ TEST_F(SymbolIndexer, UpToDateFilesAreNotParsedInUpdateProjectParts) indexer.pathsChanged({main1PathId}); indexerScheduler.syncTasks(); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); diff --git a/tests/unit/unittest/symbolquery-test.cpp b/tests/unit/unittest/symbolquery-test.cpp index c13b96fabe..a2aeb41d08 100644 --- a/tests/unit/unittest/symbolquery-test.cpp +++ b/tests/unit/unittest/symbolquery-test.cpp @@ -75,8 +75,8 @@ class SymbolQuerySlowTest : public testing::Test protected: void SetUp() override { - database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\", 1)"); - database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)"); + database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\")"); + database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\")"); database.execute("INSERT INTO directories VALUES (1, \"/path/to\")"); database.execute("INSERT INTO locations VALUES (1, 2, 3, 1, 1)"); database.execute("INSERT INTO locations VALUES (1, 4, 6, 2, 3)"); diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index de9c647099..c8ecdb66e5 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -103,10 +103,10 @@ SOURCES += \ processormanager-test.cpp \ taskscheduler-test.cpp \ compileroptionsbuilder-test.cpp \ - usedmacroandsourcestorage-test.cpp \ pchtaskgenerator-test.cpp \ compilationdatabaseutils-test.cpp \ - builddependenciesprovider-test.cpp + builddependenciesprovider-test.cpp \ + builddependenciesstorage-test.cpp !isEmpty(LIBCLANG_LIBS) { SOURCES += \ @@ -250,11 +250,10 @@ HEADERS += \ mockprocessor.h \ mockprocessormanager.h \ mocktaskscheduler.h \ - mockusedmacroandsourcestorage.h \ mockbuilddependenciesprovider.h \ - mockbuilddependencystorage.h \ mockmodifiedtimechecker.h \ - mockbuilddependenciesgenerator.h + mockbuilddependenciesgenerator.h \ + mockbuilddependenciesstorage.h !isEmpty(LIBCLANG_LIBS) { HEADERS += \ |