Clang: Refactor FilePathId

We don't need the directory id any more. It's not used widely any way.

Task-number: QTCREATORBUG-21443
Change-Id: Ia95ea4c72fe9530ac56262f61f17faca04d313ba
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-11-06 19:02:00 +01:00
parent d37ec2c1e5
commit 6eb620238b
37 changed files with 444 additions and 411 deletions

View File

@@ -133,7 +133,7 @@ public:
return m_filePathStorage.fetchSourceId(directoryId, fileName);
});
return {directoryId, fileNameId};
return fileNameId;
}
FilePath filePath(FilePathId filePathId) const
@@ -141,20 +141,20 @@ public:
if (Q_UNLIKELY(!filePathId.isValid()))
throw NoFilePathForInvalidFilePathId();
auto fetchFilePath = [&] (int id) { return m_filePathStorage.fetchDirectoryPath(id); };
Utils::PathString directoryPath = m_directoryPathCache.string(filePathId.directoryId,
fetchFilePath);
auto fetchSoureName = [&] (int id) {
return FileNameEntry{m_filePathStorage.fetchSourceName(id), filePathId.directoryId};
auto fetchSoureNameAndDirectoryId = [&] (int id) {
auto entry = m_filePathStorage.fetchSourceNameAndDirectoryId(id);
return FileNameEntry{entry.sourceName, entry.directoryId};
};
Utils::SmallString fileName = m_fileNameCache.string(filePathId.filePathId,
fetchSoureName);
FileNameEntry entry = m_fileNameCache.string(filePathId.filePathId,
fetchSoureNameAndDirectoryId);
return FilePath{directoryPath, fileName};
auto fetchDirectoryPath = [&] (int id) { return m_filePathStorage.fetchDirectoryPath(id); };
Utils::PathString directoryPath = m_directoryPathCache.string(entry.directoryId,
fetchDirectoryPath);
return FilePath{directoryPath, entry.fileName};
}
private:

View File

@@ -31,7 +31,7 @@ namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const FilePathId &filePathId)
{
debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.filePathId << ")";
debug.nospace() << "(" << filePathId.filePathId << ")";
return debug;
}

View File

@@ -39,14 +39,14 @@ class FilePathId
{
public:
constexpr FilePathId() = default;
FilePathId(int directoryId, int filePathId)
: directoryId(directoryId),
filePathId(filePathId)
FilePathId(int filePathId)
: filePathId(filePathId)
{}
bool isValid() const
{
return directoryId >= 0 && filePathId >= 0;
return filePathId >= 0;
}
friend bool operator==(FilePathId first, FilePathId second)
@@ -66,7 +66,6 @@ public:
friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId)
{
out << filePathId.directoryId;
out << filePathId.filePathId;
return out;
@@ -74,14 +73,12 @@ public:
friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId)
{
in >> filePathId.directoryId;
in >> filePathId.filePathId;
return in;
}
public:
int directoryId = -1;
int filePathId = -1;
};
@@ -97,11 +94,7 @@ template<> struct hash<ClangBackEnd::FilePathId>
using result_type = std::size_t;
result_type operator()(const argument_type& filePathId) const
{
long long hash = filePathId.directoryId;
hash = hash << 32;
hash += filePathId.filePathId;
return std::hash<long long>{}(hash);
return std::hash<int>{}(filePathId.filePathId);
}
};

View File

@@ -165,14 +165,14 @@ public:
return statement.template value<int>(directoryId, sourceName);
}
Utils::SmallString fetchSourceName(int sourceId)
Sources::SourceNameAndDirectoryId fetchSourceNameAndDirectoryId(int sourceId)
{
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectSourceNameFromSourcesBySourceId;
ReadStatement &statement = m_statementFactory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
auto optionalSourceName = statement.template value<Utils::SmallString>(sourceId);
auto optionalSourceName = statement.template value<Sources::SourceNameAndDirectoryId, 2>(sourceId);
if (!optionalSourceName)
throw SourceNameIdDoesNotExists();
@@ -181,7 +181,7 @@ public:
return optionalSourceName.value();
} catch (const Sqlite::StatementIsBusy &) {
return fetchSourceName(sourceId);
return fetchSourceNameAndDirectoryId(sourceId);
}
}

View File

@@ -69,6 +69,17 @@ public:
int sourceId;
Utils::PathString sourceName;
};
class SourceNameAndDirectoryId
{
public:
SourceNameAndDirectoryId(Utils::SmallStringView sourceName, int directoryId)
: sourceName(sourceName), directoryId(directoryId)
{}
Utils::SmallString sourceName;
int directoryId = -1;
};
} // namespace ClangBackEnd
} // namespace ClangBackEnd

View File

@@ -65,8 +65,8 @@ public:
"SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?",
database
};
ReadStatement selectSourceNameFromSourcesBySourceId{
"SELECT sourceName FROM sources WHERE sourceId = ?",
ReadStatement selectSourceNameAndDirectoryIdFromSourcesBySourceId{
"SELECT sourceName, directoryId FROM sources WHERE sourceId = ?",
database
};
WriteStatement insertIntoSources{

View File

@@ -40,7 +40,7 @@ public:
{}
Database &database;
ReadStatement selectLocationsForSymbolLocation{
"SELECT directoryId, sourceId, line, column FROM locations JOIN sources USING(sourceId) WHERE symbolId = "
"SELECT sourceId, line, column FROM locations WHERE symbolId = "
" (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?) "
"ORDER BY sourceId, line, column",
database};
@@ -59,7 +59,7 @@ public:
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND symbolName LIKE ?",
database};
ReadStatement selectLocationOfSymbol{
"SELECT (SELECT directoryId FROM sources WHERE sourceId = l.sourceId), sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?",
"SELECT sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?",
database};
};

View File

@@ -45,8 +45,8 @@ public:
SourceLocation(ClangBackEnd::FilePathId filePathId, int line, int column)
: filePathId{filePathId}, lineColumn{line, column}
{}
SourceLocation(int directoryId, int sourceId, int line, int column)
: filePathId{directoryId, sourceId}, lineColumn{line, column}
SourceLocation(int sourceId, int line, int column)
: filePathId{sourceId}, lineColumn{line, column}
{}
friend bool operator==(SourceLocation first, SourceLocation second)

View File

