2017-08-02 16:00:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "googletest.h"
|
2017-10-26 13:23:27 +02:00
|
|
|
#include "mockclangpathwatcher.h"
|
2017-08-02 16:00:55 +02:00
|
|
|
#include "mocksymbolscollector.h"
|
|
|
|
#include "mocksymbolstorage.h"
|
2018-01-22 14:21:01 +01:00
|
|
|
#include "mockfilepathcaching.h"
|
|
|
|
#include "mocksqlitetransactionbackend.h"
|
2018-10-11 18:09:55 +02:00
|
|
|
#include "mockusedmacroandsourcestorage.h"
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-02-08 17:49:02 +01:00
|
|
|
#include <filepathcaching.h>
|
|
|
|
#include <filestatuscache.h>
|
|
|
|
#include <projectpartcontainerv2.h>
|
|
|
|
#include <refactoringdatabaseinitializer.h>
|
2018-09-11 17:02:45 +02:00
|
|
|
#include <processormanager.h>
|
2017-08-02 16:00:55 +02:00
|
|
|
#include <symbolindexer.h>
|
2018-08-28 12:08:37 +02:00
|
|
|
#include <symbolindexertaskqueue.h>
|
2018-09-11 17:02:45 +02:00
|
|
|
#include <taskscheduler.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
#include <updateprojectpartsmessage.h>
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
#include <QCoreApplication>
|
2018-02-08 17:49:02 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
#include <fstream>
|
2017-08-02 16:00:55 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using Utils::PathString;
|
2018-02-06 19:03:14 +01:00
|
|
|
using ClangBackEnd::CompilerMacro;
|
2018-02-01 18:29:45 +01:00
|
|
|
using ClangBackEnd::FileStatuses;
|
2018-02-07 16:18:16 +01:00
|
|
|
using ClangBackEnd::FilePathId;
|
2018-01-22 14:21:01 +01:00
|
|
|
using ClangBackEnd::FilePathIds;
|
|
|
|
using ClangBackEnd::FilePathView;
|
2017-08-02 16:00:55 +02:00
|
|
|
using ClangBackEnd::V2::ProjectPartContainer;
|
|
|
|
using ClangBackEnd::V2::ProjectPartContainers;
|
2017-08-17 12:44:52 +02:00
|
|
|
using ClangBackEnd::V2::FileContainers;
|
2017-08-02 16:00:55 +02:00
|
|
|
using ClangBackEnd::SymbolEntries;
|
|
|
|
using ClangBackEnd::SymbolEntry;
|
2018-08-28 12:08:37 +02:00
|
|
|
using ClangBackEnd::SymbolIndexerTask;
|
|
|
|
using ClangBackEnd::SymbolIndexerTaskQueue;
|
2018-09-11 17:02:45 +02:00
|
|
|
using ClangBackEnd::TaskScheduler;
|
|
|
|
using ClangBackEnd::ProcessorManager;
|
2018-01-31 14:14:34 +01:00
|
|
|
using ClangBackEnd::SourceDependencies;
|
2017-08-02 16:00:55 +02:00
|
|
|
using ClangBackEnd::SourceLocationEntries;
|
|
|
|
using ClangBackEnd::SourceLocationEntry;
|
2018-03-22 17:46:43 +01:00
|
|
|
using ClangBackEnd::SymbolKind;
|
2018-04-09 13:30:30 +02:00
|
|
|
using ClangBackEnd::SourceLocationKind;
|
2018-01-25 15:20:47 +01:00
|
|
|
using ClangBackEnd::UsedMacros;
|
2018-02-20 12:43:05 +01:00
|
|
|
using OptionalProjectPartArtefact = Utils::optional<ClangBackEnd::ProjectPartArtefact>;
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
MATCHER_P2(IsFileId, directoryId, fileNameId,
|
|
|
|
std::string(negation ? "isn't " : "is ")
|
|
|
|
+ PrintToString(ClangBackEnd::FilePathId(directoryId, fileNameId)))
|
|
|
|
{
|
|
|
|
return arg == ClangBackEnd::FilePathId(directoryId, fileNameId);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:49:02 +01:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
|
|
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
|
|
|
ClangBackEnd::FilePathCaching filePathCache{database};
|
|
|
|
};
|
|
|
|
|
2018-09-11 17:02:45 +02:00
|
|
|
class Manager final : public ProcessorManager<NiceMock<MockSymbolsCollector>>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Processor = NiceMock<MockSymbolsCollector>;
|
|
|
|
Manager(const ClangBackEnd::GeneratedFiles &generatedFiles)
|
|
|
|
: ProcessorManager(generatedFiles)
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::unique_ptr<NiceMock<MockSymbolsCollector>> createProcessor() const
|
|
|
|
{
|
|
|
|
return std::make_unique<NiceMock<MockSymbolsCollector>>();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
class SymbolIndexer : public testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
2017-12-27 13:19:21 +01:00
|
|
|
void SetUp()
|
|
|
|
{
|
|
|
|
ON_CALL(mockCollector, symbols()).WillByDefault(ReturnRef(symbolEntries));
|
|
|
|
ON_CALL(mockCollector, sourceLocations()).WillByDefault(ReturnRef(sourceLocations));
|
2018-01-22 14:21:01 +01:00
|
|
|
ON_CALL(mockCollector, sourceFiles()).WillByDefault(ReturnRef(sourceFileIds));
|
2018-01-25 15:20:47 +01:00
|
|
|
ON_CALL(mockCollector, usedMacros()).WillByDefault(ReturnRef(usedMacros));
|
2018-02-01 18:29:45 +01:00
|
|
|
ON_CALL(mockCollector, fileStatuses()).WillByDefault(ReturnRef(fileStatus));
|
2018-01-31 14:14:34 +01:00
|
|
|
ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies));
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(A<FilePathId>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1));
|
2018-08-28 12:08:37 +02:00
|
|
|
|
|
|
|
mockCollector.setIsUsed(false);
|
2018-09-03 14:38:01 +02:00
|
|
|
|
|
|
|
generatedFiles.update(unsaved);
|
2018-08-28 12:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown()
|
|
|
|
{
|
|
|
|
syncTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void syncTasks()
|
|
|
|
{
|
|
|
|
while (!indexerQueue.tasks().empty() || !indexerScheduler.futures().empty()) {
|
|
|
|
indexerScheduler.syncTasks();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
}
|
2018-02-08 17:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetUpTestCase()
|
|
|
|
{
|
|
|
|
data = std::make_unique<Data>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestCase()
|
|
|
|
{
|
|
|
|
data.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void touchFile(FilePathId filePathId)
|
|
|
|
{
|
|
|
|
std::ofstream ostream(std::string(filePathCache.filePath(filePathId)), std::ios::binary);
|
|
|
|
ostream.write("\n", 1);
|
|
|
|
ostream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
FilePathId filePathId(Utils::SmallStringView path) const
|
|
|
|
{
|
|
|
|
return filePathCache.filePathId(ClangBackEnd::FilePathView(path));
|
2017-12-27 13:19:21 +01:00
|
|
|
}
|
2017-08-02 16:00:55 +02:00
|
|
|
|
|
|
|
protected:
|
2018-02-08 17:49:02 +01:00
|
|
|
static std::unique_ptr<Data> data; // it can be non const because data holds no tested classes
|
2018-09-11 17:02:45 +02:00
|
|
|
using Scheduler = TaskScheduler<Manager, ClangBackEnd::SymbolIndexerTask::Callable>;
|
2018-02-08 17:49:02 +01:00
|
|
|
ClangBackEnd::FilePathCaching &filePathCache = data->filePathCache;
|
|
|
|
ClangBackEnd::FilePathId main1PathId{filePathId(TESTDATA_DIR "/symbolindexer_main1.cpp")};
|
|
|
|
ClangBackEnd::FilePathId main2PathId{filePathId(TESTDATA_DIR "/symbolindexer_main2.cpp")};
|
|
|
|
ClangBackEnd::FilePathId header2PathId{filePathId(TESTDATA_DIR "/symbolindexer_header1.h")};
|
|
|
|
ClangBackEnd::FilePathId header1PathId{filePathId(TESTDATA_DIR "/symbolindexer_header2.h")};
|
2017-08-02 16:00:55 +02:00
|
|
|
PathString generatedFileName = "includecollector_generated_file.h";
|
2018-01-22 14:21:01 +01:00
|
|
|
ClangBackEnd::FilePathId generatedFilePathId{1, 21};
|
2017-08-02 16:00:55 +02:00
|
|
|
ProjectPartContainer projectPart1{"project1",
|
|
|
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
2018-02-07 16:11:28 +01:00
|
|
|
{{"BAR", "1"}, {"FOO", "1"}},
|
2018-02-08 12:48:46 +01:00
|
|
|
{"/includes"},
|
2018-01-22 14:21:01 +01:00
|
|
|
{header1PathId},
|
|
|
|
{main1PathId}};
|
2017-08-02 16:00:55 +02:00
|
|
|
ProjectPartContainer projectPart2{"project2",
|
|
|
|
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
2018-02-07 16:11:28 +01:00
|
|
|
{{"BAR", "1"}, {"FOO", "0"}},
|
2018-02-08 12:48:46 +01:00
|
|
|
{"/includes"},
|
2018-01-22 14:21:01 +01:00
|
|
|
{header2PathId},
|
|
|
|
{main2PathId}};
|
2018-02-08 17:49:02 +01:00
|
|
|
ProjectPartContainer projectPart3{"project3",
|
|
|
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
|
|
|
{{"BAR", "1"}, {"FOO", "1"}},
|
|
|
|
{"/includes", "/other/includes"},
|
|
|
|
{header1PathId},
|
|
|
|
{main1PathId}};
|
2017-08-17 12:44:52 +02:00
|
|
|
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
|
|
|
"void f();",
|
|
|
|
{}}};
|
2018-03-22 17:46:43 +01:00
|
|
|
SymbolEntries symbolEntries{{1, {"function", "function", SymbolKind::Function}}};
|
2018-04-09 13:30:30 +02:00
|
|
|
SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SourceLocationKind::Declaration}};
|
2018-01-22 14:21:01 +01:00
|
|
|
FilePathIds sourceFileIds{{1, 1}, {42, 23}};
|
2018-01-25 15:20:47 +01:00
|
|
|
UsedMacros usedMacros{{"Foo", {1, 1}}};
|
2018-02-14 18:49:25 +01:00
|
|
|
FileStatuses fileStatus{{{1, 2}, 3, 4, false}};
|
2018-01-31 14:14:34 +01:00
|
|
|
SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}};
|
2018-02-08 12:48:46 +01:00
|
|
|
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\",\"BAR\":\"1\"}", "[\"/includes\"]", 74};
|
2018-02-20 12:43:05 +01:00
|
|
|
ClangBackEnd::ProjectPartArtefact emptyArtefact{"", "", "", 74};
|
2018-09-04 14:24:42 +02:00
|
|
|
Utils::optional<ClangBackEnd::ProjectPartArtefact > nullArtefact;
|
2018-02-20 12:43:05 +01:00
|
|
|
ClangBackEnd::ProjectPartPch projectPartPch{"/path/to/pch", 4};
|
2018-01-22 14:21:01 +01:00
|
|
|
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
|
2018-10-11 18:09:55 +02:00
|
|
|
NiceMock<MockSymbolStorage> mockSymbolStorage;
|
|
|
|
NiceMock<MockUsedMacroAndSourceStorage> mockUsedMacroAndSourceStorage;
|
2017-10-26 13:23:27 +02:00
|
|
|
NiceMock<MockClangPathWatcher> mockPathWatcher;
|
2018-02-08 17:49:02 +01:00
|
|
|
ClangBackEnd::FileStatusCache fileStatusCache{filePathCache};
|
2018-09-03 14:38:01 +02:00
|
|
|
ClangBackEnd::GeneratedFiles generatedFiles;
|
2018-09-11 17:02:45 +02:00
|
|
|
Manager collectorManger{generatedFiles};
|
|
|
|
Scheduler indexerScheduler{collectorManger, indexerQueue, 1};
|
2018-08-28 12:08:37 +02:00
|
|
|
SymbolIndexerTaskQueue indexerQueue{indexerScheduler};
|
|
|
|
ClangBackEnd::SymbolIndexer indexer{indexerQueue,
|
2018-10-11 18:09:55 +02:00
|
|
|
mockSymbolStorage,
|
|
|
|
mockUsedMacroAndSourceStorage,
|
2018-02-08 17:49:02 +01:00
|
|
|
mockPathWatcher,
|
|
|
|
filePathCache,
|
|
|
|
fileStatusCache,
|
|
|
|
mockSqliteTransactionBackend};
|
2018-09-11 17:02:45 +02:00
|
|
|
MockSymbolsCollector &mockCollector{static_cast<MockSymbolsCollector&>(collectorManger.unusedProcessor())};
|
2017-08-02 16:00:55 +02:00
|
|
|
};
|
|
|
|
|
2018-02-08 17:49:02 +01:00
|
|
|
std::unique_ptr<Data> SymbolIndexer::data;
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
|
|
|
|
{
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(main1PathId, projectPart1.arguments));
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInCollector)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
|
|
|
ON_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))).WillByDefault(Return(projectPartPch));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(main1PathId,
|
2018-08-28 12:08:37 +02:00
|
|
|
ElementsAre(Eq("-I"),
|
|
|
|
Eq(TESTDATA_DIR),
|
|
|
|
Eq("-Wno-pragma-once-outside-header"),
|
|
|
|
Eq("-Xclang"),
|
|
|
|
Eq("-include-pch"),
|
|
|
|
Eq("-Xclang"),
|
|
|
|
Eq("/path/to/pch"))));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInCollector)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(main1PathId,
|
2018-08-28 12:08:37 +02:00
|
|
|
ElementsAre(Eq("-I"),
|
|
|
|
Eq(TESTDATA_DIR),
|
|
|
|
Eq("-Wno-pragma-once-outside-header"))));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 12:04:19 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsClearInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, clear()).Times(2);
|
2017-12-13 12:04:19 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-12-13 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollectorForEveryProjectPart)
|
|
|
|
{
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(_, _)).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsDoesNotCallAddFilesInCollectorForEmptyEveryProjectParts)
|
|
|
|
{
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(_, _))
|
2017-08-02 16:00:55 +02:00
|
|
|
.Times(0);
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallscollectSymbolsInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols()).Times(2);;
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsSymbolsInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, symbols()).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsSourceLocationsInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, sourceLocations()).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-08-17 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddUnsavedFilesInCollector)
|
|
|
|
{
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setUnsavedFiles(unsaved)).Times(2);
|
2017-08-17 12:44:52 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddSymbolsAndSourceLocationsInStorage)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"),
|
2018-01-29 12:07:15 +01:00
|
|
|
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
2018-02-08 12:48:46 +01:00
|
|
|
ElementsAre(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "1"}),
|
|
|
|
ElementsAre("/includes")));
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"),
|
2018-01-29 12:07:15 +01:00
|
|
|
ElementsAre("-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"),
|
2018-02-08 12:48:46 +01:00
|
|
|
ElementsAre(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "0"}),
|
|
|
|
ElementsAre("/includes")));
|
2018-01-22 14:21:01 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
|
|
|
|
2018-09-04 14:24:42 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithArtifact)
|
2018-01-22 14:21:01 +01:00
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project1"))).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"), _, _, _)).WillByDefault(Return(-1));
|
2018-01-22 14:21:01 +01:00
|
|
|
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(_, _));
|
2018-09-04 14:24:42 +02:00
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArtifact)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project2"))).WillByDefault(Return(nullArtefact));
|
|
|
|
ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _)).WillByDefault(Return(3));
|
2018-09-04 14:24:42 +02:00
|
|
|
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1, 1), IsFileId(42, 23))));
|
2018-09-04 14:24:42 +02:00
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart2});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 15:20:47 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros)
|
2018-01-23 18:08:17 +01:00
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)))
|
2018-01-23 18:08:17 +01:00
|
|
|
.Times(2);
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-01-23 18:08:17 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 18:29:45 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses)
|
2018-01-30 14:02:48 +01:00
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)))
|
2018-01-30 14:02:48 +01:00
|
|
|
.Times(2);
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-01-30 14:02:48 +01:00
|
|
|
}
|
|
|
|
|
2018-01-31 14:14:34 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateSourceDependencies)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)))
|
2018-01-31 14:14:34 +01:00
|
|
|
.Times(2);
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-01-31 14:14:34 +01:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:18:16 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsFetchProjectPartArtefacts)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId)));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart2.projectPartId)));
|
2018-02-07 16:18:16 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
2018-02-07 16:18:16 +01:00
|
|
|
}
|
|
|
|
|
2018-09-04 14:24:42 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
|
2017-08-02 16:00:55 +02:00
|
|
|
{
|
2017-12-13 12:04:19 +01:00
|
|
|
InSequence s;
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillOnce(Return(nullArtefact));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(12));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(12)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0);
|
2018-08-28 12:08:37 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(main1PathId, projectPart1.arguments));
|
2017-08-02 16:00:55 +02:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols());
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
2018-09-04 14:24:42 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
|
|
|
|
{
|
|
|
|
InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(-1));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1));
|
2018-09-04 14:24:42 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
|
|
|
EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), Eq(projectPart1.arguments)));
|
|
|
|
EXPECT_CALL(mockCollector, collectSymbols());
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(artefact.projectPartId), Eq(sourceFileIds)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
2017-12-27 13:20:24 +01:00
|
|
|
TEST_F(SymbolIndexer, CallSetNotifier)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(mockPathWatcher, setNotifier(_));
|
|
|
|
|
2018-10-11 18:09:55 +02:00
|
|
|
ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockUsedMacroAndSourceStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend};
|
2017-12-27 13:20:24 +01:00
|
|
|
}
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-02-06 11:16:29 +01:00
|
|
|
TEST_F(SymbolIndexer, PathChangedCallsFetchProjectPartArtefactInStorage)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[0]));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[1]));
|
2018-02-06 11:16:29 +01:00
|
|
|
|
|
|
|
indexer.pathsChanged(sourceFileIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
|
|
|
|
{
|
|
|
|
InSequence s;
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0]))).WillOnce(Return(artefact));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
2018-08-28 12:08:37 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(Eq(sourceFileIds[0]), Eq(artefact.compilerArguments)));
|
2018-02-06 11:16:29 +01:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols());
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
2018-02-06 11:16:29 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
indexer.pathsChanged({sourceFileIds[0]});
|
2018-02-06 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:49:02 +01:00
|
|
|
TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
|
2018-02-06 11:16:29 +01:00
|
|
|
{
|
2018-08-28 12:08:37 +02:00
|
|
|
InSequence s;
|
2018-02-06 11:16:29 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[0])).WillOnce(Return(nullArtefact));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(_)).Times(0);
|
2018-09-04 14:24:42 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
2018-02-06 11:16:29 +01:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols()).Times(0);
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
2018-02-06 11:16:29 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
indexer.pathsChanged({sourceFileIds[0]});
|
2018-02-06 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
2018-02-20 12:43:05 +01:00
|
|
|
.WillByDefault(Return(artefact));
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)))
|
2018-02-20 12:43:05 +01:00
|
|
|
.WillByDefault(Return(projectPartPch));
|
2018-08-28 12:08:37 +02:00
|
|
|
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(Eq(sourceFileIds[0]),
|
2018-08-28 12:08:37 +02:00
|
|
|
ElementsAre(Eq("-DFOO"),
|
|
|
|
Eq("-Xclang"),
|
|
|
|
Eq("-include-pch"),
|
|
|
|
Eq("-Xclang"),
|
|
|
|
Eq("/path/to/pch"))));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
indexer.pathsChanged({sourceFileIds[0]});
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
2018-02-20 12:43:05 +01:00
|
|
|
.WillByDefault(Return(artefact));
|
2018-08-28 12:08:37 +02:00
|
|
|
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(Eq(sourceFileIds[0]),
|
2018-08-28 12:08:37 +02:00
|
|
|
ElementsAre(Eq("-DFOO"))));
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
indexer.pathsChanged({sourceFileIds[0]});
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:48:46 +01:00
|
|
|
TEST_F(SymbolIndexer, CompilerMacrosAndIncludeSearchPathsAreNotDifferent)
|
2018-02-07 16:18:16 +01:00
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
2018-02-07 16:18:16 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart1,
|
|
|
|
artefact);
|
2018-02-07 16:18:16 +01:00
|
|
|
|
|
|
|
ASSERT_FALSE(areDifferent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, CompilerMacrosAreDifferent)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
2018-02-07 16:18:16 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart2,
|
|
|
|
artefact);
|
2018-02-08 12:48:46 +01:00
|
|
|
|
|
|
|
ASSERT_TRUE(areDifferent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent)
|
|
|
|
{
|
|
|
|
ProjectPartContainer projectPart3{"project3",
|
|
|
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
|
|
|
{{"BAR", "1"}, {"FOO", "1"}},
|
|
|
|
{"/includes", "/other/includes"},
|
|
|
|
{header1PathId},
|
|
|
|
{main1PathId}};
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
2018-02-08 12:48:46 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart3,
|
|
|
|
artefact);
|
2018-02-07 16:18:16 +01:00
|
|
|
|
|
|
|
ASSERT_TRUE(areDifferent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame)
|
|
|
|
{
|
2018-08-28 12:08:37 +02:00
|
|
|
InSequence s;
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
2018-02-07 16:18:16 +01:00
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
|
|
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths)));
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch()));
|
2018-08-28 12:08:37 +02:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
2018-02-07 16:18:16 +01:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols()).Times(0);
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
|
2018-10-11 18:09:55 +02:00
|
|
|
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
|
|
|
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0);
|
|
|
|
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
2018-02-07 16:18:16 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectPart(std::move(projectPart1));
|
2018-02-07 16:18:16 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:49:02 +01:00
|
|
|
TEST_F(SymbolIndexer, PathsChangedUpdatesFileStatusCache)
|
|
|
|
{
|
|
|
|
auto sourceId = filePathId(TESTDATA_DIR "/symbolindexer_pathChanged.cpp");
|
|
|
|
auto oldLastModified = fileStatusCache.lastModifiedTime(sourceId);
|
|
|
|
touchFile(sourceId);
|
|
|
|
|
|
|
|
indexer.pathsChanged({sourceId});
|
|
|
|
|
|
|
|
ASSERT_THAT(fileStatusCache.lastModifiedTime(sourceId), Gt(oldLastModified));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto filePathIds = indexer.updatableFilePathIds(projectPart2, artefact);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
ASSERT_THAT(filePathIds, projectPart2.sourcePathIds);
|
2018-02-08 17:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto filePathIds = indexer.updatableFilePathIds(projectPart3, artefact);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
ASSERT_THAT(filePathIds, projectPart3.sourcePathIds);
|
2018-02-08 17:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame)
|
|
|
|
{
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
|
|
|
ASSERT_THAT(filePathIds, IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds)
|
|
|
|
{
|
|
|
|
indexer.pathsChanged({main1PathId});
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
2018-02-08 17:49:02 +01:00
|
|
|
.WillByDefault(Return(0));
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
|
|
|
ASSERT_THAT(filePathIds, ElementsAre(main1PathId));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds)
|
|
|
|
{
|
|
|
|
indexer.pathsChanged({main1PathId});
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
2018-02-08 17:49:02 +01:00
|
|
|
.WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
|
|
|
ASSERT_THAT(filePathIds, IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, OutdatedFilesAreParsedInUpdateProjectParts)
|
|
|
|
{
|
|
|
|
indexer.pathsChanged({main1PathId});
|
2018-08-28 12:08:37 +02:00
|
|
|
indexerScheduler.syncTasks();
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
2018-02-08 17:49:02 +01:00
|
|
|
.WillByDefault(Return(0));
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), _));
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2018-02-08 17:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpToDateFilesAreNotParsedInUpdateProjectParts)
|
|
|
|
{
|
|
|
|
indexer.pathsChanged({main1PathId});
|
2018-08-28 12:08:37 +02:00
|
|
|
indexerScheduler.syncTasks();
|
2018-10-11 18:09:55 +02:00
|
|
|
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
|
|
|
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
2018-02-08 17:49:02 +01:00
|
|
|
.WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
indexer.updateProjectParts({projectPart1});
|
2018-02-08 17:49:02 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|