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"
|
2017-08-02 16:00:55 +02:00
|
|
|
|
|
|
|
#include <symbolindexer.h>
|
|
|
|
#include <updatepchprojectpartsmessage.h>
|
|
|
|
#include <projectpartcontainerv2.h>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using Utils::PathString;
|
2018-01-30 14:02:48 +01:00
|
|
|
using ClangBackEnd::FileInformations;
|
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;
|
|
|
|
using ClangBackEnd::SourceLocationEntries;
|
|
|
|
using ClangBackEnd::SourceLocationEntry;
|
|
|
|
using ClangBackEnd::SymbolType;
|
2018-01-25 15:20:47 +01:00
|
|
|
using ClangBackEnd::UsedMacros;
|
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);
|
|
|
|
}
|
|
|
|
|
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-01-30 14:02:48 +01:00
|
|
|
ON_CALL(mockCollector, fileInformations()).WillByDefault(ReturnRef(fileInformation));
|
2017-12-27 13:19:21 +01:00
|
|
|
}
|
2017-08-02 16:00:55 +02:00
|
|
|
|
|
|
|
protected:
|
2018-01-22 14:21:01 +01:00
|
|
|
ClangBackEnd::FilePathId main1PathId{1, 1};
|
|
|
|
ClangBackEnd::FilePathId main2PathId{1, 2};
|
|
|
|
ClangBackEnd::FilePathId header2PathId{1, 12};
|
|
|
|
ClangBackEnd::FilePathId header1PathId{1, 11};
|
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-01-25 13:08:02 +01:00
|
|
|
{"DEFINE"},
|
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-01-25 13:08:02 +01:00
|
|
|
{"DEFINE"},
|
2018-01-22 14:21:01 +01:00
|
|
|
{header2PathId},
|
|
|
|
{main2PathId}};
|
2017-08-17 12:44:52 +02:00
|
|
|
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
|
|
|
"void f();",
|
|
|
|
{}}};
|
2017-08-02 16:00:55 +02:00
|
|
|
SymbolEntries symbolEntries{{1, {"function", "function"}}};
|
2017-09-21 11:43:59 +02:00
|
|
|
SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SymbolType::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-01-30 14:02:48 +01:00
|
|
|
FileInformations fileInformation{{{1, 2}, 3, 4}};
|
2018-01-22 14:21:01 +01:00
|
|
|
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
|
2017-08-02 16:00:55 +02:00
|
|
|
NiceMock<MockSymbolsCollector> mockCollector;
|
|
|
|
NiceMock<MockSymbolStorage> mockStorage;
|
2017-10-26 13:23:27 +02:00
|
|
|
NiceMock<MockClangPathWatcher> mockPathWatcher;
|
2018-01-22 14:21:01 +01:00
|
|
|
NiceMock<MockFilePathCaching> mockFilePathCaching;
|
|
|
|
ClangBackEnd::SymbolIndexer indexer{mockCollector, mockStorage, mockPathWatcher, mockFilePathCaching, mockSqliteTransactionBackend};
|
2017-08-02 16:00:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, addFiles(projectPart1.sourcePathIds(), projectPart1.arguments()));
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
indexer.updateProjectParts({projectPart1}, Utils::clone(unsaved));
|
2017-08-02 16:00:55 +02: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-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
2017-12-13 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollectorForEveryProjectPart)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, addFiles(_, _)).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsDoesNotCallAddFilesInCollectorForEmptyEveryProjectParts)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(mockCollector, addFiles(_, _))
|
|
|
|
.Times(0);
|
|
|
|
|
2017-08-17 12:44:52 +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-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
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-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
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-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
2017-08-17 12:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddUnsavedFilesInCollector)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockCollector, addUnsavedFiles(unsaved)).Times(2);
|
2017-08-17 12:44:52 +02:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddSymbolsAndSourceLocationsInStorage)
|
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(2);
|
|
|
|
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(2);
|
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(2);
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
|
|
|
{
|
2018-01-29 12:07:15 +01:00
|
|
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"),
|
|
|
|
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
|
|
|
ElementsAre("DEFINE")));
|
|
|
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"),
|
|
|
|
ElementsAre("-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"),
|
|
|
|
ElementsAre("DEFINE")));
|
2018-01-22 14:21:01 +01:00
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSources)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(mockStorage, updateProjectPartSources(Eq("project1"), ElementsAre(IsFileId(1, 1), IsFileId(42, 23))));
|
|
|
|
EXPECT_CALL(mockStorage, updateProjectPartSources(Eq("project2"), ElementsAre(IsFileId(1, 1), IsFileId(42, 23))));
|
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
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-01-25 15:20:47 +01:00
|
|
|
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)))
|
2018-01-23 18:08:17 +01:00
|
|
|
.Times(2);
|
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:02:48 +01:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileInformations)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(mockStorage, insertFileInformations(Eq(fileInformation)))
|
|
|
|
.Times(2);
|
|
|
|
|
|
|
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrder)
|
|
|
|
{
|
2017-12-13 12:04:19 +01:00
|
|
|
InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(mockCollector, clear());
|
2017-08-02 16:00:55 +02:00
|
|
|
EXPECT_CALL(mockCollector, addFiles(_, _));
|
2017-08-17 12:44:52 +02:00
|
|
|
EXPECT_CALL(mockCollector, addUnsavedFiles(unsaved));
|
2017-08-02 16:00:55 +02:00
|
|
|
EXPECT_CALL(mockCollector, collectSymbols());
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
2017-08-02 16:00:55 +02:00
|
|
|
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
2018-01-29 12:07:15 +01:00
|
|
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(_, _, _));
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockStorage, updateProjectPartSources(_, _));
|
2018-01-25 15:20:47 +01:00
|
|
|
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
2018-01-30 14:02:48 +01:00
|
|
|
EXPECT_CALL(mockStorage, insertFileInformations(Eq(fileInformation)));
|
2018-01-22 14:21:01 +01:00
|
|
|
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
2017-08-02 16:00:55 +02:00
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
indexer.updateProjectParts({projectPart1}, Utils::clone(unsaved));
|
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-01-22 14:21:01 +01:00
|
|
|
ClangBackEnd::SymbolIndexer indexer{mockCollector, mockStorage, mockPathWatcher, mockFilePathCaching, mockSqliteTransactionBackend};
|
2017-12-27 13:20:24 +01:00
|
|
|
}
|
2017-08-02 16:00:55 +02:00
|
|
|
|
|
|
|
}
|