@@ -55,7 +55,7 @@ public:
const std::size_t reserveSize = 128;
return locationsStatement.template values<SourceLocation, 4>(reserveSize,
return locationsStatement.template values<SourceLocation, 3>(reserveSize,
filePathId.filePathId,
line,
utf8Column);
@@ -120,7 +120,7 @@ public:
{
ReadStatement &statement = m_statementFactory.selectLocationOfSymbol;
return statement.template value<SourceLocation, 4>(symbolId, int(kind));
return statement.template value<SourceLocation, 3>(symbolId, int(kind));
}
private:
StatementFactory &m_statementFactory;

View File

@@ -31,7 +31,7 @@
namespace ClangBackEnd {
enum SourceType : unsigned char
enum class SourceType : unsigned char
{
Any,
TopInclude,
@@ -56,7 +56,21 @@ public:
class SourceEntry
{
using int64 = long long;
public:
SourceEntry(int sourceId, int64 lastModified, int sourceType)
: lastModified(lastModified),
sourceId(sourceId),
sourceType(static_cast<SourceType>(sourceType))
{}
SourceEntry(FilePathId sourceId, SourceType sourceType, TimeStamp lastModified)
: lastModified(lastModified),
sourceId(sourceId),
sourceType(sourceType)
{}
friend
bool operator<(SourceEntry first, SourceEntry second)
{
@@ -66,13 +80,15 @@ public:
friend
bool operator==(SourceEntry first, SourceEntry second)
{
return first.sourceId == second.sourceId;
return first.sourceId == second.sourceId
&& first.sourceType == second.sourceType
&& first.lastModified == second.lastModified ;
}
public:
TimeStamp lastModified;
FilePathId sourceId;
SourceType sourceType = SourceType::Any;
TimeStamp lastModified;
};
using SourceEntries = std::vector<SourceEntry>;

View File

@@ -101,7 +101,7 @@ namespace {
V2::SourceRangeContainer convertToContainer(const clang::ast_matchers::dynamic::SourceRange sourceRange)
{
return V2::SourceRangeContainer({1, 0},
return V2::SourceRangeContainer(0,
sourceRange.Start.Line,
sourceRange.Start.Column,
0,

View File

@@ -62,20 +62,20 @@ protected:
{"--yi"},
{{"YI","1"}},
{"/yi"},
{{1, 1}},
{{1, 2}}};
{1},
{2}};
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
{"--er"},
{{"ER","2"}},
{"/er"},
{{1, 1}},
{{1, 2}, {1, 3}, {1, 4}}};
SourceEntries firstSources{{{1, 1}, SourceType::Any, 1}, {{1, 2}, SourceType::Any, 1}, {{1, 10}, SourceType::Any, 1}};
SourceEntries secondSources{{{1, 1}, SourceType::Any, 1}, {{1, 3}, SourceType::Any, 1}, {{1, 8}, SourceType::Any, 1}};
SourceEntries thirdSources{{{1, 4}, SourceType::Any, 1}, {{1, 8}, SourceType::Any, 1}, {{1, 10}, SourceType::Any, 1}};
UsedMacros firstUsedMacros{{"YI", {1, 1}}};
UsedMacros secondUsedMacros{{"LIANG", {1, 2}}, {"ER", {1, 2}}};
UsedMacros thirdUsedMacros{{"SAN", {1, 10}}};
{1},
{2, 3, 4}};
SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}};
SourceEntries secondSources{{1, SourceType::Any, 1}, {3, SourceType::Any, 1}, {8, SourceType::Any, 1}};
SourceEntries thirdSources{{4, SourceType::Any, 1}, {8, SourceType::Any, 1}, {10, SourceType::Any, 1}};
UsedMacros firstUsedMacros{{"YI", 1}};
UsedMacros secondUsedMacros{{"LIANG", 2}, {"ER", 2}};
UsedMacros thirdUsedMacros{{"SAN", 10}};
BuildDependency buildDependency{secondSources, {}, {}, {}};
};
@@ -83,7 +83,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime
{
InSequence s;
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true));
EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).Times(0);
@@ -92,9 +92,9 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime
TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage)
{
ON_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillByDefault(Return(firstSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 3})).WillByDefault(Return(secondSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 4})).WillByDefault(Return(thirdSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3})).WillByDefault(Return(secondSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4})).WillByDefault(Return(thirdSources));
ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true));
auto buildDependency = provider.create(projectPart2);
@@ -106,7 +106,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi
{
InSequence s;
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false));
EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1));
@@ -115,7 +115,7 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi
TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator)
{
ON_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillByDefault(Return(firstSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources));
ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false));
ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency));
@@ -128,25 +128,25 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta
{
InSequence s;
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillRepeatedly(Return(firstSources));
EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 1}));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 2}));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 10}));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1}));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2}));
EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10}));
provider.create(projectPart1);
}
TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate)
{
ON_CALL(mockBuildDependenciesStorage, fetchDependSources(FilePathId{1, 2})).WillByDefault(Return(firstSources));
ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2})).WillByDefault(Return(firstSources));
ON_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillByDefault(Return(true));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 1})).WillByDefault(Return(firstUsedMacros));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 2})).WillByDefault(Return(secondUsedMacros));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros(FilePathId{1, 10})).WillByDefault(Return(thirdUsedMacros));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})).WillByDefault(Return(firstUsedMacros));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})).WillByDefault(Return(secondUsedMacros));
ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})).WillByDefault(Return(thirdUsedMacros));
auto buildDependency = provider.create(projectPart1);
ASSERT_THAT(buildDependency.usedMacros, ElementsAre(UsedMacro{"YI", {1, 1}}, UsedMacro{"ER", {1, 2}}, UsedMacro{"LIANG", {1, 2}}, UsedMacro{"SAN", {1, 10}}));
ASSERT_THAT(buildDependency.usedMacros, ElementsAre(UsedMacro{"YI", 1}, UsedMacro{"ER", 2}, UsedMacro{"LIANG", 2}, UsedMacro{"SAN", 10}));
}
}

View File

@@ -73,7 +73,7 @@ protected:
FilePathView path2{"/path/path2"};
QString path1QString = QString(path1.toStringView());
QString path2QString = QString(path2.toStringView());
FilePathIds pathIds = {{1, 1}, {1, 2}};
FilePathIds pathIds = {1, 2};
std::vector<int> ids{watcher.idCache().stringIds({id1, id2, id3})};
WatcherEntry watcherEntry1{ids[0], pathIds[0]};
WatcherEntry watcherEntry2{ids[1], pathIds[0]};

View File

@@ -66,7 +66,7 @@ TEST_F(ClangQueryExampleHighlightMarker, NoCallForNotSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, SingleLineSourceRange)
{
SourceRanges sourceRanges{{{1, 1}, 1, 3, 3, 1, 10, 10, "function"}};
SourceRanges sourceRanges{{1, 1, 3, 3, 1, 10, 10, "function"}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0]));
@@ -76,7 +76,7 @@ TEST_F(ClangQueryExampleHighlightMarker, SingleLineSourceRange)
TEST_F(ClangQueryExampleHighlightMarker, OtherSingleLineSourceRange)
{
SourceRanges sourceRanges{{{1, 1}, 2, 5, 5, 2, 11, 11, "function"}};
SourceRanges sourceRanges{{1, 2, 5, 5, 2, 11, 11, "function"}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
marker.highlightBlock(1, "foo");
@@ -88,9 +88,9 @@ TEST_F(ClangQueryExampleHighlightMarker, OtherSingleLineSourceRange)
TEST_F(ClangQueryExampleHighlightMarker, CascadedSingleLineSourceRanges)
{
InSequence sequence;
SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 1, 15, 15, "void function"},
{{1, 1}, 1, 2, 2, 1, 6, 6, "void"},
{{1, 1}, 1, 7, 7, 1, 15, 15, "function"}};
SourceRanges sourceRanges{{1, 1, 2, 2, 1, 15, 15, "void function"},
{1, 1, 2, 2, 1, 6, 6, "void"},
{1, 1, 7, 7, 1, 15, 15, "function"}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(1, 13, textFormats[0]));
@@ -103,7 +103,7 @@ TEST_F(ClangQueryExampleHighlightMarker, CascadedSingleLineSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, DualLineSourceRanges)
{
InSequence sequence;
SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 2, 4, 20, "void f()\n {}"}};
SourceRanges sourceRanges{{1, 1, 2, 2, 2, 4, 20, "void f()\n {}"}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0]));
@@ -116,7 +116,7 @@ TEST_F(ClangQueryExampleHighlightMarker, DualLineSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, MultipleLineSourceRanges)
{
InSequence sequence;
SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 3, 3, 20, "void f()\n {\n }"}};
SourceRanges sourceRanges{{1, 1, 2, 2, 3, 3, 20, "void f()\n {\n }"}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0]));
@@ -131,9 +131,9 @@ TEST_F(ClangQueryExampleHighlightMarker, MultipleLineSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, MoreMultipleLineSourceRanges)
{
InSequence sequence;
SourceRanges sourceRanges{{{1, 1}, 1, 1, 0, 4, 2, 0, ""},
{{1, 1}, 2, 2, 0, 2, 7, 0, ""},
{{1, 1}, 3, 2, 0, 3, 7, 0, ""}};
SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""},
{1, 2, 2, 0, 2, 7, 0, ""},
{1, 3, 2, 0, 3, 7, 0, ""}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[0]));
@@ -152,9 +152,9 @@ TEST_F(ClangQueryExampleHighlightMarker, MoreMultipleLineSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, CascadedMultipleLineSourceRanges)
{
InSequence sequence;
SourceRanges sourceRanges{{{1, 1}, 1, 1, 0, 4, 2, 0, ""},
{{1, 1}, 2, 2, 0, 3, 4, 0, ""},
{{1, 1}, 2, 11, 0, 2, 16, 0, ""}};
SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""},
{1, 2, 2, 0, 3, 4, 0, ""},
{1, 2, 11, 0, 2, 16, 0, ""}};
Marker marker(std::move(sourceRanges), highlighter, textFormats);
EXPECT_CALL(highlighter, setFormat(0, 9, textFormats[0]));
@@ -173,7 +173,7 @@ TEST_F(ClangQueryExampleHighlightMarker, CascadedMultipleLineSourceRanges)
TEST_F(ClangQueryExampleHighlightMarker, FormatSingle)
{
SourceRange sourceRange{{1, 1}, 1, 3, 3, 1, 10, 10};
SourceRange sourceRange{1, 1, 3, 3, 1, 10, 10};
EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0]));
@@ -182,7 +182,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatSingle)
TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleStart)
{
SourceRange sourceRange{{1, 1}, 1, 3, 3, 2, 9, 20};
SourceRange sourceRange{1, 1, 3, 3, 2, 9, 20};
EXPECT_CALL(highlighter, setFormat(2, 8, textFormats[0]));
@@ -191,7 +191,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleStart)
TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleEnd)
{
SourceRange sourceRange{{1, 1}, 1, 3, 3, 2, 8, 20};
SourceRange sourceRange{1, 1, 3, 3, 2, 8, 20};
EXPECT_CALL(highlighter, setFormat(0, 7, textFormats[1]));
@@ -200,7 +200,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleEnd)
TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleMiddle)
{
SourceRange sourceRange{{1, 1}, 1, 3, 3, 3, 8, 20};
SourceRange sourceRange{1, 1, 3, 3, 3, 8, 20};
EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[2]));

