aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/unittest')
-rw-r--r--tests/unit/unittest/builddependenciesprovider-test.cpp51
-rw-r--r--tests/unit/unittest/builddependenciesstorage-test.cpp102
-rw-r--r--tests/unit/unittest/builddependencycollector-test.cpp264
-rw-r--r--tests/unit/unittest/clangformat-test.cpp220
-rw-r--r--tests/unit/unittest/commandlinebuilder-test.cpp15
-rw-r--r--tests/unit/unittest/data/highlightingmarks.cpp9
-rw-r--r--tests/unit/unittest/filepathstorage-test.cpp26
-rw-r--r--tests/unit/unittest/gtest-creator-printing.cpp38
-rw-r--r--tests/unit/unittest/gtest-creator-printing.h2
-rw-r--r--tests/unit/unittest/mockbuilddependenciesstorage.h13
-rw-r--r--tests/unit/unittest/mockprojectparts.h4
-rw-r--r--tests/unit/unittest/mocksqlitedatabase.h4
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.cpp7
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.h7
-rw-r--r--tests/unit/unittest/mocksqlitewritestatement.h18
-rw-r--r--tests/unit/unittest/mocksymbolstorage.h3
-rw-r--r--tests/unit/unittest/pchcreator-test.cpp60
-rw-r--r--tests/unit/unittest/pchmanagerserver-test.cpp35
-rw-r--r--tests/unit/unittest/pchtaskgenerator-test.cpp4
-rw-r--r--tests/unit/unittest/pchtasksmerger-test.cpp4
-rw-r--r--tests/unit/unittest/projectparts-test.cpp4
-rw-r--r--tests/unit/unittest/refactoringdatabaseinitializer-test.cpp27
-rw-r--r--tests/unit/unittest/symbolindexer-test.cpp63
-rw-r--r--tests/unit/unittest/symbolscollector-test.cpp2
-rw-r--r--tests/unit/unittest/symbolstorage-test.cpp14
-rw-r--r--tests/unit/unittest/tokenprocessor-test.cpp18
-rw-r--r--tests/unit/unittest/usedmacrocollector-test.cpp2
-rw-r--r--tests/unit/unittest/usedmacrofilter-test.cpp43
28 files changed, 716 insertions, 343 deletions
diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp
index 2a5372c55dc..b69965cc56f 100644
--- a/tests/unit/unittest/builddependenciesprovider-test.cpp
+++ b/tests/unit/unittest/builddependenciesprovider-test.cpp
@@ -99,9 +99,7 @@ protected:
UsedMacros thirdUsedMacros{{"SAN", 10}};
FilePathIds sourceFiles{1, 3, 8};
ClangBackEnd::SourceDependencies sourceDependencies{{1, 3}, {1, 8}};
- ClangBackEnd::FileStatuses fileStatuses{{1, 21, 12, false},
- {3, 21, 12, false},
- {8, 21, 12, false}};
+ ClangBackEnd::FileStatuses fileStatuses{{1, 21, 12}, {3, 21, 12}, {8, 21, 12}};
BuildDependency buildDependency{
secondSources,
secondUsedMacros,
@@ -117,7 +115,9 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
EXPECT_CALL(mockBuildDependenciesStorage,
- fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ .WillOnce(Return(11));
+ EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11))
.WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true));
@@ -132,15 +132,24 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime
TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage)
{
- 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(mockBuildDependenciesStorage,
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart2")))
+ .WillByDefault(Return(11));
+ ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).WillByDefault(Return(firstSources));
+ ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, 11)).WillByDefault(Return(secondSources));
+ ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, 11)).WillByDefault(Return(thirdSources));
ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true));
auto buildDependency = provider.create(projectPart2);
- ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(2), HasSourceId(3), HasSourceId(4), HasSourceId(8), HasSourceId(10)));
+ ASSERT_THAT(buildDependency.sources,
+ ElementsAre(HasSourceId(1),
+ HasSourceId(2),
+ HasSourceId(3),
+ HasSourceId(4),
+ HasSourceId(8),
+ HasSourceId(10)));
}
TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTimeStampsAreNotUpToDate)
@@ -149,15 +158,17 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
EXPECT_CALL(mockBuildDependenciesStorage,
- fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ .WillOnce(Return(11));
+ EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<int>(11)))
.WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false));
EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1))
.WillOnce(Return(buildDependency));
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
- EXPECT_CALL(mockBuildDependenciesStorage, updateSources(Eq(secondSources)));
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatuses)));
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSources(Eq(secondSources), 11));
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatuses)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(secondUsedMacros)));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
@@ -167,13 +178,16 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi
TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator)
{
- ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources));
+ ON_CALL(mockBuildDependenciesStorage,
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ .WillByDefault(Return(11));
+ ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).WillByDefault(Return(firstSources));
ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false));
ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency));
auto buildDependency = provider.create(projectPart1);
- ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8)));
+ ASSERT_THAT(buildDependency.sources, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8)));
}
TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeStampsAreUpToDate)
@@ -181,7 +195,11 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta
InSequence s;
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
- EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources));
+ EXPECT_CALL(mockBuildDependenciesStorage,
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ .WillOnce(Return(11));
+ EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11))
+ .WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true));
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
@@ -195,7 +213,10 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta
TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate)
{
- ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources));
+ ON_CALL(mockBuildDependenciesStorage,
+ fetchProjectPartId(TypedEq<Utils::SmallStringView>("ProjectPart1")))
+ .WillByDefault(Return(11));
+ ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).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/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp
index d69f8b868a2..30db7ea408a 100644
--- a/tests/unit/unittest/builddependenciesstorage-test.cpp
+++ b/tests/unit/unittest/builddependenciesstorage-test.cpp
@@ -55,17 +55,20 @@ protected:
MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.syncNewUsedMacrosStatement;
MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement;
MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement;
- MockSqliteWriteStatement &insertFileStatuses = storage.insertFileStatusesStatement;
+ MockSqliteWriteStatement &insertOrUpdateFileStatusesStatement = storage.insertOrUpdateFileStatusesStatement;
MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.insertIntoNewSourceDependenciesStatement;
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.syncNewSourceDependenciesStatement;
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.deleteOutdatedSourceDependenciesStatement;
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.deleteNewSourceDependenciesStatement;
MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.getLowestLastModifiedTimeOfDependencies;
- MockSqliteWriteStatement &updateBuildDependencyTimeStampStatement = storage.updateBuildDependencyTimeStampStatement;
- MockSqliteWriteStatement &updateSourceTypeStatement = storage.updateSourceTypeStatement;
+ MockSqliteWriteStatement &insertOrUpdateProjectPartsSourcesStatement = storage.insertOrUpdateProjectPartsSourcesStatement;
MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement;
MockSqliteReadStatement &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement;
MockSqliteReadStatement &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement;
+ MockSqliteWriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement;
+ MockSqliteWriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement;
+ MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartNameStatement
+ = storage.deleteAllProjectPartsSourcesWithProjectPartNameStatement;
};
TEST_F(BuildDependenciesStorage, ConvertStringsToJson)
@@ -81,8 +84,10 @@ TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros)
{
InSequence sequence;
- EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(42u), TypedEq<Utils::SmallStringView>("FOO")));
- EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(43u), TypedEq<Utils::SmallStringView>("BAR")));
+ EXPECT_CALL(insertIntoNewUsedMacrosStatement,
+ write(TypedEq<int>(42), TypedEq<Utils::SmallStringView>("FOO")));
+ EXPECT_CALL(insertIntoNewUsedMacrosStatement,
+ write(TypedEq<int>(43), TypedEq<Utils::SmallStringView>("BAR")));
EXPECT_CALL(syncNewUsedMacrosStatement, execute());
EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute());
EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute());
@@ -90,12 +95,14 @@ TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros)
storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}});
}
-TEST_F(BuildDependenciesStorage, InsertFileStatuses)
+TEST_F(BuildDependenciesStorage, InsertOrUpdateFileStatuses)
{
- 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)));
+ EXPECT_CALL(insertOrUpdateFileStatusesStatement,
+ write(TypedEq<int>(42), TypedEq<off_t>(1), TypedEq<time_t>(2)));
+ EXPECT_CALL(insertOrUpdateFileStatusesStatement,
+ write(TypedEq<int>(43), TypedEq<off_t>(4), TypedEq<time_t>(5)));
- storage.insertFileStatuses({{42, 1, 2, false}, {43, 4, 5, true}});
+ storage.insertOrUpdateFileStatuses({{42, 1, 2}, {43, 4, 5}});
}
TEST_F(BuildDependenciesStorage, InsertOrUpdateSourceDependencies)
@@ -125,7 +132,6 @@ TEST_F(BuildDependenciesStorage, AddTablesInConstructor)
Storage storage{mockDatabase};
}
-
TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists)
{
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1)));
@@ -168,48 +174,82 @@ TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable)
TEST_F(BuildDependenciesStorage, UpdateSources)
{
InSequence s;
- SourceEntries entries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
+ SourceEntries entries{{1, SourceType::TopProjectInclude, 10, ClangBackEnd::HasMissingIncludes::Yes},
+ {2, SourceType::TopSystemInclude, 20}};
+
+ EXPECT_CALL(deleteAllProjectPartsSourcesWithProjectPartNameStatement, write(TypedEq<int>(22)));
+ EXPECT_CALL(insertOrUpdateProjectPartsSourcesStatement,
+ write(TypedEq<int>(1), TypedEq<int>(22), TypedEq<uchar>(0), TypedEq<uchar>(1)));
+ EXPECT_CALL(insertOrUpdateProjectPartsSourcesStatement,
+ write(TypedEq<int>(2), TypedEq<int>(22), TypedEq<uchar>(1), TypedEq<uchar>(0)));
+
+ storage.insertOrUpdateSources(entries, 22);
+}
+
+TEST_F(BuildDependenciesStorage, UpdatePchCreationTimeStamp)
+{
+ InSequence s;
- EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1)));
- EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(0), TypedEq<int>(1)));
- EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(20), TypedEq<int>(2)));
- EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(1), TypedEq<int>(2)));
+ EXPECT_CALL(mockDatabase, immediateBegin());
+ EXPECT_CALL(updatePchCreationTimeStampStatement,
+ write(TypedEq<long long>(101), TypedEq<Utils::SmallStringView>("project1")));
+ EXPECT_CALL(mockDatabase, commit());
- storage.updateSources(entries);
+ storage.updatePchCreationTimeStamp(101, "project1");
}
-TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithNonExistingProjectPartDontFetchesSourceDependencies)
+TEST_F(BuildDependenciesStorage, CallsFetchProjectIdWithNonExistingProjectPartName)
{
- EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{}));
- EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, _, _)).Times(0);
+ EXPECT_CALL(fetchProjectPartIdStatement,
+ valueReturnInt32(TypedEq<Utils::SmallStringView>("test")));
+ EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test")));
- storage.fetchDependSources(22, "test");
+ storage.fetchProjectPartId("test");
}
-TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithExistingProjectPartFetchesSourceDependencies)
+TEST_F(BuildDependenciesStorage, CallsFetchProjectIdWithExistingProjectPart)
{
- EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20}));
- EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20));
+ EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test")))
+ .WillOnce(Return(Utils::optional<int>{20}));
+ EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test"))).Times(0);
- storage.fetchDependSources(22, "test");
+ storage.fetchProjectPartId("test");
}
-TEST_F(BuildDependenciesStorage, FetchDependSourcesWithNonExistingProjectPartReturnsEmptySourceEntries)
+TEST_F(BuildDependenciesStorage, FetchProjectIdWithNonExistingProjectPartName)
{
- EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{}));
+ ON_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test")))
+ .WillByDefault(Return(Utils::optional<int>{}));
+ ON_CALL(mockDatabase, lastInsertedRowId()).WillByDefault(Return(21));
- auto entries = storage.fetchDependSources(22, "test");
+ int id = storage.fetchProjectPartId("test");
+
+ ASSERT_THAT(id, 21);
+}
+
+TEST_F(BuildDependenciesStorage, FetchProjectIdWithExistingProjectPartName)
+{
+ ON_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test")))
+ .WillByDefault(Return(Utils::optional<int>{20}));
+
+ int id = storage.fetchProjectPartId("test");
+
+ ASSERT_THAT(id, 20);
+}
+
+TEST_F(BuildDependenciesStorage, CallsFetchDependSources)
+{
+ EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20));
- ASSERT_THAT(entries, IsEmpty());
+ storage.fetchDependSources(22, 20);
}
-TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries)
+TEST_F(BuildDependenciesStorage, FetchDependSources)
{
SourceEntries sourceEntries{{1, SourceType::TopProjectInclude, 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");
+ auto entries = storage.fetchDependSources(22, 20);
ASSERT_THAT(entries, sourceEntries);
}
diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp
index aa46fc77bb1..58506662322 100644
--- a/tests/unit/unittest/builddependencycollector-test.cpp
+++ b/tests/unit/unittest/builddependencycollector-test.cpp
@@ -47,19 +47,37 @@ using ClangBackEnd::BuildDependency;
using ClangBackEnd::FilePathId;
using ClangBackEnd::FilePathIds;
using ClangBackEnd::FilePathView;
+using ClangBackEnd::HasMissingIncludes;
using ClangBackEnd::SourceDependency;
using ClangBackEnd::SourceType;
using ClangBackEnd::UsedMacro;
namespace {
-MATCHER_P2(HasInclude, sourceId, sourceType,
+MATCHER_P2(HasSource,
+ sourceId,
+ sourceType,
std::string(negation ? "hasn't " : "has ")
- + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1)))
+ + PrintToString(ClangBackEnd::SourceEntry(
+ sourceId, sourceType, -1, ClangBackEnd::HasMissingIncludes::No)))
{
const ClangBackEnd::SourceEntry &entry = arg;
- return entry.sourceId == sourceId && entry.sourceType == sourceType;
+ return entry.sourceId == sourceId && entry.sourceType == sourceType
+ && entry.hasMissingIncludes == ClangBackEnd::HasMissingIncludes::No;
+}
+
+MATCHER_P3(HasSource,
+ sourceId,
+ sourceType,
+ hasMissingIncludes,
+ std::string(negation ? "hasn't " : "has ")
+ + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1, hasMissingIncludes)))
+{
+ const ClangBackEnd::SourceEntry &entry = arg;
+
+ return entry.sourceId == sourceId && entry.sourceType == sourceType
+ && entry.hasMissingIncludes == hasMissingIncludes;
}
class BuildDependencyCollector : public ::testing::Test
@@ -107,50 +125,50 @@ protected:
ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const
{
- return {id(filePath), fileSize(filePath), lastModified(filePath), false};
+ return {id(filePath), fileSize(filePath), lastModified(filePath)};
}
- static FilePathIds filteredIncludes(const ClangBackEnd::SourceEntries &includes,
- ClangBackEnd::SourceType includeType)
+ static FilePathIds filteredSources(const ClangBackEnd::SourceEntries &sources,
+ ClangBackEnd::SourceType sourceType)
{
- FilePathIds filteredIncludes;
+ FilePathIds filteredSources;
- for (const ClangBackEnd::SourceEntry &include : includes) {
- if (include.sourceType == includeType)
- filteredIncludes.push_back(include.sourceId);
+ for (const ClangBackEnd::SourceEntry &source : sources) {
+ if (source.sourceType == sourceType)
+ filteredSources.push_back(source.sourceId);
}
- return filteredIncludes;
+ return filteredSources;
}
- static FilePathIds topIncludes(const ClangBackEnd::SourceEntries &includes)
+ static FilePathIds topSources(const ClangBackEnd::SourceEntries &sources)
{
- return filteredIncludes(includes, ClangBackEnd::SourceType::TopProjectInclude);
+ return filteredSources(sources, ClangBackEnd::SourceType::TopProjectInclude);
}
- static FilePathIds systemTopIncludes(const ClangBackEnd::SourceEntries &includes)
+ static FilePathIds systemTopSources(const ClangBackEnd::SourceEntries &sources)
{
- return filteredIncludes(includes, ClangBackEnd::SourceType::TopSystemInclude);
+ return filteredSources(sources, ClangBackEnd::SourceType::TopSystemInclude);
}
- static FilePathIds userIncludes(const ClangBackEnd::SourceEntries &includes)
+ static FilePathIds userSources(const ClangBackEnd::SourceEntries &sources)
{
- return filteredIncludes(includes, ClangBackEnd::SourceType::UserInclude);
+ return filteredSources(sources, ClangBackEnd::SourceType::UserInclude);
}
- static FilePathIds projectPartIncludes(const ClangBackEnd::SourceEntries &includes)
+ static FilePathIds projectPartSources(const ClangBackEnd::SourceEntries &sources)
{
- return filteredIncludes(includes, ClangBackEnd::SourceType::ProjectInclude);
+ return filteredSources(sources, ClangBackEnd::SourceType::ProjectInclude);
}
- static FilePathIds allIncludes(const ClangBackEnd::SourceEntries &includes)
+ static FilePathIds sources(const ClangBackEnd::SourceEntries &sources)
{
- FilePathIds filteredIncludes;
+ FilePathIds filteredSources;
- for (const ClangBackEnd::SourceEntry &include : includes)
- filteredIncludes.push_back(include.sourceId);
+ for (const ClangBackEnd::SourceEntry &source : sources)
+ filteredSources.push_back(source.sourceId);
- return filteredIncludes;
+ return filteredSources;
}
protected:
@@ -173,26 +191,31 @@ TEST_F(BuildDependencyCollector, IncludesExternalHeader)
{
collector.collect();
- ASSERT_THAT(allIncludes(collector.includeIds()),
+ ASSERT_THAT(sources(collector.sourceEntries()),
AllOf(Contains(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")),
Contains(id(TESTDATA_DIR "/builddependencycollector/external/external2.h")),
- Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h")),
- Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))));
+ Contains(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h")),
+ Contains(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h"))));
}
TEST_F(BuildDependencyCollector, InternalHeaderAreUserIncludes)
{
collector.collect();
- ASSERT_THAT(userIncludes(collector.includeIds()), Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h")));
+ ASSERT_THAT(userSources(collector.sourceEntries()),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h")));
}
TEST_F(BuildDependencyCollector, NoDuplicate)
{
collector.collect();
- ASSERT_THAT(allIncludes(collector.includeIds()),
+ ASSERT_THAT(sources(collector.sourceEntries()),
UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"),
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
@@ -206,15 +229,18 @@ TEST_F(BuildDependencyCollector, IncludesAreSorted)
{
collector.collect();
- ASSERT_THAT(allIncludes(collector.includeIds()),
- ElementsAre(
- id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
- id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external2.h")));
+ ASSERT_THAT(sources(collector.sourceEntries()),
+ ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h")));
}
TEST_F(BuildDependencyCollector, If)
@@ -223,8 +249,9 @@ TEST_F(BuildDependencyCollector, If)
emptyCollector.collect();
- ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
- ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h")));
+ ASSERT_THAT(sources(emptyCollector.sourceEntries()),
+ ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/true.h")));
}
TEST_F(BuildDependencyCollector, LocalPath)
@@ -233,8 +260,9 @@ TEST_F(BuildDependencyCollector, LocalPath)
emptyCollector.collect();
- ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
+ ASSERT_THAT(sources(emptyCollector.sourceEntries()),
UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"),
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
@@ -250,20 +278,23 @@ TEST_F(BuildDependencyCollector, IgnoreMissingFile)
emptyCollector.collect();
- ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
- UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")));
+ ASSERT_THAT(sources(emptyCollector.sourceEntries()),
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")));
}
TEST_F(BuildDependencyCollector, IncludesOnlyTopExternalHeader)
{
collector.collect();
- ASSERT_THAT(topIncludes(collector.includeIds()),
- UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
+ ASSERT_THAT(
+ topSources(collector.sourceEntries()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
}
TEST_F(BuildDependencyCollector, TopIncludeInIfMacro)
@@ -273,7 +304,7 @@ TEST_F(BuildDependencyCollector, TopIncludeInIfMacro)
emptyCollector.collect();
- ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
+ ASSERT_THAT(topSources(emptyCollector.sourceEntries()),
ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h")));
}
@@ -283,10 +314,11 @@ TEST_F(BuildDependencyCollector, TopIncludeWithLocalPath)
emptyCollector.collect();
- ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
- UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
+ ASSERT_THAT(
+ topSources(emptyCollector.sourceEntries()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
}
TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile)
@@ -296,8 +328,9 @@ TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile)
emptyCollector.collect();
- ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
- UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")));
+ ASSERT_THAT(topSources(emptyCollector.sourceEntries()),
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h")));
}
TEST_F(BuildDependencyCollector, SourceFiles)
@@ -620,10 +653,37 @@ TEST_F(BuildDependencyCollector, MissingInclude)
emptyCollector.collect();
- ASSERT_THAT(emptyCollector.includeIds(),
- ElementsAre(
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
- SourceType::UserInclude)));
+ ASSERT_THAT(
+ emptyCollector.sourceEntries(),
+ UnorderedElementsAre(
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main5.cpp"),
+ SourceType::Source,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missinginclude2.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/project/indirect_missinginclude.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/project/indirect_missinginclude3.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/project/indirect_missinginclude4.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missinginclude3.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/project/indirect_missinginclude2.h"),
+ SourceType::ProjectInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ SourceType::UserInclude,
+ HasMissingIncludes::No)));
}
@@ -643,10 +703,12 @@ TEST_F(BuildDependencyCollector, GeneratedFile)
emptyCollector.collect();
- ASSERT_THAT(emptyCollector.includeIds(),
- ElementsAre(
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"),
- SourceType::UserInclude)));
+ ASSERT_THAT(
+ emptyCollector.sourceEntries(),
+ ElementsAre(HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main6.cpp"),
+ SourceType::Source),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"),
+ SourceType::UserInclude)));
}
TEST_F(BuildDependencyCollector, CreateFakeFileContent)
@@ -715,41 +777,43 @@ TEST_F(BuildDependencyCollector, Create)
fileStatus(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
fileStatus(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
ClangBackEnd::FileStatus(
- id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"),
- 12,
- 0,
- false))),
- Field(&BuildDependency::includes,
- UnorderedElementsAre(
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
- SourceType::UserInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
- SourceType::UserInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
- SourceType::TopProjectInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- SourceType::TopProjectInclude),
- HasInclude(id(TESTDATA_DIR
- "/builddependencycollector/external/indirect_external.h"),
- SourceType::ProjectInclude),
- HasInclude(id(TESTDATA_DIR
- "/builddependencycollector/external/indirect_external2.h"),
- SourceType::ProjectInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
- SourceType::TopProjectInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
- SourceType::TopSystemInclude),
- HasInclude(id(TESTDATA_DIR
- "/builddependencycollector/system/indirect_system.h"),
- SourceType::SystemInclude),
- HasInclude(id(TESTDATA_DIR
- "/builddependencycollector/system/indirect_system2.h"),
- SourceType::SystemInclude),
- HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
- SourceType::UserInclude),
- HasInclude(id(TESTDATA_DIR
- "/builddependencycollector/project/generated_file.h"),
- SourceType::TopProjectInclude))),
+ id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), 12, 0))),
+ Field(
+ &BuildDependency::sources,
+ UnorderedElementsAre(
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ SourceType::Source,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
+ SourceType::UserInclude,
+ HasMissingIncludes::Yes),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ SourceType::UserInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ SourceType::UserInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ SourceType::TopProjectInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ SourceType::TopProjectInclude),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h"),
+ SourceType::ProjectInclude),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h"),
+ SourceType::ProjectInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ SourceType::TopProjectInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ SourceType::TopSystemInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
+ SourceType::SystemInclude),
+ HasSource(id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system2.h"),
+ SourceType::SystemInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
+ SourceType::UserInclude),
+ HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"),
+ SourceType::UserInclude))),
Field(&BuildDependency::usedMacros,
UnorderedElementsAre(
UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
@@ -843,6 +907,6 @@ TEST_F(BuildDependencyCollector, Clear)
auto buildDependency = collector.create(projectPart);
- ASSERT_THAT(buildDependency.includes, IsEmpty());
+ ASSERT_THAT(buildDependency.sources, IsEmpty());
}
} // namespace
diff --git a/tests/unit/unittest/clangformat-test.cpp b/tests/unit/unittest/clangformat-test.cpp
index 115ecaf763e..ad2c8bf3e36 100644
--- a/tests/unit/unittest/clangformat-test.cpp
+++ b/tests/unit/unittest/clangformat-test.cpp
@@ -32,9 +32,8 @@
namespace TextEditor {
class TabSettings
-{
-};
-}
+{};
+} // namespace TextEditor
namespace {
@@ -58,10 +57,7 @@ public:
: ClangFormatIndenter(doc)
{}
- bool formatWhileTyping() const override
- {
- return true;
- }
+ bool formatWhileTyping() const override { return true; }
};
class ClangFormat : public ::testing::Test
@@ -76,6 +72,7 @@ protected:
void insertLines(const std::vector<QString> &lines)
{
+ doc.clear();
cursor.setPosition(0);
for (size_t lineNumber = 1; lineNumber <= lines.size(); ++lineNumber) {
if (lineNumber > 1)
@@ -104,6 +101,7 @@ protected:
QTextCursor cursor{&doc};
};
+// clang-format off
TEST_F(ClangFormat, IndentBasicFile)
{
insertLines({"int main()",
@@ -121,14 +119,14 @@ TEST_F(ClangFormat, IndentBasicFile)
TEST_F(ClangFormat, IndentEmptyLine)
{
- insertLines({"int main",
+ insertLines({"int main()",
"{",
"",
"}"});
indenter.indent(cursor, QChar::Null, TextEditor::TabSettings());
- ASSERT_THAT(documentLines(), ElementsAre("int main",
+ ASSERT_THAT(documentLines(), ElementsAre("int main()",
"{",
" ",
"}"));
@@ -365,7 +363,148 @@ TEST_F(ClangFormat, IndentEmptyLineAndKeepPreviousEmptyLines)
"}"));
}
-TEST_F(ClangFormat, IndentFunctionBodyAndFormatBeforeIt)
+TEST_F(ClangFormat, IndentOnElectricCharacterButNotRemoveEmptyLinesBefore)
+{
+ insertLines({"{",
+ " ",
+ " ",
+ "if ()",
+ "}"});
+
+ indenter.indentBlock(doc.findBlockByNumber(3), '(', TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("{",
+ " ",
+ " ",
+ " if ()",
+ "}"));
+}
+
+TEST_F(ClangFormat, IndentAfterExtraSpaceInpreviousLine)
+{
+ insertLines({"if (a ",
+ "&& b)"});
+
+ indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (a",
+ " && b)"));
+}
+
+TEST_F(ClangFormat, IndentEmptyLineInsideParantheses)
+{
+ insertLines({"if (a ",
+ "",
+ " && b)"});
+
+ indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (a",
+ " ",
+ " && b)"));
+}
+
+TEST_F(ClangFormat, EmptyLineInInitializerList)
+{
+ insertLines({"Bar foo{a,",
+ "",
+ "};"});
+
+ indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("Bar foo{a,",
+ " ",
+ "};"));
+}
+
+TEST_F(ClangFormat, IndentClosingBraceAfterComma)
+{
+ insertLines({"Bar foo{a,",
+ "}"});
+
+ indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("Bar foo{a,",
+ " }"));
+}
+
+TEST_F(ClangFormat, DoNotIndentClosingBraceAfterSemicolon)
+{
+ insertLines({"{",
+ " a;"
+ "}"});
+
+ indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("{",
+ " a;"
+ "}"));
+}
+
+TEST_F(ClangFormat, SameIndentAfterSecondNewLineAfterIf)
+{
+ insertLines({"if (a)",
+ " ",
+ ""});
+
+ indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (a)",
+ " ",
+ " "));
+}
+
+TEST_F(ClangFormat, IndentAfterNewLineInsideIfWithFunctionCall)
+{
+ insertLines({"if (foo()",
+ ")"});
+
+ indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (foo()",
+ " )"));
+}
+
+TEST_F(ClangFormat, SameIndentAfterSecondNewLineInsideIfWithFunctionCall)
+{
+ insertLines({"if (foo()",
+ " ",
+ ")"});
+
+ indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (foo()",
+ " ",
+ " )"));
+}
+
+TEST_F(ClangFormat, SameIndentAfterSecondNonEmptyNewLineInsideIfWithFunctionCall)
+{
+ insertLines({"if (foo()",
+ " ",
+ "bar)"});
+
+ indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("if (foo()",
+ " ",
+ " bar)"));
+}
+
+TEST_F(ClangFormat, SameIndentsOnNewLinesAfterComments)
+{
+ insertLines({"namespace {} //comment",
+ "",
+ ""});
+
+ indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("namespace {} //comment",
+ "",
+ ""));
+}
+
+TEST_F(ClangFormat, IndentFunctionBodyButNotFormatBeforeIt)
{
insertLines({"int foo(int a, int b,",
" int c, int d",
@@ -375,8 +514,9 @@ TEST_F(ClangFormat, IndentFunctionBodyAndFormatBeforeIt)
extendedIndenter.indentBlock(doc.findBlockByNumber(3), QChar::Null, TextEditor::TabSettings());
- ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b, int c, int d)",
- "{",
+ ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b,",
+ " int c, int d",
+ " ) {",
" ",
"}"));
}
@@ -404,13 +544,11 @@ TEST_F(ClangFormat, ReformatToEmptyFunction)
insertLines({"int foo(int a, int b, int c, int d)",
"{",
" ",
- "}",
- ""});
+ "}"});
- extendedIndenter.indentBlock(doc.findBlockByNumber(4), QChar::Null, TextEditor::TabSettings());
+ extendedIndenter.indentBlock(doc.findBlockByNumber(3), '}', TextEditor::TabSettings());
- ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b, int c, int d) {}",
- ""));
+ ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b, int c, int d) {}"));
}
TEST_F(ClangFormat, ReformatToNonEmptyFunction)
@@ -421,13 +559,12 @@ TEST_F(ClangFormat, ReformatToNonEmptyFunction)
extendedIndenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
- ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b)",
- "{",
+ ASSERT_THAT(documentLines(), ElementsAre("int foo(int a, int b) {",
" ",
"}"));
}
-TEST_F(ClangFormat, IndentIfBodyAndFormatBeforeIt)
+TEST_F(ClangFormat, IndentClosingScopeAndFormatBeforeIt)
{
insertLines({"if(a && b",
" &&c && d",
@@ -435,10 +572,9 @@ TEST_F(ClangFormat, IndentIfBodyAndFormatBeforeIt)
"",
"}"});
- extendedIndenter.indentBlock(doc.findBlockByNumber(3), QChar::Null, TextEditor::TabSettings());
+ extendedIndenter.indentBlock(doc.findBlockByNumber(4), '}', TextEditor::TabSettings());
ASSERT_THAT(documentLines(), ElementsAre("if (a && b && c && d) {",
- " ",
"}"));
}
@@ -496,7 +632,7 @@ TEST_F(ClangFormat, IndentAndFormatCompleteStatementOnClosingScope)
"}"));
}
-TEST_F(ClangFormat, IndentAndFormatWithEmptyLines)
+TEST_F(ClangFormat, OnlyIndentClosingParenthesis)
{
insertLines({"foo(a,",
" ",
@@ -505,7 +641,25 @@ TEST_F(ClangFormat, IndentAndFormatWithEmptyLines)
extendedIndenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
ASSERT_THAT(documentLines(), ElementsAre("foo(a,",
- "",
+ " ",
+ " )"));
+}
+
+TEST_F(ClangFormat, EquallyIndentInsideParenthesis)
+{
+ insertLines({"if (a",
+ ")"});
+ extendedIndenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
+ auto linesAfterFirstLineBreak = documentLines();
+ insertLines({"if (a",
+ " ",
+ ")"});
+ extendedIndenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(linesAfterFirstLineBreak, ElementsAre("if (a",
+ " )"));
+ ASSERT_THAT(documentLines(), ElementsAre("if (a",
+ " ",
" )"));
}
@@ -623,4 +777,22 @@ TEST_F(ClangFormat, FormatTemplateparameters)
ASSERT_THAT(documentLines(), ElementsAre("using Alias = Template<A, B, C>"));
}
+TEST_F(ClangFormat, SortIncludes)
+{
+ insertLines({"#include \"b.h\"",
+ "#include \"a.h\"",
+ "",
+ "#include <bb.h>",
+ "#include <aa.h>"});
+
+ indenter.format({{1, 5}});
+
+ ASSERT_THAT(documentLines(), ElementsAre("#include \"a.h\"",
+ "#include \"b.h\"",
+ "",
+ "#include <aa.h>",
+ "#include <bb.h>"));
}
+// clang-format on
+
+} // namespace
diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp
index a75c8d8a35c..328b832b9c4 100644
--- a/tests/unit/unittest/commandlinebuilder-test.cpp
+++ b/tests/unit/unittest/commandlinebuilder-test.cpp
@@ -139,6 +139,7 @@ TYPED_TEST(CommandLineBuilder, CHeader)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang",
+ "-w",
"-DNOMINMAX",
"-x",
"c-header",
@@ -156,6 +157,7 @@ TYPED_TEST(CommandLineBuilder, CSource)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang",
+ "-w",
"-DNOMINMAX",
"-x",
"c",
@@ -174,6 +176,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCHeader)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang",
+ "-w",
"-DNOMINMAX",
"-x",
"objective-c-header",
@@ -192,6 +195,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCSource)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang",
+ "-w",
"-DNOMINMAX",
"-x",
"objective-c",
@@ -209,6 +213,7 @@ TYPED_TEST(CommandLineBuilder, CppHeader)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -227,6 +232,7 @@ TYPED_TEST(CommandLineBuilder, CppSource)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++",
@@ -246,6 +252,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppHeader)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"objective-c++-header",
@@ -265,6 +272,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppSource)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"objective-c++",
@@ -498,6 +506,7 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -525,6 +534,7 @@ TYPED_TEST(CommandLineBuilder, EmptySourceFile)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -539,6 +549,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -555,6 +566,7 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -574,6 +586,7 @@ TYPED_TEST(CommandLineBuilder, OutputFile)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -596,6 +609,7 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -619,6 +633,7 @@ TYPED_TEST(CommandLineBuilder, CompilerMacros)
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp
index e1a48903ca3..a703e89a11b 100644
--- a/tests/unit/unittest/data/highlightingmarks.cpp
+++ b/tests/unit/unittest/data/highlightingmarks.cpp
@@ -686,3 +686,12 @@ class NonConstParameterConstructor
NonConstParameterConstructor bar(foo);
}
};
+
+class StaticMembersAccess
+{
+protected:
+ static int protectedValue;
+
+private:
+ static int privateValue;
+};
diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp
index be689b44f32..c08c84e9132 100644
--- a/tests/unit/unittest/filepathstorage-test.cpp
+++ b/tests/unit/unittest/filepathstorage-test.cpp
@@ -189,7 +189,8 @@ TEST_F(FilePathStorage, CallWriteForWriteDirectory)
TEST_F(FilePathStorage, CallWriteForWriteSource)
{
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("unknownfile.h")));
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h")));
storage.writeSourceId(5, "unknownfile.h");
}
@@ -280,7 +281,8 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntry)
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("unknownfile.h")));
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("unknownfile.h")));
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
storage.fetchSourceId(5, "unknownfile.h");
@@ -347,7 +349,8 @@ TEST_F(FilePathStorage, RestartFetchSourceIdIfTheDatabaseIsBusyInBeginBecauseThe
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
@@ -360,13 +363,16 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheDatabase
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
- .WillOnce(Throw(Sqlite::StatementIsBusy("busy")));;
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
+ .WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
+ ;
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
@@ -379,12 +385,14 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheIndexIsC
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
- EXPECT_CALL(insertIntoSources, write(5, TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
- .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy")));;
+ EXPECT_CALL(insertIntoSources,
+ write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
+ .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
- valueReturnInt32(5, Eq("otherunknownfile.h")));
+ valueReturnInt32(5, Eq("otherunknownfile.h")))
+ .WillOnce(Return(Utils::optional<int>(42)));
EXPECT_CALL(mockDatabase, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp
index 8427e79af8a..2befb52417c 100644
--- a/tests/unit/unittest/gtest-creator-printing.cpp
+++ b/tests/unit/unittest/gtest-creator-printing.cpp
@@ -45,7 +45,6 @@
#include <fulltokeninfo.h>
#include <includesearchpath.h>
#include <nativefilepath.h>
-#include <pchcreatorincludes.h>
#include <pchtask.h>
#include <precompiledheadersupdatedmessage.h>
#include <projectpartartefact.h>
@@ -1138,6 +1137,7 @@ const char* progressTypeToString(ClangBackEnd::ProgressType type)
case ProgressType::Invalid: return "Invalid";
case ProgressType::PrecompiledHeader: return "PrecompiledHeader";
case ProgressType::Indexing: return "Indexing";
+ case ProgressType::DependencyCreation: return "DependencyCreation";
}
return nullptr;
@@ -1150,11 +1150,6 @@ std::ostream &operator<<(std::ostream &out, const ProgressMessage &message)
<< message.total << ")";
}
-std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes)
-{
- return out << "(" << includes.includeIds << ", " << includes.topIncludeIds << ", "
- << includes.topSystemIncludeIds << ")";
-}
std::ostream &operator<<(std::ostream &out, const PchTask &task)
{
return out << "(" << task.projectPartIds << ", " << task.includes << ", " << task.compilerMacros
@@ -1171,11 +1166,11 @@ std::ostream &operator<<(std::ostream &out, const PchTaskSet &taskSet)
std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency)
{
return out << "(\n"
- << "includes: " << dependency.includes << ",\n"
- << "usedMacros: " << dependency.usedMacros << ",\n"
- << "fileStatuses: " << dependency.fileStatuses << ",\n"
- << "sourceFiles: " << dependency.sourceFiles << ",\n"
- << "sourceDependencies: " << dependency.sourceDependencies << ",\n"
+ << "includes: " << dependency.sources << ",\n"
+ << "usedMacros: " << dependency.usedMacros << ",\n"
+ << "fileStatuses: " << dependency.fileStatuses << ",\n"
+ << "sourceFiles: " << dependency.sourceFiles << ",\n"
+ << "sourceDependencies: " << dependency.sourceDependencies << ",\n"
<< ")";
}
@@ -1184,7 +1179,7 @@ std::ostream &operator<<(std::ostream &out, const SlotUsage &slotUsage)
return out << "(" << slotUsage.free << ", " << slotUsage.used << ")";
}
-const char *sourceTypeString(SourceType sourceType)
+const char *typeToString(SourceType sourceType)
{
using ClangBackEnd::SymbolTag;
@@ -1199,6 +1194,22 @@ const char *sourceTypeString(SourceType sourceType)
return "ProjectInclude";
case SourceType::UserInclude:
return "UserInclude";
+ case SourceType::Source:
+ return "Source";
+ }
+
+ return "";
+}
+
+const char *typeToString(HasMissingIncludes hasMissingIncludes)
+{
+ using ClangBackEnd::SymbolTag;
+
+ switch (hasMissingIncludes) {
+ case HasMissingIncludes::No:
+ return "HasMissingIncludes::No";
+ case HasMissingIncludes::Yes:
+ return "HasMissingIncludes::Yes";
}
return "";
@@ -1206,7 +1217,8 @@ const char *sourceTypeString(SourceType sourceType)
std::ostream &operator<<(std::ostream &out, const SourceEntry &entry)
{
- return out << "(" << entry.sourceId << ", " << sourceTypeString(entry.sourceType) << ")";
+ return out << "(" << entry.sourceId << ", " << typeToString(entry.sourceType) << ", "
+ << typeToString(entry.hasMissingIncludes) << ")";
}
const char *typeToString(IncludeSearchPathType type)
diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h
index cb63fd56bb9..75eae281ae4 100644
--- a/tests/unit/unittest/gtest-creator-printing.h
+++ b/tests/unit/unittest/gtest-creator-printing.h
@@ -186,7 +186,6 @@ class SuspendResumeJobsEntry;
class ReferencesResult;
class SymbolIndexerTask;
class ProgressMessage;
-class PchCreatorIncludes;
class PchTask;
class PchTaskSet;
class BuildDependency;
@@ -277,7 +276,6 @@ std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry);
std::ostream &operator<<(std::ostream &os, const ReferencesResult &value);
std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task);
std::ostream &operator<<(std::ostream &out, const ProgressMessage &message);
-std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes);
std::ostream &operator<<(std::ostream &out, const PchTask &task);
std::ostream &operator<<(std::ostream &out, const PchTaskSet &taskSet);
std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency);
diff --git a/tests/unit/unittest/mockbuilddependenciesstorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h
index a654579a831..739c13cf8da 100644
--- a/tests/unit/unittest/mockbuilddependenciesstorage.h
+++ b/tests/unit/unittest/mockbuilddependenciesstorage.h
@@ -32,19 +32,22 @@
class MockBuildDependenciesStorage : public ClangBackEnd::BuildDependenciesStorageInterface
{
public:
- MOCK_METHOD1(updateSources,
- void (const ClangBackEnd::SourceEntries &sources));
+ MOCK_METHOD2(insertOrUpdateSources,
+ void(const ClangBackEnd::SourceEntries &sources, int projectPartId));
MOCK_METHOD1(insertOrUpdateUsedMacros,
void (const ClangBackEnd::UsedMacros &usedMacros));
- MOCK_METHOD1(insertFileStatuses,
- void (const ClangBackEnd::FileStatuses &fileStatuses));
+ MOCK_METHOD1(insertOrUpdateFileStatuses, void(const ClangBackEnd::FileStatuses &fileStatuses));
MOCK_METHOD1(insertOrUpdateSourceDependencies,
void (const ClangBackEnd::SourceDependencies &sourceDependencies));
MOCK_CONST_METHOD1(fetchLowestLastModifiedTime,
long long (ClangBackEnd::FilePathId sourceId));
MOCK_CONST_METHOD2(fetchDependSources,
- ClangBackEnd::SourceEntries (ClangBackEnd::FilePathId sourceId, Utils::SmallStringView));
+ ClangBackEnd::SourceEntries(ClangBackEnd::FilePathId sourceId,
+ int projectPartId));
MOCK_CONST_METHOD1(fetchUsedMacros,
ClangBackEnd::UsedMacros (ClangBackEnd::FilePathId sourceId));
+ MOCK_METHOD1(fetchProjectPartId, int(Utils::SmallStringView projectPartName));
+ MOCK_METHOD2(updatePchCreationTimeStamp,
+ void(long long pchCreationTimeStamp, Utils::SmallStringView projectPartName));
};
diff --git a/tests/unit/unittest/mockprojectparts.h b/tests/unit/unittest/mockprojectparts.h
index 7c7a2daf4aa..15ec0238468 100644
--- a/tests/unit/unittest/mockprojectparts.h
+++ b/tests/unit/unittest/mockprojectparts.h
@@ -27,9 +27,9 @@
#include "googletest.h"
-#include <projectpartsinterface.h>
+#include <projectpartsmanagerinterface.h>
-class MockProjectParts : public ClangBackEnd::ProjectPartsInterface
+class MockProjectPartsManager : public ClangBackEnd::ProjectPartsManagerInterface
{
public:
MOCK_METHOD1(update,
diff --git a/tests/unit/unittest/mocksqlitedatabase.h b/tests/unit/unittest/mocksqlitedatabase.h
index 0b890e01f0a..5bef2ba8c51 100644
--- a/tests/unit/unittest/mocksqlitedatabase.h
+++ b/tests/unit/unittest/mocksqlitedatabase.h
@@ -39,8 +39,8 @@
class MockSqliteDatabase : public MockSqliteTransactionBackend
{
public:
- using ReadStatement = MockSqliteReadStatement;
- using WriteStatement = MockSqliteWriteStatement;
+ using ReadStatement = NiceMock<MockSqliteReadStatement>;
+ using WriteStatement = NiceMock<MockSqliteWriteStatement>;
MOCK_METHOD1(execute,
void (Utils::SmallStringView sqlStatement));
diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp
index b9cecd4d1aa..04d2a07c142 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.cpp
+++ b/tests/unit/unittest/mocksqlitereadstatement.cpp
@@ -186,9 +186,10 @@ MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, con
return valueReturnSourceLocation(symbolId, locationKind);
}
-template <>
-SourceEntries
-MockSqliteReadStatement::values<SourceEntry, 3>(std::size_t reserveSize, const int &filePathId, const int &projectPartId)
+template<>
+SourceEntries MockSqliteReadStatement::values<SourceEntry, 4>(std::size_t reserveSize,
+ const int &filePathId,
+ const int &projectPartId)
{
return valuesReturnSourceEntries(reserveSize, filePathId, projectPartId);
}
diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h
index 43c88eb0441..5c6fbdef772 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.h
+++ b/tests/unit/unittest/mocksqlitereadstatement.h
@@ -255,9 +255,10 @@ template <>
Utils::optional<SourceLocation>
MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind);
-template <>
-SourceEntries
-MockSqliteReadStatement::values<SourceEntry, 3>(std::size_t reserveSize, const int&, const int&);
+template<>
+SourceEntries MockSqliteReadStatement::values<SourceEntry, 4>(std::size_t reserveSize,
+ const int &,
+ const int &);
template <>
Utils::optional<Sources::SourceNameAndDirectoryId>
diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h
index ee7df6362f7..4b369845aa6 100644
--- a/tests/unit/unittest/mocksqlitewritestatement.h
+++ b/tests/unit/unittest/mocksqlitewritestatement.h
@@ -42,8 +42,7 @@ public:
MOCK_METHOD0(execute,
void ());
- MOCK_METHOD2(bind,
- void (int index, Utils::SmallStringView value));
+ MOCK_METHOD2(bind, void(int, Utils::SmallStringView));
MOCK_METHOD2(bindValues,
void (Utils::SmallStringView, Utils::SmallStringView));
@@ -60,11 +59,11 @@ public:
MOCK_METHOD5(write,
void (long long, int, int, int, int));
- MOCK_METHOD2(write,
- void (uint, Utils::SmallStringView));
+ MOCK_METHOD2(write, void(uint, Utils::SmallStringView));
- MOCK_METHOD2(write,
- void (Utils::SmallStringView, Utils::SmallStringView));
+ MOCK_METHOD2(write, void(int, Utils::SmallStringView));
+
+ MOCK_METHOD2(write, void(Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD3(write,
void (Utils::SmallStringView, Utils::SmallStringView, long long));
@@ -103,17 +102,16 @@ public:
MOCK_METHOD3(write,
void (uint, uint, uint));
- MOCK_METHOD4(write,
- void (int, off_t, time_t, bool));
+ MOCK_METHOD3(write, void(int, off_t, time_t));
MOCK_METHOD2(write,
void (uint, uint));
MOCK_METHOD2(write,
void (uchar, int));
-
+ MOCK_METHOD4(write, void(int, int, uchar, uchar));
MOCK_METHOD2(write,
void (long long, int));
-
+ MOCK_METHOD2(write, void(long long, Utils::SmallStringView));
Utils::SmallString sqlStatement;
};
diff --git a/tests/unit/unittest/mocksymbolstorage.h b/tests/unit/unittest/mocksymbolstorage.h
index 325e18b1c97..c4b55fcfe41 100644
--- a/tests/unit/unittest/mocksymbolstorage.h
+++ b/tests/unit/unittest/mocksymbolstorage.h
@@ -46,9 +46,6 @@ public:
Utils::Language language,
Utils::LanguageVersion languageVersion,
Utils::LanguageExtension languageExtension));
- MOCK_METHOD2(updateProjectPartSources,
- void(int projectPartId,
- const ClangBackEnd::FilePathIds &sourceFilePathIds));
MOCK_CONST_METHOD1(fetchProjectPartArtefact,
Utils::optional<ClangBackEnd::ProjectPartArtefact> (ClangBackEnd::FilePathId sourceId));
MOCK_CONST_METHOD1(fetchProjectPartArtefact,
diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp
index d891a089871..3dbafc8aa08 100644
--- a/tests/unit/unittest/pchcreator-test.cpp
+++ b/tests/unit/unittest/pchcreator-test.cpp
@@ -28,6 +28,7 @@
#include "fakeprocess.h"
#include "filesystem-utilities.h"
+#include "mockbuilddependenciesstorage.h"
#include "mockclangpathwatcher.h"
#include "mockpchmanagerclient.h"
#include "testenvironment.h"
@@ -97,16 +98,22 @@ protected:
FileContainer generatedFile{generatedFilePath.clone(), "#pragma once", {}};
NiceMock<MockPchManagerClient> mockPchManagerClient;
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
- ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
+ NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage;
+ ClangBackEnd::PchCreator creator{environment,
+ database,
+ mockPchManagerClient,
+ mockClangPathWatcher,
+ mockBuildDependenciesStorage};
PchTask pchTask1{
"project1",
{id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external2.h")},
- {id(generatedFilePath),
- id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ {id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external2.h")},
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(generatedFilePath),
+ id(main2Path)},
{},
{},
{},
@@ -134,6 +141,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
ASSERT_THAT(arguments,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -158,6 +166,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch)
ASSERT_THAT(arguments,
ElementsAre("clang++",
+ "-w",
"-DNOMINMAX",
"-x",
"c++-header",
@@ -190,25 +199,24 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient)
creator.doInMainThreadAfterFinished();
}
-TEST_F(PchCreatorVerySlowTest, AllIncludesAreWatchedAfterSucess)
+TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterSucess)
{
creator.generatePch(std::move(pchTask1));
- EXPECT_CALL(
- mockClangPathWatcher,
- updateIdPaths(ElementsAre(
- AllOf(Field(&ClangBackEnd::IdPaths::id, "project1"),
- Field(&ClangBackEnd::IdPaths::filePathIds,
- UnorderedElementsAre(
- id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
- id(TESTDATA_DIR "/builddependencycollector/external/external2.h")))))));
+ EXPECT_CALL(mockClangPathWatcher,
+ updateIdPaths(ElementsAre(AllOf(
+ Field(&ClangBackEnd::IdPaths::id, "project1"),
+ Field(&ClangBackEnd::IdPaths::filePathIds,
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp")))))));
creator.doInMainThreadAfterFinished();
}
-
-TEST_F(PchCreatorVerySlowTest, AllIncludesAreNotWatchedAfterFail)
+TEST_F(PchCreatorVerySlowTest, SourcesAreNotWatchedAfterFail)
{
pchTask1.systemIncludeSearchPaths = {};
pchTask1.projectIncludeSearchPaths = {};
@@ -222,6 +230,15 @@ TEST_F(PchCreatorVerySlowTest, AllIncludesAreNotWatchedAfterFail)
creator.doInMainThreadAfterFinished();
}
+TEST_F(PchCreatorVerySlowTest, PchCreationTimeStampsAreUpdated)
+{
+ creator.generatePch(std::move(pchTask1));
+
+ EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(_, Eq("project1")));
+
+ creator.doInMainThreadAfterFinished();
+}
+
TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForPchTask)
{
creator.generatePch(std::move(pchTask1));
@@ -241,6 +258,15 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchCleared)
ASSERT_THAT(creator.projectPartPch(), ClangBackEnd::ProjectPartPch{});
}
+TEST_F(PchCreatorVerySlowTest, SourcesCleared)
+{
+ creator.generatePch(std::move(pchTask1));
+
+ creator.clear();
+
+ ASSERT_THAT(creator.sources(), IsEmpty());
+}
+
TEST_F(PchCreatorVerySlowTest, ClangToolCleared)
{
creator.generatePch(std::move(pchTask1));
@@ -266,7 +292,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask
ASSERT_THAT(creator.projectPartPch(),
AllOf(Field(&ProjectPartPch::projectPartId, Eq("faultyProjectPart")),
Field(&ProjectPartPch::pchPath, IsEmpty()),
- Field(&ProjectPartPch::lastModified, Eq(-1))));
+ Field(&ProjectPartPch::lastModified, Gt(0))));
}
TEST_F(PchCreatorVerySlowTest, GeneratedFile)
diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp
index 5a2ca172c00..370667edc84 100644
--- a/tests/unit/unittest/pchmanagerserver-test.cpp
+++ b/tests/unit/unittest/pchmanagerserver-test.cpp
@@ -55,7 +55,7 @@ class PchManagerServer : public ::testing::Test
{
server.setClient(&mockPchManagerClient);
- ON_CALL(mockProjectParts, update(projectParts)).WillByDefault(Return(projectParts));
+ ON_CALL(mockProjectPartsManager, update(projectParts)).WillByDefault(Return(projectParts));
ON_CALL(mockGeneratedFiles, isValid()).WillByDefault(Return(true));
}
@@ -67,13 +67,15 @@ class PchManagerServer : public ::testing::Test
protected:
NiceMock<MockPchTaskGenerator> mockPchTaskGenerator;
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
- NiceMock<MockProjectParts> mockProjectParts;
+ NiceMock<MockProjectPartsManager> mockProjectPartsManager;
NiceMock<MockGeneratedFiles> mockGeneratedFiles;
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
ClangBackEnd::FilePathCaching filePathCache{database};
- ClangBackEnd::PchManagerServer server{
- mockClangPathWatcher, mockPchTaskGenerator, mockProjectParts, mockGeneratedFiles};
+ ClangBackEnd::PchManagerServer server{mockClangPathWatcher,
+ mockPchTaskGenerator,
+ mockProjectPartsManager,
+ mockGeneratedFiles};
NiceMock<MockPchManagerClient> mockPchManagerClient;
SmallString projectPartId1 = "project1";
SmallString projectPartId2 = "project2";
@@ -117,7 +119,7 @@ TEST_F(PchManagerServer, FilterProjectPartsAndSendThemToQueue)
{
InSequence s;
- EXPECT_CALL(mockProjectParts, update(updateProjectPartsMessage.projectsParts))
+ EXPECT_CALL(mockProjectPartsManager, update(updateProjectPartsMessage.projectsParts))
.WillOnce(Return(projectParts2));
EXPECT_CALL(
mockPchTaskGenerator, addProjectParts(Eq(projectParts2), ElementsAre("toolChainArgument")));
@@ -152,7 +154,7 @@ TEST_F(PchManagerServer, RemoveIncludesFromFileWatcher)
TEST_F(PchManagerServer, RemoveProjectPartsFromProjectParts)
{
- EXPECT_CALL(mockProjectParts, remove(removeProjectPartsMessage.projectsPartIds));
+ EXPECT_CALL(mockProjectPartsManager, remove(removeProjectPartsMessage.projectsPartIds));
server.removeProjectParts(removeProjectPartsMessage.clone());
}
@@ -161,7 +163,10 @@ TEST_F(PchManagerServer, SetPathWatcherNotifier)
{
EXPECT_CALL(mockClangPathWatcher, setNotifier(_));
- ClangBackEnd::PchManagerServer server{mockClangPathWatcher, mockPchTaskGenerator, mockProjectParts, mockGeneratedFiles};
+ ClangBackEnd::PchManagerServer server{mockClangPathWatcher,
+ mockPchTaskGenerator,
+ mockProjectPartsManager,
+ mockGeneratedFiles};
}
TEST_F(PchManagerServer, UpdateProjectPartQueueByPathIds)
@@ -169,8 +174,8 @@ TEST_F(PchManagerServer, UpdateProjectPartQueueByPathIds)
server.updateProjectParts(
ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}});
- EXPECT_CALL(mockProjectParts, projects(ElementsAre(projectPart1.projectPartId)))
- .WillOnce(Return(std::vector<ClangBackEnd::ProjectPartContainer>{{projectPart1}}));
+ EXPECT_CALL(mockProjectPartsManager, projects(ElementsAre(projectPart1.projectPartId)))
+ .WillOnce(Return(std::vector<ClangBackEnd::ProjectPartContainer>{{projectPart1}}));
EXPECT_CALL(mockPchTaskGenerator, addProjectParts(ElementsAre(projectPart1), ElementsAre("toolChainArgument")));
server.pathsWithIdsChanged({projectPartId1});
@@ -213,11 +218,11 @@ TEST_F(PchManagerServer, DontGeneratePchIfGeneratedFilesAreNotValid)
{
InSequence s;
- EXPECT_CALL(mockProjectParts, update(ElementsAre(projectPart1)))
+ EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1)))
.WillOnce(Return(ProjectPartContainers{projectPart1}));
EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(false));
EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0);
- EXPECT_CALL(mockProjectParts, updateDeferred(ElementsAre(projectPart1)));
+ EXPECT_CALL(mockProjectPartsManager, updateDeferred(ElementsAre(projectPart1)));
server.updateProjectParts(
ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}});
@@ -227,11 +232,11 @@ TEST_F(PchManagerServer, GeneratePchIfGeneratedFilesAreValid)
{
InSequence s;
- EXPECT_CALL(mockProjectParts, update(ElementsAre(projectPart1)))
+ EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1)))
.WillOnce(Return(ProjectPartContainers{projectPart1}));
EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(true));
EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _));
- EXPECT_CALL(mockProjectParts, updateDeferred(_)).Times(0);
+ EXPECT_CALL(mockProjectPartsManager, updateDeferred(_)).Times(0);
server.updateProjectParts(
ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}});
@@ -247,7 +252,7 @@ TEST_F(PchManagerServer, AfterUpdatingGeneratedFilesAreValidSoGeneratePchs)
EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles));
EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(true));
- EXPECT_CALL(mockProjectParts, deferredUpdates())
+ EXPECT_CALL(mockProjectPartsManager, deferredUpdates())
.WillOnce(Return(ClangBackEnd::ProjectPartContainers{projectPart1}));
EXPECT_CALL(mockPchTaskGenerator,
addProjectParts(ElementsAre(projectPart1), ElementsAre("toolChainArgument")));
@@ -265,7 +270,7 @@ TEST_F(PchManagerServer, AfterUpdatingGeneratedFilesAreStillInvalidSoNoPchsGener
EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles));
EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(false));
- EXPECT_CALL(mockProjectParts, deferredUpdates()).Times(0);
+ EXPECT_CALL(mockProjectPartsManager, deferredUpdates()).Times(0);
EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0);
server.updateGeneratedFiles(updateGeneratedFilesMessage.clone());
diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp
index d85432baf25..a6946f7ccff 100644
--- a/tests/unit/unittest/pchtaskgenerator-test.cpp
+++ b/tests/unit/unittest/pchtaskgenerator-test.cpp
@@ -99,7 +99,7 @@ TEST_F(PchTaskGenerator, AddProjectParts)
Field(&PchTaskSet::system,
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(5)),
- Field(&PchTask::allIncludes, IsEmpty()),
+ Field(&PchTask::sources, IsEmpty()),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
Field(&PchTask::systemIncludeSearchPaths,
@@ -116,7 +116,7 @@ TEST_F(PchTaskGenerator, AddProjectParts)
&PchTaskSet::project,
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(3)),
- Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
+ Field(&PchTask::sources, ElementsAre(1, 2, 3, 4, 5)),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
Field(&PchTask::systemIncludeSearchPaths,
diff --git a/tests/unit/unittest/pchtasksmerger-test.cpp b/tests/unit/unittest/pchtasksmerger-test.cpp
index c279da505e7..da61d14adbd 100644
--- a/tests/unit/unittest/pchtasksmerger-test.cpp
+++ b/tests/unit/unittest/pchtasksmerger-test.cpp
@@ -272,14 +272,14 @@ TEST_F(PchTasksMerger, MergeAllIncludes)
{
Merger::mergePchTasks(systemTask1, systemTask2);
- ASSERT_THAT(systemTask1.allIncludes, ElementsAre(1, 2, 3, 11, 12, 13));
+ ASSERT_THAT(systemTask1.sources, ElementsAre(1, 2, 3, 11, 12, 13));
}
TEST_F(PchTasksMerger, DontAllMergeIncludes)
{
Merger::mergePchTasks(systemTask1, systemTask3);
- ASSERT_THAT(systemTask1.allIncludes, ElementsAre(1, 2, 3));
+ ASSERT_THAT(systemTask1.sources, ElementsAre(1, 2, 3));
}
TEST_F(PchTasksMerger, MergeProjectIds)
diff --git a/tests/unit/unittest/projectparts-test.cpp b/tests/unit/unittest/projectparts-test.cpp
index 8ab342b2f18..16f1ef09889 100644
--- a/tests/unit/unittest/projectparts-test.cpp
+++ b/tests/unit/unittest/projectparts-test.cpp
@@ -25,7 +25,7 @@
#include "googletest.h"
-#include <projectparts.h>
+#include <projectpartsmanager.h>
#include <projectpartcontainer.h>
@@ -41,7 +41,7 @@ using ClangBackEnd::FilePathId;
class ProjectParts : public testing::Test
{
protected:
- ClangBackEnd::ProjectParts projectParts;
+ ClangBackEnd::ProjectPartsManager projectParts;
FilePathId firstHeader{1};
FilePathId secondHeader{2};
FilePathId firstSource{11};
diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
index 7e1e730b179..ebd67dccba0 100644
--- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
+++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
@@ -102,7 +102,10 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable)
{
InSequence s;
- EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)")));
+ EXPECT_CALL(mockDatabase,
+ execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, "
+ "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, "
+ "hasMissingIncludes 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)")));
@@ -124,7 +127,11 @@ 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, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)")));
+ EXPECT_CALL(
+ mockDatabase,
+ execute(Eq(
+ "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, "
+ "lastModified INTEGER)")));
initializer.createFileStatusesTable();
}
@@ -171,13 +178,20 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
"TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, "
"language INTEGER, languageVersion INTEGER, languageExtension INTEGER)")));
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, sourceType INTEGER)")));
+ EXPECT_CALL(mockDatabase,
+ execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, "
+ "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, "
+ "hasMissingIncludes 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, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)")));
+ EXPECT_CALL(
+ mockDatabase,
+ execute(Eq(
+ "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, "
+ "lastModified 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, projectPchPath TEXT, projectPchBuildTime INTEGER, systemPchPath TEXT, systemPchBuildTime INTEGER)")));
@@ -215,7 +229,10 @@ TEST_F(RefactoringDatabaseInitializer, DontCreateIfAlreadyInitialized)
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))).Times(0);
- EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))).Times(0);
+ EXPECT_CALL(mockDatabase,
+ execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, "
+ "size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)")))
+ .Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))).Times(0);
diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp
index eecd388f024..ea015bdee65 100644
--- a/tests/unit/unittest/symbolindexer-test.cpp
+++ b/tests/unit/unittest/symbolindexer-test.cpp
@@ -73,13 +73,6 @@ using ClangBackEnd::SourceLocationKind;
using ClangBackEnd::UsedMacros;
using OptionalProjectPartArtefact = Utils::optional<ClangBackEnd::ProjectPartArtefact>;
-MATCHER_P(IsFileId, fileNameId,
- std::string(negation ? "isn't " : "is ")
- + PrintToString(ClangBackEnd::FilePathId(fileNameId)))
-{
- return arg == ClangBackEnd::FilePathId(fileNameId);
-}
-
struct Data
{
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
@@ -211,7 +204,7 @@ protected:
SourceLocationEntries sourceLocations{{1, 1, {42, 23}, SourceLocationKind::Declaration}};
FilePathIds sourceFileIds{1, 23};
UsedMacros usedMacros{{"Foo", 1}};
- FileStatuses fileStatus{{2, 3, 4, false}};
+ FileStatuses fileStatus{{2, 3, 4}};
SourceDependencies sourceDependencies{{1, 2}, {1, 3}};
Utils::SmallString systemIncludeSearchPathsText{
R"([["/includes", 1, 2], [")" TESTDATA_DIR R"(" ,2 , 3], ["/other/includes", 3, 3]])"};
@@ -269,6 +262,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
EXPECT_CALL(mockCollector,
setFile(main1PathId,
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -301,6 +295,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
EXPECT_CALL(mockCollector,
setFile(main1PathId,
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -335,6 +330,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC
EXPECT_CALL(mockCollector,
setFile(main1PathId,
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -442,26 +438,6 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
indexer.updateProjectParts({projectPart1, projectPart2});
}
-TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithArtifact)
-{
- ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project1"))).WillByDefault(Return(artefact));
- ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"), _, _, _, _, _, _, _)).WillByDefault(Return(-1));
-
- EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(_, _));
-
- indexer.updateProjectParts({projectPart1});
-}
-
-TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArtifact)
-{
- ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project2"))).WillByDefault(Return(nullArtefact));
- ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _, _, _, _, _)).WillByDefault(Return(3));
-
- EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1), IsFileId(23))));
-
- indexer.updateProjectParts({projectPart2});
-}
-
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros)
{
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros)))
@@ -472,7 +448,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros)
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses)
{
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus)))
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus)))
.Times(2);
indexer.updateProjectParts({projectPart1, projectPart2});
@@ -516,6 +492,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
EXPECT_CALL(mockCollector,
setFile(main1PathId,
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -538,9 +515,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
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(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus)));
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
@@ -569,6 +545,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
EXPECT_CALL(mockCollector,
setFile(Eq(main1PathId),
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -591,9 +568,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
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(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus)));
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
@@ -624,6 +600,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderButGetsAnErrorForCollectingS
EXPECT_CALL(mockCollector,
setFile(main1PathId,
ElementsAre("clang++",
+ "-w",
"-Wno-pragma-once-outside-header",
"-DNOMINMAX",
"-x",
@@ -646,9 +623,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderButGetsAnErrorForCollectingS
EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false));
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0);
- EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds))).Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))).Times(0);
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))).Times(0);
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))).Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)))
.Times(0);
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
@@ -689,6 +665,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
EXPECT_CALL(mockCollector,
setFile(Eq(sourceFileIds[0]),
ElementsAre("clang++",
+ "-w",
"-DFOO",
"-DNOMINMAX",
"-x",
@@ -711,9 +688,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
EXPECT_CALL(mockCollector, collectSymbols());
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
- EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus)));
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus)));
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
EXPECT_CALL(mockSqliteTransactionBackend, commit());
@@ -732,9 +708,8 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
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(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0);
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0);
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(_)).Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0);
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
@@ -753,6 +728,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrderButGetsAnErrorForCollectingSy
EXPECT_CALL(mockCollector,
setFile(Eq(sourceFileIds[0]),
ElementsAre("clang++",
+ "-w",
"-DFOO",
"-DNOMINMAX",
"-x",
@@ -775,10 +751,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrderButGetsAnErrorForCollectingSy
EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false));
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0);
- EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds)))
- .Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))).Times(0);
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))).Times(0);
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))).Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)))
.Times(0);
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
@@ -797,6 +771,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
EXPECT_CALL(mockCollector,
setFile(Eq(sourceFileIds[0]),
ElementsAre("clang++",
+ "-w",
"-DFOO",
"-DNOMINMAX",
"-x",
@@ -833,6 +808,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
EXPECT_CALL(mockCollector,
setFile(Eq(sourceFileIds[0]),
ElementsAre("clang++",
+ "-w",
"-DFOO",
"-DNOMINMAX",
"-x",
@@ -950,9 +926,8 @@ TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame)
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(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0);
- EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0);
+ EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(_)).Times(0);
EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0);
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp
index 2d7025373f3..48e4420dc12 100644
--- a/tests/unit/unittest/symbolscollector-test.cpp
+++ b/tests/unit/unittest/symbolscollector-test.cpp
@@ -147,7 +147,7 @@ protected:
ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const
{
- return {filePathId(filePath), fileSize(filePath), lastModified(filePath), false};
+ return {filePathId(filePath), fileSize(filePath), lastModified(filePath)};
}
SymbolIndex symbolId(const Utils::SmallString &symbolName)
diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp
index f9a3d0a7dee..ddd71362523 100644
--- a/tests/unit/unittest/symbolstorage-test.cpp
+++ b/tests/unit/unittest/symbolstorage-test.cpp
@@ -70,8 +70,6 @@ protected:
MockSqliteWriteStatement &deleteNewLocationsTableStatement = storage.m_deleteNewLocationsTableStatement;
MockSqliteWriteStatement &insertOrUpdateProjectPartStatement = storage.m_insertOrUpdateProjectPartStatement;
MockSqliteReadStatement &getProjectPartIdStatement = storage.m_getProjectPartIdStatement;
- MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartIdStatement = storage.m_deleteAllProjectPartsSourcesWithProjectPartIdStatement;
- MockSqliteWriteStatement &insertProjectPartSourcesStatement = storage.m_insertProjectPartSourcesStatement;
MockSqliteReadStatement &getProjectPartArtefactsBySourceId = storage.m_getProjectPartArtefactsBySourceId;
MockSqliteReadStatement &getProjectPartArtefactsByProjectPartName = storage.m_getProjectPartArtefactsByProjectPartName;
@@ -212,18 +210,6 @@ TEST_F(SymbolStorage, InsertOrUpdateProjectPart)
Utils::LanguageExtension::None);
}
-
-TEST_F(SymbolStorage, UpdateProjectPartSources)
-{
- InSequence sequence;
-
- EXPECT_CALL(deleteAllProjectPartsSourcesWithProjectPartIdStatement, write(TypedEq<int>(42)));
- EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(1)));
- EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(2)));
-
- storage.updateProjectPartSources(42, {1, 2});
-}
-
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement)
{
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp
index 3383c9a3b93..8d79bc95cbf 100644
--- a/tests/unit/unittest/tokenprocessor-test.cpp
+++ b/tests/unit/unittest/tokenprocessor-test.cpp
@@ -1704,6 +1704,24 @@ TEST_F(TokenProcessor, LambdaLocalVariableCapture)
ASSERT_THAT(infos[4], HasOnlyType(HighlightingType::LocalVariable));
}
+TEST_F(TokenProcessor, StaticProtectedMember)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(693, 31));
+
+ ClangBackEnd::TokenInfoContainer container(infos[2]);
+
+ ASSERT_THAT(container.extraInfo.accessSpecifier, ClangBackEnd::AccessSpecifier::Protected);
+}
+
+TEST_F(TokenProcessor, StaticPrivateMember)
+{
+ const auto infos = translationUnit.fullTokenInfosInRange(sourceRange(696, 29));
+
+ ClangBackEnd::TokenInfoContainer container(infos[2]);
+
+ ASSERT_THAT(container.extraInfo.accessSpecifier, ClangBackEnd::AccessSpecifier::Private);
+}
+
Data *TokenProcessor::d;
void TokenProcessor::SetUpTestCase()
diff --git a/tests/unit/unittest/usedmacrocollector-test.cpp b/tests/unit/unittest/usedmacrocollector-test.cpp
index 61f7fcd99b4..31aa4fab382 100644
--- a/tests/unit/unittest/usedmacrocollector-test.cpp
+++ b/tests/unit/unittest/usedmacrocollector-test.cpp
@@ -68,7 +68,7 @@ protected:
ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const
{
- return {filePathId(filePath), fileSize(filePath), lastModified(filePath), false};
+ return {filePathId(filePath), fileSize(filePath), lastModified(filePath)};
}
protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
diff --git a/tests/unit/unittest/usedmacrofilter-test.cpp b/tests/unit/unittest/usedmacrofilter-test.cpp
index bdde5417afb..788a443eee2 100644
--- a/tests/unit/unittest/usedmacrofilter-test.cpp
+++ b/tests/unit/unittest/usedmacrofilter-test.cpp
@@ -41,11 +41,13 @@ using ClangBackEnd::CompilerMacros;
class UsedMacroFilter : public testing::Test
{
protected:
- SourceEntries includes{{1, SourceType::UserInclude, 0},
- {2, SourceType::SystemInclude, 0},
- {3, SourceType::ProjectInclude, 0},
- {4, SourceType::TopSystemInclude, 0},
- {5, SourceType::TopProjectInclude, 0}};
+ SourceEntries sources{{1, SourceType::UserInclude, 0},
+ {2, SourceType::SystemInclude, 0},
+ {3, SourceType::ProjectInclude, 0},
+ {4, SourceType::TopSystemInclude, 0},
+ {5, SourceType::TopProjectInclude, 0},
+ {6, SourceType::Source, 0},
+ {7, SourceType::TopProjectInclude, 0, ClangBackEnd::HasMissingIncludes::Yes}};
UsedMacros usedMacros{{"YI", 1},
{"ER", 2},
{"SE", 2},
@@ -65,57 +67,62 @@ protected:
TEST_F(UsedMacroFilter, SystemIncludes)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.systemIncludes, ElementsAre(FilePathId{2}, FilePathId{4}));
}
TEST_F(UsedMacroFilter, ProjectIncludes)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.projectIncludes, ElementsAre(FilePathId{3}, FilePathId{5}));
}
TEST_F(UsedMacroFilter, TopSystemIncludes)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.topSystemIncludes, ElementsAre(FilePathId{4}));
}
TEST_F(UsedMacroFilter, TopProjectIncludes)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.topProjectIncludes, ElementsAre(FilePathId{5}));
}
-TEST_F(UsedMacroFilter, AllIncludes)
+TEST_F(UsedMacroFilter, Sources)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
-
- ASSERT_THAT(filter.allIncludes,
- ElementsAre(FilePathId{1}, FilePathId{2}, FilePathId{3}, FilePathId{4}, FilePathId{5}));
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
+
+ ASSERT_THAT(filter.sources,
+ ElementsAre(FilePathId{1},
+ FilePathId{2},
+ FilePathId{3},
+ FilePathId{4},
+ FilePathId{5},
+ FilePathId{6}));
}
TEST_F(UsedMacroFilter, SystemUsedMacros)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.systemUsedMacros, ElementsAre("ER", "SE", "LIU"));
}
TEST_F(UsedMacroFilter, ProjectUsedMacros)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.projectUsedMacros, ElementsAre("QI", "WU", "SAN"));
}
TEST_F(UsedMacroFilter, SystemCompileMacros)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.systemCompilerMacros,
ElementsAre(CompilerMacro{"ER", "2", 2},
@@ -125,7 +132,7 @@ TEST_F(UsedMacroFilter, SystemCompileMacros)
TEST_F(UsedMacroFilter, ProjectCompileMacros)
{
- ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros);
+ ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.projectCompilerMacros,
ElementsAre(CompilerMacro{"QI"},