forked from qt-creator/qt-creator
Clang: Split symbol storage
We need UsedMacros and source related statements in the PCH manager too, so we have to split that class. Task-number: QTCREATORBUG-21289 Change-Id: Ie27d4b518b3d6d9174e93fcb243fdb55a09ddf51 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -26,7 +26,9 @@ HEADERS += \
|
||||
$$PWD/collectusedmacroactionfactory.h \
|
||||
$$PWD/collectusedmacrosaction.h \
|
||||
$$PWD/collectusedmacrosandsourcespreprocessorcallbacks.h \
|
||||
$$PWD/usedmacrosandsourcescollector.h
|
||||
$$PWD/usedmacrosandsourcescollector.h \
|
||||
$$PWD/usedmacroandsourcestorageinterface.h \
|
||||
$$PWD/usedmacroandsourcestorage.h
|
||||
|
||||
!isEmpty(LIBTOOLING_LIBS) {
|
||||
SOURCES += \
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "usedmacroandsourcestorageinterface.h"
|
||||
|
||||
#include <compilermacro.h>
|
||||
#include <sqliteexception.h>
|
||||
#include <sqlitetable.h>
|
||||
#include <sqlitetransaction.h>
|
||||
|
||||
#include <utils/smallstringview.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
template<typename Database=Sqlite::Database>
|
||||
class UsedMacroAndSourceStorage final : public UsedMacroAndSourceStorageInterface
|
||||
{
|
||||
using ReadStatement = typename Database::ReadStatement;
|
||||
using WriteStatement = typename Database::WriteStatement;
|
||||
public:
|
||||
UsedMacroAndSourceStorage(Database &database)
|
||||
: m_transaction(database),
|
||||
m_database(database)
|
||||
{
|
||||
m_transaction.commit();
|
||||
}
|
||||
|
||||
void insertFileStatuses(const FileStatuses &fileStatuses) override
|
||||
{
|
||||
WriteStatement &statement = m_insertFileStatuses;
|
||||
|
||||
for (const FileStatus &fileStatus : fileStatuses)
|
||||
statement.write(fileStatus.filePathId.filePathId,
|
||||
fileStatus.size,
|
||||
fileStatus.lastModified,
|
||||
fileStatus.isInPrecompiledHeader);
|
||||
}
|
||||
|
||||
long long fetchLowestLastModifiedTime(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_getLowestLastModifiedTimeOfDependencies;
|
||||
|
||||
return statement.template value<long long>(sourceId.filePathId).value_or(0);
|
||||
}
|
||||
|
||||
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_insertIntoNewUsedMacrosStatement;
|
||||
for (const UsedMacro &usedMacro : usedMacros)
|
||||
insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName);
|
||||
|
||||
m_syncNewUsedMacrosStatement.execute();
|
||||
m_deleteOutdatedUsedMacrosStatement.execute();
|
||||
m_deleteNewUsedMacrosTableStatement.execute();
|
||||
}
|
||||
|
||||
void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_insertIntoNewSourceDependenciesStatement;
|
||||
for (SourceDependency sourceDependency : sourceDependencies)
|
||||
insertStatement.write(sourceDependency.filePathId.filePathId,
|
||||
sourceDependency.dependencyFilePathId.filePathId);
|
||||
|
||||
m_syncNewSourceDependenciesStatement.execute();
|
||||
m_deleteOutdatedSourceDependenciesStatement.execute();
|
||||
m_deleteNewSourceDependenciesStatement.execute();
|
||||
}
|
||||
|
||||
static Utils::SmallString toJson(const Utils::SmallStringVector &strings)
|
||||
{
|
||||
QJsonDocument document;
|
||||
QJsonArray array;
|
||||
|
||||
std::transform(strings.begin(), strings.end(), std::back_inserter(array), [] (const auto &string) {
|
||||
return QJsonValue(string.data());
|
||||
});
|
||||
|
||||
document.setArray(array);
|
||||
|
||||
return document.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
static Utils::SmallString toJson(const CompilerMacros &compilerMacros)
|
||||
{
|
||||
QJsonDocument document;
|
||||
QJsonObject object;
|
||||
|
||||
for (const CompilerMacro ¯o : compilerMacros)
|
||||
object.insert(QString(macro.key), QString(macro.value));
|
||||
|
||||
document.setObject(object);
|
||||
|
||||
return document.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
Sqlite::Table createNewUsedMacrosTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newUsedMacros");
|
||||
table.setUseTemporaryTable(true);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, macroNameColumn});
|
||||
|
||||
table.initialize(m_database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewSourceDependenciesTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newSourceDependencies");
|
||||
table.setUseTemporaryTable(true);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &dependencySourceIdColumn = table.addColumn("dependencySourceId", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, dependencySourceIdColumn});
|
||||
|
||||
table.initialize(m_database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
public:
|
||||
Sqlite::ImmediateNonThrowingDestructorTransaction m_transaction;
|
||||
Database &m_database;
|
||||
Sqlite::Table newUsedMacroTable{createNewUsedMacrosTable()};
|
||||
Sqlite::Table newNewSourceDependenciesTable{createNewSourceDependenciesTable()};
|
||||
WriteStatement m_insertIntoNewUsedMacrosStatement{
|
||||
"INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_syncNewUsedMacrosStatement{
|
||||
"INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteOutdatedUsedMacrosStatement{
|
||||
"DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteNewUsedMacrosTableStatement{
|
||||
"DELETE FROM newUsedMacros",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getLowestLastModifiedTimeOfDependencies{
|
||||
"WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = sourceIds.sourceId",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_insertIntoNewSourceDependenciesStatement{
|
||||
"INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_insertFileStatuses{
|
||||
"INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_syncNewSourceDependenciesStatement{
|
||||
"INSERT INTO sourceDependencies(sourceId, dependencySourceId) SELECT sourceId, dependencySourceId FROM newSourceDependencies WHERE NOT EXISTS (SELECT sourceId FROM sourceDependencies WHERE sourceDependencies.sourceId == newSourceDependencies.sourceId AND sourceDependencies.dependencySourceId == newSourceDependencies.dependencySourceId)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteOutdatedSourceDependenciesStatement{
|
||||
"DELETE FROM sourceDependencies WHERE sourceId IN (SELECT sourceId FROM newSourceDependencies) AND NOT EXISTS (SELECT sourceId FROM newSourceDependencies WHERE newSourceDependencies.sourceId == sourceDependencies.sourceId AND newSourceDependencies.dependencySourceId == sourceDependencies.dependencySourceId)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteNewSourceDependenciesStatement{
|
||||
"DELETE FROM newSourceDependencies",
|
||||
m_database
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "filestatus.h"
|
||||
#include "sourcedependency.h"
|
||||
#include "usedmacro.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class UsedMacroAndSourceStorageInterface
|
||||
{
|
||||
public:
|
||||
UsedMacroAndSourceStorageInterface() = default;
|
||||
UsedMacroAndSourceStorageInterface(const UsedMacroAndSourceStorageInterface &) = delete;
|
||||
UsedMacroAndSourceStorageInterface &operator=(const UsedMacroAndSourceStorageInterface &) = delete;
|
||||
|
||||
virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0;
|
||||
virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0;
|
||||
virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0;
|
||||
virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
~UsedMacroAndSourceStorageInterface() = default;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -9,7 +9,6 @@ HEADERS += \
|
||||
$$PWD/symbolscollectorinterface.h \
|
||||
$$PWD/symbolstorageinterface.h \
|
||||
$$PWD/symbolstorage.h \
|
||||
$$PWD/storagesqlitestatementfactory.h \
|
||||
$$PWD/symbolindexing.h \
|
||||
$$PWD/symbolindexinginterface.h \
|
||||
$$PWD/collectmacrospreprocessorcallbacks.h \
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sqlitetransaction.h>
|
||||
#include <sqlitetable.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
template<typename DatabaseType>
|
||||
class StorageSqliteStatementFactory
|
||||
{
|
||||
public:
|
||||
using Database = DatabaseType;
|
||||
using ReadStatement = typename Database::ReadStatement;
|
||||
using WriteStatement = typename Database::WriteStatement;
|
||||
|
||||
StorageSqliteStatementFactory(Database &database)
|
||||
: transaction(database),
|
||||
database(database)
|
||||
{
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
Sqlite::Table createNewSymbolsTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newSymbols");
|
||||
table.setUseTemporaryTable(true);
|
||||
table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
|
||||
const Sqlite::Column &symbolIdColumn = table.addColumn("symbolId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text);
|
||||
const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text);
|
||||
table.addColumn("symbolKind", Sqlite::ColumnType::Integer);
|
||||
table.addIndex({usrColumn, symbolNameColumn});
|
||||
table.addIndex({symbolIdColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewLocationsTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newLocations");
|
||||
table.setUseTemporaryTable(true);
|
||||
table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer);
|
||||
table.addColumn("symbolId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer);
|
||||
table.addColumn("locationKind", Sqlite::ColumnType::Integer);
|
||||
table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewUsedMacrosTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newUsedMacros");
|
||||
table.setUseTemporaryTable(true);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, macroNameColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewSourceDependenciesTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newSourceDependencies");
|
||||
table.setUseTemporaryTable(true);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &dependencySourceIdColumn = table.addColumn("dependencySourceId", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, dependencySourceIdColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
public:
|
||||
Sqlite::ImmediateNonThrowingDestructorTransaction transaction;
|
||||
Database &database;
|
||||
Sqlite::Table newSymbolsTablet{createNewSymbolsTable()};
|
||||
Sqlite::Table newLocationsTable{createNewLocationsTable()};
|
||||
Sqlite::Table newUsedMacroTable{createNewUsedMacrosTable()};
|
||||
Sqlite::Table newNewSourceDependenciesTable{createNewSourceDependenciesTable()};
|
||||
WriteStatement insertSymbolsToNewSymbolsStatement{
|
||||
"INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)",
|
||||
database};
|
||||
WriteStatement insertLocationsToNewLocationsStatement{
|
||||
"INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)",
|
||||
database
|
||||
};
|
||||
ReadStatement selectNewSourceIdsStatement{
|
||||
"SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources WHERE newLocations.sourceId == sources.sourceId)",
|
||||
database
|
||||
};
|
||||
WriteStatement addNewSymbolsToSymbolsStatement{
|
||||
"INSERT INTO symbols(usr, symbolName, symbolKind) "
|
||||
"SELECT usr, symbolName, symbolKind FROM newSymbols WHERE NOT EXISTS "
|
||||
"(SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)",
|
||||
database
|
||||
};
|
||||
WriteStatement syncNewSymbolsFromSymbolsStatement{
|
||||
"UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = symbols.usr)",
|
||||
database
|
||||
};
|
||||
WriteStatement syncSymbolsIntoNewLocationsStatement{
|
||||
"UPDATE newLocations SET symbolId = (SELECT symbolId FROM newSymbols WHERE newSymbols.temporarySymbolId = newLocations.temporarySymbolId)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteAllLocationsFromUpdatedFilesStatement{
|
||||
"DELETE FROM locations WHERE sourceId IN (SELECT DISTINCT sourceId FROM newLocations)",
|
||||
database
|
||||
};
|
||||
WriteStatement insertNewLocationsInLocationsStatement{
|
||||
"INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteNewSymbolsTableStatement{
|
||||
"DELETE FROM newSymbols",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteNewLocationsTableStatement{
|
||||
"DELETE FROM newLocations",
|
||||
database
|
||||
};
|
||||
WriteStatement insertProjectPartStatement{
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros, includeSearchPaths) VALUES (?,?,?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement updateProjectPartStatement{
|
||||
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ?, includeSearchPaths = ? WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartIdStatement{
|
||||
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteAllProjectPartsSourcesWithProjectPartIdStatement{
|
||||
"DELETE FROM projectPartsSources WHERE projectPartId = ?",
|
||||
database
|
||||
};
|
||||
WriteStatement insertProjectPartSourcesStatement{
|
||||
"INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)",
|
||||
database
|
||||
};
|
||||
ReadStatement getCompileArgumentsForFileIdStatement{
|
||||
"SELECT compilerArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
WriteStatement insertIntoNewUsedMacrosStatement{
|
||||
"INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement syncNewUsedMacrosStatement{
|
||||
"INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteOutdatedUsedMacrosStatement{
|
||||
"DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteNewUsedMacrosTableStatement{
|
||||
"DELETE FROM newUsedMacros",
|
||||
database
|
||||
};
|
||||
WriteStatement insertFileStatuses{
|
||||
"INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement insertIntoNewSourceDependenciesStatement{
|
||||
"INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement syncNewSourceDependenciesStatement{
|
||||
"INSERT INTO sourceDependencies(sourceId, dependencySourceId) SELECT sourceId, dependencySourceId FROM newSourceDependencies WHERE NOT EXISTS (SELECT sourceId FROM sourceDependencies WHERE sourceDependencies.sourceId == newSourceDependencies.sourceId AND sourceDependencies.dependencySourceId == newSourceDependencies.dependencySourceId)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteOutdatedSourceDependenciesStatement{
|
||||
"DELETE FROM sourceDependencies WHERE sourceId IN (SELECT sourceId FROM newSourceDependencies) AND NOT EXISTS (SELECT sourceId FROM newSourceDependencies WHERE newSourceDependencies.sourceId == sourceDependencies.sourceId AND newSourceDependencies.dependencySourceId == sourceDependencies.dependencySourceId)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteNewSourceDependenciesStatement{
|
||||
"DELETE FROM newSourceDependencies",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartArtefactsBySourceId{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartArtefactsByProjectPartName{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
ReadStatement getLowestLastModifiedTimeOfDependencies{
|
||||
"WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = sourceIds.sourceId",
|
||||
database
|
||||
};
|
||||
ReadStatement getPrecompiledHeader{
|
||||
"SELECT pchPath, pchBuildTime FROM precompiledHeaders WHERE projectPartId = ?",
|
||||
database
|
||||
};
|
||||
};
|
||||
} // namespace ClangBackEnd
|
||||
@@ -58,12 +58,14 @@ private:
|
||||
|
||||
SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
UsedMacroAndSourceStorageInterface &usedMacroAndSourceStorage,
|
||||
ClangPathWatcherInterface &pathWatcher,
|
||||
FilePathCachingInterface &filePathCache,
|
||||
FileStatusCache &fileStatusCache,
|
||||
Sqlite::TransactionInterface &transactionInterface)
|
||||
: m_symbolIndexerTaskQueue(symbolIndexerTaskQueue),
|
||||
m_symbolStorage(symbolStorage),
|
||||
m_usedMacroAndSourceStorage(usedMacroAndSourceStorage),
|
||||
m_pathWatcher(pathWatcher),
|
||||
m_filePathCache(filePathCache),
|
||||
m_fileStatusCache(fileStatusCache),
|
||||
@@ -115,11 +117,11 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart)
|
||||
m_symbolStorage.updateProjectPartSources(projectPartId,
|
||||
symbolsCollector.sourceFiles());
|
||||
|
||||
m_symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
|
||||
m_usedMacroAndSourceStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
|
||||
|
||||
m_symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
|
||||
m_usedMacroAndSourceStorage.insertFileStatuses(symbolsCollector.fileStatuses());
|
||||
|
||||
m_symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
|
||||
m_usedMacroAndSourceStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
|
||||
|
||||
transaction.commit();
|
||||
};
|
||||
@@ -180,11 +182,11 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
|
||||
|
||||
m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles());
|
||||
|
||||
m_symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
|
||||
m_usedMacroAndSourceStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
|
||||
|
||||
m_symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
|
||||
m_usedMacroAndSourceStorage.insertFileStatuses(symbolsCollector.fileStatuses());
|
||||
|
||||
m_symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
|
||||
m_usedMacroAndSourceStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
|
||||
|
||||
transaction.commit();
|
||||
};
|
||||
@@ -212,7 +214,7 @@ FilePathIds SymbolIndexer::filterChangedFiles(const V2::ProjectPartContainer &pr
|
||||
ids.reserve(projectPart.sourcePathIds.size());
|
||||
|
||||
for (const FilePathId &sourceId : projectPart.sourcePathIds) {
|
||||
long long oldLastModified = m_symbolStorage.fetchLowestLastModifiedTime(sourceId);
|
||||
long long oldLastModified = m_usedMacroAndSourceStorage.fetchLowestLastModifiedTime(sourceId);
|
||||
long long currentLastModified = m_fileStatusCache.lastModifiedTime(sourceId);
|
||||
if (oldLastModified < currentLastModified)
|
||||
ids.push_back(sourceId);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "filestatuscache.h"
|
||||
#include "symbolindexertaskqueueinterface.h"
|
||||
#include "symbolstorageinterface.h"
|
||||
#include "usedmacroandsourcestorageinterface.h"
|
||||
#include "clangpathwatcher.h"
|
||||
|
||||
#include <projectpartcontainerv2.h>
|
||||
@@ -42,6 +43,7 @@ class SymbolIndexer final : public ClangPathWatcherNotifier
|
||||
public:
|
||||
SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
UsedMacroAndSourceStorageInterface &usedMacroAndSourceStorage,
|
||||
ClangPathWatcherInterface &pathWatcher,
|
||||
FilePathCachingInterface &filePathCache,
|
||||
FileStatusCache &fileStatusCache,
|
||||
@@ -71,6 +73,7 @@ public:
|
||||
private:
|
||||
SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue;
|
||||
SymbolStorageInterface &m_symbolStorage;
|
||||
UsedMacroAndSourceStorageInterface &m_usedMacroAndSourceStorage;
|
||||
ClangPathWatcherInterface &m_pathWatcher;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
FileStatusCache &m_fileStatusCache;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "symbolindexinginterface.h"
|
||||
|
||||
#include "storagesqlitestatementfactory.h"
|
||||
#include "symbolindexer.h"
|
||||
#include "symbolscollector.h"
|
||||
#include "processormanager.h"
|
||||
@@ -35,6 +34,8 @@
|
||||
#include "taskscheduler.h"
|
||||
#include "symbolstorage.h"
|
||||
|
||||
#include <usedmacroandsourcestorage.h>
|
||||
|
||||
#include <refactoringdatabaseinitializer.h>
|
||||
#include <filepathcachingfwd.h>
|
||||
|
||||
@@ -73,13 +74,14 @@ private:
|
||||
class SymbolIndexing final : public SymbolIndexingInterface
|
||||
{
|
||||
public:
|
||||
using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<Sqlite::Database>;
|
||||
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
|
||||
using UsedMacroAndSourceStorage = ClangBackEnd::UsedMacroAndSourceStorage<Sqlite::Database>;
|
||||
using SymbolStorage = ClangBackEnd::SymbolStorage<Sqlite::Database>;
|
||||
SymbolIndexing(Sqlite::Database &database,
|
||||
FilePathCachingInterface &filePathCache,
|
||||
const GeneratedFiles &generatedFiles)
|
||||
: m_filePathCache(filePathCache),
|
||||
m_statementFactory(database),
|
||||
m_usedMacroAndSourceStorage(database),
|
||||
m_symbolStorage(database),
|
||||
m_collectorManger(generatedFiles, database),
|
||||
m_indexerScheduler(m_collectorManger, m_indexerQueue, std::thread::hardware_concurrency())
|
||||
{
|
||||
@@ -109,8 +111,8 @@ public:
|
||||
private:
|
||||
using SymbolIndexerTaskScheduler = TaskScheduler<SymbolsCollectorManager, SymbolIndexerTask::Callable>;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
StatementFactory m_statementFactory;
|
||||
Storage m_symbolStorage{m_statementFactory};
|
||||
UsedMacroAndSourceStorage m_usedMacroAndSourceStorage;
|
||||
SymbolStorage m_symbolStorage;
|
||||
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache};
|
||||
FileStatusCache m_fileStatusCache{m_filePathCache};
|
||||
SymbolsCollectorManager m_collectorManger;
|
||||
@@ -118,10 +120,11 @@ private:
|
||||
SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler};
|
||||
SymbolIndexer m_indexer{m_indexerQueue,
|
||||
m_symbolStorage,
|
||||
m_usedMacroAndSourceStorage,
|
||||
m_sourceWatcher,
|
||||
m_filePathCache,
|
||||
m_fileStatusCache,
|
||||
m_statementFactory.database};
|
||||
m_symbolStorage.m_database};
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
#include "symbolstorageinterface.h"
|
||||
|
||||
#include <filepathcachingfwd.h>
|
||||
#include <sqliteexception.h>
|
||||
#include <sqlitetransaction.h>
|
||||
#include <filepathcachingfwd.h>
|
||||
#include <sqlitetable.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -37,17 +38,19 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
template <typename StatementFactory>
|
||||
template <typename DatabaseType>
|
||||
class SymbolStorage final : public SymbolStorageInterface
|
||||
{
|
||||
using ReadStatement = typename StatementFactory::ReadStatement;
|
||||
using WriteStatement = typename StatementFactory::WriteStatement;
|
||||
using Database = typename StatementFactory::Database;
|
||||
using Database = DatabaseType;
|
||||
using ReadStatement = typename Database::ReadStatement;
|
||||
using WriteStatement = typename Database::WriteStatement;
|
||||
|
||||
public:
|
||||
SymbolStorage(StatementFactory &statementFactory)
|
||||
: m_statementFactory(statementFactory)
|
||||
SymbolStorage(Database &database)
|
||||
: m_transaction(database),
|
||||
m_database(database)
|
||||
{
|
||||
m_transaction.commit();
|
||||
}
|
||||
|
||||
void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries,
|
||||
@@ -69,95 +72,54 @@ public:
|
||||
const CompilerMacros &compilerMacros,
|
||||
const Utils::SmallStringVector &includeSearchPaths) override
|
||||
{
|
||||
m_statementFactory.database.setLastInsertedRowId(-1);
|
||||
m_database.setLastInsertedRowId(-1);
|
||||
|
||||
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
||||
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
|
||||
Utils::SmallString includeSearchPathsAsJason = toJson(includeSearchPaths);
|
||||
|
||||
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
||||
WriteStatement &insertStatement = m_insertProjectPartStatement;
|
||||
insertStatement.write(projectPartName,
|
||||
compilerArguementsAsJson,
|
||||
compilerMacrosAsJson,
|
||||
includeSearchPathsAsJason);
|
||||
|
||||
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
||||
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
||||
if (m_database.lastInsertedRowId() == -1) {
|
||||
WriteStatement &updateStatement = m_updateProjectPartStatement;
|
||||
updateStatement.write(compilerArguementsAsJson,
|
||||
compilerMacrosAsJson,
|
||||
includeSearchPathsAsJason,
|
||||
projectPartName);
|
||||
}
|
||||
|
||||
return int(m_statementFactory.database.lastInsertedRowId());
|
||||
return int(m_database.lastInsertedRowId());
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartArtefactsBySourceId;
|
||||
ReadStatement &statement = m_getProjectPartArtefactsBySourceId;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 4>(sourceId.filePathId);
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartArtefactsByProjectPartName;
|
||||
ReadStatement &statement = m_getProjectPartArtefactsByProjectPartName;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 4>(projectPartName);
|
||||
}
|
||||
|
||||
long long fetchLowestLastModifiedTime(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getLowestLastModifiedTimeOfDependencies;
|
||||
|
||||
return statement.template value<long long>(sourceId.filePathId).value_or(0);
|
||||
}
|
||||
|
||||
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedMacrosStatement;
|
||||
for (const UsedMacro &usedMacro : usedMacros)
|
||||
insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName);
|
||||
|
||||
m_statementFactory.syncNewUsedMacrosStatement.execute();
|
||||
m_statementFactory.deleteOutdatedUsedMacrosStatement.execute();
|
||||
m_statementFactory.deleteNewUsedMacrosTableStatement.execute();
|
||||
}
|
||||
|
||||
void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_statementFactory.insertIntoNewSourceDependenciesStatement;
|
||||
for (SourceDependency sourceDependency : sourceDependencies)
|
||||
insertStatement.write(sourceDependency.filePathId.filePathId,
|
||||
sourceDependency.dependencyFilePathId.filePathId);
|
||||
|
||||
m_statementFactory.syncNewSourceDependenciesStatement.execute();
|
||||
m_statementFactory.deleteOutdatedSourceDependenciesStatement.execute();
|
||||
m_statementFactory.deleteNewSourceDependenciesStatement.execute();
|
||||
}
|
||||
|
||||
void updateProjectPartSources(int projectPartId,
|
||||
const FilePathIds &sourceFilePathIds) override
|
||||
{
|
||||
WriteStatement &deleteStatement = m_statementFactory.deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
||||
WriteStatement &deleteStatement = m_deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
||||
deleteStatement.write(projectPartId);
|
||||
|
||||
WriteStatement &insertStatement = m_statementFactory.insertProjectPartSourcesStatement;
|
||||
WriteStatement &insertStatement = m_insertProjectPartSourcesStatement;
|
||||
for (const FilePathId &sourceFilePathId : sourceFilePathIds)
|
||||
insertStatement.write(projectPartId, sourceFilePathId.filePathId);
|
||||
}
|
||||
|
||||
void insertFileStatuses(const FileStatuses &fileStatuses)
|
||||
{
|
||||
WriteStatement &statement = m_statementFactory.insertFileStatuses;
|
||||
|
||||
for (const FileStatus &fileStatus : fileStatuses)
|
||||
statement.write(fileStatus.filePathId.filePathId,
|
||||
fileStatus.size,
|
||||
fileStatus.lastModified,
|
||||
fileStatus.isInPrecompiledHeader);
|
||||
}
|
||||
|
||||
static Utils::SmallString toJson(const Utils::SmallStringVector &strings)
|
||||
{
|
||||
QJsonDocument document;
|
||||
@@ -187,7 +149,7 @@ public:
|
||||
|
||||
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
|
||||
{
|
||||
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;
|
||||
WriteStatement &statement = m_insertSymbolsToNewSymbolsStatement;
|
||||
|
||||
for (const auto &symbolEntry : symbolEntries) {
|
||||
statement.write(symbolEntry.first,
|
||||
@@ -199,7 +161,7 @@ public:
|
||||
|
||||
void fillTemporaryLocationsTable(const SourceLocationEntries &sourceLocations)
|
||||
{
|
||||
WriteStatement &statement = m_statementFactory.insertLocationsToNewLocationsStatement;
|
||||
WriteStatement &statement = m_insertLocationsToNewLocationsStatement;
|
||||
|
||||
for (const auto &locationEntry : sourceLocations) {
|
||||
statement.write(locationEntry.symbolId,
|
||||
@@ -212,42 +174,42 @@ public:
|
||||
|
||||
void addNewSymbolsToSymbols()
|
||||
{
|
||||
m_statementFactory.addNewSymbolsToSymbolsStatement.execute();
|
||||
m_addNewSymbolsToSymbolsStatement.execute();
|
||||
}
|
||||
|
||||
void syncNewSymbolsFromSymbols()
|
||||
{
|
||||
m_statementFactory.syncNewSymbolsFromSymbolsStatement.execute();
|
||||
m_syncNewSymbolsFromSymbolsStatement.execute();
|
||||
}
|
||||
|
||||
void syncSymbolsIntoNewLocations()
|
||||
{
|
||||
m_statementFactory.syncSymbolsIntoNewLocationsStatement.execute();
|
||||
m_syncSymbolsIntoNewLocationsStatement.execute();
|
||||
}
|
||||
|
||||
void deleteAllLocationsFromUpdatedFiles()
|
||||
{
|
||||
m_statementFactory.deleteAllLocationsFromUpdatedFilesStatement.execute();
|
||||
m_deleteAllLocationsFromUpdatedFilesStatement.execute();
|
||||
}
|
||||
|
||||
void insertNewLocationsInLocations()
|
||||
{
|
||||
m_statementFactory.insertNewLocationsInLocationsStatement.execute();
|
||||
m_insertNewLocationsInLocationsStatement.execute();
|
||||
}
|
||||
|
||||
void deleteNewSymbolsTable()
|
||||
{
|
||||
m_statementFactory.deleteNewSymbolsTableStatement.execute();
|
||||
m_deleteNewSymbolsTableStatement.execute();
|
||||
}
|
||||
|
||||
void deleteNewLocationsTable()
|
||||
{
|
||||
m_statementFactory.deleteNewLocationsTableStatement.execute();
|
||||
m_deleteNewLocationsTableStatement.execute();
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartPch> fetchPrecompiledHeader(int projectPartId) const
|
||||
{
|
||||
return m_statementFactory.getPrecompiledHeader.template value<ProjectPartPch, 2>(projectPartId);
|
||||
return m_getPrecompiledHeader.template value<ProjectPartPch, 2>(projectPartId);
|
||||
}
|
||||
|
||||
SourceLocationEntries sourceLocations() const
|
||||
@@ -255,8 +217,124 @@ public:
|
||||
return SourceLocationEntries();
|
||||
}
|
||||
|
||||
private:
|
||||
StatementFactory &m_statementFactory;
|
||||
Sqlite::Table createNewSymbolsTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newSymbols");
|
||||
table.setUseTemporaryTable(true);
|
||||
table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
|
||||
const Sqlite::Column &symbolIdColumn = table.addColumn("symbolId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text);
|
||||
const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text);
|
||||
table.addColumn("symbolKind", Sqlite::ColumnType::Integer);
|
||||
table.addIndex({usrColumn, symbolNameColumn});
|
||||
table.addIndex({symbolIdColumn});
|
||||
|
||||
table.initialize(m_database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewLocationsTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newLocations");
|
||||
table.setUseTemporaryTable(true);
|
||||
table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer);
|
||||
table.addColumn("symbolId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer);
|
||||
table.addColumn("locationKind", Sqlite::ColumnType::Integer);
|
||||
table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn});
|
||||
|
||||
table.initialize(m_database);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
public:
|
||||
Sqlite::ImmediateNonThrowingDestructorTransaction m_transaction;
|
||||
Database &m_database;
|
||||
Sqlite::Table newSymbolsTablet{createNewSymbolsTable()};
|
||||
Sqlite::Table newLocationsTable{createNewLocationsTable()};
|
||||
WriteStatement m_insertSymbolsToNewSymbolsStatement{
|
||||
"INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)",
|
||||
m_database};
|
||||
WriteStatement m_insertLocationsToNewLocationsStatement{
|
||||
"INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)",
|
||||
m_database
|
||||
};
|
||||
ReadStatement m_selectNewSourceIdsStatement{
|
||||
"SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources WHERE newLocations.sourceId == sources.sourceId)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_addNewSymbolsToSymbolsStatement{
|
||||
"INSERT INTO symbols(usr, symbolName, symbolKind) "
|
||||
"SELECT usr, symbolName, symbolKind FROM newSymbols WHERE NOT EXISTS "
|
||||
"(SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_syncNewSymbolsFromSymbolsStatement{
|
||||
"UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = symbols.usr)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_syncSymbolsIntoNewLocationsStatement{
|
||||
"UPDATE newLocations SET symbolId = (SELECT symbolId FROM newSymbols WHERE newSymbols.temporarySymbolId = newLocations.temporarySymbolId)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteAllLocationsFromUpdatedFilesStatement{
|
||||
"DELETE FROM locations WHERE sourceId IN (SELECT DISTINCT sourceId FROM newLocations)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_insertNewLocationsInLocationsStatement{
|
||||
"INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteNewSymbolsTableStatement{
|
||||
"DELETE FROM newSymbols",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteNewLocationsTableStatement{
|
||||
"DELETE FROM newLocations",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_insertProjectPartStatement{
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros, includeSearchPaths) VALUES (?,?,?,?)",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_updateProjectPartStatement{
|
||||
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ?, includeSearchPaths = ? WHERE projectPartName = ?",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getProjectPartIdStatement{
|
||||
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_deleteAllProjectPartsSourcesWithProjectPartIdStatement{
|
||||
"DELETE FROM projectPartsSources WHERE projectPartId = ?",
|
||||
m_database
|
||||
};
|
||||
WriteStatement m_insertProjectPartSourcesStatement{
|
||||
"INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getCompileArgumentsForFileIdStatement{
|
||||
"SELECT compilerArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getProjectPartArtefactsBySourceId{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getProjectPartArtefactsByProjectPartName{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
m_database
|
||||
};
|
||||
mutable ReadStatement m_getPrecompiledHeader{
|
||||
"SELECT pchPath, pchBuildTime FROM precompiledHeaders WHERE projectPartId = ?",
|
||||
m_database
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -55,12 +55,8 @@ public:
|
||||
const Utils::SmallStringVector &includeSearchPaths) = 0;
|
||||
virtual void updateProjectPartSources(int projectPartId,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0;
|
||||
virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0;
|
||||
virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0;
|
||||
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const = 0;
|
||||
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const = 0;
|
||||
virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0;
|
||||
virtual Utils::optional<ProjectPartPch> fetchPrecompiledHeader(int projectPartId) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -45,18 +45,10 @@ public:
|
||||
MOCK_METHOD2(updateProjectPartSources,
|
||||
void(int projectPartId,
|
||||
const ClangBackEnd::FilePathIds &sourceFilePathIds));
|
||||
MOCK_METHOD1(insertOrUpdateUsedMacros,
|
||||
void (const ClangBackEnd::UsedMacros &usedMacros));
|
||||
MOCK_METHOD1(insertFileStatuses,
|
||||
void (const ClangBackEnd::FileStatuses &fileStatuses));
|
||||
MOCK_METHOD1(insertOrUpdateSourceDependencies,
|
||||
void (const ClangBackEnd::SourceDependencies &sourceDependencies));
|
||||
MOCK_CONST_METHOD1(fetchProjectPartArtefact,
|
||||
Utils::optional<ClangBackEnd::ProjectPartArtefact> (ClangBackEnd::FilePathId sourceId));
|
||||
MOCK_CONST_METHOD1(fetchProjectPartArtefact,
|
||||
Utils::optional<ClangBackEnd::ProjectPartArtefact> (Utils::SmallStringView projectPartName));
|
||||
MOCK_CONST_METHOD1(fetchLowestLastModifiedTime,
|
||||
long long (ClangBackEnd::FilePathId sourceId));
|
||||
MOCK_CONST_METHOD1(fetchPrecompiledHeader,
|
||||
Utils::optional<ClangBackEnd::ProjectPartPch> (int projectPartId));
|
||||
};
|
||||
|
||||
45
tests/unit/unittest/mockusedmacroandsourcestorage.h
Normal file
45
tests/unit/unittest/mockusedmacroandsourcestorage.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include "mocksqlitedatabase.h"
|
||||
|
||||
#include <usedmacroandsourcestorageinterface.h>
|
||||
|
||||
class MockUsedMacroAndSourceStorage : public ClangBackEnd::UsedMacroAndSourceStorageInterface
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(insertOrUpdateUsedMacros,
|
||||
void (const ClangBackEnd::UsedMacros &usedMacros));
|
||||
MOCK_METHOD1(insertFileStatuses,
|
||||
void (const ClangBackEnd::FileStatuses &fileStatuses));
|
||||
MOCK_METHOD1(insertOrUpdateSourceDependencies,
|
||||
void (const ClangBackEnd::SourceDependencies &sourceDependencies));
|
||||
MOCK_CONST_METHOD1(fetchLowestLastModifiedTime,
|
||||
long long (ClangBackEnd::FilePathId sourceId));
|
||||
};
|
||||
@@ -1,282 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include "mocksqlitedatabase.h"
|
||||
#include "mocksqlitereadstatement.h"
|
||||
#include "mocksqlitewritestatement.h"
|
||||
|
||||
#include <storagesqlitestatementfactory.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
|
||||
|
||||
using Sqlite::Table;
|
||||
|
||||
class StorageSqliteStatementFactory : public testing::Test
|
||||
{
|
||||
protected:
|
||||
NiceMock<MockSqliteDatabase> mockDatabase;
|
||||
StatementFactory factory{mockDatabase};
|
||||
};
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddNewSymbolsTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
|
||||
|
||||
factory.createNewSymbolsTable();
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddNewLocationsTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
|
||||
|
||||
factory.createNewLocationsTable();
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddNewUsedMacroTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)")));
|
||||
|
||||
factory.createNewUsedMacrosTable();
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddNewSourceDependenciesTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, dependencySourceId TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId ON newSourceDependencies(sourceId, dependencySourceId)")));
|
||||
|
||||
factory.createNewSourceDependenciesTable();
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddTablesInConstructor)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, immediateBegin());
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, dependencySourceId TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId ON newSourceDependencies(sourceId, dependencySourceId)")));
|
||||
EXPECT_CALL(mockDatabase, commit());
|
||||
|
||||
StatementFactory factory{mockDatabase};
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertNewSymbolsStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.insertSymbolsToNewSymbolsStatement.sqlStatement,
|
||||
Eq("INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertNewLocationsToLocations)
|
||||
{
|
||||
ASSERT_THAT(factory.insertLocationsToNewLocationsStatement.sqlStatement,
|
||||
Eq("INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, SelectNewSourceIdsStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.selectNewSourceIdsStatement.sqlStatement,
|
||||
Eq("SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources WHERE newLocations.sourceId == sources.sourceId)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, AddNewSymbolsToSymbolsStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.addNewSymbolsToSymbolsStatement.sqlStatement,
|
||||
Eq("INSERT INTO symbols(usr, symbolName, symbolKind) SELECT usr, symbolName, symbolKind FROM newSymbols WHERE NOT EXISTS (SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, SyncNewSymbolsFromSymbolsStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.syncNewSymbolsFromSymbolsStatement.sqlStatement,
|
||||
Eq("UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = symbols.usr)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, SyncSymbolsIntoNewLocations)
|
||||
{
|
||||
ASSERT_THAT(factory.syncSymbolsIntoNewLocationsStatement.sqlStatement,
|
||||
Eq("UPDATE newLocations SET symbolId = (SELECT symbolId FROM newSymbols WHERE newSymbols.temporarySymbolId = newLocations.temporarySymbolId)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteAllLocationsFromUpdatedFiles)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteAllLocationsFromUpdatedFilesStatement.sqlStatement,
|
||||
Eq("DELETE FROM locations WHERE sourceId IN (SELECT DISTINCT sourceId FROM newLocations)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertNewLocationsInLocations)
|
||||
{
|
||||
ASSERT_THAT(factory.insertNewLocationsInLocationsStatement.sqlStatement,
|
||||
Eq("INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteNewSymbolsTableStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteNewSymbolsTableStatement.sqlStatement,
|
||||
Eq("DELETE FROM newSymbols"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteNewLocationsTableStatement)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteNewLocationsTableStatement.sqlStatement,
|
||||
Eq("DELETE FROM newLocations"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertProjectPart)
|
||||
{
|
||||
ASSERT_THAT(factory.insertProjectPartStatement.sqlStatement,
|
||||
Eq("INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros, includeSearchPaths) VALUES (?,?,?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, UpdateProjectPart)
|
||||
{
|
||||
ASSERT_THAT(factory.updateProjectPartStatement.sqlStatement,
|
||||
Eq("UPDATE projectParts SET compilerArguments = ?, compilerMacros = ?, includeSearchPaths = ? WHERE projectPartName = ?"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetProjectPartIdForProjectPartName)
|
||||
{
|
||||
ASSERT_THAT(factory.getProjectPartIdStatement.sqlStatement,
|
||||
Eq("SELECT projectPartId FROM projectParts WHERE projectPartName = ?"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteAllProjectPartsSourcesWithProjectPartId)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteAllProjectPartsSourcesWithProjectPartIdStatement.sqlStatement,
|
||||
Eq("DELETE FROM projectPartsSources WHERE projectPartId = ?"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertProjectPartsSources)
|
||||
{
|
||||
ASSERT_THAT(factory.insertProjectPartSourcesStatement.sqlStatement,
|
||||
Eq("INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetCompileArgumentsForFileId)
|
||||
{
|
||||
ASSERT_THAT(factory.getCompileArgumentsForFileIdStatement.sqlStatement,
|
||||
Eq("SELECT compilerArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertIntoNewUsedMacros)
|
||||
{
|
||||
ASSERT_THAT(factory.insertIntoNewUsedMacrosStatement.sqlStatement,
|
||||
Eq("INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, SyncNewUsedMacros)
|
||||
{
|
||||
ASSERT_THAT(factory.syncNewUsedMacrosStatement.sqlStatement,
|
||||
Eq("INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteOutdatedUnusedMacros)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteOutdatedUsedMacrosStatement.sqlStatement,
|
||||
Eq("DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteAllInNewUnusedMacros)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteNewUsedMacrosTableStatement.sqlStatement,
|
||||
Eq("DELETE FROM newUsedMacros"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertFileStatuses)
|
||||
{
|
||||
ASSERT_THAT(factory.insertFileStatuses.sqlStatement,
|
||||
Eq("INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, InsertIntoNewSourceDependencies)
|
||||
{
|
||||
ASSERT_THAT(factory.insertIntoNewSourceDependenciesStatement.sqlStatement,
|
||||
Eq("INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, SyncNewSourceDependencies)
|
||||
{
|
||||
ASSERT_THAT(factory.syncNewSourceDependenciesStatement.sqlStatement,
|
||||
Eq("INSERT INTO sourceDependencies(sourceId, dependencySourceId) SELECT sourceId, dependencySourceId FROM newSourceDependencies WHERE NOT EXISTS (SELECT sourceId FROM sourceDependencies WHERE sourceDependencies.sourceId == newSourceDependencies.sourceId AND sourceDependencies.dependencySourceId == newSourceDependencies.dependencySourceId)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteOutdatedSourceDependencies)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteOutdatedSourceDependenciesStatement.sqlStatement,
|
||||
Eq("DELETE FROM sourceDependencies WHERE sourceId IN (SELECT sourceId FROM newSourceDependencies) AND NOT EXISTS (SELECT sourceId FROM newSourceDependencies WHERE newSourceDependencies.sourceId == sourceDependencies.sourceId AND newSourceDependencies.dependencySourceId == sourceDependencies.dependencySourceId)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, DeleteAllInNewSourceDependencies)
|
||||
{
|
||||
ASSERT_THAT(factory.deleteNewSourceDependenciesStatement.sqlStatement,
|
||||
Eq("DELETE FROM newSourceDependencies"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetProjectPartCompilerArgumentsAndCompilerMacrosBySourceId)
|
||||
{
|
||||
ASSERT_THAT(factory.getProjectPartArtefactsBySourceId.sqlStatement,
|
||||
Eq("SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetProjectPartArtefactsByProjectPartName)
|
||||
{
|
||||
ASSERT_THAT(factory.getProjectPartArtefactsByProjectPartName.sqlStatement,
|
||||
Eq("SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?"));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetLowestLastModifiedTimeOfDependencies)
|
||||
{
|
||||
ASSERT_THAT(factory.getLowestLastModifiedTimeOfDependencies.sqlStatement,
|
||||
Eq("WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = sourceIds.sourceId"));
|
||||
}
|
||||
|
||||
TEST_F(StorageSqliteStatementFactory, GetPrecompiledHeaderForProjectPartName)
|
||||
{
|
||||
ASSERT_THAT(factory.getPrecompiledHeader.sqlStatement,
|
||||
Eq("SELECT pchPath, pchBuildTime FROM precompiledHeaders WHERE projectPartId = ?"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "mocksymbolstorage.h"
|
||||
#include "mockfilepathcaching.h"
|
||||
#include "mocksqlitetransactionbackend.h"
|
||||
#include "mockusedmacroandsourcestorage.h"
|
||||
|
||||
#include <filepathcaching.h>
|
||||
#include <filestatuscache.h>
|
||||
@@ -110,8 +111,8 @@ protected:
|
||||
ON_CALL(mockCollector, usedMacros()).WillByDefault(ReturnRef(usedMacros));
|
||||
ON_CALL(mockCollector, fileStatuses()).WillByDefault(ReturnRef(fileStatus));
|
||||
ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies));
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(A<FilePathId>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(A<FilePathId>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1));
|
||||
|
||||
mockCollector.setIsUsed(false);
|
||||
|
||||
@@ -195,7 +196,8 @@ protected:
|
||||
Utils::optional<ClangBackEnd::ProjectPartArtefact > nullArtefact;
|
||||
ClangBackEnd::ProjectPartPch projectPartPch{"/path/to/pch", 4};
|
||||
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
|
||||
NiceMock<MockSymbolStorage> mockStorage;
|
||||
NiceMock<MockSymbolStorage> mockSymbolStorage;
|
||||
NiceMock<MockUsedMacroAndSourceStorage> mockUsedMacroAndSourceStorage;
|
||||
NiceMock<MockClangPathWatcher> mockPathWatcher;
|
||||
ClangBackEnd::FileStatusCache fileStatusCache{filePathCache};
|
||||
ClangBackEnd::GeneratedFiles generatedFiles;
|
||||
@@ -203,7 +205,8 @@ protected:
|
||||
Scheduler indexerScheduler{collectorManger, indexerQueue, 1};
|
||||
SymbolIndexerTaskQueue indexerQueue{indexerScheduler};
|
||||
ClangBackEnd::SymbolIndexer indexer{indexerQueue,
|
||||
mockStorage,
|
||||
mockSymbolStorage,
|
||||
mockUsedMacroAndSourceStorage,
|
||||
mockPathWatcher,
|
||||
filePathCache,
|
||||
fileStatusCache,
|
||||
@@ -222,8 +225,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInCollector)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
||||
ON_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))).WillByDefault(Return(projectPartPch));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
||||
ON_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))).WillByDefault(Return(projectPartPch));
|
||||
|
||||
EXPECT_CALL(mockCollector, setFile(main1PathId,
|
||||
ElementsAre(Eq("-I"),
|
||||
@@ -239,7 +242,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInCollector)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillByDefault(Return(emptyArtefact));
|
||||
|
||||
EXPECT_CALL(mockCollector, setFile(main1PathId,
|
||||
ElementsAre(Eq("-I"),
|
||||
@@ -301,18 +304,18 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddUnsavedFilesInCollector)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddSymbolsAndSourceLocationsInStorage)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(2);
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(2);
|
||||
|
||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||
}
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"),
|
||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"),
|
||||
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
||||
ElementsAre(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "1"}),
|
||||
ElementsAre("/includes")));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"),
|
||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"),
|
||||
ElementsAre("-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"),
|
||||
ElementsAre(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "0"}),
|
||||
ElementsAre("/includes")));
|
||||
@@ -322,27 +325,27 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithArtifact)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project1"))).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"), _, _, _)).WillByDefault(Return(-1));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project1"))).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"), _, _, _)).WillByDefault(Return(-1));
|
||||
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(_, _));
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(_, _));
|
||||
|
||||
indexer.updateProjectParts({projectPart1});
|
||||
}
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArtifact)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project2"))).WillByDefault(Return(nullArtefact));
|
||||
ON_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _)).WillByDefault(Return(3));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project2"))).WillByDefault(Return(nullArtefact));
|
||||
ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _)).WillByDefault(Return(3));
|
||||
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1, 1), IsFileId(42, 23))));
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1, 1), IsFileId(42, 23))));
|
||||
|
||||
indexer.updateProjectParts({projectPart2});
|
||||
}
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)))
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)))
|
||||
.Times(2);
|
||||
|
||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||
@@ -350,7 +353,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)))
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)))
|
||||
.Times(2);
|
||||
|
||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||
@@ -358,7 +361,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateSourceDependencies)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)))
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)))
|
||||
.Times(2);
|
||||
|
||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||
@@ -366,8 +369,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateSourceDependencies)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateProjectPartsCallsFetchProjectPartArtefacts)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId)));
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart2.projectPartId)));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId)));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart2.projectPartId)));
|
||||
|
||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||
}
|
||||
@@ -377,19 +380,19 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillOnce(Return(nullArtefact));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(12));
|
||||
EXPECT_CALL(mockStorage, fetchPrecompiledHeader(Eq(12)));
|
||||
EXPECT_CALL(mockStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillOnce(Return(nullArtefact));
|
||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(12));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(12)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
EXPECT_CALL(mockCollector, setFile(main1PathId, projectPart1.arguments));
|
||||
EXPECT_CALL(mockCollector, collectSymbols());
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
|
||||
indexer.updateProjectParts({projectPart1});
|
||||
@@ -400,19 +403,19 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(-1));
|
||||
EXPECT_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
||||
EXPECT_CALL(mockStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(-1));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), Eq(projectPart1.arguments)));
|
||||
EXPECT_CALL(mockCollector, collectSymbols());
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(TypedEq<int>(artefact.projectPartId), Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(artefact.projectPartId), Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
|
||||
indexer.updateProjectParts({projectPart1});
|
||||
@@ -422,13 +425,13 @@ TEST_F(SymbolIndexer, CallSetNotifier)
|
||||
{
|
||||
EXPECT_CALL(mockPathWatcher, setNotifier(_));
|
||||
|
||||
ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend};
|
||||
ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockUsedMacroAndSourceStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend};
|
||||
}
|
||||
|
||||
TEST_F(SymbolIndexer, PathChangedCallsFetchProjectPartArtefactInStorage)
|
||||
{
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(sourceFileIds[0]));
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(sourceFileIds[1]));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[0]));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[1]));
|
||||
|
||||
indexer.pathsChanged(sourceFileIds);
|
||||
}
|
||||
@@ -438,17 +441,17 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0]))).WillOnce(Return(artefact));
|
||||
EXPECT_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0]))).WillOnce(Return(artefact));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
EXPECT_CALL(mockCollector, setFile(Eq(sourceFileIds[0]), Eq(artefact.compilerArguments)));
|
||||
EXPECT_CALL(mockCollector, collectSymbols());
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies)));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
|
||||
indexer.pathsChanged({sourceFileIds[0]});
|
||||
@@ -459,17 +462,17 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin());
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(sourceFileIds[0])).WillOnce(Return(nullArtefact));
|
||||
EXPECT_CALL(mockStorage, fetchPrecompiledHeader(_)).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(sourceFileIds[0])).WillOnce(Return(nullArtefact));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(_)).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
||||
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
||||
EXPECT_CALL(mockCollector, collectSymbols()).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(_)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
||||
|
||||
indexer.pathsChanged({sourceFileIds[0]});
|
||||
@@ -477,9 +480,9 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
||||
.WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)))
|
||||
ON_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)))
|
||||
.WillByDefault(Return(projectPartPch));
|
||||
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
||||
|
||||
@@ -495,7 +498,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
|
||||
|
||||
TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
|
||||
.WillByDefault(Return(artefact));
|
||||
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
||||
|
||||
@@ -508,7 +511,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
|
||||
|
||||
TEST_F(SymbolIndexer, CompilerMacrosAndIncludeSearchPathsAreNotDifferent)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
|
||||
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart1,
|
||||
artefact);
|
||||
@@ -518,7 +521,7 @@ TEST_F(SymbolIndexer, CompilerMacrosAndIncludeSearchPathsAreNotDifferent)
|
||||
|
||||
TEST_F(SymbolIndexer, CompilerMacrosAreDifferent)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
|
||||
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart2,
|
||||
artefact);
|
||||
@@ -534,7 +537,7 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent)
|
||||
{"/includes", "/other/includes"},
|
||||
{header1PathId},
|
||||
{main1PathId}};
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
|
||||
auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart3,
|
||||
artefact);
|
||||
@@ -545,21 +548,21 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent)
|
||||
TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame)
|
||||
{
|
||||
InSequence s;
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths)));
|
||||
EXPECT_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact));
|
||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths)));
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit());
|
||||
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
||||
EXPECT_CALL(mockCollector, collectSymbols()).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0);
|
||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
||||
EXPECT_CALL(mockStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertFileStatuses(_)).Times(0);
|
||||
EXPECT_CALL(mockStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0);
|
||||
EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0);
|
||||
EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0);
|
||||
EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0);
|
||||
|
||||
indexer.updateProjectPart(std::move(projectPart1));
|
||||
@@ -578,7 +581,7 @@ TEST_F(SymbolIndexer, PathsChangedUpdatesFileStatusCache)
|
||||
|
||||
TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
|
||||
auto filePathIds = indexer.updatableFilePathIds(projectPart2, artefact);
|
||||
|
||||
@@ -587,7 +590,7 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent)
|
||||
|
||||
TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
|
||||
auto filePathIds = indexer.updatableFilePathIds(projectPart3, artefact);
|
||||
|
||||
@@ -596,8 +599,8 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent)
|
||||
|
||||
TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame)
|
||||
{
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
|
||||
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
||||
|
||||
@@ -607,8 +610,8 @@ TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame)
|
||||
TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds)
|
||||
{
|
||||
indexer.pathsChanged({main1PathId});
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
.WillByDefault(Return(0));
|
||||
|
||||
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
||||
@@ -619,8 +622,8 @@ TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds)
|
||||
TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds)
|
||||
{
|
||||
indexer.pathsChanged({main1PathId});
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
.WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
|
||||
auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
|
||||
@@ -632,8 +635,8 @@ TEST_F(SymbolIndexer, OutdatedFilesAreParsedInUpdateProjectParts)
|
||||
{
|
||||
indexer.pathsChanged({main1PathId});
|
||||
indexerScheduler.syncTasks();
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
.WillByDefault(Return(0));
|
||||
|
||||
EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), _));
|
||||
@@ -645,8 +648,8 @@ TEST_F(SymbolIndexer, UpToDateFilesAreNotParsedInUpdateProjectParts)
|
||||
{
|
||||
indexer.pathsChanged({main1PathId});
|
||||
indexerScheduler.syncTasks();
|
||||
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
|
||||
ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
|
||||
.WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
|
||||
|
||||
EXPECT_CALL(mockCollector, setFile(_, _)).Times(0);
|
||||
|
||||
@@ -28,12 +28,9 @@
|
||||
#include "mockfilepathcaching.h"
|
||||
#include "mocksqlitedatabase.h"
|
||||
|
||||
#include <storagesqlitestatementfactory.h>
|
||||
#include <symbolstorage.h>
|
||||
#include <sqlitedatabase.h>
|
||||
|
||||
#include <storagesqlitestatementfactory.h>
|
||||
|
||||
#include <utils/optional.h>
|
||||
|
||||
namespace {
|
||||
@@ -45,56 +42,43 @@ using ClangBackEnd::SymbolEntries;
|
||||
using ClangBackEnd::SymbolEntry;
|
||||
using ClangBackEnd::SourceLocationEntries;
|
||||
using ClangBackEnd::SourceLocationEntry;
|
||||
using ClangBackEnd::StorageSqliteStatementFactory;
|
||||
using ClangBackEnd::SymbolIndex;
|
||||
using ClangBackEnd::SourceLocationKind;
|
||||
using ClangBackEnd::SymbolKind;
|
||||
using Sqlite::Database;
|
||||
using Sqlite::Table;
|
||||
|
||||
using StatementFactory = StorageSqliteStatementFactory<MockSqliteDatabase>;
|
||||
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
|
||||
using Storage = ClangBackEnd::SymbolStorage<MockSqliteDatabase>;
|
||||
|
||||
class SymbolStorage : public testing::Test
|
||||
{
|
||||
protected:
|
||||
NiceMock<MockSqliteDatabase> mockDatabase;
|
||||
StatementFactory statementFactory{mockDatabase};
|
||||
MockSqliteWriteStatement &insertSymbolsToNewSymbolsStatement = statementFactory.insertSymbolsToNewSymbolsStatement;
|
||||
MockSqliteWriteStatement &insertLocationsToNewLocationsStatement = statementFactory.insertLocationsToNewLocationsStatement;
|
||||
MockSqliteReadStatement &selectNewSourceIdsStatement = statementFactory.selectNewSourceIdsStatement;
|
||||
MockSqliteWriteStatement &addNewSymbolsToSymbolsStatement = statementFactory.addNewSymbolsToSymbolsStatement;
|
||||
MockSqliteWriteStatement &syncNewSymbolsFromSymbolsStatement = statementFactory.syncNewSymbolsFromSymbolsStatement;
|
||||
MockSqliteWriteStatement &syncSymbolsIntoNewLocationsStatement = statementFactory.syncSymbolsIntoNewLocationsStatement;
|
||||
MockSqliteWriteStatement &deleteAllLocationsFromUpdatedFilesStatement = statementFactory.deleteAllLocationsFromUpdatedFilesStatement;
|
||||
MockSqliteWriteStatement &insertNewLocationsInLocationsStatement = statementFactory.insertNewLocationsInLocationsStatement;
|
||||
MockSqliteWriteStatement &deleteNewSymbolsTableStatement = statementFactory.deleteNewSymbolsTableStatement;
|
||||
MockSqliteWriteStatement &deleteNewLocationsTableStatement = statementFactory.deleteNewLocationsTableStatement;
|
||||
MockSqliteWriteStatement &insertProjectPartStatement = statementFactory.insertProjectPartStatement;
|
||||
MockSqliteWriteStatement &updateProjectPartStatement = statementFactory.updateProjectPartStatement;
|
||||
MockSqliteReadStatement &getProjectPartIdStatement = statementFactory.getProjectPartIdStatement;
|
||||
MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartIdStatement = statementFactory.deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
||||
MockSqliteWriteStatement &insertProjectPartSourcesStatement = statementFactory.insertProjectPartSourcesStatement;
|
||||
MockSqliteWriteStatement &insertIntoNewUsedMacrosStatement = statementFactory.insertIntoNewUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &syncNewUsedMacrosStatement = statementFactory.syncNewUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = statementFactory.deleteOutdatedUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = statementFactory.deleteNewUsedMacrosTableStatement;
|
||||
MockSqliteWriteStatement &insertFileStatuses = statementFactory.insertFileStatuses;
|
||||
MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = statementFactory.insertIntoNewSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = statementFactory.syncNewSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = statementFactory.deleteOutdatedSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = statementFactory.deleteNewSourceDependenciesStatement;
|
||||
MockSqliteReadStatement &getProjectPartArtefactsBySourceId = statementFactory.getProjectPartArtefactsBySourceId;
|
||||
MockSqliteReadStatement &getProjectPartArtefactsByProjectPartName = statementFactory.getProjectPartArtefactsByProjectPartName;
|
||||
MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = statementFactory.getLowestLastModifiedTimeOfDependencies;
|
||||
MockSqliteReadStatement &getPrecompiledHeader = statementFactory.getPrecompiledHeader;
|
||||
Storage storage{mockDatabase};
|
||||
MockSqliteWriteStatement &insertSymbolsToNewSymbolsStatement = storage.m_insertSymbolsToNewSymbolsStatement;
|
||||
MockSqliteWriteStatement &insertLocationsToNewLocationsStatement = storage.m_insertLocationsToNewLocationsStatement;
|
||||
MockSqliteReadStatement &selectNewSourceIdsStatement = storage.m_selectNewSourceIdsStatement;
|
||||
MockSqliteWriteStatement &addNewSymbolsToSymbolsStatement = storage.m_addNewSymbolsToSymbolsStatement;
|
||||
MockSqliteWriteStatement &syncNewSymbolsFromSymbolsStatement = storage.m_syncNewSymbolsFromSymbolsStatement;
|
||||
MockSqliteWriteStatement &syncSymbolsIntoNewLocationsStatement = storage.m_syncSymbolsIntoNewLocationsStatement;
|
||||
MockSqliteWriteStatement &deleteAllLocationsFromUpdatedFilesStatement = storage.m_deleteAllLocationsFromUpdatedFilesStatement;
|
||||
MockSqliteWriteStatement &insertNewLocationsInLocationsStatement = storage.m_insertNewLocationsInLocationsStatement;
|
||||
MockSqliteWriteStatement &deleteNewSymbolsTableStatement = storage.m_deleteNewSymbolsTableStatement;
|
||||
MockSqliteWriteStatement &deleteNewLocationsTableStatement = storage.m_deleteNewLocationsTableStatement;
|
||||
MockSqliteWriteStatement &insertProjectPartStatement = storage.m_insertProjectPartStatement;
|
||||
MockSqliteWriteStatement &updateProjectPartStatement = storage.m_updateProjectPartStatement;
|
||||
MockSqliteReadStatement &getProjectPartIdStatement = storage.m_getProjectPartIdStatement;
|
||||
MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartIdStatement = storage.m_deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
||||
MockSqliteWriteStatement &insertProjectPartSourcesStatement = storage.m_insertProjectPartSourcesStatement;
|
||||
MockSqliteReadStatement &getProjectPartArtefactsBySourceId = storage.m_getProjectPartArtefactsBySourceId;
|
||||
MockSqliteReadStatement &getProjectPartArtefactsByProjectPartName = storage.m_getProjectPartArtefactsByProjectPartName;
|
||||
MockSqliteReadStatement &getPrecompiledHeader = storage.m_getPrecompiledHeader;
|
||||
|
||||
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}};
|
||||
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\"}", "[\"/includes\"]", 74};
|
||||
Storage storage{statementFactory};
|
||||
};
|
||||
|
||||
TEST_F(SymbolStorage, CreateAndFillTemporaryLocationsTable)
|
||||
@@ -232,40 +216,6 @@ TEST_F(SymbolStorage, UpdateProjectPartSources)
|
||||
storage.updateProjectPartSources(42, {{1, 1}, {1, 2}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, InsertOrUpdateUsedMacros)
|
||||
{
|
||||
InSequence sequence;
|
||||
|
||||
EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(42u), TypedEq<Utils::SmallStringView>("FOO")));
|
||||
EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(43u), TypedEq<Utils::SmallStringView>("BAR")));
|
||||
EXPECT_CALL(syncNewUsedMacrosStatement, execute());
|
||||
EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute());
|
||||
EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute());
|
||||
|
||||
storage.insertOrUpdateUsedMacros({{"FOO", {1, 42}}, {"BAR", {1, 43}}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, 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}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, InsertOrUpdateSourceDependencies)
|
||||
{
|
||||
InSequence sequence;
|
||||
|
||||
EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq<int>(42), TypedEq<int>(1)));
|
||||
EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq<int>(42), TypedEq<int>(2)));
|
||||
EXPECT_CALL(syncNewSourceDependenciesStatement, execute());
|
||||
EXPECT_CALL(deleteOutdatedSourceDependenciesStatement, execute());
|
||||
EXPECT_CALL(deleteNewSourceDependenciesStatement, execute());
|
||||
|
||||
storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement)
|
||||
{
|
||||
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
|
||||
@@ -302,24 +252,6 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameReturnArtefact)
|
||||
ASSERT_THAT(result, Eq(artefact));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists)
|
||||
{
|
||||
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1)));
|
||||
|
||||
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 1});
|
||||
|
||||
ASSERT_THAT(lowestLastModified, Eq(0));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, FetchLowestLastModifiedTime)
|
||||
{
|
||||
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21)))
|
||||
.WillRepeatedly(Return(12));
|
||||
|
||||
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 21});
|
||||
|
||||
ASSERT_THAT(lowestLastModified, Eq(12));
|
||||
}
|
||||
TEST_F(SymbolStorage, FetchPrecompiledHeaderCallsValueInStatement)
|
||||
{
|
||||
EXPECT_CALL(getPrecompiledHeader, valueReturnProjectPartPch(Eq(25)));
|
||||
@@ -338,7 +270,41 @@ TEST_F(SymbolStorage, FetchPrecompiledHeader)
|
||||
ASSERT_THAT(precompiledHeader.value(), Eq(pch));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddNewSymbolsTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
|
||||
|
||||
storage.createNewSymbolsTable();
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddNewLocationsTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
|
||||
|
||||
storage.createNewLocationsTable();
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddTablesInConstructor)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, immediateBegin());
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
|
||||
EXPECT_CALL(mockDatabase, commit());
|
||||
|
||||
Storage storage{mockDatabase};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ SOURCES += \
|
||||
symbolstorage-test.cpp \
|
||||
mocksqlitereadstatement.cpp \
|
||||
symbolquery-test.cpp \
|
||||
storagesqlitestatementfactory-test.cpp \
|
||||
sqliteindex-test.cpp \
|
||||
sqlitetransaction-test.cpp \
|
||||
refactoringdatabaseinitializer-test.cpp \
|
||||
@@ -246,7 +245,9 @@ HEADERS += \
|
||||
mockprojectpartqueue.h \
|
||||
mockprocessor.h \
|
||||
mockprocessormanager.h \
|
||||
mocktaskscheduler.h
|
||||
mocktaskscheduler.h \
|
||||
usedmacroandsourcestorage-test.h \
|
||||
mockusedmacroandsourcestorage.h
|
||||
|
||||
!isEmpty(LIBCLANG_LIBS) {
|
||||
HEADERS += \
|
||||
|
||||
163
tests/unit/unittest/usedmacroandsourcestorage-test.h
Normal file
163
tests/unit/unittest/usedmacroandsourcestorage-test.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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"
|
||||
|
||||
#include "mockfilepathcaching.h"
|
||||
#include "mocksqlitedatabase.h"
|
||||
|
||||
#include <sqlitedatabase.h>
|
||||
#include <usedmacroandsourcestorage.h>
|
||||
|
||||
#include <storagesqlitestatementfactory.h>
|
||||
|
||||
#include <utils/optional.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using Utils::PathString;
|
||||
using ClangBackEnd::FilePathId;
|
||||
using ClangBackEnd::FilePathCachingInterface;
|
||||
using Sqlite::Database;
|
||||
using Sqlite::Table;
|
||||
|
||||
using Storage = ClangBackEnd::UsedMacroAndSourceStorage<MockSqliteDatabase>;
|
||||
|
||||
class SymbolStorage : public testing::Test
|
||||
{
|
||||
protected:
|
||||
NiceMock<MockSqliteDatabase> mockDatabase;
|
||||
Storage storage{mockDatabase};
|
||||
MockSqliteWriteStatement &insertIntoNewUsedMacrosStatement = storage.m_insertIntoNewUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.m_syncNewUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.m_deleteOutdatedUsedMacrosStatement;
|
||||
MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.m_deleteNewUsedMacrosTableStatement;
|
||||
MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatuses;
|
||||
MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.m_insertIntoNewSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.m_syncNewSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.m_deleteOutdatedSourceDependenciesStatement;
|
||||
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.m_deleteNewSourceDependenciesStatement;
|
||||
MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.m_getLowestLastModifiedTimeOfDependencies;
|
||||
};
|
||||
|
||||
TEST_F(SymbolStorage, ConvertStringsToJson)
|
||||
{
|
||||
Utils::SmallStringVector strings{"foo", "bar", "foo"};
|
||||
|
||||
auto jsonText = storage.toJson(strings);
|
||||
|
||||
ASSERT_THAT(jsonText, Eq("[\"foo\",\"bar\",\"foo\"]"));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, InsertOrUpdateUsedMacros)
|
||||
{
|
||||
InSequence sequence;
|
||||
|
||||
EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(42u), TypedEq<Utils::SmallStringView>("FOO")));
|
||||
EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq<uint>(43u), TypedEq<Utils::SmallStringView>("BAR")));
|
||||
EXPECT_CALL(syncNewUsedMacrosStatement, execute());
|
||||
EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute());
|
||||
EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute());
|
||||
|
||||
storage.insertOrUpdateUsedMacros({{"FOO", {1, 42}}, {"BAR", {1, 43}}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, 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}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, InsertOrUpdateSourceDependencies)
|
||||
{
|
||||
InSequence sequence;
|
||||
|
||||
EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq<int>(42), TypedEq<int>(1)));
|
||||
EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq<int>(42), TypedEq<int>(2)));
|
||||
EXPECT_CALL(syncNewSourceDependenciesStatement, execute());
|
||||
EXPECT_CALL(deleteOutdatedSourceDependenciesStatement, execute());
|
||||
EXPECT_CALL(deleteNewSourceDependenciesStatement, execute());
|
||||
|
||||
storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}});
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddTablesInConstructor)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, immediateBegin());
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, dependencySourceId TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId ON newSourceDependencies(sourceId, dependencySourceId)")));
|
||||
EXPECT_CALL(mockDatabase, commit());
|
||||
|
||||
Storage storage{mockDatabase};
|
||||
}
|
||||
|
||||
|
||||
TEST_F(SymbolStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists)
|
||||
{
|
||||
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1)));
|
||||
|
||||
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 1});
|
||||
|
||||
ASSERT_THAT(lowestLastModified, Eq(0));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, FetchLowestLastModifiedTime)
|
||||
{
|
||||
EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21)))
|
||||
.WillRepeatedly(Return(12));
|
||||
|
||||
auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 21});
|
||||
|
||||
ASSERT_THAT(lowestLastModified, Eq(12));
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddNewUsedMacroTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)")));
|
||||
|
||||
factory.createNewUsedMacrosTable();
|
||||
}
|
||||
|
||||
TEST_F(SymbolStorage, AddNewSourceDependenciesTable)
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, dependencySourceId TEXT)")));
|
||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId ON newSourceDependencies(sourceId, dependencySourceId)")));
|
||||
|
||||
factory.createNewSourceDependenciesTable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user