View File

@@ -74,10 +74,10 @@ TEST_F(ClangQueryHighlightMarker, NoCallForNoMessagesAndContexts)
TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextsForASingleLine)
{
InSequence sequence;
Messages messages{{{{0, 1}, 1, 5, 0, 1, 10, 0}, ErrorType::RegistryMatcherNotFound, {}},
{{{0, 1}, 1, 30, 0, 1, 40, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Contexts contexts{{{{0, 1}, 1, 2, 0, 1, 15, 0}, ContextType::MatcherArg, {}},
{{{0, 1}, 1, 20, 0, 1, 50, 0}, ContextType::MatcherArg, {}}};
Messages messages{{{1, 1, 5, 0, 1, 10, 0}, ErrorType::RegistryMatcherNotFound, {}},
{{1, 1, 30, 0, 1, 40, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Contexts contexts{{{1, 1, 2, 0, 1, 15, 0}, ContextType::MatcherArg, {}},
{{1, 1, 20, 0, 1, 50, 0}, ContextType::MatcherArg, {}}};
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
EXPECT_CALL(highlighter, setFormat(1, 13, contextTextFormat));
@@ -91,7 +91,7 @@ TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextsForASingleLine)
TEST_F(ClangQueryHighlightMarker, CallForMessagesForAMultiLine)
{
InSequence sequence;
Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Contexts contexts;
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
@@ -107,8 +107,8 @@ TEST_F(ClangQueryHighlightMarker, CallForMessagesForAMultiLine)
TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextForAMultiLine)
{
InSequence sequence;
Messages messages{{{{1, 1}, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Contexts contexts{{{{1, 1}, 1, 2, 0, 3, 4, 0}, ContextType::MatcherArg, {}}};
Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}};
Contexts contexts{{{1, 1, 2, 0, 3, 4, 0}, ContextType::MatcherArg, {}}};
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
EXPECT_CALL(highlighter, setFormat(1, 11, contextTextFormat));
@@ -136,7 +136,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesIfEmpty)
TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition)
{
Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0},
Messages messages{{{1, 1, 5, 0, 3, 3, 0},
ErrorType::RegistryMatcherNotFound,
{"foo"}}};
Contexts contexts;
@@ -149,7 +149,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition)
TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition)
{
Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0},
Messages messages{{{1, 1, 5, 0, 3, 3, 0},
ErrorType::RegistryMatcherNotFound,
{"foo"}}};
Contexts contexts;
@@ -162,7 +162,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition)
TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition)
{
Message message{{{0, 1}, 1, 5, 0, 3, 3, 0},
Message message{{1, 1, 5, 0, 3, 3, 0},
ErrorType::RegistryMatcherNotFound,
{"foo"}};
Messages messages{message.clone()};
@@ -176,7 +176,7 @@ TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition)
TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition)
{
Message message{{{0, 1}, 1, 5, 0, 3, 3, 0},
Message message{{1, 1, 5, 0, 3, 3, 0},
ErrorType::RegistryMatcherNotFound,
{"foo"}};
Messages messages{message.clone()};
@@ -190,7 +190,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition)
TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 1, 6);
@@ -199,7 +199,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine)
TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 4);
@@ -208,7 +208,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn)
TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 5);
@@ -217,7 +217,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn)
TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 6);
@@ -226,7 +226,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn)
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 4, 1);
@@ -235,7 +235,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine)
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 4);
@@ -244,7 +244,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn)
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 3);
@@ -253,7 +253,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn)
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 2);
@@ -262,7 +262,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn)
TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
bool isInBetween = marker.isInsideRange(sourceRange, 1, 6);
@@ -271,7 +271,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine)
TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 4, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0};
bool isInBetween = marker.isInsideRange(sourceRange, 5, 1);
@@ -280,7 +280,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine)
TEST_F(ClangQueryHighlightMarker, InBetweenLine)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 4, 3, 0};
SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0};
bool isInBetween = marker.isInsideRange(sourceRange, 3, 1);
@@ -289,7 +289,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLine)
TEST_F(ClangQueryHighlightMarker, SingleLineBefore)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0};
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
bool isInRange = marker.isInsideRange(sourceRange, 2, 4);
@@ -298,7 +298,7 @@ TEST_F(ClangQueryHighlightMarker, SingleLineBefore)
TEST_F(ClangQueryHighlightMarker, SingleLineAfter)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0};
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
bool isInRange = marker.isInsideRange(sourceRange, 2, 11);
@@ -307,7 +307,7 @@ TEST_F(ClangQueryHighlightMarker, SingleLineAfter)
TEST_F(ClangQueryHighlightMarker, SingleLineInRange)
{
SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0};
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
bool isInRange = marker.isInsideRange(sourceRange, 2, 6);
@@ -328,7 +328,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsIfEmpty)
TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition)
{
Messages messages;
Contexts contexts{{{{0, 1}, 1, 5, 0, 3, 3, 0},
Contexts contexts{{{1, 1, 5, 0, 3, 3, 0},
ContextType::MatcherArg,
{"foo"}}};
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
@@ -341,7 +341,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition)
TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition)
{
Messages messages;
Contexts contexts{{{{0, 1}, 1, 5, 0, 3, 3, 0},
Contexts contexts{{{1, 1, 5, 0, 3, 3, 0},
ContextType::MatcherArg,
{"foo"}}};
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
@@ -353,7 +353,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition)
TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition)
{
Context context{{{0, 1}, 1, 5, 0, 3, 3, 0},
Context context{{1, 1, 5, 0, 3, 3, 0},
ContextType::MatcherArg,
{"foo"}};
Messages messages;
@@ -367,7 +367,7 @@ TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition)
TEST_F(ClangQueryHighlightMarker, NoContextsForOutsidePosition)
{
Context context{{{0, 1}, 1, 5, 0, 3, 3, 0},
Context context{{1, 1, 5, 0, 3, 3, 0},
ContextType::MatcherArg,
{"foo"}};
Messages messages;

View File

@@ -36,11 +36,28 @@ using Cache = ClangBackEnd::FilePathCache<NiceMock<MockFilePathStorage>>;
using ClangBackEnd::FilePathId;
using NFP = ClangBackEnd::FilePath;
using ClangBackEnd::FilePathView;
using ClangBackEnd::Sources::SourceNameAndDirectoryId;
class FilePathCache : public testing::Test
{
protected:
void SetUp();
void SetUp()
{
ON_CALL(mockStorage, fetchDirectoryId(Eq("/path/to")))
.WillByDefault(Return(5));
ON_CALL(mockStorage, fetchDirectoryId(Eq("/path2/to")))
.WillByDefault(Return(6));
ON_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp")))
.WillByDefault(Return(42));
ON_CALL(mockStorage, fetchSourceId(5, Eq("file2.cpp")))
.WillByDefault(Return(63));
ON_CALL(mockStorage, fetchSourceId(6, Eq("file.cpp")))
.WillByDefault(Return(72));
ON_CALL(mockStorage, fetchDirectoryPath(5))
.WillByDefault(Return(Utils::PathString("/path/to")));
ON_CALL(mockStorage, fetchSourceNameAndDirectoryId(42))
.WillByDefault(Return(SourceNameAndDirectoryId("file.cpp", 5)));
}
protected:
NiceMock<MockFilePathStorage> mockStorage;
@@ -61,13 +78,6 @@ TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCalls)
cache.filePathId(FilePathView("/path/to/file.cpp"));
}
TEST_F(FilePathCache, DirectoryIdOfFilePathIdWithOutAnyEntry)
{
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
ASSERT_THAT(filePathId.directoryId, 5);
}
TEST_F(FilePathCache, FilePathIdOfFilePathIdWithOutAnyEntry)
{
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
@@ -113,24 +123,6 @@ TEST_F(FilePathCache, GetFilePathIdWithDirectoryIdCached)
ASSERT_THAT(filePathId.filePathId, 63);
}
TEST_F(FilePathCache, GetDirectyIdWithCachedValue)
{
cache.filePathId(FilePathView("/path/to/file.cpp"));
auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp"));
ASSERT_THAT(filePathId.directoryId, 5);
}
TEST_F(FilePathCache, GetDirectyIdWithDirectoryIdCached)
{
cache.filePathId(FilePathView("/path/to/file.cpp"));
auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp"));
ASSERT_THAT(filePathId.directoryId, 5);
}
TEST_F(FilePathCache, ThrowForGettingAFilePathWithAnInvalidId)
{
FilePathId filePathId;
@@ -149,7 +141,7 @@ TEST_F(FilePathCache, GetAFilePath)
TEST_F(FilePathCache, GetAFilePathWithCachedFilePathId)
{
FilePathId filePathId{5, 42};
FilePathId filePathId{42};
auto filePath = cache.filePath(filePathId);
@@ -174,22 +166,4 @@ TEST_F(FilePathCache, DuplicateFilePathsAreEqual)
ASSERT_THAT(filePath2Id, Eq(filePath1Id));
}
void FilePathCache::SetUp()
{
ON_CALL(mockStorage, fetchDirectoryId(Eq("/path/to")))
.WillByDefault(Return(5));
ON_CALL(mockStorage, fetchDirectoryId(Eq("/path2/to")))
.WillByDefault(Return(6));
ON_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp")))
.WillByDefault(Return(42));
ON_CALL(mockStorage, fetchSourceId(5, Eq("file2.cpp")))
.WillByDefault(Return(63));
ON_CALL(mockStorage, fetchSourceId(6, Eq("file.cpp")))
.WillByDefault(Return(72));
ON_CALL(mockStorage, fetchDirectoryPath(5))
.WillByDefault(Return(Utils::PathString("/path/to")));
ON_CALL(mockStorage, fetchSourceName(42))
.WillByDefault(Return(Utils::SmallString("file.cpp")));
}
}

View File

@@ -43,7 +43,58 @@ using ClangBackEnd::Sources::Source;
class FilePathStorage : public testing::Test
{
protected:
void SetUp();
void SetUp()
{
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(_))
.WillByDefault(Return(Utils::optional<int>()));
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(Utils::SmallStringView("")))
.WillByDefault(Return(Utils::optional<int>(0)));
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(Utils::SmallStringView("/path/to")))
.WillByDefault(Return(Utils::optional<int>(5)));
ON_CALL(mockDatabase, lastInsertedRowId())
.WillByDefault(Return(12));
ON_CALL(selectAllDirectories,
valuesReturnStdVectorDirectory(_))
.WillByDefault(Return(std::vector<Directory>{{1, "/path/to"}, {2, "/other/path"}}));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(_, _))
.WillByDefault(Return(Utils::optional<int>()));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(0, Utils::SmallStringView("")))
.WillByDefault(Return(Utils::optional<int>(0)));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Utils::SmallStringView("file.h")))
.WillByDefault(Return(Utils::optional<int>(42)));
ON_CALL(selectAllSources,
valuesReturnStdVectorSource(_))
.WillByDefault(Return(std::vector<Source>{{1, "file.h"}, {4, "file.cpp"}}));
ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId,
valueReturnPathString(5))
.WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to")));
ON_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId,
valueReturnSourceNameAndDirectoryId(42))
.WillByDefault(Return(Utils::optional<ClangBackEnd::Sources::SourceNameAndDirectoryId>({"file.cpp", 5})));
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, valueReturnInt32(_))
.Times(AnyNumber());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(_, _))
.Times(AnyNumber());
EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>()))
.Times(AnyNumber());
EXPECT_CALL(insertIntoSources, write(An<uint>(), A<Utils::SmallStringView>()))
.Times(AnyNumber());
EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_))
.Times(AnyNumber());
EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(_))
.Times(AnyNumber());
EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(_))
.Times(AnyNumber());
EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(_))
.Times(AnyNumber());
}
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
@@ -51,7 +102,7 @@ protected:
MockSqliteReadStatement &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath;
MockSqliteReadStatement &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName;
MockSqliteReadStatement &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId;
MockSqliteReadStatement &selectSourceNameFromSourcesBySourceId = factory.selectSourceNameFromSourcesBySourceId;
MockSqliteReadStatement &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
MockSqliteReadStatement &selectAllDirectories = factory.selectAllDirectories;
MockSqliteWriteStatement &insertIntoDirectories = factory.insertIntoDirectories;
MockSqliteWriteStatement &insertIntoSources = factory.insertIntoSources;
@@ -397,22 +448,23 @@ TEST_F(FilePathStorage, ThrowAsFetchingDirectoryPathForNonExistingId)
TEST_F(FilePathStorage, CallValueForFetchSoureNameForId)
{
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(42));
EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42));
EXPECT_CALL(mockDatabase, commit());
storage.fetchSourceName(42);
storage.fetchSourceNameAndDirectoryId(42);
}
TEST_F(FilePathStorage, FetchSoureNameForId)
{
auto path = storage.fetchSourceName(42);
auto entry = storage.fetchSourceNameAndDirectoryId(42);
ASSERT_THAT(path, Eq("file.cpp"));
ASSERT_THAT(entry.sourceName, Eq("file.cpp"));
ASSERT_THAT(entry.directoryId, 5);
}
TEST_F(FilePathStorage, ThrowAsFetchingSourceNameForNonExistingId)
{
ASSERT_THROW(storage.fetchSourceName(12), ClangBackEnd::SourceNameIdDoesNotExists);
ASSERT_THROW(storage.fetchSourceNameAndDirectoryId(12), ClangBackEnd::SourceNameIdDoesNotExists);
}
TEST_F(FilePathStorage, RestartFetchSourceNameIfTheDatabaseIsBusyInBegin)
@@ -425,11 +477,11 @@ TEST_F(FilePathStorage, RestartFetchSourceNameIfTheDatabaseIsBusyInBegin)
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(42));
EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
storage.fetchSourceName(42);
storage.fetchSourceNameAndDirectoryId(42);
}
TEST_F(FilePathStorage, RestartFetchDirectoryPathIfTheDatabaseIsBusyInBegin)
@@ -483,56 +535,4 @@ TEST_F(FilePathStorage, RestartFetchAllSourcesIfBeginIsBusy)
storage.fetchAllSources();
}
void FilePathStorage::SetUp()
{
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(_))
.WillByDefault(Return(Utils::optional<int>()));
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(Utils::SmallStringView("")))
.WillByDefault(Return(Utils::optional<int>(0)));
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(Utils::SmallStringView("/path/to")))
.WillByDefault(Return(Utils::optional<int>(5)));
ON_CALL(mockDatabase, lastInsertedRowId())
.WillByDefault(Return(12));
ON_CALL(selectAllDirectories,
valuesReturnStdVectorDirectory(_))
.WillByDefault(Return(std::vector<Directory>{{1, "/path/to"}, {2, "/other/path"}}));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(_, _))
.WillByDefault(Return(Utils::optional<int>()));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(0, Utils::SmallStringView("")))
.WillByDefault(Return(Utils::optional<int>(0)));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Utils::SmallStringView("file.h")))
.WillByDefault(Return(Utils::optional<int>(42)));
ON_CALL(selectAllSources,
valuesReturnStdVectorSource(_))
.WillByDefault(Return(std::vector<Source>{{1, "file.h"}, {4, "file.cpp"}}));
ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId,
valueReturnPathString(5))
.WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to")));
ON_CALL(selectSourceNameFromSourcesBySourceId,
valueReturnSmallString(42))
.WillByDefault(Return(Utils::optional<Utils::SmallString>("file.cpp")));
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, valueReturnInt32(_))
.Times(AnyNumber());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(_, _))
.Times(AnyNumber());
EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>()))
.Times(AnyNumber());
EXPECT_CALL(insertIntoSources, write(An<uint>(), A<Utils::SmallStringView>()))
.Times(AnyNumber());
EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_))
.Times(AnyNumber());
EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(_))
.Times(AnyNumber());
EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(_))
.Times(AnyNumber());
EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(_))
.Times(AnyNumber());
}
}

View File

@@ -63,8 +63,8 @@ TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceIdFromSourcesByDirecto
TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceNameFromSourcesByDirectoryIdAndSourceId)
{
ASSERT_THAT(factory.selectSourceNameFromSourcesBySourceId.sqlStatement,
Eq("SELECT sourceName FROM sources WHERE sourceId = ?"));
ASSERT_THAT(factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId.sqlStatement,
Eq("SELECT sourceName, directoryId FROM sources WHERE sourceId = ?"));
}
TEST_F(FilePathStorageSqliteStatementFactory, SelectAllDirectories)

View File

@@ -171,7 +171,7 @@ namespace ClangBackEnd {
std::ostream &operator<<(std::ostream &out, const FilePathId &id)
{
return out << "(" << id.directoryId << ", " << id.filePathId << ")";
return out << "(" << id.filePathId << ")";
}
std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView)
@@ -1086,8 +1086,8 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe
std::ostream &operator<<(std::ostream &os, const SourceLocationContainer &container)
{
os << "(("
<< container.filePathId.directoryId << ", " << container.filePathId.filePathId << "), "
os << "("
<< container.filePathId.filePathId << ", "
<< container.line << ", "
<< container.column << ", "
<< container.offset

View File

@@ -69,7 +69,7 @@ protected:
int length = 0;
QString newText;
Utils::LineColumn lineColumn{4, 3};
ClangBackEnd::FilePathId filePathId{42, 64};
ClangBackEnd::FilePathId filePathId{64};
ClangRefactoring::SourceLocation sourceLocation{filePathId, lineColumn};
};

View File

@@ -27,6 +27,8 @@
#include "googletest.h"
#include <filepathstoragesources.h>
class MockFilePathStorage
{
public:
@@ -36,7 +38,7 @@ public:
int (int directoryId, Utils::SmallStringView sourceName));
MOCK_METHOD1(fetchDirectoryPath,
Utils::PathString (int directoryId));
MOCK_METHOD1(fetchSourceName,
Utils::SmallString (int sourceId));
MOCK_METHOD1(fetchSourceNameAndDirectoryId,
ClangBackEnd::Sources::SourceNameAndDirectoryId (int sourceId));
};

View File

@@ -27,7 +27,7 @@
template <>
SourceLocations
MockSqliteReadStatement::values<SourceLocation, 4>(std::size_t reserveSize,
MockSqliteReadStatement::values<SourceLocation, 3>(std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column)
@@ -158,7 +158,21 @@ MockSqliteReadStatement::value<Utils::SmallString>(const int &sourceId)
template <>
Utils::optional<SourceLocation>
MockSqliteReadStatement::value<SourceLocation, 4>(const long long &symbolId, const int &locationKind)
MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind)
{
return valueReturnSourceLocation(symbolId, locationKind);
}
template <>
SourceEntries
MockSqliteReadStatement::values<SourceEntry, 3>(std::size_t reserveSize, const int &filePathId, const int &projectPartId)
{
return valuesReturnSourceEntries(reserveSize, filePathId, projectPartId);
}
template <>
Utils::optional<Sources::SourceNameAndDirectoryId>
MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int &id)
{
return valueReturnSourceNameAndDirectoryId(id);
}

View File

@@ -33,6 +33,7 @@
#include <stringcachefwd.h>
#include <projectpartartefact.h>
#include <projectpartpch.h>
#include <sourceentry.h>
#include <symbol.h>
#include <cpptools/usages.h>
@@ -45,6 +46,8 @@
#include <vector>
using std::int64_t;
using ClangBackEnd::SourceEntry;
using ClangBackEnd::SourceEntries;
using ClangRefactoring::SourceLocation;
using ClangRefactoring::SourceLocations;
namespace Sources = ClangBackEnd::Sources;
@@ -73,6 +76,9 @@ public:
MOCK_METHOD1(valuesReturnStdVectorSource,
std::vector<Sources::Source>(std::size_t));
MOCK_METHOD3(valuesReturnSourceEntries,
SourceEntries(std::size_t, int, int));
MOCK_METHOD1(valueReturnInt32,
Utils::optional<int>(Utils::SmallStringView));
@@ -88,6 +94,9 @@ public:
MOCK_METHOD1(valueReturnSmallString,
Utils::optional<Utils::SmallString>(int));
MOCK_METHOD1(valueReturnSourceNameAndDirectoryId,
Utils::optional<Sources::SourceNameAndDirectoryId>(int));
MOCK_METHOD1(valueReturnProjectPartArtefact,
Utils::optional<ClangBackEnd::ProjectPartArtefact>(int));
@@ -137,7 +146,7 @@ public:
template <>
SourceLocations
MockSqliteReadStatement::values<SourceLocation, 4>(
MockSqliteReadStatement::values<SourceLocation, 3>(
std::size_t reserveSize,
const int &sourceId,
const int &line,
@@ -219,4 +228,12 @@ MockSqliteReadStatement::value<Utils::SmallString>(const int&);
template <>
Utils::optional<SourceLocation>
MockSqliteReadStatement::value<SourceLocation, 4>(const long long &symbolId, const int &locationKind);
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 <>
Utils::optional<Sources::SourceNameAndDirectoryId>
MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int&);

View File

@@ -99,5 +99,11 @@ public:
MOCK_METHOD2(write,
void (uint, uint));
MOCK_METHOD2(write,
void (uchar, int));
MOCK_METHOD2(write,
void (long long, int));
Utils::SmallString sqlStatement;
};

View File

@@ -78,7 +78,7 @@ protected:
PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp";
PathString header1Path = TESTDATA_DIR "/includecollector_header1.h";
PathString header2Path = TESTDATA_DIR "/includecollector_header2.h";
ClangBackEnd::IdPaths idPath{projectPartId1, {{1, 1}, {1, 2}}};
ClangBackEnd::IdPaths idPath{projectPartId1, {1, 2}};
ProjectPartContainer projectPart1{projectPartId1.clone(),
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{{"DEFINE", "1"}},

View File

@@ -49,7 +49,7 @@ protected:
{"/yi"},
{{1, 1}},
{{1, 2}}};
SourceEntries firstSources{{{1, 1}, SourceType::Any, 1}, {{1, 2}, SourceType::Any, 1}, {{1, 10}, SourceType::Any, 1}};
SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}};
BuildDependency buildDependency{firstSources, {}, {}, {}};
};

View File

@@ -45,26 +45,26 @@ protected:
{"--yi"},
{{"YI","1"}},
{"/yi"},
{{1, 1}},
{{1, 2}}};
{1},
{2}};
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
{"--er"},
{{"ER","2"}},
{"/bar"},
{{2, 1}},
{{2, 2}}};
{1},
{2}};
ClangBackEnd::V2::ProjectPartContainer projectPart2b{"ProjectPart2",
{"--liang"},
{{"LIANG","3"}},
{"/liang"},
{{2, 3}},
{{2, 2}, {2, 4}}};
{3},
{2, 4}};
ClangBackEnd::V2::ProjectPartContainer projectPart3{"ProjectPart3",
{"--san"},
{{"SAN","2"}},
{"/SAN"},
{{3, 1}},
{{3, 2}}};
{1},
{2}};
};
TEST_F(ProjectPartQueue, AddProjectPart)

View File

@@ -42,11 +42,11 @@ class ProjectParts : public testing::Test
{
protected:
ClangBackEnd::ProjectParts projectParts;
FilePathId firstHeader{1, 1};
FilePathId secondHeader{1, 2};
FilePathId firstSource{1, 11};
FilePathId secondSource{1, 12};
FilePathId thirdSource{1, 13};
FilePathId firstHeader{1};
FilePathId secondHeader{2};
FilePathId firstSource{11};
FilePathId secondSource{12};
FilePathId thirdSource{13};
ProjectPartContainer projectPartContainer1{"id",
{"-DUNIX", "-O2"},
{{"DEFINE", "1"}},

View File

@@ -85,10 +85,10 @@ protected:
CppTools::ProjectPart::Ptr projectPart;
CppTools::ProjectFile projectFile{qStringFilePath, CppTools::ProjectFile::CXXSource};
SourceLocationsForRenamingMessage renameMessage{"symbol",
{{{{1, 42}, 1, 1, 0}, {{1, 42}, 2, 5, 10}}},
{{{42, 1, 1, 0}, {42, 2, 5, 10}}},
1};
SourceRangesForQueryMessage queryResultMessage{{{{{1, 42}, 1, 1, 0, 1, 5, 4, ""},
{{1, 42}, 2, 1, 5, 2, 5, 10, ""}}}};
SourceRangesForQueryMessage queryResultMessage{{{{42, 1, 1, 0, 1, 5, 4, ""},
{42, 2, 1, 5, 2, 5, 10, ""}}}};
SourceRangesForQueryMessage emptyQueryResultMessage;
};
@@ -212,7 +212,7 @@ TEST_F(RefactoringClient, ResultCounterIsZeroAfterSettingExpectedResultCount)
TEST_F(RefactoringClient, XXX)
{
const Core::Search::TextRange textRange{{1,0,1},{1,0,1}};
const ClangBackEnd::SourceRangeWithTextContainer sourceRange{{1, 1}, 1, 1, 1, 1, 1, 1, "function"};
const ClangBackEnd::SourceRangeWithTextContainer sourceRange{1, 1, 1, 1, 1, 1, 1, "function"};
EXPECT_CALL(mockSearchHandle, addResult(QString("/path/to/file"), QString("function"), textRange))
.Times(1);
@@ -234,9 +234,9 @@ void RefactoringClient::SetUp()
client.setSearchHandle(&mockSearchHandle);
client.setExpectedResultCount(1);
ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1, 1})))
ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1})))
.WillByDefault(Return(FilePath(PathString("/path/to/file"))));
ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1, 42})))
ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{42})))
.WillByDefault(Return(clangBackEndFilePath));
}

View File

@@ -74,7 +74,7 @@ using SourceRangeExtractorSlowTest = SourceRangeExtractor;
TEST_F(SourceRangeExtractorSlowTest, ExtractSourceRangeContainer)
{
SourceRangeWithTextContainer sourceRangeContainer{{1, 1}, 1, 1, 0, 1, 10, 9, Utils::SmallString("int value;")};
SourceRangeWithTextContainer sourceRangeContainer{1, 1, 1, 0, 1, 10, 9, Utils::SmallString("int value;")};
extractor.addSourceRange(sourceRange);

View File

@@ -42,19 +42,19 @@ protected:
protected:
SourceRangeWithTextContainers sourceRanges1{{{1, 1}, 1, 1, 1, 2, 1, 4, "foo"},
{{1, 1}, 1, 1, 1, 2, 2, 5, "foo"},
{{1, 2}, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges2{{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"},
{{1, 1}, 1, 1, 1, 2, 1, 4, "foo"},
{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}};
SourceRangeWithTextContainers sourceRanges3{{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"},
{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges4{{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"},
{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"},
{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges5{{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"},
{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}};
SourceRangeWithTextContainers sourceRanges1{{1, 1, 1, 1, 2, 1, 4, "foo"},
{1, 1, 1, 1, 2, 2, 5, "foo"},
{2, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges2{{3, 1, 1, 1, 2, 1, 4, "foo"},
{1, 1, 1, 1, 2, 1, 4, "foo"},
{1, 1, 1, 1, 2, 3, 6, "foo"}};
SourceRangeWithTextContainers sourceRanges3{{1, 1, 1, 1, 2, 3, 6, "foo"},
{3, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges4{{1, 1, 1, 1, 2, 3, 6, "foo"},
{3, 1, 1, 1, 2, 1, 4, "foo"},
{3, 1, 1, 1, 2, 1, 4, "foo"}};
SourceRangeWithTextContainers sourceRanges5{{3, 1, 1, 1, 2, 1, 4, "foo"},
{1, 1, 1, 1, 2, 3, 6, "foo"}};
SourceRangesForQueryMessage message1{{Utils::clone(sourceRanges1)}};
SourceRangesForQueryMessage message2{{Utils::clone(sourceRanges2)}};
ClangBackEnd::SourceRangeFilter filter{3};

View File

@@ -37,103 +37,103 @@ protected:
TEST_F(SourcesManager, TouchFilePathIdFirstTime)
{
ASSERT_FALSE(sources.alreadyParsed({1, 1}, 56));
ASSERT_FALSE(sources.alreadyParsed(1, 56));
}
TEST_F(SourcesManager, TouchFilePathIdTwoTimesWithSameTime)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
ASSERT_FALSE(sources.alreadyParsed({1, 1}, 56));
ASSERT_FALSE(sources.alreadyParsed(1, 56));
}
TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithSameTime)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 1}, 56));
ASSERT_TRUE(sources.alreadyParsed(1, 56));
}
TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithOlderTime)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 1}, 55));
ASSERT_TRUE(sources.alreadyParsed(1, 55));
}
TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithNewerTime)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
ASSERT_FALSE(sources.alreadyParsed({1, 1}, 57));
ASSERT_FALSE(sources.alreadyParsed(1, 57));
}
TEST_F(SourcesManager, MultipleFileIds)
{
sources.alreadyParsed({1, 1}, 455);
sources.alreadyParsed({1, 4}, 56);
sources.alreadyParsed({1, 3}, 85);
sources.alreadyParsed({1, 6}, 56);
sources.alreadyParsed({1, 2}, 45);
sources.alreadyParsed(1, 455);
sources.alreadyParsed(4, 56);
sources.alreadyParsed(3, 85);
sources.alreadyParsed(6, 56);
sources.alreadyParsed(2, 45);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 3}, 85));
ASSERT_TRUE(sources.alreadyParsed(3, 85));
}
TEST_F(SourcesManager, UpdateModifiedTimeStampsWithNewerTimeStamp)
{
sources.alreadyParsed({1, 1}, 455);
sources.alreadyParsed({1, 4}, 56);
sources.alreadyParsed({1, 3}, 85);
sources.alreadyParsed({1, 6}, 56);
sources.alreadyParsed({1, 2}, 45);
sources.alreadyParsed(1, 455);
sources.alreadyParsed(4, 56);
sources.alreadyParsed(3, 85);
sources.alreadyParsed(6, 56);
sources.alreadyParsed(2, 45);
sources.updateModifiedTimeStamps();
sources.alreadyParsed({1, 3}, 86);
sources.alreadyParsed(3, 86);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 3}, 86));
ASSERT_TRUE(sources.alreadyParsed(3, 86));
}
TEST_F(SourcesManager, DontUpdateModifiedTimeStampsWithOlderTimeStamp)
{
sources.alreadyParsed({1, 1}, 455);
sources.alreadyParsed({1, 4}, 56);
sources.alreadyParsed({1, 3}, 85);
sources.alreadyParsed({1, 6}, 56);
sources.alreadyParsed({1, 2}, 45);
sources.alreadyParsed(1, 455);
sources.alreadyParsed(4, 56);
sources.alreadyParsed(3, 85);
sources.alreadyParsed(6, 56);
sources.alreadyParsed(2, 45);
sources.updateModifiedTimeStamps();
sources.alreadyParsed({1, 3}, 84);
sources.alreadyParsed(3, 84);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 3}, 85));
ASSERT_TRUE(sources.alreadyParsed(3, 85));
}
TEST_F(SourcesManager, ZeroTime)
{
sources.alreadyParsed({1, 1}, 0);
sources.alreadyParsed(1, 0);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 1}, 0));
ASSERT_TRUE(sources.alreadyParsed(1, 0));
}
TEST_F(SourcesManager, TimeIsUpdated)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed({1, 1}, 57);
sources.alreadyParsed(1, 56);
sources.alreadyParsed(1, 57);
sources.updateModifiedTimeStamps();
ASSERT_TRUE(sources.alreadyParsed({1, 1}, 57));
ASSERT_TRUE(sources.alreadyParsed(1, 57));
}
TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization)
@@ -143,22 +143,22 @@ TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization)
TEST_F(SourcesManager, AnyDependFileIsModified)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
ASSERT_TRUE(sources.dependentFilesModified());
}
TEST_F(SourcesManager, AnyDependFileIsModifiedAfterParsingTwoTimesSameTimeStamp)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.alreadyParsed(1, 56);
ASSERT_TRUE(sources.dependentFilesModified());
}
TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
ASSERT_FALSE(sources.dependentFilesModified());
@@ -166,68 +166,68 @@ TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate)
TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterNotAlreadyPared)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
ASSERT_FALSE(sources.dependentFilesModified());
}
TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterAlreadyPared)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed(1, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsed({1, 1}, 57);
sources.alreadyParsed(1, 57);
ASSERT_TRUE(sources.dependentFilesModified());
}
TEST_F(SourcesManager, AnyDependFileIsModifiedAfterUpdateNewTimeStamp)
{
sources.alreadyParsed({1, 1}, 56);
sources.alreadyParsed({1, 2}, 56);
sources.alreadyParsed(1, 56);
sources.alreadyParsed(2, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsed({1, 1}, 57);
sources.alreadyParsed(1, 57);
sources.alreadyParsed({1, 2}, 56);
sources.alreadyParsed(2, 56);
ASSERT_TRUE(sources.dependentFilesModified());
}
TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewTimeStamp)
{
sources.alreadyParsedAllDependentFiles({1, 1}, 56);
sources.alreadyParsedAllDependentFiles({1, 2}, 56);
sources.alreadyParsedAllDependentFiles(1, 56);
sources.alreadyParsedAllDependentFiles(2, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsedAllDependentFiles({1, 1}, 57);
sources.alreadyParsedAllDependentFiles(1, 57);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 56);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56);
ASSERT_FALSE(alreadyParsed);
}
TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewSecondTimeStamp)
{
sources.alreadyParsedAllDependentFiles({1, 1}, 56);
sources.alreadyParsedAllDependentFiles({1, 2}, 56);
sources.alreadyParsedAllDependentFiles(1, 56);
sources.alreadyParsedAllDependentFiles(2, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsedAllDependentFiles({1, 1}, 56);
sources.alreadyParsedAllDependentFiles(1, 56);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 57);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 57);
ASSERT_FALSE(alreadyParsed);
}
TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateSameTimeStamps)
{
sources.alreadyParsedAllDependentFiles({1, 1}, 56);
sources.alreadyParsedAllDependentFiles({1, 2}, 56);
sources.alreadyParsedAllDependentFiles(1, 56);
sources.alreadyParsedAllDependentFiles(2, 56);
sources.updateModifiedTimeStamps();
sources.alreadyParsedAllDependentFiles({1, 1}, 56);
sources.alreadyParsedAllDependentFiles(1, 56);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 56);
bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56);
ASSERT_TRUE(alreadyParsed);
}

View File

@@ -71,11 +71,11 @@ using ClangBackEnd::SourceLocationKind;
using ClangBackEnd::UsedMacros;
using OptionalProjectPartArtefact = Utils::optional<ClangBackEnd::ProjectPartArtefact>;
MATCHER_P2(IsFileId, directoryId, fileNameId,
MATCHER_P(IsFileId, fileNameId,
std::string(negation ? "isn't " : "is ")
+ PrintToString(ClangBackEnd::FilePathId(directoryId, fileNameId)))
+ PrintToString(ClangBackEnd::FilePathId(fileNameId)))
{
return arg == ClangBackEnd::FilePathId(directoryId, fileNameId);
return arg == ClangBackEnd::FilePathId(fileNameId);
}
struct Data
@@ -163,7 +163,7 @@ protected:
ClangBackEnd::FilePathId header2PathId{filePathId(TESTDATA_DIR "/symbolindexer_header1.h")};
ClangBackEnd::FilePathId header1PathId{filePathId(TESTDATA_DIR "/symbolindexer_header2.h")};
PathString generatedFileName = "includecollector_generated_file.h";
ClangBackEnd::FilePathId generatedFilePathId{1, 21};
ClangBackEnd::FilePathId generatedFilePathId21;
ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{{"BAR", "1"}, {"FOO", "1"}},
@@ -186,11 +186,11 @@ protected:
"void f();",
{}}};
SymbolEntries symbolEntries{{1, {"function", "function", SymbolKind::Function}}};
SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SourceLocationKind::Declaration}};
FilePathIds sourceFileIds{{1, 1}, {42, 23}};
UsedMacros usedMacros{{"Foo", {1, 1}}};
FileStatuses fileStatus{{{1, 2}, 3, 4, false}};
SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}};
SourceLocationEntries sourceLocations{{1, 1, {42, 23}, SourceLocationKind::Declaration}};
FilePathIds sourceFileIds{1, 23};
UsedMacros usedMacros{{"Foo", 1}};
FileStatuses fileStatus{{2, 3, 4, false}};
SourceDependencies sourceDependencies{{1, 2}, {1, 3}};
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\",\"BAR\":\"1\"}", "[\"/includes\"]", 74};
ClangBackEnd::ProjectPartArtefact emptyArtefact{"", "", "", 74};
Utils::optional<ClangBackEnd::ProjectPartArtefact > nullArtefact;
@@ -338,7 +338,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArti
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, 1), IsFileId(42, 23))));
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1), IsFileId(23))));
indexer.updateProjectParts({projectPart2});
}

View File

@@ -56,82 +56,82 @@ protected:
TEST_F(SymbolIndexerTaskQueue, AddTasks)
{
queue.addOrUpdateTasks({{{1, 2}, 1, Callable{}},
{{1, 4}, 1, Callable{}}});
queue.addOrUpdateTasks({{2, 1, Callable{}},
{4, 1, Callable{}}});
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
ASSERT_THAT(queue.tasks(),
ElementsAre(IsTask(FilePathId{1, 1}, 1),
IsTask(FilePathId{1, 2}, 1),
IsTask(FilePathId{1, 3}, 1),
IsTask(FilePathId{1, 4}, 1),
IsTask(FilePathId{1, 5}, 1)));
ElementsAre(IsTask(1, 1),
IsTask(2, 1),
IsTask(3, 1),
IsTask(4, 1),
IsTask(5, 1)));
}
TEST_F(SymbolIndexerTaskQueue, ReplaceTask)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 1, Callable{}},
{{1, 3}, 1, Callable{}}});
queue.addOrUpdateTasks({{2, 1, Callable{}},
{3, 1, Callable{}}});
ASSERT_THAT(queue.tasks(),
ElementsAre(IsTask(FilePathId{1, 1}, 1),
IsTask(FilePathId{1, 2}, 1),
IsTask(FilePathId{1, 3}, 1),
IsTask(FilePathId{1, 5}, 1)));
ElementsAre(IsTask(1, 1),
IsTask(2, 1),
IsTask(3, 1),
IsTask(5, 1)));
}
TEST_F(SymbolIndexerTaskQueue, AddTaskWithDifferentProjectId)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 2, Callable{}},
{{1, 3}, 2, Callable{}}});
queue.addOrUpdateTasks({{2, 2, Callable{}},
{3, 2, Callable{}}});
ASSERT_THAT(queue.tasks(),
ElementsAre(IsTask(FilePathId{1, 1}, 1),
IsTask(FilePathId{1, 2}, 2),
IsTask(FilePathId{1, 3}, 1),
IsTask(FilePathId{1, 3}, 2),
IsTask(FilePathId{1, 5}, 1)));
ElementsAre(IsTask(1, 1),
IsTask(2, 2),
IsTask(3, 1),
IsTask(3, 2),
IsTask(5, 1)));
}
TEST_F(SymbolIndexerTaskQueue, RemoveTaskByProjectParts)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 2, Callable{}},
{{1, 3}, 2, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 3, Callable{}},
{{1, 3}, 3, Callable{}}});
queue.addOrUpdateTasks({{{1, 2}, 4, Callable{}},
{{1, 3}, 4, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
queue.addOrUpdateTasks({{2, 2, Callable{}},
{3, 2, Callable{}}});
queue.addOrUpdateTasks({{2, 3, Callable{}},
{3, 3, Callable{}}});
queue.addOrUpdateTasks({{2, 4, Callable{}},
{3, 4, Callable{}}});
queue.removeTasks({2, 3});
ASSERT_THAT(queue.tasks(),
ElementsAre(IsTask(FilePathId{1, 1}, 1),
IsTask(FilePathId{1, 2}, 4),
IsTask(FilePathId{1, 3}, 1),
IsTask(FilePathId{1, 3}, 4),
IsTask(FilePathId{1, 5}, 1)));
ElementsAre(IsTask(1, 1),
IsTask(2, 4),
IsTask(3, 1),
IsTask(3, 4),
IsTask(5, 1)));
}
TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler)
{
InSequence s;
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(2));
EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(2)));
@@ -152,9 +152,9 @@ TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksWithNoTaskIn
TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndMoveAllTasksInSchedulerIfMoreSlotsAreFree)
{
InSequence s;
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(4));
EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(3)));
@@ -164,9 +164,9 @@ TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndMoveAllTasksInSchedu
TEST_F(SymbolIndexerTaskQueue, ProcessTasksRemovesProcessedTasks)
{
queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}},
{{1, 3}, 1, Callable{}},
{{1, 5}, 1, Callable{}}});
queue.addOrUpdateTasks({{1, 1, Callable{}},
{3, 1, Callable{}},
{5, 1, Callable{}}});
ON_CALL(mockTaskScheduler, freeSlots()).WillByDefault(Return(2));
queue.processEntries();

View File

@@ -61,12 +61,12 @@ protected:
MockSqliteReadStatement &selectSymbolsForKindAndStartsWith2 = mockStatementFactory.selectSymbolsForKindAndStartsWith2;
MockSqliteReadStatement &selectSymbolsForKindAndStartsWith3 = mockStatementFactory.selectSymbolsForKindAndStartsWith3;
MockSqliteReadStatement &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol;
SourceLocations locations{{{1, 1}, 1, 1},
{{1, 1}, 2, 3},
{{1, 2}, 1, 1},
{{1, 2}, 3, 1},
{{1, 4}, 1, 1},
{{1, 4}, 1, 3}};
SourceLocations locations{{1, 1, 1},
{1, 2, 3},
{2, 1, 1},
{2, 3, 1},
{4, 1, 1},
{4, 1, 3}};
MockQuery query{mockStatementFactory};
};
@@ -96,28 +96,28 @@ TEST_F(SymbolQuery, LocationsAtCallsValues)
{
EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7));
query.locationsAt({1, 42}, 14, 7);
query.locationsAt(42, 14, 7);
}
TEST_F(SymbolQuerySlowTest, LocationsAt)
{
auto locations = query.locationsAt({1, 2}, 4, 6);
auto locations = query.locationsAt(2, 4, 6);
ASSERT_THAT(locations,
UnorderedElementsAre(SourceLocation({1, 1}, 2, 3),
SourceLocation({1, 2}, 4, 6)));
UnorderedElementsAre(SourceLocation(1, 2, 3),
SourceLocation(2, 4, 6)));
}
TEST_F(SymbolQuery, SourceUsagesAtCallsValues)
{
EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7));
query.sourceUsagesAt({1, 42}, 14, 7);
query.sourceUsagesAt(42, 14, 7);
}
TEST_F(SymbolQuerySlowTest, SourceUsagesAt)
{
auto usages = query.sourceUsagesAt({1, 2}, 4, 6);
auto usages = query.sourceUsagesAt(2, 4, 6);
ASSERT_THAT(usages,
UnorderedElementsAre(CppTools::Usage("/path/to/filename.h", 2, 3),
@@ -190,7 +190,7 @@ TEST_F(SymbolQuerySlowTest, LocationForSymbolId)
{
auto location = query.locationForSymbolId(1, SourceLocationKind::Definition);
ASSERT_THAT(location.value(), Eq(SourceLocation({1, 2}, {4, 6})));
ASSERT_THAT(location.value(), Eq(SourceLocation(2, {4, 6})));
}
}

View File

@@ -76,8 +76,8 @@ protected:
SymbolEntries symbolEntries{{1, {"functionUSR", "function", SymbolKind::Function}},
{2, {"function2USR", "function2", SymbolKind::Function}}};
SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SourceLocationKind::Declaration},
{2, {1, 4}, {7, 11}, SourceLocationKind::Definition}};
SourceLocationEntries sourceLocations{{1, 3, {42, 23}, SourceLocationKind::Declaration},
{2, 4, {7, 11}, SourceLocationKind::Definition}};
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\"}", "[\"/includes\"]", 74};
};
@@ -213,7 +213,7 @@ TEST_F(SymbolStorage, UpdateProjectPartSources)
EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(1)));
EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(2)));
storage.updateProjectPartSources(42, {{1, 1}, {1, 2}});
storage.updateProjectPartSources(42, {1, 2});
}
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement)
@@ -221,7 +221,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement)
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
storage.fetchProjectPartArtefact({2, 1});
storage.fetchProjectPartArtefact(1);
}
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdReturnArtefact)
@@ -229,7 +229,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdReturnArtefact)
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
auto result = storage.fetchProjectPartArtefact({2, 1});
auto result = storage.fetchProjectPartArtefact(1);
ASSERT_THAT(result, Eq(artefact));
}
@@ -239,7 +239,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameCallsValueInStatement
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
storage.fetchProjectPartArtefact({2, 1});
storage.fetchProjectPartArtefact(1);
}
TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameReturnArtefact)
@@ -247,7 +247,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameReturnArtefact)
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
auto result = storage.fetchProjectPartArtefact({2, 1});
auto result = storage.fetchProjectPartArtefact(1);
ASSERT_THAT(result, Eq(artefact));
}

View File

@@ -79,7 +79,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateUsedMacros)
EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute());
EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute());
storage.insertOrUpdateUsedMacros({{"FOO", {1, 42}}, {"BAR", {1, 43}}});
storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}});
}
TEST_F(UsedMacroAndSourceStorage, InsertFileStatuses)
@@ -87,7 +87,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertFileStatuses)
EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(42), TypedEq<off_t>(1), TypedEq<time_t>(2), TypedEq<bool>(false)));
EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(43), TypedEq<off_t>(4), TypedEq<time_t>(5), TypedEq<bool>(true)));
storage.insertFileStatuses({{{1, 42}, 1, 2, false}, {{1, 43}, 4, 5, true}});
storage.insertFileStatuses({{42, 1, 2, false}, {43, 4, 5, true}});
}
TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies)
@@ -100,7 +100,7 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies)
EXPECT_CALL(deleteOutdatedSourceDependenciesStatement, execute());
EXPECT_CALL(deleteNewSourceDependenciesStatement, execute());
storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}});
storage.insertOrUpdateSourceDependencies({{42, 1}, {42, 2}});
}
TEST_F(UsedMacroAndSourceStorage, AddTablesInConstructor)
@@ -122,7 +122,7 @@ TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTimeIfNoModificationTim
{
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1)));
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 1});
auto lowestLastModified = storage.fetchLowestLastModifiedTime(1);
ASSERT_THAT(lowestLastModified, Eq(0));
}
@@ -132,7 +132,7 @@ TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTime)
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21)))
.WillRepeatedly(Return(12));
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 21});
auto lowestLastModified = storage.fetchLowestLastModifiedTime(21);
ASSERT_THAT(lowestLastModified, Eq(12));
}