Sqlite: Move result count to class declaration

It move the magic number of column results to the sql statement
and improves the mock a little bit.

Change-Id: I101067444cf27ec5dea0c72de7fd484a7e8710f0
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-03-24 18:10:55 +01:00
parent eb516063d3
commit 7785a3a651
58 changed files with 1038 additions and 1967 deletions

View File

@@ -39,7 +39,8 @@ namespace ClangBackEnd {
template <typename StatementFactory>
class FilePathStorage
{
using ReadStatement = typename StatementFactory::ReadStatement;
template<int ResultCount>
using ReadStatement = typename StatementFactory::template ReadStatement<ResultCount>;
using WriteStatement = typename StatementFactory::WriteStatement;
using Database = typename StatementFactory::Database;
@@ -84,7 +85,7 @@ public:
Utils::optional<int> readDirectoryId(Utils::SmallStringView directoryPath)
{
ReadStatement &statement = m_statementFactory.selectDirectoryIdFromDirectoriesByDirectoryPath;
auto &statement = m_statementFactory.selectDirectoryIdFromDirectoriesByDirectoryPath;
return statement.template value<int>(directoryPath);
}
@@ -103,7 +104,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectDirectoryPathFromDirectoriesByDirectoryId;
auto &statement = m_statementFactory.selectDirectoryPathFromDirectoriesByDirectoryId;
auto optionalDirectoryPath = statement.template value<Utils::PathString>(directoryPathId);
@@ -123,9 +124,9 @@ public:
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectAllDirectories;
auto &statement = m_statementFactory.selectAllDirectories;
auto directories = statement.template values<Sources::Directory, 2>(256);
auto directories = statement.template values<Sources::Directory>(256);
transaction.commit();
@@ -164,7 +165,7 @@ public:
int writeSourceId(int directoryId, Utils::SmallStringView sourceName)
{
WriteStatement &statement = m_statementFactory.insertIntoSources;
auto &statement = m_statementFactory.insertIntoSources;
statement.write(directoryId, sourceName);
@@ -173,7 +174,7 @@ public:
Utils::optional<int> readSourceId(int directoryId, Utils::SmallStringView sourceName)
{
ReadStatement &statement = m_statementFactory.selectSourceIdFromSourcesByDirectoryIdAndSourceName;
auto &statement = m_statementFactory.selectSourceIdFromSourcesByDirectoryIdAndSourceName;
return statement.template value<int>(directoryId, sourceName);
}
@@ -183,9 +184,10 @@ public:
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
auto &statement = m_statementFactory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
auto optionalSourceName = statement.template value<Sources::SourceNameAndDirectoryId, 2>(sourceId);
auto optionalSourceName = statement.template value<Sources::SourceNameAndDirectoryId>(
sourceId);
if (!optionalSourceName)
throw SourceNameIdDoesNotExists();
@@ -203,7 +205,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectDirectoryIdFromSourcesBySourceId;
auto &statement = m_statementFactory.selectDirectoryIdFromSourcesBySourceId;
auto optionalDirectoryId = statement.template value<int>(sourceId);
@@ -223,9 +225,9 @@ public:
try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectAllSources;
auto &statement = m_statementFactory.selectAllSources;
auto sources = statement.template values<Sources::Source, 3>(8192);
auto sources = statement.template values<Sources::Source>(8192);
transaction.commit();

View File

@@ -35,8 +35,9 @@ class FilePathStorageSqliteStatementFactory
{
public:
using Database = DatabaseType;
using ReadStatement = typename DatabaseType::ReadStatement;
using WriteStatement = typename DatabaseType::WriteStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
using WriteStatement = typename Database::WriteStatement;
FilePathStorageSqliteStatementFactory(Database &database)
: database(database)
@@ -45,32 +46,28 @@ public:
public:
Database &database;
ReadStatement selectDirectoryIdFromDirectoriesByDirectoryPath{
"SELECT directoryId FROM directories WHERE directoryPath = ?",
database
};
ReadStatement selectDirectoryPathFromDirectoriesByDirectoryId{
ReadStatement<1> selectDirectoryIdFromDirectoriesByDirectoryPath{
"SELECT directoryId FROM directories WHERE directoryPath = ?", database};
ReadStatement<1> selectDirectoryPathFromDirectoriesByDirectoryId{
"SELECT directoryPath FROM directories WHERE directoryId = ?", database};
ReadStatement selectAllDirectories{"SELECT directoryPath, directoryId FROM directories", database};
ReadStatement<2> selectAllDirectories{"SELECT directoryPath, directoryId FROM directories",
database};
WriteStatement insertIntoDirectories{
"INSERT INTO directories(directoryPath) VALUES (?)",
database
};
ReadStatement selectSourceIdFromSourcesByDirectoryIdAndSourceName{
"SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?",
database
};
ReadStatement selectSourceNameAndDirectoryIdFromSourcesBySourceId{
"SELECT sourceName, directoryId FROM sources WHERE sourceId = ?",
database
};
ReadStatement selectDirectoryIdFromSourcesBySourceId{
ReadStatement<1> selectSourceIdFromSourcesByDirectoryIdAndSourceName{
"SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?", database};
ReadStatement<2> selectSourceNameAndDirectoryIdFromSourcesBySourceId{
"SELECT sourceName, directoryId FROM sources WHERE sourceId = ?", database};
ReadStatement<1> selectDirectoryIdFromSourcesBySourceId{
"SELECT directoryId FROM sources WHERE sourceId = ?", database};
WriteStatement insertIntoSources{
"INSERT INTO sources(directoryId, sourceName) VALUES (?,?)",
database
};
ReadStatement selectAllSources{"SELECT sourceName, directoryId, sourceId FROM sources", database};
ReadStatement<3> selectAllSources{"SELECT sourceName, directoryId, sourceId FROM sources",
database};
};
} // namespace ClangBackEnd

View File

@@ -36,7 +36,8 @@ namespace ClangBackEnd {
template<typename Database = Sqlite::Database>
class ProjectPartsStorage final : public ProjectPartsStorageInterface
{
using ReadStatement = typename Database::ReadStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
using WriteStatement = typename Database::WriteStatement;
public:
@@ -52,7 +53,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
auto values = fetchProjectPartsStatement.template values<ProjectPartContainer, 8>(4096);
auto values = fetchProjectPartsStatement.template values<ProjectPartContainer>(4096);
transaction.commit();
@@ -91,7 +92,7 @@ public:
Sqlite::DeferredTransaction transaction{database};
for (ProjectPartId projectPartId : projectPartIds) {
auto value = fetchProjectPartByIdStatement.template value<ProjectPartContainer, 8>(
auto value = fetchProjectPartByIdStatement.template value<ProjectPartContainer>(
projectPartId.projectPathId);
if (value) {
value->headerPathIds = fetchHeaders(projectPartId);
@@ -243,9 +244,9 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
ReadStatement &statement = getProjectPartArtefactsBySourceId;
auto &statement = getProjectPartArtefactsBySourceId;
auto value = statement.template value<ProjectPartArtefact, 8>(sourceId.filePathId);
auto value = statement.template value<ProjectPartArtefact>(sourceId.filePathId);
transaction.commit();
@@ -260,9 +261,9 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
ReadStatement &statement = getProjectPartArtefactsByProjectPartId;
auto &statement = getProjectPartArtefactsByProjectPartId;
auto value = statement.template value<ProjectPartArtefact, 8>(projectPartId.projectPathId);
auto value = statement.template value<ProjectPartArtefact>(projectPartId.projectPathId);
transaction.commit();
@@ -342,9 +343,9 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
ReadStatement &statement = fetchAllProjectPartNamesAndIdsStatement;
auto &statement = fetchAllProjectPartNamesAndIdsStatement;
auto values = statement.template values<Internal::ProjectPartNameId, 2>(256);
auto values = statement.template values<Internal::ProjectPartNameId>(256);
transaction.commit();
@@ -357,18 +358,18 @@ public:
public:
Sqlite::ImmediateNonThrowingDestructorTransaction transaction;
Database &database;
mutable ReadStatement fetchProjectPartIdStatement{
mutable ReadStatement<1> fetchProjectPartIdStatement{
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?", database};
mutable WriteStatement insertProjectPartNameStatement{
"INSERT INTO projectParts(projectPartName) VALUES (?)", database};
mutable ReadStatement fetchProjectPartNameStatement{
mutable ReadStatement<1> fetchProjectPartNameStatement{
"SELECT projectPartName FROM projectParts WHERE projectPartId = ?", database};
mutable ReadStatement fetchProjectPartsStatement{
mutable ReadStatement<8> fetchProjectPartsStatement{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts",
database};
mutable ReadStatement fetchProjectPartByIdStatement{
mutable ReadStatement<8> fetchProjectPartByIdStatement{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts WHERE projectPartId = ?",
@@ -378,13 +379,13 @@ public:
"systemIncludeSearchPaths=?004, projectIncludeSearchPaths=?005, language=?006, "
"languageVersion=?007, languageExtension=?008 WHERE projectPartId = ?001",
database};
mutable ReadStatement getProjectPartArtefactsBySourceId{
mutable ReadStatement<8> getProjectPartArtefactsBySourceId{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts WHERE projectPartId = (SELECT "
"projectPartId FROM projectPartsFiles WHERE sourceId = ?)",
database};
mutable ReadStatement getProjectPartArtefactsByProjectPartId{
mutable ReadStatement<8> getProjectPartArtefactsByProjectPartId{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts WHERE projectPartId = ?",
@@ -397,17 +398,17 @@ public:
"INSERT INTO projectPartsHeaders(projectPartId, sourceId) VALUES (?,?)", database};
WriteStatement insertProjectPartsSourcesStatement{
"INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)", database};
mutable ReadStatement fetchProjectPartsHeadersByIdStatement{
mutable ReadStatement<1> fetchProjectPartsHeadersByIdStatement{
"SELECT sourceId FROM projectPartsHeaders WHERE projectPartId = ? ORDER BY sourceId",
database};
mutable ReadStatement fetchProjectPartsSourcesByIdStatement{
mutable ReadStatement<1> fetchProjectPartsSourcesByIdStatement{
"SELECT sourceId FROM projectPartsSources WHERE projectPartId = ? ORDER BY sourceId",
database};
mutable ReadStatement fetchProjectPrecompiledHeaderBuildTimeStatement{
mutable ReadStatement<1> fetchProjectPrecompiledHeaderBuildTimeStatement{
"SELECT projectPchBuildTime FROM precompiledHeaders WHERE projectPartId = ?", database};
WriteStatement resetDependentIndexingTimeStampsStatement{
"UPDATE fileStatuses SET indexingTimeStamp = NULL WHERE sourceId = ?", database};
mutable ReadStatement fetchAllProjectPartNamesAndIdsStatement{
mutable ReadStatement<2> fetchAllProjectPartNamesAndIdsStatement{
"SELECT projectPartName, projectPartId FROM projectParts", database};
};
} // namespace ClangBackEnd

View File

@@ -30,15 +30,15 @@ add_qtc_library(Sqlite
sqliteexception.cpp sqliteexception.h
sqliteglobal.cpp sqliteglobal.h
sqliteindex.h
sqlitereadstatement.cpp sqlitereadstatement.h
sqlitereadwritestatement.cpp sqlitereadwritestatement.h
sqlitereadstatement.h
sqlitereadwritestatement.h
sqlitesessionchangeset.cpp sqlitesessionchangeset.h
sqlitesessions.cpp sqlitesessions.h
sqlitetable.h
sqlitetransaction.h
sqlitetransaction.h
sqlitevalue.h
sqlitewritestatement.cpp sqlitewritestatement.h
sqlitewritestatement.h
sqlstatementbuilder.cpp sqlstatementbuilder.h
sqlstatementbuilderexception.h
tableconstraints.h

View File

@@ -15,11 +15,8 @@ SOURCES += \
$$PWD/sqlitedatabasebackend.cpp \
$$PWD/sqliteexception.cpp \
$$PWD/sqliteglobal.cpp \
$$PWD/sqlitereadstatement.cpp \
$$PWD/sqlitereadwritestatement.cpp \
$$PWD/sqlitesessionchangeset.cpp \
$$PWD/sqlitesessions.cpp \
$$PWD/sqlitewritestatement.cpp \
$$PWD/sqlstatementbuilder.cpp \
$$PWD/utf8string.cpp \
$$PWD/utf8stringvector.cpp \

View File

@@ -10,12 +10,9 @@ SOURCES += \
sqlitedatabaseconnectionproxy.cpp \
sqliteexception.cpp \
sqliteglobal.cpp \
sqlitereadstatement.cpp \
sqlitereadwritestatement.cpp \
sqlitestatement.cpp \
sqlitetransaction.cpp \
sqliteworkerthread.cpp \
sqlitewritestatement.cpp \
sqlstatementbuilder.cpp \
utf8string.cpp \
utf8stringvector.cpp \

View File

@@ -159,7 +159,7 @@ extern template SQLITE_EXPORT Utils::SmallStringView BaseStatement::fetchValue<U
extern template SQLITE_EXPORT Utils::SmallString BaseStatement::fetchValue<Utils::SmallString>(int column) const;
extern template SQLITE_EXPORT Utils::PathString BaseStatement::fetchValue<Utils::PathString>(int column) const;
template <typename BaseStatement>
template<typename BaseStatement, int ResultCount>
class StatementImplementation : public BaseStatement
{
@@ -192,18 +192,15 @@ public:
resetter.reset();
}
template <typename ResultType,
int ResultTypeCount = 1>
template<typename ResultType>
std::vector<ResultType> values(std::size_t reserveSize)
{
BaseStatement::checkColumnCount(ResultTypeCount);
Resetter resetter{*this};
std::vector<ResultType> resultValues;
resultValues.reserve(std::max(reserveSize, m_maximumResultCount));
while (BaseStatement::next())
emplaceBackValues<ResultTypeCount>(resultValues);
emplaceBackValues(resultValues);
setMaximumResultCount(resultValues.size());
@@ -212,11 +209,9 @@ public:
return resultValues;
}
template<typename ResultType, int ResultTypeCount = 1, typename... QueryTypes>
template<typename ResultType, typename... QueryTypes>
auto values(std::size_t reserveSize, const QueryTypes &...queryValues)
{
BaseStatement::checkColumnCount(ResultTypeCount);
Resetter resetter{*this};
std::vector<ResultType> resultValues;
resultValues.reserve(std::max(reserveSize, m_maximumResultCount));
@@ -224,7 +219,7 @@ public:
bindValues(queryValues...);
while (BaseStatement::next())
emplaceBackValues<ResultTypeCount>(resultValues);
emplaceBackValues(resultValues);
setMaximumResultCount(resultValues.size());
@@ -233,66 +228,16 @@ public:
return resultValues;
}
template<typename ResultType, int ResultTypeCount = 1, typename QueryElementType>
auto values(std::size_t reserveSize, const std::vector<QueryElementType> &queryValues)
{
BaseStatement::checkColumnCount(ResultTypeCount);
std::vector<ResultType> resultValues;
resultValues.reserve(std::max(reserveSize, m_maximumResultCount));
for (const QueryElementType &queryValue : queryValues) {
Resetter resetter{*this};
bindValues(queryValue);
while (BaseStatement::next())
emplaceBackValues<ResultTypeCount>(resultValues);
setMaximumResultCount(resultValues.size());
resetter.reset();
}
return resultValues;
}
template<typename ResultType, int ResultTypeCount = 1, typename... QueryElementTypes>
auto values(std::size_t reserveSize,
const std::vector<std::tuple<QueryElementTypes...>> &queryTuples)
{
BaseStatement::checkColumnCount(ResultTypeCount);
using Container = std::vector<ResultType>;
Container resultValues;
resultValues.reserve(std::max(reserveSize, m_maximumResultCount));
for (const auto &queryTuple : queryTuples) {
Resetter resetter{*this};
bindTupleValues(queryTuple);
while (BaseStatement::next())
emplaceBackValues<ResultTypeCount>(resultValues);
setMaximumResultCount(resultValues.size());
resetter.reset();
}
return resultValues;
}
template<typename ResultType, int ResultTypeCount = 1, typename... QueryTypes>
template<typename ResultType, typename... QueryTypes>
auto value(const QueryTypes &...queryValues)
{
BaseStatement::checkColumnCount(ResultTypeCount);
Resetter resetter{*this};
Utils::optional<ResultType> resultValue;
bindValues(queryValues...);
if (BaseStatement::next())
resultValue = assignValue<Utils::optional<ResultType>, ResultTypeCount>();
resultValue = assignValue<Utils::optional<ResultType>>();
resetter.reset();
@@ -311,17 +256,15 @@ public:
return statement.template fetchValue<Type>(0);
}
template<int ResultTypeCount = 1, typename Callable, typename... QueryTypes>
template<typename Callable, typename... QueryTypes>
void readCallback(Callable &&callable, const QueryTypes &...queryValues)
{
BaseStatement::checkColumnCount(ResultTypeCount);
Resetter resetter{*this};
bindValues(queryValues...);
while (BaseStatement::next()) {
auto control = callCallable<ResultTypeCount>(callable);
auto control = callCallable(callable);
if (control == CallbackControl::Abort)
break;
@@ -333,14 +276,12 @@ public:
template<int ResultTypeCount = 1, typename Container, typename... QueryTypes>
void readTo(Container &container, const QueryTypes &...queryValues)
{
BaseStatement::checkColumnCount(ResultTypeCount);
Resetter resetter{*this};
bindValues(queryValues...);
while (BaseStatement::next())
emplaceBackValues<ResultTypeCount>(container);
emplaceBackValues(container);
resetter.reset();
}
@@ -399,18 +340,21 @@ private:
int column;
};
template <typename ContainerType,
int... ColumnIndices>
constexpr int resultCount(int localResultCount) const
{
return ResultCount < 0 ? localResultCount : ResultCount;
}
template<typename ContainerType, int... ColumnIndices>
void emplaceBackValues(ContainerType &container, std::integer_sequence<int, ColumnIndices...>)
{
container.emplace_back(ValueGetter(*this, ColumnIndices)...);
}
template <int ResultTypeCount,
typename ContainerType>
template<typename ContainerType>
void emplaceBackValues(ContainerType &container)
{
emplaceBackValues(container, std::make_integer_sequence<int, ResultTypeCount>{});
emplaceBackValues(container, std::make_integer_sequence<int, ResultCount>{});
}
template <typename ResultOptionalType,
@@ -420,11 +364,10 @@ private:
return ResultOptionalType(Utils::in_place, ValueGetter(*this, ColumnIndices)...);
}
template <typename ResultOptionalType,
int ResultTypeCount>
template<typename ResultOptionalType>
ResultOptionalType assignValue()
{
return assignValue<ResultOptionalType>(std::make_integer_sequence<int, ResultTypeCount>{});
return assignValue<ResultOptionalType>(std::make_integer_sequence<int, ResultCount>{});
}
template<typename Callable, int... ColumnIndices>
@@ -433,10 +376,10 @@ private:
return std::invoke(callable, ValueGetter(*this, ColumnIndices)...);
}
template<int ResultTypeCount, typename Callable>
template<typename Callable>
CallbackControl callCallable(Callable &&callable)
{
return callCallable(callable, std::make_integer_sequence<int, ResultTypeCount>{});
return callCallable(callable, std::make_integer_sequence<int, ResultCount>{});
}
template<typename ValueType>

View File

@@ -47,11 +47,11 @@ public:
public:
Database &database;
ReadWriteStatement deferredBegin{"BEGIN", database};
ReadWriteStatement immediateBegin{"BEGIN IMMEDIATE", database};
ReadWriteStatement exclusiveBegin{"BEGIN EXCLUSIVE", database};
ReadWriteStatement commitBegin{"COMMIT", database};
ReadWriteStatement rollbackBegin{"ROLLBACK", database};
ReadWriteStatement<> deferredBegin{"BEGIN", database};
ReadWriteStatement<> immediateBegin{"BEGIN IMMEDIATE", database};
ReadWriteStatement<> exclusiveBegin{"BEGIN EXCLUSIVE", database};
ReadWriteStatement<> commitBegin{"COMMIT", database};
ReadWriteStatement<> rollbackBegin{"ROLLBACK", database};
Sessions sessions{database, "main", "databaseSessions"};
};

View File

@@ -42,8 +42,10 @@ namespace Sqlite {
using namespace std::chrono_literals;
template<int ResultCount>
class ReadStatement;
class WriteStatement;
template<int ResultCount>
class ReadWriteStatement;
class SQLITE_EXPORT Database final : public TransactionInterface, public DatabaseInterface
@@ -54,9 +56,11 @@ class SQLITE_EXPORT Database final : public TransactionInterface, public Databas
public:
using MutexType = std::mutex;
using ReadStatement = Sqlite::ReadStatement;
template<int ResultCount>
using ReadStatement = Sqlite::ReadStatement<ResultCount>;
using WriteStatement = Sqlite::WriteStatement;
using ReadWriteStatement = Sqlite::ReadWriteStatement;
template<int ResultCount = 0>
using ReadWriteStatement = Sqlite::ReadWriteStatement<ResultCount>;
using BusyHandler = DatabaseBackend::BusyHandler;
Database();

View File

@@ -128,7 +128,9 @@ sqlite3 *DatabaseBackend::sqliteDatabaseHandle() const
void DatabaseBackend::setPragmaValue(Utils::SmallStringView pragmaKey, Utils::SmallStringView newPragmaValue)
{
execute(Utils::SmallString{"PRAGMA ", pragmaKey, "='", newPragmaValue, "'"});
ReadWriteStatement<1>{Utils::SmallString{"PRAGMA ", pragmaKey, "='", newPragmaValue, "'"},
m_database}
.execute();
Utils::SmallString pragmeValueInDatabase = toValue<Utils::SmallString>("PRAGMA " + pragmaKey);
checkPragmaValue(pragmeValueInDatabase, newPragmaValue);
@@ -172,7 +174,7 @@ void DatabaseBackend::setLastInsertedRowId(int64_t rowId)
void DatabaseBackend::execute(Utils::SmallStringView sqlStatement)
{
try {
ReadWriteStatement statement(sqlStatement, m_database);
ReadWriteStatement<0> statement(sqlStatement, m_database);
statement.execute();
} catch (StatementIsBusy &) {
execute(sqlStatement);
@@ -454,7 +456,7 @@ template <typename Type>
Type DatabaseBackend::toValue(Utils::SmallStringView sqlStatement)
{
try {
ReadWriteStatement statement(sqlStatement, m_database);
ReadWriteStatement<1> statement(sqlStatement, m_database);
statement.next();

View File

@@ -1,45 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 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 "sqlitereadstatement.h"
#include "sqlite3.h"
namespace Sqlite {
ReadStatement::ReadStatement(Utils::SmallStringView sqlStatement,
Database &database)
: StatementImplementation(sqlStatement, database)
{
checkIsReadOnlyStatement();
}
void ReadStatement::checkIsReadOnlyStatement()
{
if (!isReadOnlyStatement())
throw NotReadOnlySqlStatement("SqliteStatement::SqliteReadStatement: is not read only statement!");
}
} // namespace Sqlite

View File

@@ -29,19 +29,37 @@
namespace Sqlite {
class SQLITE_EXPORT ReadStatement final : protected StatementImplementation<BaseStatement>
template<int ResultCount>
class ReadStatement final : protected StatementImplementation<BaseStatement, ResultCount>
{
public:
explicit ReadStatement(Utils::SmallStringView sqlStatement, Database &database);
using Base = StatementImplementation<BaseStatement, ResultCount>;
using StatementImplementation::readCallback;
using StatementImplementation::readTo;
using StatementImplementation::toValue;
using StatementImplementation::value;
using StatementImplementation::values;
public:
ReadStatement(Utils::SmallStringView sqlStatement, Database &database)
: Base{sqlStatement, database}
{
checkIsReadOnlyStatement();
Base::checkColumnCount(ResultCount);
}
using Base::readCallback;
using Base::readTo;
using Base::toValue;
using Base::value;
using Base::values;
protected:
void checkIsReadOnlyStatement();
void checkIsReadOnlyStatement()
{
if (!Base::isReadOnlyStatement())
throw NotReadOnlySqlStatement(
"SqliteStatement::SqliteReadStatement: is not read only statement!");
}
};
template<int ResultCount>
ReadStatement(ReadStatement<ResultCount> &) -> ReadStatement<ResultCount>;
template<int ResultCount>
ReadStatement(const ReadStatement<ResultCount> &) -> ReadStatement<ResultCount>;
} // namespace Sqlite

View File

@@ -1,36 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 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 "sqlitereadwritestatement.h"
namespace Sqlite {
ReadWriteStatement::ReadWriteStatement(Utils::SmallStringView sqlStatement,
Database &database)
: StatementImplementation(sqlStatement, database)
{
}
} // namespace Sqlite

View File

@@ -29,20 +29,26 @@
namespace Sqlite {
class SQLITE_EXPORT ReadWriteStatement final : protected StatementImplementation<BaseStatement>
template<int ResultCount = 0>
class ReadWriteStatement final : protected StatementImplementation<BaseStatement, ResultCount>
{
friend class DatabaseBackend;
using Base = StatementImplementation<BaseStatement, ResultCount>;
public:
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database);
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database)
: Base{sqlStatement, database}
{
Base::checkColumnCount(ResultCount);
}
using StatementImplementation::execute;
using StatementImplementation::readCallback;
using StatementImplementation::readTo;
using StatementImplementation::toValue;
using StatementImplementation::value;
using StatementImplementation::values;
using StatementImplementation::write;
using Base::execute;
using Base::readCallback;
using Base::readTo;
using Base::toValue;
using Base::value;
using Base::values;
using Base::write;
};
} // namespace Sqlite

View File

@@ -127,7 +127,7 @@ void Internal::SessionsBase::createSessionTable(Database &database)
void Sessions::revert()
{
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id DESC"},
database};
@@ -151,7 +151,7 @@ void Sessions::revert()
void Sessions::apply()
{
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id"},
database};
@@ -187,7 +187,7 @@ void Sessions::deleteAll()
SessionChangeSets Sessions::changeSets() const
{
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id DESC"},
database};

View File

@@ -1,43 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 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 "sqlitewritestatement.h"
namespace Sqlite {
WriteStatement::WriteStatement(Utils::SmallStringView sqlStatement,
Database &database)
: StatementImplementation(sqlStatement, database)
{
checkIsWritableStatement();
}
void WriteStatement::checkIsWritableStatement()
{
if (isReadOnlyStatement())
throw NotWriteSqlStatement("SqliteStatement::SqliteWriteStatement: is not a writable statement!");
}
} // namespace Sqlite

View File

@@ -29,17 +29,28 @@
namespace Sqlite {
class SQLITE_EXPORT WriteStatement : protected StatementImplementation<BaseStatement>
class WriteStatement : protected StatementImplementation<BaseStatement, -1>
{
public:
explicit WriteStatement(Utils::SmallStringView sqlStatement, Database &database);
using Base = StatementImplementation<BaseStatement, -1>;
public:
WriteStatement(Utils::SmallStringView sqlStatement, Database &database)
: StatementImplementation(sqlStatement, database)
{
checkIsWritableStatement();
}
using StatementImplementation::execute;
using StatementImplementation::database;
using StatementImplementation::execute;
using StatementImplementation::write;
protected:
void checkIsWritableStatement();
void checkIsWritableStatement()
{
if (Base::isReadOnlyStatement())
throw NotWriteSqlStatement(
"SqliteStatement::SqliteWriteStatement: is not a writable statement!");
}
};
} // namespace Sqlite

View File

@@ -27,51 +27,54 @@
namespace ClangRefactoring {
template<typename Database,
typename ReadStatement>
template<typename Database>
class QuerySqliteStatementFactory
{
public:
using DatabaseType = Database;
using ReadStatementType = ReadStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
QuerySqliteStatementFactory(Database &database)
: database(database)
{}
Database &database;
ReadStatement selectLocationsForSymbolLocation{
ReadStatement<3> selectLocationsForSymbolLocation{
"SELECT sourceId, line, column FROM locations WHERE symbolId = "
" (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?) "
"ORDER BY sourceId, line, column",
database};
ReadStatement selectSourceUsagesForSymbolLocation{
ReadStatement<3> selectSourceUsagesForSymbolLocation{
"SELECT directoryPath || '/' || sourceName, line, column "
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
"column=?)",
database};
ReadStatement selectSourceUsagesOrderedForSymbolLocation{
ReadStatement<3> selectSourceUsagesOrderedForSymbolLocation{
"SELECT directoryPath || '/' || sourceName, line, column "
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
"column=?) ORDER BY locationKind LIMIT 2",
database};
ReadStatement selectSourceUsagesByLocationKindForSymbolLocation{
ReadStatement<3> selectSourceUsagesByLocationKindForSymbolLocation{
"SELECT directoryPath || '/' || sourceName, line, column "
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND "
"column=?) AND locationKind = ?",
database};
ReadStatement selectSymbolsForKindAndStartsWith{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName LIKE ?",
ReadStatement<3> selectSymbolsForKindAndStartsWith{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName "
"LIKE ?",
database};
ReadStatement selectSymbolsForKindAndStartsWith2{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND symbolName LIKE ?",
ReadStatement<3> selectSymbolsForKindAndStartsWith2{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND "
"symbolName LIKE ?",
database};
ReadStatement selectSymbolsForKindAndStartsWith3{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND symbolName LIKE ?",
ReadStatement<3> selectSymbolsForKindAndStartsWith3{
"SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND "
"symbolName LIKE ?",
database};
ReadStatement selectLocationOfSymbol{
ReadStatement<3> selectLocationOfSymbol{
"SELECT sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?",
database};
};

View File

@@ -40,8 +40,6 @@ namespace ClangRefactoring {
template <typename StatementFactory>
class SymbolQuery final : public SymbolQueryInterface
{
using ReadStatement = typename StatementFactory::ReadStatementType;
public:
SymbolQuery(StatementFactory &statementFactory)
: m_statementFactory(statementFactory)
@@ -51,11 +49,11 @@ public:
int line,
int utf8Column) const override
{
ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
auto &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
const std::size_t reserveSize = 128;
return locationsStatement.template values<SourceLocation, 3>(reserveSize,
return locationsStatement.template values<SourceLocation>(reserveSize,
filePathId.filePathId,
line,
utf8Column);
@@ -65,11 +63,11 @@ public:
int line,
int utf8Column) const override
{
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
auto &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
const std::size_t reserveSize = 128;
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
return locationsStatement.template values<CppTools::Usage>(reserveSize,
filePathId.filePathId,
line,
utf8Column);
@@ -80,11 +78,11 @@ public:
int utf8Column,
ClangBackEnd::SourceLocationKind kind) const override
{
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
auto &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
const std::size_t reserveSize = 128;
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
return locationsStatement.template values<CppTools::Usage>(reserveSize,
filePathId.filePathId,
line,
utf8Column,
@@ -95,11 +93,11 @@ public:
int line,
int utf8Column) const override
{
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation;
auto &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation;
const std::size_t reserveSize = 128;
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
return locationsStatement.template values<CppTools::Usage>(reserveSize,
filePathId.filePathId,
line,
utf8Column);
@@ -108,18 +106,18 @@ public:
Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind,
Utils::SmallStringView searchTerm) const
{
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith;
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith;
return statement.template values<Symbol, 3>(100, int(symbolKind), searchTerm);
return statement.template values<Symbol>(100, int(symbolKind), searchTerm);
}
Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1,
ClangBackEnd::SymbolKind symbolKind2,
Utils::SmallStringView searchTerm) const
{
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2;
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2;
return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), searchTerm);
return statement.template values<Symbol>(100, int(symbolKind1), int(symbolKind2), searchTerm);
}
Symbols symbolsWithThreeSymbolKinds(ClangBackEnd::SymbolKind symbolKind1,
@@ -127,9 +125,13 @@ public:
ClangBackEnd::SymbolKind symbolKind3,
Utils::SmallStringView searchTerm) const
{
ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3;
auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3;
return statement.template values<Symbol, 3>(100, int(symbolKind1), int(symbolKind2), int(symbolKind3), searchTerm);
return statement.template values<Symbol>(100,
int(symbolKind1),
int(symbolKind2),
int(symbolKind3),
searchTerm);
}
Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds,
@@ -148,9 +150,9 @@ public:
Utils::optional<SourceLocation> locationForSymbolId(SymbolId symbolId,
ClangBackEnd::SourceLocationKind kind) const override
{
ReadStatement &statement = m_statementFactory.selectLocationOfSymbol;
auto &statement = m_statementFactory.selectLocationOfSymbol;
return statement.template value<SourceLocation, 3>(symbolId, int(kind));
return statement.template value<SourceLocation>(symbolId, int(kind));
}
private:
StatementFactory &m_statementFactory;

View File

@@ -43,7 +43,8 @@ template<typename DatabaseType>
class ImageCacheStorage : public ImageCacheStorageInterface
{
public:
using ReadStatement = typename DatabaseType::ReadStatement;
template<int ResultCount>
using ReadStatement = typename DatabaseType::template ReadStatement<ResultCount>;
using WriteStatement = typename DatabaseType::WriteStatement;
ImageCacheStorage(DatabaseType &database)
@@ -272,11 +273,11 @@ public:
DatabaseType &database;
Initializer initializer{database};
Sqlite::ImmediateNonThrowingDestructorTransaction transaction{database};
mutable ReadStatement selectImageStatement{
mutable ReadStatement<1> selectImageStatement{
"SELECT image FROM images WHERE name=?1 AND mtime >= ?2", database};
mutable ReadStatement selectSmallImageStatement{
mutable ReadStatement<1> selectSmallImageStatement{
"SELECT smallImage FROM images WHERE name=?1 AND mtime >= ?2", database};
mutable ReadStatement selectIconStatement{
mutable ReadStatement<1> selectIconStatement{
"SELECT icon FROM icons WHERE name=?1 AND mtime >= ?2", database};
WriteStatement upsertImageStatement{
"INSERT INTO images(name, mtime, image, smallImage) VALUES (?1, ?2, ?3, ?4) ON "

View File

@@ -43,7 +43,8 @@ namespace ClangBackEnd {
template<typename Database=Sqlite::Database>
class BuildDependenciesStorage final : public BuildDependenciesStorageInterface
{
using ReadStatement = typename Database::ReadStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
using WriteStatement = typename Database::WriteStatement;
public:
BuildDependenciesStorage(Database &database)
@@ -99,7 +100,7 @@ public:
long long fetchLowestLastModifiedTime(FilePathId sourceId) const override
{
ReadStatement &statement = getLowestLastModifiedTimeOfDependencies;
auto &statement = getLowestLastModifiedTimeOfDependencies;
return statement.template value<long long>(sourceId.filePathId).value_or(0);
}
@@ -143,12 +144,12 @@ public:
SourceEntries fetchDependSources(FilePathId sourceId, ProjectPartId projectPartId) const override
{
return fetchSourceDependenciesStatement
.template values<SourceEntry, 4>(300, sourceId.filePathId, projectPartId.projectPathId);
.template values<SourceEntry>(300, sourceId.filePathId, projectPartId.projectPathId);
}
UsedMacros fetchUsedMacros(FilePathId sourceId) const override
{
return fetchUsedMacrosStatement.template values<UsedMacro, 2>(128, sourceId.filePathId);
return fetchUsedMacrosStatement.template values<UsedMacro>(128, sourceId.filePathId);
}
void updatePchCreationTimeStamp(long long pchCreationTimeStamp, ProjectPartId projectPartId) override
@@ -191,8 +192,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
auto timeStamps = fetchIndexingTimeStampsStatement.template values<SourceTimeStamp, 2>(
1024);
auto timeStamps = fetchIndexingTimeStampsStatement.template values<SourceTimeStamp>(1024);
transaction.commit();
@@ -208,7 +208,7 @@ public:
Sqlite::DeferredTransaction transaction{database};
auto timeStamps = fetchIncludedIndexingTimeStampsStatement
.template values<SourceTimeStamp, 2>(1024, sourcePathId.filePathId);
.template values<SourceTimeStamp>(1024, sourcePathId.filePathId);
transaction.commit();
@@ -325,10 +325,12 @@ public:
"DELETE FROM newUsedMacros",
database
};
mutable 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
};
mutable ReadStatement<1> 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};
WriteStatement insertIntoNewSourceDependenciesStatement{
"INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)",
database
@@ -356,13 +358,13 @@ public:
"CONFLICT(sourceId, projectPartId) DO UPDATE SET sourceType = ?003, "
"hasMissingIncludes = ?004",
database};
mutable ReadStatement fetchPchSourcesStatement{
mutable ReadStatement<1> fetchPchSourcesStatement{
"SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? AND sourceType IN (0, 1, "
"3, 4) ORDER BY sourceId",
database};
mutable ReadStatement fetchSourcesStatement{
mutable ReadStatement<1> fetchSourcesStatement{
"SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? ORDER BY sourceId", database};
mutable ReadStatement fetchSourceDependenciesStatement{
mutable ReadStatement<4> fetchSourceDependenciesStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION "
"SELECT dependencySourceId FROM sourceDependencies, "
"collectedDependencies WHERE sourceDependencies.sourceId == "
@@ -371,16 +373,14 @@ public:
"collectedDependencies NATURAL JOIN projectPartsFiles WHERE "
"projectPartId = ? ORDER BY sourceId",
database};
mutable ReadStatement fetchProjectPartIdStatement{
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?",
database
};
mutable ReadStatement<1> fetchProjectPartIdStatement{
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?", database};
WriteStatement insertProjectPartNameStatement{
"INSERT INTO projectParts(projectPartName) VALUES (?)", database};
mutable ReadStatement fetchUsedMacrosStatement{
"SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ? ORDER BY sourceId, macroName",
database
};
mutable ReadStatement<2> fetchUsedMacrosStatement{
"SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ? ORDER BY sourceId, "
"macroName",
database};
WriteStatement updatePchCreationTimeStampStatement{
"UPDATE projectPartsFiles SET pchCreationTimeStamp = ?001 WHERE projectPartId = ?002",
database};
@@ -390,16 +390,16 @@ public:
"INSERT INTO fileStatuses(sourceId, indexingTimeStamp) VALUES (?001, ?002) ON "
"CONFLICT(sourceId) DO UPDATE SET indexingTimeStamp = ?002",
database};
mutable ReadStatement fetchIncludedIndexingTimeStampsStatement{
mutable ReadStatement<2> fetchIncludedIndexingTimeStampsStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT "
"dependencySourceId FROM sourceDependencies, collectedDependencies WHERE "
"sourceDependencies.sourceId == collectedDependencies.sourceId) SELECT DISTINCT sourceId, "
"indexingTimeStamp FROM collectedDependencies NATURAL LEFT JOIN fileStatuses ORDER BY "
"sourceId",
database};
mutable ReadStatement fetchIndexingTimeStampsStatement{
mutable ReadStatement<2> fetchIndexingTimeStampsStatement{
"SELECT sourceId, indexingTimeStamp FROM fileStatuses ORDER BY sourceId", database};
mutable ReadStatement fetchDependentSourceIdsStatement{
mutable ReadStatement<1> fetchDependentSourceIdsStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT "
"sourceDependencies.sourceId FROM sourceDependencies, collectedDependencies WHERE "
"sourceDependencies.dependencySourceId == collectedDependencies.sourceId) SELECT sourceId "

View File

@@ -38,7 +38,8 @@ namespace ClangBackEnd {
template<typename Database=Sqlite::Database>
class PrecompiledHeaderStorage final : public PrecompiledHeaderStorageInterface
{
using ReadStatement = typename Database::ReadStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
using WriteStatement = typename Database::WriteStatement;
public:
PrecompiledHeaderStorage(Database &database)
@@ -184,7 +185,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
auto value = fetchPrecompiledHeadersStatement.template value<PchPaths, 2>(
auto value = fetchPrecompiledHeadersStatement.template value<PchPaths>(
projectPartId.projectPathId);
transaction.commit();
@@ -204,7 +205,7 @@ public:
try {
Sqlite::DeferredTransaction transaction{database};
auto value = fetchTimeStampsStatement.template value<PrecompiledHeaderTimeStamps, 2>(
auto value = fetchTimeStampsStatement.template value<PrecompiledHeaderTimeStamps>(
projectPartId.projectPathId);
transaction.commit();
@@ -265,23 +266,22 @@ public:
"systemPchPath=NULL,systemPchBuildTime=NULL,projectPchPath=NULL,projectPchBuildTime=NULL "
"WHERE projectPartId = ?",
database};
ReadStatement fetchSystemPrecompiledHeaderPathStatement{
ReadStatement<1> fetchSystemPrecompiledHeaderPathStatement{
"SELECT systemPchPath FROM precompiledHeaders WHERE projectPartId = ?", database};
mutable ReadStatement fetchPrecompiledHeaderStatement{
mutable ReadStatement<1> fetchPrecompiledHeaderStatement{
"SELECT ifnull(nullif(projectPchPath, ''), systemPchPath) "
"FROM precompiledHeaders WHERE projectPartId = ?",
database};
mutable ReadStatement fetchPrecompiledHeadersStatement{
mutable ReadStatement<2> fetchPrecompiledHeadersStatement{
"SELECT projectPchPath, systemPchPath FROM precompiledHeaders WHERE projectPartId = ?",
database};
mutable ReadStatement fetchTimeStampsStatement{
mutable ReadStatement<2> fetchTimeStampsStatement{
"SELECT projectPchBuildTime, systemPchBuildTime FROM precompiledHeaders WHERE "
"projectPartId = ?",
database};
mutable ReadStatement fetchAllPchPathsStatement{
mutable ReadStatement<1> fetchAllPchPathsStatement{
"SELECT DISTINCT systemPchPath FROM precompiledHeaders UNION ALL SELECT "
"DISTINCT projectPchPath FROM precompiledHeaders",
database};
};
}
} // namespace ClangBackEnd

View File

@@ -45,7 +45,8 @@ template<typename DatabaseType = Sqlite::Database>
class SymbolStorage final : public SymbolStorageInterface
{
using Database = DatabaseType;
using ReadStatement = typename Database::ReadStatement;
template<int ResultCount>
using ReadStatement = typename Database::template ReadStatement<ResultCount>;
using WriteStatement = typename Database::WriteStatement;
public:
@@ -166,7 +167,7 @@ public:
"INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, "
"locationKind) VALUES(?,?,?,?,?)",
database};
ReadStatement selectNewSourceIdsStatement{
ReadStatement<1> selectNewSourceIdsStatement{
"SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources "
"WHERE newLocations.sourceId == sources.sourceId)",
database};

View File

@@ -110,12 +110,8 @@ add_qtc_test(unittest GTEST
mocksearch.h
mocksearchhandle.h
mocksearchresult.h
mocksqlitedatabase.h
mocksqlitereadstatement.cpp
mocksqlitereadstatement.h
mocksqlitestatement.h
mocksqlitetransactionbackend.h
mocksqlitewritestatement.h
mocksymbolindexertaskqueue.h
mocksymbolindexing.h
mocksymbolquery.h

View File

@@ -26,7 +26,7 @@
#include "googletest.h"
#include "mockfilepathcaching.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <builddependenciesstorage.h>
#include <refactoringdatabaseinitializer.h>
@@ -48,37 +48,40 @@ using Sqlite::Database;
using Sqlite::Table;
using Utils::PathString;
using Storage = ClangBackEnd::BuildDependenciesStorage<MockSqliteDatabase>;
using Storage = ClangBackEnd::BuildDependenciesStorage<SqliteDatabaseMock>;
class BuildDependenciesStorage : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
Storage storage{mockDatabase};
MockSqliteWriteStatement &insertIntoNewUsedMacrosStatement = storage.insertIntoNewUsedMacrosStatement;
MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.syncNewUsedMacrosStatement;
MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement;
MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement;
MockSqliteWriteStatement &insertOrUpdateFileStatusesStatement = storage.insertOrUpdateFileStatusesStatement;
MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.insertIntoNewSourceDependenciesStatement;
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.syncNewSourceDependenciesStatement;
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.deleteOutdatedSourceDependenciesStatement;
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.deleteNewSourceDependenciesStatement;
MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.getLowestLastModifiedTimeOfDependencies;
MockSqliteWriteStatement &insertOrUpdateProjectPartsFilesStatement = storage.insertOrUpdateProjectPartsFilesStatement;
MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement;
MockSqliteReadStatement &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement;
MockSqliteReadStatement &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement;
MockSqliteWriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement;
MockSqliteWriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement;
MockSqliteWriteStatement &deleteAllProjectPartsFilesWithProjectPartNameStatement
NiceMock<SqliteDatabaseMock> databaseMock;
template<int ResultCount>
using ReadStatement = NiceMock<SqliteDatabaseMock>::ReadStatement<ResultCount>;
using WriteStatement = NiceMock<SqliteDatabaseMock>::WriteStatement;
Storage storage{databaseMock};
WriteStatement &insertIntoNewUsedMacrosStatement = storage.insertIntoNewUsedMacrosStatement;
WriteStatement &syncNewUsedMacrosStatement = storage.syncNewUsedMacrosStatement;
WriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement;
WriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement;
WriteStatement &insertOrUpdateFileStatusesStatement = storage.insertOrUpdateFileStatusesStatement;
WriteStatement &insertIntoNewSourceDependenciesStatement = storage.insertIntoNewSourceDependenciesStatement;
WriteStatement &syncNewSourceDependenciesStatement = storage.syncNewSourceDependenciesStatement;
WriteStatement &deleteOutdatedSourceDependenciesStatement = storage.deleteOutdatedSourceDependenciesStatement;
WriteStatement &deleteNewSourceDependenciesStatement = storage.deleteNewSourceDependenciesStatement;
ReadStatement<1> &getLowestLastModifiedTimeOfDependencies = storage.getLowestLastModifiedTimeOfDependencies;
WriteStatement &insertOrUpdateProjectPartsFilesStatement = storage.insertOrUpdateProjectPartsFilesStatement;
ReadStatement<4> &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement;
ReadStatement<1> &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement;
ReadStatement<2> &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement;
WriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement;
WriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement;
WriteStatement &deleteAllProjectPartsFilesWithProjectPartNameStatement
= storage.deleteAllProjectPartsFilesWithProjectPartNameStatement;
MockSqliteReadStatement &fetchPchSourcesStatement = storage.fetchPchSourcesStatement;
MockSqliteReadStatement &fetchSourcesStatement = storage.fetchSourcesStatement;
MockSqliteWriteStatement &inserOrUpdateIndexingTimesStampStatement = storage.inserOrUpdateIndexingTimesStampStatement;
MockSqliteReadStatement &fetchIndexingTimeStampsStatement = storage.fetchIndexingTimeStampsStatement;
MockSqliteReadStatement &fetchIncludedIndexingTimeStampsStatement = storage.fetchIncludedIndexingTimeStampsStatement;
MockSqliteReadStatement &fetchDependentSourceIdsStatement = storage.fetchDependentSourceIdsStatement;
ReadStatement<1> &fetchPchSourcesStatement = storage.fetchPchSourcesStatement;
ReadStatement<1> &fetchSourcesStatement = storage.fetchSourcesStatement;
WriteStatement &inserOrUpdateIndexingTimesStampStatement = storage.inserOrUpdateIndexingTimesStampStatement;
ReadStatement<2> &fetchIndexingTimeStampsStatement = storage.fetchIndexingTimeStampsStatement;
ReadStatement<2> &fetchIncludedIndexingTimeStampsStatement = storage.fetchIncludedIndexingTimeStampsStatement;
ReadStatement<1> &fetchDependentSourceIdsStatement = storage.fetchDependentSourceIdsStatement;
};
TEST_F(BuildDependenciesStorage, ConvertStringsToJson)
@@ -132,14 +135,24 @@ TEST_F(BuildDependenciesStorage, 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());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(databaseMock,
execute(
Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON "
"newUsedMacros(sourceId, macroName)")));
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, "
"dependencySourceId TEXT)")));
EXPECT_CALL(
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId "
"ON newSourceDependencies(sourceId, dependencySourceId)")));
EXPECT_CALL(databaseMock, commit());
Storage storage{mockDatabase};
Storage storage{databaseMock};
}
TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists)
@@ -165,8 +178,12 @@ TEST_F(BuildDependenciesStorage, 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)")));
EXPECT_CALL(databaseMock,
execute(
Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)")));
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON "
"newUsedMacros(sourceId, macroName)")));
storage.createNewUsedMacrosTable();
}
@@ -175,8 +192,14 @@ TEST_F(BuildDependenciesStorage, 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)")));
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, "
"dependencySourceId TEXT)")));
EXPECT_CALL(
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId "
"ON newSourceDependencies(sourceId, dependencySourceId)")));
storage.createNewSourceDependenciesTable();
}
@@ -200,9 +223,9 @@ TEST_F(BuildDependenciesStorage, UpdatePchCreationTimeStamp)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(updatePchCreationTimeStampStatement, write(TypedEq<long long>(101), TypedEq<int>(1)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.updatePchCreationTimeStamp(101, 1);
}
@@ -255,9 +278,9 @@ TEST_F(BuildDependenciesStorage, FetchPchSourcesCalls)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
auto sources = storage.fetchPchSources(22);
}
@@ -266,13 +289,13 @@ TEST_F(BuildDependenciesStorage, FetchPchSourcesCallsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
auto sources = storage.fetchPchSources(22);
}
@@ -291,13 +314,13 @@ TEST_F(BuildDependenciesStorage, FetchIndexingTimeStampsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchIndexingTimeStampsStatement, valuesReturnSourceTimeStamps(1024))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchIndexingTimeStampsStatement, valuesReturnSourceTimeStamps(1024));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchIndexingTimeStamps();
}
@@ -306,12 +329,12 @@ TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampWithoutTransaction)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin()).Times(0);
EXPECT_CALL(databaseMock, immediateBegin()).Times(0);
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit()).Times(0);
EXPECT_CALL(databaseMock, commit()).Times(0);
storage.insertOrUpdateIndexingTimeStampsWithoutTransaction({1, 2}, 34);
}
@@ -320,12 +343,12 @@ TEST_F(BuildDependenciesStorage, InsertIndexingTimeStamp)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34);
}
@@ -334,13 +357,13 @@ TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(1), TypedEq<long long>(34)));
EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement,
write(TypedEq<int>(2), TypedEq<long long>(34)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34);
}
@@ -349,15 +372,15 @@ TEST_F(BuildDependenciesStorage, FetchIncludedIndexingTimeStampsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchIncludedIndexingTimeStampsStatement,
valuesReturnSourceTimeStamps(1024, TypedEq<int>(1)))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchIncludedIndexingTimeStampsStatement,
valuesReturnSourceTimeStamps(1024, TypedEq<int>(1)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchIncludedIndexingTimeStamps(1);
}
@@ -366,16 +389,16 @@ TEST_F(BuildDependenciesStorage, FetchDependentSourceIdsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq<int>(3)));
EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq<int>(2)))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq<int>(3)));
EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq<int>(2)));
EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq<int>(7)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDependentSourceIds({3, 2, 7});
}

View File

@@ -26,7 +26,7 @@
#include "googletest.h"
#include "mockfilepathstorage.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <filepathcache.h>
@@ -75,10 +75,10 @@ protected:
}
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
NiceMock<MockFilePathStorage> mockStorage{mockDatabase};
NiceMock<SqliteDatabaseMock> databaseMock;
NiceMock<MockFilePathStorage> mockStorage{databaseMock};
Cache cache{mockStorage};
NiceMock<MockFilePathStorage> mockStorageFilled{mockDatabase};
NiceMock<MockFilePathStorage> mockStorageFilled{databaseMock};
Cache cacheNotFilled{mockStorageFilled};
};
@@ -402,14 +402,14 @@ TEST_F(FilePathCache, AddFilePathsCalls)
Cache cacheFilled{mockStorageFilled};
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path3/to"))).WillOnce(Return(7));
EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0);
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))).WillOnce(Return(99));
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(6, Eq("file2.h"))).WillOnce(Return(106));
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(7, Eq("file.h"))).WillOnce(Return(101));
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0);
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
cacheFilled.addFilePaths(
FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"});
@@ -420,10 +420,10 @@ TEST_F(FilePathCache, DontUseTransactionIfNotAddingFilesInAddFilePathsCalls)
Cache cacheFilled{mockStorageFilled};
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin()).Times(0);
EXPECT_CALL(databaseMock, deferredBegin()).Times(0);
EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0);
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0);
EXPECT_CALL(mockDatabase, commit()).Times(0);
EXPECT_CALL(databaseMock, commit()).Times(0);
cacheFilled.addFilePaths(FilePathViews{"/path/to/file.cpp"});
}
@@ -433,10 +433,10 @@ TEST_F(FilePathCache, UseTransactionIfAddingFilesOnlyInAddFilePathsCalls)
Cache cacheFilled{mockStorageFilled};
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0);
EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
cacheFilled.addFilePaths(FilePathViews{"/path/to/file.h"});
}

View File

@@ -26,17 +26,18 @@
#include "googletest.h"
#include "mockmutex.h"
#include "mocksqlitedatabase.h"
#include "mocksqlitereadstatement.h"
#include "mocksqlitewritestatement.h"
#include "sqlitedatabasemock.h"
#include <filepathstorage.h>
#include <filepathstoragesqlitestatementfactory.h>
namespace {
using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<SqliteDatabaseMock>>;
using Storage = ClangBackEnd::FilePathStorage<StatementFactory>;
template<int ResultCount>
using ReadStatement = NiceMock<SqliteDatabaseMock>::ReadStatement<ResultCount>;
using WriteStatement = NiceMock<SqliteDatabaseMock>::WriteStatement;
using ClangBackEnd::Sources::Directory;
using ClangBackEnd::Sources::Source;
@@ -54,7 +55,7 @@ protected:
ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(Utils::SmallStringView("/path/to")))
.WillByDefault(Return(Utils::optional<int>(5)));
ON_CALL(mockDatabase, lastInsertedRowId())
ON_CALL(databaseMock, lastInsertedRowId())
.WillByDefault(Return(12));
ON_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_))
.WillByDefault(Return(std::vector<Directory>{{"/path/to", 1}, {"/other/path", 2}}));
@@ -98,17 +99,17 @@ protected:
}
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
StatementFactory factory{mockDatabase};
MockSqliteReadStatement &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath;
MockSqliteReadStatement &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName;
MockSqliteReadStatement &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId;
MockSqliteReadStatement &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
MockSqliteReadStatement &selectAllDirectories = factory.selectAllDirectories;
MockSqliteWriteStatement &insertIntoDirectories = factory.insertIntoDirectories;
MockSqliteWriteStatement &insertIntoSources = factory.insertIntoSources;
MockSqliteReadStatement &selectAllSources = factory.selectAllSources;
MockSqliteReadStatement &selectDirectoryIdFromSourcesBySourceId = factory.selectDirectoryIdFromSourcesBySourceId;
NiceMock<SqliteDatabaseMock> databaseMock;
StatementFactory factory{databaseMock};
ReadStatement<1> &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath;
ReadStatement<1> &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName;
ReadStatement<1> &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId;
ReadStatement<2> &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId;
ReadStatement<2> &selectAllDirectories = factory.selectAllDirectories;
WriteStatement &insertIntoDirectories = factory.insertIntoDirectories;
WriteStatement &insertIntoSources = factory.insertIntoSources;
ReadStatement<3> &selectAllSources = factory.selectAllSources;
ReadStatement<1> &selectDirectoryIdFromSourcesBySourceId = factory.selectDirectoryIdFromSourcesBySourceId;
Storage storage{factory};
};
@@ -229,10 +230,10 @@ TEST_F(FilePathStorage, CallSelectForFetchingDirectoryIdForKnownPath)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/path/to")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryId("/path/to");
}
@@ -241,10 +242,10 @@ TEST_F(FilePathStorage, CallSelectForFetchingSourceIdForKnownPath)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("file.h")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceId(5, "file.h");
}
@@ -267,11 +268,11 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdForUnknownPath)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/some/not/known/path")));
EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/some/not/known/path")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryId("/some/not/known/path");
}
@@ -280,12 +281,12 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntry)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("unknownfile.h")));
EXPECT_CALL(insertIntoSources,
write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceId(5, "unknownfile.h");
}
@@ -294,13 +295,13 @@ TEST_F(FilePathStorage, RestartFetchDirectoryIDIfTheStatementIsBusyInBeginBecaus
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryId("/other/unknow/path");
}
@@ -310,17 +311,17 @@ TEST_F(FilePathStorage,
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path")))
.WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryId("/other/unknow/path");
}
@@ -329,16 +330,16 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdTwoTimesIfTheInd
{
InSequence s;
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(databaseMock,deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path")))
.WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock,deferredBegin());
EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath,
valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryId("/other/unknow/path");
}
@@ -347,14 +348,14 @@ TEST_F(FilePathStorage, RestartFetchSourceIdIfTheStatementIsBusyInBeginBecauseTh
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
EXPECT_CALL(insertIntoSources,
write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
}
@@ -364,19 +365,19 @@ TEST_F(FilePathStorage,
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
EXPECT_CALL(insertIntoSources,
write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
.WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
EXPECT_CALL(insertIntoSources,
write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
}
@@ -385,18 +386,18 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheIndexIsC
{
InSequence s;
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(databaseMock,deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")));
EXPECT_CALL(insertIntoSources,
write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h")))
.WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase,deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock,deferredBegin());
EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(5, Eq("otherunknownfile.h")))
.WillOnce(Return(Utils::optional<int>(42)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceId(5, "otherunknownfile.h");
}
@@ -417,27 +418,27 @@ TEST_F(FilePathStorage, SelectAllSources)
TEST_F(FilePathStorage, CallSelectAllDirectories)
{
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchAllDirectories();
}
TEST_F(FilePathStorage, CallSelectAllSources)
{
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchAllSources();
}
TEST_F(FilePathStorage, CallValueForFetchDirectoryPathForId)
{
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchDirectoryPath(5);
}
@@ -456,9 +457,9 @@ TEST_F(FilePathStorage, ThrowAsFetchingDirectoryPathForNonExistingId)
TEST_F(FilePathStorage, CallValueForFetchSoureNameForId)
{
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchSourceNameAndDirectoryId(42);
}
@@ -480,15 +481,15 @@ TEST_F(FilePathStorage, RestartFetchSourceNameIfTheStatementIsBusyInBegin)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, unlock());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchSourceNameAndDirectoryId(42);
}
@@ -497,15 +498,15 @@ TEST_F(FilePathStorage, RestartFetchDirectoryPathIfTheStatementIsBusyInBegin)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, unlock());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchDirectoryPath(5);
}
@@ -514,15 +515,15 @@ TEST_F(FilePathStorage, RestartFetchAllDirectoriesIfBeginIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, unlock());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchAllDirectories();
}
@@ -531,15 +532,15 @@ TEST_F(FilePathStorage, RestartFetchAllSourcesIfBeginIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, unlock());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchAllSources();
}
@@ -560,11 +561,11 @@ TEST_F(FilePathStorage, FetchDirectoryIdCalls)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(42)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchDirectoryId(42);
}
@@ -573,15 +574,15 @@ TEST_F(FilePathStorage, FetchDirectoryIdCallsDatabaseIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback()).Times(0);
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(databaseMock, rollback()).Times(0);
EXPECT_CALL(databaseMock, unlock());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(42)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, unlock());
storage.fetchDirectoryId(42);
}
@@ -590,11 +591,11 @@ TEST_F(FilePathStorage, FetchDirectoryIdCallsThrows)
{
InSequence s;
EXPECT_CALL(mockDatabase, lock());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(41)));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, unlock());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, unlock());
ASSERT_ANY_THROW(storage.fetchDirectoryId(41));
}

View File

@@ -26,21 +26,19 @@
#include "googletest.h"
#include "mockmutex.h"
#include "mocksqlitedatabase.h"
#include "mocksqlitereadstatement.h"
#include "mocksqlitewritestatement.h"
#include "sqlitedatabasemock.h"
#include <filepathstoragesqlitestatementfactory.h>
namespace {
using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<SqliteDatabaseMock>>;
class FilePathStorageSqliteStatementFactory : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
StatementFactory factory{mockDatabase};
NiceMock<SqliteDatabaseMock> databaseMock;
StatementFactory factory{databaseMock};
};
TEST_F(FilePathStorageSqliteStatementFactory, SelectDirectoryIdFromDirectoriesByDirectoryPath)

View File

@@ -55,14 +55,15 @@ MATCHER_P2(IsIconEntry,
class ImageCacheStorageTest : public testing::Test
{
protected:
using ReadStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::ReadStatement;
template<int ResultCount>
using ReadStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::ReadStatement<ResultCount>;
using WriteStatement = QmlDesigner::ImageCacheStorage<SqliteDatabaseMock>::WriteStatement;
NiceMock<SqliteDatabaseMock> databaseMock;
QmlDesigner::ImageCacheStorage<SqliteDatabaseMock> storage{databaseMock};
ReadStatement &selectImageStatement = storage.selectImageStatement;
ReadStatement &selectSmallImageStatement = storage.selectSmallImageStatement;
ReadStatement &selectIconStatement = storage.selectIconStatement;
ReadStatement<1> &selectImageStatement = storage.selectImageStatement;
ReadStatement<1> &selectSmallImageStatement = storage.selectSmallImageStatement;
ReadStatement<1> &selectIconStatement = storage.selectIconStatement;
WriteStatement &upsertImageStatement = storage.upsertImageStatement;
WriteStatement &upsertIconStatement = storage.upsertIconStatement;
QImage image1{10, 10, QImage::Format_ARGB32};

View File

@@ -25,7 +25,7 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <lastchangedrowid.h>
@@ -34,7 +34,7 @@ namespace {
class LastChangedRowId : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"};
};
@@ -112,7 +112,7 @@ TEST_F(LastChangedRowId, TakeLastRowIdResetsRowIdToMinusOne)
class LastChangedRowIdWithTwoTables : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"};
};
@@ -197,7 +197,7 @@ TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowIdResetsRowIdToMinusOne)
class LastChangedRowIdWithThreeTables : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"};
};
@@ -290,7 +290,7 @@ TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowIdResetsRowIdToMinusOne)
class LastChangedRowIdWithNoDatabaseAndTable : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase};
};
@@ -350,7 +350,7 @@ TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowIdResetsRowIdToMinusOn
class LastChangedRowIdWithNoTable : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"};
};

View File

@@ -27,15 +27,15 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <filepathstoragesources.h>
class MockFilePathStorage
{
public:
MockFilePathStorage(MockSqliteDatabase &mockDatabase)
: mockDatabase{mockDatabase}
MockFilePathStorage(SqliteDatabaseMock &databaseMock)
: databaseMock{databaseMock}
{}
MOCK_METHOD1(fetchDirectoryId, int(Utils::SmallStringView directoryPath));
@@ -50,8 +50,8 @@ public:
MOCK_METHOD0(fetchAllDirectories, std::vector<ClangBackEnd::Sources::Directory>());
MOCK_METHOD0(fetchAllSources, std::vector<ClangBackEnd::Sources::Source>());
MockSqliteDatabase &database() { return mockDatabase; }
SqliteDatabaseMock &database() { return databaseMock; }
MockSqliteDatabase &mockDatabase;
SqliteDatabaseMock &databaseMock;
};

View File

@@ -1,73 +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 "googletest.h"
#include "mocksqlitereadstatement.h"
#include "mocksqlitetransactionbackend.h"
#include "mocksqlitewritestatement.h"
#include <sqlitedatabaseinterface.h>
#include <sqlitetable.h>
#include <sqlitetransaction.h>
#include <utils/smallstringview.h>
class MockSqliteDatabase : public MockSqliteTransactionBackend, public Sqlite::DatabaseInterface
{
public:
using ReadStatement = NiceMock<MockSqliteReadStatement>;
using WriteStatement = NiceMock<MockSqliteWriteStatement>;
MOCK_METHOD1(execute,
void (Utils::SmallStringView sqlStatement));
MOCK_CONST_METHOD0(lastInsertedRowId,
int64_t ());
MOCK_CONST_METHOD1(setLastInsertedRowId,
void (int64_t));
MOCK_CONST_METHOD0(isInitialized,
bool ());
MOCK_METHOD1(setIsInitialized,
void (bool));
MOCK_METHOD0(walCheckpointFull, void());
MOCK_METHOD2(setUpdateHook,
void(void *object,
void (*)(void *object, int, char const *database, char const *, long long rowId)));
MOCK_METHOD0(resetUpdateHook, void());
MOCK_METHOD0(applyAndUpdateSessions, void());
MOCK_METHOD1(setAttachedTables, void(const Utils::SmallStringVector &tables));
};

View File

@@ -1,284 +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 "mocksqlitereadstatement.h"
template <>
SourceLocations
MockSqliteReadStatement::values<SourceLocation, 3>(std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column)
{
return valuesReturnSourceLocations(reserveSize, sourceId, line, column);
}
template <>
CppTools::Usages
MockSqliteReadStatement::values<CppTools::Usage, 3>(
std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column)
{
return valuesReturnSourceUsages(reserveSize, sourceId, line, column);
}
template<>
CppTools::Usages MockSqliteReadStatement::values<CppTools::Usage, 3>(std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column,
const int &locationKind)
{
return valuesReturnSourceUsages(reserveSize, sourceId, line, column, locationKind);
}
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int &symbolKind,
const Utils::SmallStringView &searchTerm)
{
return valuesReturnSymbols(reserveSize, symbolKind, searchTerm);
}
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int &symbolKind1,
const int &symbolKind2,
const Utils::SmallStringView &searchTerm)
{
return valuesReturnSymbols(reserveSize, symbolKind1, symbolKind2, searchTerm);
}
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int &symbolKind1,
const int &symbolKind2,
const int &symbolKind3,
const Utils::SmallStringView &searchTerm)
{
return valuesReturnSymbols(reserveSize, symbolKind1, symbolKind2, symbolKind3, searchTerm);
}
template <>
UsedMacros
MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>(
std::size_t reserveSize,
const int &sourceId)
{
return valuesReturnUsedMacros(reserveSize, sourceId);
}
template<>
FilePathIds MockSqliteReadStatement::values<ClangBackEnd::FilePathId>(std::size_t reserveSize,
const int &projectPartId)
{
return valuesReturnFilePathIds(reserveSize, projectPartId);
}
template<>
ClangBackEnd::FilePaths MockSqliteReadStatement::values<ClangBackEnd::FilePath>(std::size_t reserveSize)
{
return valuesReturnFilePaths(reserveSize);
}
template <>
std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize)
{
return valuesReturnStdVectorDirectory(reserveSize);
}
template<>
std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 3>(std::size_t reserveSize)
{
return valuesReturnStdVectorSource(reserveSize);
}
template<>
ProjectPartNameIds MockSqliteReadStatement::values<ProjectPartNameId, 2>(std::size_t reserveSize)
{
return valuesReturnProjectPartNameIds(reserveSize);
}
template <>
Utils::optional<int>
MockSqliteReadStatement::value<int>(const Utils::SmallStringView &text)
{
return valueReturnInt32(text);
}
template <>
Utils::optional<int>
MockSqliteReadStatement::value<int>(const Utils::PathString &text)
{
return valueReturnInt32(text);
}
template<>
Utils::optional<ClangBackEnd::ProjectPartId> MockSqliteReadStatement::value<ClangBackEnd::ProjectPartId>(
const Utils::SmallStringView &text)
{
return valueReturnProjectPartId(text);
}
template <>
Utils::optional<int>
MockSqliteReadStatement::value<int>(const int &directoryId, const Utils::SmallStringView &text)
{
return valueReturnInt32(directoryId, text);
}
template<>
Utils::optional<int> MockSqliteReadStatement::value<int>(const int &value)
{
return valueReturnInt32(value);
}
template <>
Utils::optional<long long>
MockSqliteReadStatement::value<long long>(const int &sourceId)
{
return valueReturnInt64(sourceId);
}
template <>
Utils::optional<Utils::PathString>
MockSqliteReadStatement::value<Utils::PathString>(const int &directoryId)
{
return valueReturnPathString(directoryId);
}
template <>
Utils::optional<Utils::PathString>
MockSqliteReadStatement::value<Utils::PathString>(const Utils::SmallStringView &path)
{
return valueReturnPathString(path);
}
template<>
Utils::optional<ClangBackEnd::FilePath> MockSqliteReadStatement::value<ClangBackEnd::FilePath>(
const int &path)
{
return valueReturnFilePath(path);
}
template <>
Utils::optional<ClangBackEnd::ProjectPartArtefact>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 8>(const int& sourceId)
{
return valueReturnProjectPartArtefact(sourceId);
}
template <>
Utils::optional<ClangBackEnd::ProjectPartArtefact>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 8>(const Utils::SmallStringView &projectPartName)
{
return valueReturnProjectPartArtefact(projectPartName);
}
template<>
Utils::optional<ClangBackEnd::ProjectPartContainer>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartContainer, 8>(const int &id)
{
return valueReturnProjectPartContainer(id);
}
template<>
ClangBackEnd::ProjectPartContainers MockSqliteReadStatement::values<ClangBackEnd::ProjectPartContainer,
8>(std::size_t reserveSize)
{
return valuesReturnProjectPartContainers(reserveSize);
}
template<>
Utils::optional<ClangBackEnd::ProjectPartPch>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartPch, 3>(const int &projectPartId)
{
return valueReturnProjectPartPch(projectPartId);
}
template<>
Utils::optional<ClangBackEnd::PchPaths> MockSqliteReadStatement::value<ClangBackEnd::PchPaths, 2>(
const int &projectPartId)
{
return valueReturnPchPaths(projectPartId);
}
template<>
Utils::optional<Utils::SmallString> MockSqliteReadStatement::value<Utils::SmallString>(const int &sourceId)
{
return valueReturnSmallString(sourceId);
}
template <>
Utils::optional<SourceLocation>
MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind)
{
return valueReturnSourceLocation(symbolId, locationKind);
}
template<>
SourceEntries MockSqliteReadStatement::values<SourceEntry, 4>(std::size_t reserveSize,
const int &filePathId,
const int &projectPartId)
{
return valuesReturnSourceEntries(reserveSize, filePathId, projectPartId);
}
template<>
SourceTimeStamps MockSqliteReadStatement::values<SourceTimeStamp, 2>(std::size_t reserveSize)
{
return valuesReturnSourceTimeStamps(reserveSize);
}
template<>
SourceTimeStamps MockSqliteReadStatement::values<SourceTimeStamp, 2>(std::size_t reserveSize,
const int &sourcePathId)
{
return valuesReturnSourceTimeStamps(reserveSize, sourcePathId);
}
template <>
Utils::optional<Sources::SourceNameAndDirectoryId>
MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int &id)
{
return valueReturnSourceNameAndDirectoryId(id);
}
template<>
Utils::optional<ClangBackEnd::PrecompiledHeaderTimeStamps>
MockSqliteReadStatement::value<ClangBackEnd::PrecompiledHeaderTimeStamps, 2>(const int &projectPartId)
{
return valuesReturnPrecompiledHeaderTimeStamps(projectPartId);
}

View File

@@ -1,334 +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 "googletest.h"
#include <sourcelocations.h>
#include <filepathstoragesources.h>
#include <pchpaths.h>
#include <projectpartartefact.h>
#include <projectpartcontainer.h>
#include <projectpartpch.h>
#include <projectpartstoragestructs.h>
#include <sourceentry.h>
#include <stringcachefwd.h>
#include <symbol.h>
#include <usedmacro.h>
#include <cpptools/usages.h>
#include <utils/optional.h>
#include <utils/smallstring.h>
#include <cstdint>
#include <tuple>
#include <vector>
using ClangBackEnd::FilePathIds;
using ClangBackEnd::SourceEntries;
using ClangBackEnd::SourceEntry;
using ClangBackEnd::SourceTimeStamp;
using ClangBackEnd::SourceTimeStamps;
using ClangRefactoring::SourceLocation;
using ClangRefactoring::SourceLocations;
using std::int64_t;
namespace Sources = ClangBackEnd::Sources;
using ClangBackEnd::PrecompiledHeaderTimeStamps;
using ClangBackEnd::UsedMacros;
using ClangBackEnd::Internal::ProjectPartNameId;
using ClangBackEnd::Internal::ProjectPartNameIds;
using ClangRefactoring::Symbol;
using ClangRefactoring::Symbols;
class MockSqliteDatabase;
class MockSqliteReadStatement
{
public:
MockSqliteReadStatement() = default;
MockSqliteReadStatement(Utils::SmallStringView sqlStatement, MockSqliteDatabase &)
: sqlStatement(sqlStatement)
{}
MOCK_METHOD4(valuesReturnSourceLocations,
SourceLocations(std::size_t, int, int, int));
MOCK_METHOD4(valuesReturnSourceUsages, CppTools::Usages(std::size_t, int, int, int));
MOCK_METHOD5(valuesReturnSourceUsages, CppTools::Usages(std::size_t, int, int, int, int));
MOCK_METHOD1(valuesReturnStdVectorDirectory,
std::vector<Sources::Directory>(std::size_t));
MOCK_METHOD1(valuesReturnStdVectorSource,
std::vector<Sources::Source>(std::size_t));
MOCK_METHOD3(valuesReturnSourceEntries,
SourceEntries(std::size_t, int, int));
MOCK_METHOD2(valuesReturnUsedMacros, UsedMacros(std::size_t, int));
MOCK_METHOD2(valuesReturnFilePathIds, FilePathIds(std::size_t, int));
MOCK_METHOD1(valuesReturnProjectPartNameIds, ProjectPartNameIds(std::size_t));
MOCK_METHOD1(valueReturnInt32, Utils::optional<int>(Utils::SmallStringView));
MOCK_METHOD2(valueReturnInt32, Utils::optional<int>(int, Utils::SmallStringView));
MOCK_METHOD1(valueReturnInt32, Utils::optional<int>(int));
MOCK_METHOD1(valueReturnInt64, Utils::optional<long long>(int));
MOCK_METHOD1(valueReturnPathString,
Utils::optional<Utils::PathString>(int));
MOCK_METHOD1(valueReturnPathString,
Utils::optional<Utils::PathString>(Utils::SmallStringView));
MOCK_METHOD1(valueReturnFilePath, Utils::optional<ClangBackEnd::FilePath>(int));
MOCK_METHOD1(valuesReturnFilePaths, ClangBackEnd::FilePaths(std::size_t));
MOCK_METHOD1(valueReturnSmallString,
Utils::optional<Utils::SmallString>(int));
MOCK_METHOD1(valueReturnSourceNameAndDirectoryId,
Utils::optional<Sources::SourceNameAndDirectoryId>(int));
MOCK_METHOD1(valueReturnProjectPartArtefact,
Utils::optional<ClangBackEnd::ProjectPartArtefact>(int));
MOCK_METHOD1(valueReturnProjectPartArtefact,
Utils::optional<ClangBackEnd::ProjectPartArtefact>(Utils::SmallStringView));
MOCK_METHOD1(valuesReturnProjectPartArtefacts, ClangBackEnd::ProjectPartArtefacts(std::size_t));
MOCK_METHOD1(valueReturnProjectPartContainer,
Utils::optional<ClangBackEnd::ProjectPartContainer>(int));
MOCK_METHOD1(valuesReturnProjectPartContainers, ClangBackEnd::ProjectPartContainers(std::size_t));
MOCK_METHOD1(valueReturnProjectPartPch, Utils::optional<ClangBackEnd::ProjectPartPch>(int));
MOCK_METHOD1(valueReturnPchPaths, Utils::optional<ClangBackEnd::PchPaths>(int));
MOCK_METHOD3(valuesReturnSymbols, Symbols(std::size_t, int, Utils::SmallStringView));
MOCK_METHOD4(valuesReturnSymbols,
Symbols(std::size_t, int, int, Utils::SmallStringView));
MOCK_METHOD5(valuesReturnSymbols,
Symbols(std::size_t, int, int, int, Utils::SmallStringView));
MOCK_METHOD2(valueReturnSourceLocation,
SourceLocation(long long, int));
MOCK_METHOD1(valueReturnProjectPartId,
Utils::optional<ClangBackEnd::ProjectPartId>(Utils::SmallStringView));
MOCK_METHOD1(valuesReturnSourceTimeStamps, SourceTimeStamps(std::size_t));
MOCK_METHOD2(valuesReturnSourceTimeStamps, SourceTimeStamps(std::size_t, int sourcePathId));
MOCK_METHOD1(valuesReturnPrecompiledHeaderTimeStamps,
PrecompiledHeaderTimeStamps(int projectPartId));
template<typename ResultType, int ResultTypeCount = 1, typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize, const QueryType &... queryValues);
template <typename ResultType,
int ResultTypeCount = 1,
typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize);
template <typename ResultType,
int ResultTypeCount = 1,
template <typename...> class QueryContainerType,
typename QueryElementType>
std::vector<ResultType> values(std::size_t reserveSize,
const QueryContainerType<QueryElementType> &queryValues);
template <typename ResultType,
int ResultTypeCount = 1,
typename... QueryTypes>
Utils::optional<ResultType> value(const QueryTypes&... queryValues);
public:
Utils::SmallString sqlStatement;
};
template <>
SourceLocations
MockSqliteReadStatement::values<SourceLocation, 3>(
std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column);
template <>
CppTools::Usages
MockSqliteReadStatement::values<CppTools::Usage, 3>(
std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column);
template<>
CppTools::Usages MockSqliteReadStatement::values<CppTools::Usage, 3>(std::size_t reserveSize,
const int &sourceId,
const int &line,
const int &column,
const int &locationKind);
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int&,
const Utils::SmallStringView&);
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int&,
const int&,
const Utils::SmallStringView&);
template <>
Symbols
MockSqliteReadStatement::values<Symbol, 3>(
std::size_t reserveSize,
const int&,
const int&,
const int&,
const Utils::SmallStringView&);
template <>
UsedMacros
MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>(
std::size_t reserveSize,
const int &sourceId);
template<>
FilePathIds MockSqliteReadStatement::values<ClangBackEnd::FilePathId>(std::size_t reserveSize,
const int &projectPartId);
template<>
ClangBackEnd::FilePaths MockSqliteReadStatement::values<ClangBackEnd::FilePath>(std::size_t reserveSize);
template <>
std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize);
template<>
std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 3>(std::size_t reserveSize);
template<>
ProjectPartNameIds MockSqliteReadStatement::values<ProjectPartNameId, 2>(std::size_t reserveSize);
template<>
Utils::optional<int> MockSqliteReadStatement::value<int>(const Utils::SmallStringView &);
template <>
Utils::optional<int>
MockSqliteReadStatement::value<int>(const Utils::PathString&);
template<>
Utils::optional<ClangBackEnd::ProjectPartId> MockSqliteReadStatement::value<ClangBackEnd::ProjectPartId>(
const Utils::SmallStringView &);
template<>
Utils::optional<ClangBackEnd::FilePath> MockSqliteReadStatement::value<ClangBackEnd::FilePath>(
const int &);
template <>
Utils::optional<int>
MockSqliteReadStatement::value<int>(const int&, const Utils::SmallStringView&);
template<>
Utils::optional<int> MockSqliteReadStatement::value<int>(const int &);
template <>
Utils::optional<long long>
MockSqliteReadStatement::value<long long>(const ClangBackEnd::FilePathId&);
template <>
Utils::optional<Utils::PathString>
MockSqliteReadStatement::value<Utils::PathString>(const int&);
template <>
Utils::optional<Utils::PathString>
MockSqliteReadStatement::value<Utils::PathString>(const Utils::SmallStringView&);
template <>
Utils::optional<ClangBackEnd::ProjectPartArtefact>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 8>(const int&);
template <>
Utils::optional<ClangBackEnd::ProjectPartArtefact>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 8>(const int&);
template<>
Utils::optional<ClangBackEnd::ProjectPartContainer>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartContainer, 8>(const int &);
template<>
Utils::optional<ClangBackEnd::PchPaths> MockSqliteReadStatement::value<ClangBackEnd::PchPaths, 2>(
const int &);
template<>
ClangBackEnd::ProjectPartContainers MockSqliteReadStatement::values<ClangBackEnd::ProjectPartContainer,
8>(std::size_t reserveSize);
template<>
Utils::optional<ClangBackEnd::ProjectPartPch>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartPch, 3>(const int &);
template <>
Utils::optional<Utils::SmallString>
MockSqliteReadStatement::value<Utils::SmallString>(const int&);
template <>
Utils::optional<SourceLocation>
MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind);
template<>
SourceEntries MockSqliteReadStatement::values<SourceEntry, 4>(std::size_t reserveSize,
const int &,
const int &);
template<>
SourceTimeStamps MockSqliteReadStatement::values<SourceTimeStamp, 2>(std::size_t reserveSize);
template<>
SourceTimeStamps MockSqliteReadStatement::values<SourceTimeStamp, 2>(std::size_t reserveSize,
const int &sourcePathId);
template <>
Utils::optional<Sources::SourceNameAndDirectoryId>
MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int&);
template<>
Utils::optional<ClangBackEnd::PrecompiledHeaderTimeStamps>
MockSqliteReadStatement::value<ClangBackEnd::PrecompiledHeaderTimeStamps, 2>(const int &);

View File

@@ -58,6 +58,8 @@ public:
MOCK_METHOD1(prepare, void(Utils::SmallStringView sqlStatement));
MOCK_METHOD1(checkColumnCount, void(int));
MOCK_CONST_METHOD0(isReadOnlyStatement, bool());
};
template<>
@@ -96,13 +98,12 @@ Utils::PathString BaseMockSqliteStatement::fetchValue<Utils::PathString>(int col
return fetchPathStringValue(column);
}
class MockSqliteStatement : public Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>>
template<int ResultCount = 1>
class MockSqliteStatement
: public Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>, ResultCount>
{
public:
explicit MockSqliteStatement()
: Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>>()
{}
explicit MockSqliteStatement() {}
protected:
void checkIsWritableStatement();

View File

@@ -1,118 +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 "googletest.h"
#include <utils/smallstring.h>
class MockSqliteDatabase;
class MockSqliteWriteStatement
{
public:
MockSqliteWriteStatement() = default;
MockSqliteWriteStatement(Utils::SmallStringView sqlStatement, MockSqliteDatabase &)
: sqlStatement(sqlStatement)
{}
MOCK_METHOD0(execute,
void ());
MOCK_METHOD2(bind, void(int, Utils::SmallStringView));
MOCK_METHOD2(bindValues,
void (Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD4(write,
void (uint, Utils::SmallStringView, Utils::SmallStringView, uint));
MOCK_METHOD4(write,
void (uint, uint, uint, uint));
MOCK_METHOD4(write,
void (long long, int, int, int));
MOCK_METHOD5(write,
void (long long, int, int, int, int));
MOCK_METHOD2(write, void(uint, Utils::SmallStringView));
MOCK_METHOD2(write, void(int, Utils::SmallStringView));
MOCK_METHOD2(write, void(Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD3(write, void(int, Utils::SmallStringView, long long));
MOCK_METHOD3(write,
void (Utils::SmallStringView, Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD4(write,
void (Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView));
MOCK_METHOD8(write,
void(int,
Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView,
int,
int,
int));
MOCK_METHOD1(write,
void (Utils::SmallStringView));
MOCK_METHOD1(write,
void (long long));
MOCK_METHOD1(write,
void (int));
MOCK_METHOD2(write, void(int, long long));
MOCK_METHOD2(write,
void (int, int));
MOCK_METHOD3(write,
void (uint, uint, uint));
MOCK_METHOD3(write, void(int, off_t, time_t));
MOCK_METHOD2(write,
void (uint, uint));
MOCK_METHOD2(write,
void (uchar, int));
MOCK_METHOD4(write, void(int, int, uchar, uchar));
MOCK_METHOD2(write,
void (long long, int));
MOCK_METHOD2(write, void(long long, Utils::SmallStringView));
Utils::SmallString sqlStatement;
};

View File

@@ -27,7 +27,7 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <symbolstorageinterface.h>

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <precompiledheaderstorage.h>
#include <refactoringdatabaseinitializer.h>
@@ -35,25 +35,28 @@
namespace {
using Storage = ClangBackEnd::PrecompiledHeaderStorage<NiceMock<MockSqliteDatabase>>;
using Storage = ClangBackEnd::PrecompiledHeaderStorage<NiceMock<SqliteDatabaseMock>>;
template<int ResultCount>
using ReadStatement = NiceMock<SqliteDatabaseMock>::ReadStatement<ResultCount>;
using WriteStatement = NiceMock<SqliteDatabaseMock>::WriteStatement;
class PrecompiledHeaderStorage : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> database;
NiceMock<SqliteDatabaseMock> database;
Storage storage{database};
MockSqliteWriteStatement &insertProjectPrecompiledHeaderStatement = storage.insertProjectPrecompiledHeaderStatement;
MockSqliteWriteStatement &deleteProjectPrecompiledHeaderStatement = storage.deleteProjectPrecompiledHeaderStatement;
MockSqliteWriteStatement &deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement
WriteStatement &insertProjectPrecompiledHeaderStatement = storage.insertProjectPrecompiledHeaderStatement;
WriteStatement &deleteProjectPrecompiledHeaderStatement = storage.deleteProjectPrecompiledHeaderStatement;
WriteStatement &deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement
= storage.deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement;
MockSqliteWriteStatement &insertSystemPrecompiledHeaderStatement = storage.insertSystemPrecompiledHeaderStatement;
MockSqliteWriteStatement &deleteSystemPrecompiledHeaderStatement = storage.deleteSystemPrecompiledHeaderStatement;
MockSqliteWriteStatement &deleteSystemAndProjectPrecompiledHeaderStatement = storage.deleteSystemAndProjectPrecompiledHeaderStatement;
MockSqliteReadStatement &fetchSystemPrecompiledHeaderPathStatement = storage.fetchSystemPrecompiledHeaderPathStatement;
MockSqliteReadStatement &fetchPrecompiledHeaderStatement = storage.fetchPrecompiledHeaderStatement;
MockSqliteReadStatement &fetchPrecompiledHeadersStatement = storage.fetchPrecompiledHeadersStatement;
MockSqliteReadStatement &fetchTimeStampsStatement = storage.fetchTimeStampsStatement;
MockSqliteReadStatement &fetchAllPchPathsStatement = storage.fetchAllPchPathsStatement;
WriteStatement &insertSystemPrecompiledHeaderStatement = storage.insertSystemPrecompiledHeaderStatement;
WriteStatement &deleteSystemPrecompiledHeaderStatement = storage.deleteSystemPrecompiledHeaderStatement;
WriteStatement &deleteSystemAndProjectPrecompiledHeaderStatement = storage.deleteSystemAndProjectPrecompiledHeaderStatement;
ReadStatement<1> &fetchSystemPrecompiledHeaderPathStatement = storage.fetchSystemPrecompiledHeaderPathStatement;
ReadStatement<1> &fetchPrecompiledHeaderStatement = storage.fetchPrecompiledHeaderStatement;
ReadStatement<2> &fetchPrecompiledHeadersStatement = storage.fetchPrecompiledHeadersStatement;
ReadStatement<2> &fetchTimeStampsStatement = storage.fetchTimeStampsStatement;
ReadStatement<1> &fetchAllPchPathsStatement = storage.fetchAllPchPathsStatement;
};
TEST_F(PrecompiledHeaderStorage, UseTransaction)

View File

@@ -25,7 +25,7 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <builddependenciesstorage.h>
#include <projectpartsstorage.h>
@@ -72,7 +72,10 @@ protected:
class ProjectPartsStorage : public testing::Test, public Data
{
using Storage = ClangBackEnd::ProjectPartsStorage<MockSqliteDatabase>;
using Storage = ClangBackEnd::ProjectPartsStorage<SqliteDatabaseMock>;
template<int ResultCount>
using ReadStatement = NiceMock<SqliteDatabaseMock>::ReadStatement<ResultCount>;
using WriteStatement = NiceMock<SqliteDatabaseMock>::WriteStatement;
protected:
ProjectPartsStorage()
@@ -90,26 +93,25 @@ protected:
ON_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(_, Eq(2)))
.WillByDefault(Return(projectPart2.sourcePathIds));
}
NiceMock<MockSqliteDatabase> mockDatabase;
Storage storage{mockDatabase};
MockSqliteReadStatement &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement;
MockSqliteWriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement;
MockSqliteReadStatement &fetchProjectPartNameStatement = storage.fetchProjectPartNameStatement;
MockSqliteReadStatement &fetchProjectPartsStatement = storage.fetchProjectPartsStatement;
MockSqliteReadStatement &fetchProjectPartByIdStatement = storage.fetchProjectPartByIdStatement;
MockSqliteWriteStatement &updateProjectPartStatement = storage.updateProjectPartStatement;
MockSqliteReadStatement &getProjectPartArtefactsBySourceId = storage.getProjectPartArtefactsBySourceId;
MockSqliteReadStatement &getProjectPartArtefactsByProjectPartId = storage.getProjectPartArtefactsByProjectPartId;
MockSqliteWriteStatement &deleteProjectPartsHeadersByIdStatement = storage.deleteProjectPartsHeadersByIdStatement;
MockSqliteWriteStatement &deleteProjectPartsSourcesByIdStatement = storage.deleteProjectPartsSourcesByIdStatement;
MockSqliteWriteStatement &insertProjectPartsHeadersStatement = storage.insertProjectPartsHeadersStatement;
MockSqliteWriteStatement &insertProjectPartsSourcesStatement = storage.insertProjectPartsSourcesStatement;
MockSqliteReadStatement &fetchProjectPartsHeadersByIdStatement = storage.fetchProjectPartsHeadersByIdStatement;
MockSqliteReadStatement &fetchProjectPartsSourcesByIdStatement = storage.fetchProjectPartsSourcesByIdStatement;
MockSqliteReadStatement &fetchProjectPrecompiledHeaderPathStatement = storage.fetchProjectPrecompiledHeaderBuildTimeStatement;
MockSqliteReadStatement &fetchProjectPrecompiledHeaderBuildTimeStatement = storage.fetchProjectPrecompiledHeaderBuildTimeStatement;
MockSqliteWriteStatement &resetDependentIndexingTimeStampsStatement = storage.resetDependentIndexingTimeStampsStatement;
MockSqliteReadStatement &fetchAllProjectPartNamesAndIdsStatement = storage.fetchAllProjectPartNamesAndIdsStatement;
NiceMock<SqliteDatabaseMock> databaseMock;
Storage storage{databaseMock};
ReadStatement<1> &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement;
WriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement;
ReadStatement<1> &fetchProjectPartNameStatement = storage.fetchProjectPartNameStatement;
ReadStatement<8> &fetchProjectPartsStatement = storage.fetchProjectPartsStatement;
ReadStatement<8> &fetchProjectPartByIdStatement = storage.fetchProjectPartByIdStatement;
WriteStatement &updateProjectPartStatement = storage.updateProjectPartStatement;
ReadStatement<8> &getProjectPartArtefactsBySourceId = storage.getProjectPartArtefactsBySourceId;
ReadStatement<8> &getProjectPartArtefactsByProjectPartId = storage.getProjectPartArtefactsByProjectPartId;
WriteStatement &deleteProjectPartsHeadersByIdStatement = storage.deleteProjectPartsHeadersByIdStatement;
WriteStatement &deleteProjectPartsSourcesByIdStatement = storage.deleteProjectPartsSourcesByIdStatement;
WriteStatement &insertProjectPartsHeadersStatement = storage.insertProjectPartsHeadersStatement;
WriteStatement &insertProjectPartsSourcesStatement = storage.insertProjectPartsSourcesStatement;
ReadStatement<1> &fetchProjectPartsHeadersByIdStatement = storage.fetchProjectPartsHeadersByIdStatement;
ReadStatement<1> &fetchProjectPartsSourcesByIdStatement = storage.fetchProjectPartsSourcesByIdStatement;
ReadStatement<1> &fetchProjectPrecompiledHeaderBuildTimeStatement = storage.fetchProjectPrecompiledHeaderBuildTimeStatement;
WriteStatement &resetDependentIndexingTimeStampsStatement = storage.resetDependentIndexingTimeStampsStatement;
ReadStatement<2> &fetchAllProjectPartNamesAndIdsStatement = storage.fetchAllProjectPartNamesAndIdsStatement;
IncludeSearchPaths systemIncludeSearchPaths{{"/includes", 1, IncludeSearchPathType::BuiltIn},
{"/other/includes", 2, IncludeSearchPathType::System}};
IncludeSearchPaths projectIncludeSearchPaths{{"/project/includes", 1, IncludeSearchPathType::User},
@@ -134,11 +136,11 @@ TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithNonExistingProjectPartName)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")));
EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartId("test");
}
@@ -158,12 +160,12 @@ TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithExistingProjectPart)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")))
.WillOnce(Return(Utils::optional<ProjectPartId>{20}));
EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test"))).Times(0);
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartId("test");
}
@@ -184,17 +186,17 @@ TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithBusyDatabaset)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")));
EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test")))
.WillOnce(Throw(Sqlite::StatementIsBusy("busy")));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")));
EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq<Utils::SmallStringView>("test")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartId("test");
}
@@ -204,7 +206,7 @@ TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartName)
ON_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")))
.WillByDefault(Return(Utils::optional<ProjectPartId>{}));
ON_CALL(mockDatabase, lastInsertedRowId()).WillByDefault(Return(21));
ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21));
auto id = storage.fetchProjectPartId("test");
@@ -216,7 +218,7 @@ TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartNameUnguarde
ON_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")))
.WillByDefault(Return(Utils::optional<ProjectPartId>{}));
ON_CALL(mockDatabase, lastInsertedRowId()).WillByDefault(Return(21));
ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21));
auto id = storage.fetchProjectPartIdUnguarded("test");
@@ -232,7 +234,7 @@ TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartNameAndIsBus
EXPECT_CALL(fetchProjectPartIdStatement,
valueReturnProjectPartId(TypedEq<Utils::SmallStringView>("test")))
.WillOnce(Return(ClangBackEnd::ProjectPartId{21}));
ON_CALL(mockDatabase, lastInsertedRowId()).WillByDefault(Return(21));
ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21));
auto id = storage.fetchProjectPartId("test");
@@ -265,10 +267,10 @@ TEST_F(ProjectPartsStorage, FetchProjectPartName)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq<int>(12)))
.WillOnce(Return(Utils::optional<Utils::PathString>{"test"}));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartName(12);
}
@@ -277,14 +279,14 @@ TEST_F(ProjectPartsStorage, FetchProjectPartNameStatementIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq<int>(12)))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq<int>(12)))
.WillOnce(Return(Utils::optional<Utils::PathString>{"test"}));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartName(12);
}
@@ -293,9 +295,9 @@ TEST_F(ProjectPartsStorage, FetchProjectParts)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartsStatement, valuesReturnProjectPartContainers(4096));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectParts();
}
@@ -304,7 +306,7 @@ TEST_F(ProjectPartsStorage, FetchProjectPartsByIds)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1)));
EXPECT_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(1024, Eq(1)));
EXPECT_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(1024, Eq(1)));
@@ -313,7 +315,7 @@ TEST_F(ProjectPartsStorage, FetchProjectPartsByIds)
EXPECT_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(1024, Eq(2)));
EXPECT_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(1024, Eq(2)));
EXPECT_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(2)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectParts({1, 2});
}
@@ -322,15 +324,15 @@ TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1)));
EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2)))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1)));
EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectParts({1, 2});
}
@@ -385,7 +387,7 @@ TEST_F(ProjectPartsStorage, UpdateProjectParts)
{
InSequence sequence;
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(updateProjectPartStatement,
write(TypedEq<int>(1),
TypedEq<Utils::SmallStringView>(R"(["-m32"])"),
@@ -416,7 +418,7 @@ TEST_F(ProjectPartsStorage, UpdateProjectParts)
EXPECT_CALL(deleteProjectPartsSourcesByIdStatement, write(TypedEq<int>(2)));
EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq<int>(2), TypedEq<int>(7)));
EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq<int>(2), TypedEq<int>(8)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.updateProjectParts({projectPart1, projectPart2});
}
@@ -425,8 +427,8 @@ TEST_F(ProjectPartsStorage, UpdateProjectPartsIsBusy)
{
InSequence sequence;
EXPECT_CALL(mockDatabase, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(updateProjectPartStatement,
write(TypedEq<int>(1),
TypedEq<Utils::SmallStringView>(R"(["-m32"])"),
@@ -436,7 +438,7 @@ TEST_F(ProjectPartsStorage, UpdateProjectPartsIsBusy)
2,
35,
2));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.updateProjectParts({projectPart1});
}
@@ -445,10 +447,10 @@ TEST_F(ProjectPartsStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatem
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartArtefact(FilePathId{1});
}
@@ -457,14 +459,14 @@ TEST_F(ProjectPartsStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatem
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1))
.WillRepeatedly(Return(artefact));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartArtefact(FilePathId{1});
}
@@ -483,10 +485,10 @@ TEST_F(ProjectPartsStorage, FetchProjectPartArtefactByProjectPartIdCallsValueInS
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74))
.WillRepeatedly(Return(artefact));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartArtefact(ProjectPartId{74});
}
@@ -505,14 +507,14 @@ TEST_F(ProjectPartsStorage, FetchProjectPartArtefactByProjectPartIdReturnArtefac
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74))
.WillRepeatedly(Return(artefact));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchProjectPartArtefact(ProjectPartId{74});
}
@@ -521,12 +523,12 @@ TEST_F(ProjectPartsStorage, ResetDependentIndexingTimeStamps)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(3)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(4)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(7)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(8)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.resetIndexingTimeStamps({projectPart1, projectPart2});
}
@@ -535,13 +537,13 @@ TEST_F(ProjectPartsStorage, ResetDependentIndexingTimeStampsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, immediateBegin());
EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(3)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(4)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(7)));
EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq<int>(8)));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.resetIndexingTimeStamps({projectPart1, projectPart2});
}
@@ -550,10 +552,10 @@ TEST_F(ProjectPartsStorage, FetchAllProjectPartNamesAndIdsCalls)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_))
.WillRepeatedly(Return(projectPartNameIds));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchAllProjectPartNamesAndIds();
}
@@ -562,14 +564,14 @@ TEST_F(ProjectPartsStorage, FetchAllProjectPartNamesAndIdsCallsIsBusy)
{
InSequence s;
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_))
.WillOnce(Throw(Sqlite::StatementIsBusy{""}));
EXPECT_CALL(mockDatabase, rollback());
EXPECT_CALL(mockDatabase, deferredBegin());
EXPECT_CALL(databaseMock, rollback());
EXPECT_CALL(databaseMock, deferredBegin());
EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_))
.WillRepeatedly(Return(projectPartNameIds));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(databaseMock, commit());
storage.fetchAllProjectPartNamesAndIds();
}

View File

@@ -25,30 +25,30 @@
#include "googletest.h"
#include <mocksqlitedatabase.h>
#include <sqlitedatabasemock.h>
#include <refactoringdatabaseinitializer.h>
namespace {
using Initializer = ClangBackEnd::RefactoringDatabaseInitializer<NiceMock<MockSqliteDatabase>>;
using Initializer = ClangBackEnd::RefactoringDatabaseInitializer<NiceMock<SqliteDatabaseMock>>;
using Sqlite::Table;
class RefactoringDatabaseInitializer : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
Initializer initializer{mockDatabase};
NiceMock<SqliteDatabaseMock> databaseMock;
Initializer initializer{databaseMock};
};
TEST_F(RefactoringDatabaseInitializer, AddSymbolsTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)")));
initializer.createSymbolsTable();
}
@@ -57,10 +57,10 @@ TEST_F(RefactoringDatabaseInitializer, AddLocationsTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)")));
EXPECT_CALL(databaseMock,
execute(Eq(
"CREATE INDEX IF NOT EXISTS index_locations_symbolId ON locations(symbolId)")));
initializer.createLocationsTable();
@@ -70,8 +70,8 @@ TEST_F(RefactoringDatabaseInitializer, AddSourcesTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)")));
initializer.createSourcesTable();
}
@@ -80,8 +80,8 @@ TEST_F(RefactoringDatabaseInitializer, AddDirectoriesTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)")));
initializer.createDirectoriesTable();
}
@@ -90,12 +90,12 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsTable)
{
InSequence s;
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY "
"KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros "
"TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, "
"language INTEGER, languageVersion INTEGER, languageExtension INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
initializer.createProjectPartsTable();
}
@@ -104,12 +104,12 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsFilesTable)
{
InSequence s;
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, "
"sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, "
"hasMissingIncludes INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)")));
EXPECT_CALL(databaseMock,
execute(Eq(
"CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType "
"ON projectPartsFiles(projectPartId, sourceType)")));
@@ -121,9 +121,9 @@ TEST_F(RefactoringDatabaseInitializer, AddUsedMacrosTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)")));
initializer.createUsedMacrosTable();
}
@@ -133,7 +133,7 @@ TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable)
InSequence s;
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(Eq(
"CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, "
"lastModified INTEGER, indexingTimeStamp INTEGER)")));
@@ -145,16 +145,16 @@ TEST_F(RefactoringDatabaseInitializer, AddSourceDependenciesTable)
{
InSequence s;
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, "
"dependencySourceId INTEGER)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON "
"sourceDependencies(sourceId, dependencySourceId)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_dependencySourceId_sourceId ON "
"sourceDependencies(dependencySourceId, sourceId)")));
@@ -166,7 +166,7 @@ TEST_F(RefactoringDatabaseInitializer, AddPrecompiledHeaderTable)
{
InSequence s;
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, systemPchPath TEXT, systemPchBuildTime INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, systemPchPath TEXT, systemPchBuildTime INTEGER)")));
initializer.createPrecompiledHeadersTable();
}
@@ -175,10 +175,10 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsHeadersTable)
{
InSequence s;
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, "
"sourceId INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON "
"projectPartsHeaders(projectPartId)")));
@@ -189,10 +189,10 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable)
{
InSequence s;
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, "
"sourceId INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON "
"projectPartsSources(projectPartId)")));
@@ -203,166 +203,166 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
{
InSequence s;
EXPECT_CALL(mockDatabase, isInitialized()).WillOnce(Return(false));
EXPECT_CALL(mockDatabase, exclusiveBegin());
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, isInitialized()).WillOnce(Return(false));
EXPECT_CALL(databaseMock, exclusiveBegin());
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr "
"TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON "
"symbols(symbolKind, symbolName)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, "
"column INTEGER, sourceId INTEGER, locationKind INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column "
"ON locations(sourceId, line, column)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON "
"locations(sourceId, locationKind)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq(
"CREATE INDEX IF NOT EXISTS index_locations_symbolId ON locations(symbolId)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, "
"directoryId INTEGER, sourceName TEXT)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName "
"ON sources(directoryId, sourceName)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY "
"KEY, directoryPath TEXT)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON "
"directories(directoryPath)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(
Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY "
"KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros "
"TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, "
"language INTEGER, languageVersion INTEGER, languageExtension INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName "
"ON projectParts(projectPartName)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, "
"sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, "
"hasMissingIncludes INTEGER)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId "
"ON projectPartsFiles(sourceId, projectPartId)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType ON "
"projectPartsFiles(projectPartId, sourceType)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, "
"sourceId INTEGER, macroName TEXT)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON "
"usedMacros(sourceId, macroName)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(Eq(
"CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, "
"lastModified INTEGER, indexingTimeStamp INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, "
"dependencySourceId INTEGER)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON "
"sourceDependencies(sourceId, dependencySourceId)")));
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_dependencySourceId_sourceId ON "
"sourceDependencies(dependencySourceId, sourceId)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER "
"PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, "
"systemPchPath TEXT, systemPchBuildTime INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, "
"sourceId INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON "
"projectPartsHeaders(projectPartId)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, "
"sourceId INTEGER)")));
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON "
"projectPartsSources(projectPartId)")));
EXPECT_CALL(mockDatabase, commit());
EXPECT_CALL(mockDatabase, setIsInitialized(true));
EXPECT_CALL(databaseMock, commit());
EXPECT_CALL(databaseMock, setIsInitialized(true));
Initializer initializer{mockDatabase};
Initializer initializer{databaseMock};
}
TEST_F(RefactoringDatabaseInitializer, DontCreateIfAlreadyInitialized)
{
InSequence s;
EXPECT_CALL(mockDatabase, isInitialized()).WillOnce(Return(true));
EXPECT_CALL(mockDatabase, exclusiveBegin()).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))).Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, isInitialized()).WillOnce(Return(true));
EXPECT_CALL(databaseMock, exclusiveBegin()).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))).Times(0);
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY "
"KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros "
"TEXT, includeSearchPaths TEXT)")))
.Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, sourceId INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId ON projectPartsFiles(projectPartId)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))).Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, sourceId INTEGER)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId ON projectPartsFiles(projectPartId)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))).Times(0);
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, "
"size INTEGER, lastModified INTEGER, indexingTimeStamp INTEGER)")))
.Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))).Times(0);
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))).Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))).Times(0);
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))).Times(0);
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, "
"sourceId INTEGER)")))
.Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON "
"projectPartsHeaders(projectPartId)")))
.Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, "
"sourceId INTEGER)")))
.Times(0);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON "
"projectPartsSources(projectPartId)")))
.Times(0);
EXPECT_CALL(mockDatabase, commit()).Times(0);
EXPECT_CALL(databaseMock, commit()).Times(0);
Initializer initializer{mockDatabase};
Initializer initializer{databaseMock};
}
}

View File

@@ -73,7 +73,7 @@ protected:
std::vector<Utils::SmallString> names() const
{
return Sqlite::ReadStatement("SELECT name FROM test", database).values<Utils::SmallString>(8);
return Sqlite::ReadStatement<1>("SELECT name FROM test", database).values<Utils::SmallString>(8);
}
static void updateHookCallback(

View File

@@ -40,7 +40,8 @@
class SqliteDatabaseMock : public SqliteTransactionBackendMock, public Sqlite::DatabaseInterface
{
public:
using ReadStatement = NiceMock<SqliteReadStatementMock>;
template<int ResultCount>
using ReadStatement = NiceMock<SqliteReadStatementMock<ResultCount>>;
using WriteStatement = NiceMock<SqliteWriteStatementMock>;
MOCK_METHOD(void, prepare, (Utils::SmallStringView sqlStatement), ());

View File

@@ -27,34 +27,9 @@
#include "sqlitedatabasemock.h"
SqliteReadStatementMock::SqliteReadStatementMock(Utils::SmallStringView sqlStatement,
SqliteReadStatementMockBase::SqliteReadStatementMockBase(Utils::SmallStringView sqlStatement,
SqliteDatabaseMock &databaseMock)
: sqlStatement(sqlStatement)
{
databaseMock.prepare(sqlStatement);
}
template<>
std::vector<Utils::SmallString> SqliteReadStatementMock::values<Utils::SmallString>(std::size_t reserveSize)
{
return valuesReturnStringVector(reserveSize);
}
template<>
std::vector<long long> SqliteReadStatementMock::values<long long>(std::size_t reserveSize)
{
return valuesReturnRowIds(reserveSize);
}
template<>
Utils::optional<long long> SqliteReadStatementMock::value<long long>()
{
return valueReturnLongLong();
}
template<>
Utils::optional<Sqlite::ByteArrayBlob> SqliteReadStatementMock::value<Sqlite::ByteArrayBlob>(
const Utils::SmallStringView &name, const long long &blob)
{
return valueReturnBlob(name, blob);
}

View File

@@ -27,7 +27,19 @@
#include "googletest.h"
#include <cpptools/usages.h>
#include <filepathstoragesources.h>
#include <pchpaths.h>
#include <projectpartartefact.h>
#include <projectpartcontainer.h>
#include <projectpartpch.h>
#include <projectpartstoragestructs.h>
#include <sourceentry.h>
#include <sourcelocations.h>
#include <sqliteblob.h>
#include <stringcachefwd.h>
#include <symbol.h>
#include <usedmacro.h>
#include <utils/optional.h>
#include <utils/smallstring.h>
@@ -37,57 +49,196 @@
#include <tuple>
#include <vector>
using ClangBackEnd::FilePathIds;
using ClangBackEnd::SourceEntries;
using ClangBackEnd::SourceEntry;
using ClangBackEnd::SourceTimeStamp;
using ClangBackEnd::SourceTimeStamps;
using ClangRefactoring::SourceLocation;
using ClangRefactoring::SourceLocations;
using std::int64_t;
namespace Sources = ClangBackEnd::Sources;
using ClangBackEnd::PrecompiledHeaderTimeStamps;
using ClangBackEnd::UsedMacros;
using ClangBackEnd::Internal::ProjectPartNameId;
using ClangBackEnd::Internal::ProjectPartNameIds;
using ClangRefactoring::Symbol;
using ClangRefactoring::Symbols;
class SqliteDatabaseMock;
class SqliteReadStatementMock
class SqliteReadStatementMockBase
{
public:
SqliteReadStatementMock() = default;
SqliteReadStatementMock(Utils::SmallStringView sqlStatement, SqliteDatabaseMock &databaseMock);
SqliteReadStatementMockBase() = default;
SqliteReadStatementMockBase(Utils::SmallStringView sqlStatement, SqliteDatabaseMock &databaseMock);
MOCK_METHOD(std::vector<Utils::SmallString>, valuesReturnStringVector, (std::size_t), ());
MOCK_METHOD(std::vector<long long>, valuesReturnRowIds, (std::size_t), ());
MOCK_METHOD(Utils::optional<long long>, valueReturnLongLong, (), ());
MOCK_METHOD(Utils::optional<long long>, valueReturnInt64, (), ());
MOCK_METHOD(Utils::optional<Sqlite::ByteArrayBlob>,
valueReturnBlob,
(Utils::SmallStringView, long long),
());
template<typename ResultType, int ResultTypeCount = 1, typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize, const QueryType &... queryValues);
MOCK_METHOD(SourceLocations, valuesReturnSourceLocations, (std::size_t, int, int, int), ());
template <typename ResultType,
int ResultTypeCount = 1,
typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize);
MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int), ());
template <typename ResultType,
int ResultTypeCount = 1,
template <typename...> class QueryContainerType,
typename QueryElementType>
std::vector<ResultType> values(std::size_t reserveSize,
const QueryContainerType<QueryElementType> &queryValues);
MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int, int), ());
template <typename ResultType,
int ResultTypeCount = 1,
typename... QueryTypes>
Utils::optional<ResultType> value(const QueryTypes&... queryValues);
MOCK_METHOD(std::vector<Sources::Directory>, valuesReturnStdVectorDirectory, (std::size_t), ());
MOCK_METHOD(std::vector<Sources::Source>, valuesReturnStdVectorSource, (std::size_t), ());
MOCK_METHOD(SourceEntries, valuesReturnSourceEntries, (std::size_t, int, int), ());
MOCK_METHOD(UsedMacros, valuesReturnUsedMacros, (std::size_t, int), ());
MOCK_METHOD(FilePathIds, valuesReturnFilePathIds, (std::size_t, int), ());
MOCK_METHOD(ProjectPartNameIds, valuesReturnProjectPartNameIds, (std::size_t), ());
MOCK_METHOD(Utils::optional<int>, valueReturnInt32, (Utils::SmallStringView), ());
MOCK_METHOD(Utils::optional<int>, valueReturnInt32, (int, Utils::SmallStringView), ());
MOCK_METHOD(Utils::optional<int>, valueReturnInt32, (int), ());
MOCK_METHOD(Utils::optional<long long>, valueReturnInt64, (int), ());
MOCK_METHOD(Utils::optional<Utils::PathString>, valueReturnPathString, (int), ());
MOCK_METHOD(Utils::optional<Utils::PathString>, valueReturnPathString, (Utils::SmallStringView), ());
MOCK_METHOD(Utils::optional<ClangBackEnd::FilePath>, valueReturnFilePath, (int), ());
MOCK_METHOD(ClangBackEnd::FilePaths, valuesReturnFilePaths, (std::size_t), ());
MOCK_METHOD(Utils::optional<Utils::SmallString>, valueReturnSmallString, (int), ());
MOCK_METHOD(Utils::optional<Sources::SourceNameAndDirectoryId>,
valueReturnSourceNameAndDirectoryId,
(int) );
MOCK_METHOD(Utils::optional<ClangBackEnd::ProjectPartArtefact>,
valueReturnProjectPartArtefact,
(int) );
MOCK_METHOD(Utils::optional<ClangBackEnd::ProjectPartArtefact>,
valueReturnProjectPartArtefact,
(Utils::SmallStringView));
MOCK_METHOD(ClangBackEnd::ProjectPartArtefacts, valuesReturnProjectPartArtefacts, (std::size_t), ());
MOCK_METHOD(Utils::optional<ClangBackEnd::ProjectPartContainer>,
valueReturnProjectPartContainer,
(int) );
MOCK_METHOD(ClangBackEnd::ProjectPartContainers,
valuesReturnProjectPartContainers,
(std::size_t),
());
MOCK_METHOD(Utils::optional<ClangBackEnd::ProjectPartPch>, valueReturnProjectPartPch, (int), ());
MOCK_METHOD(Utils::optional<ClangBackEnd::PchPaths>, valueReturnPchPaths, (int), ());
MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, Utils::SmallStringView), ());
MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, int, Utils::SmallStringView), ());
MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, int, int, Utils::SmallStringView), ());
MOCK_METHOD(SourceLocation, valueReturnSourceLocation, (long long, int), ());
MOCK_METHOD(Utils::optional<ClangBackEnd::ProjectPartId>,
valueReturnProjectPartId,
(Utils::SmallStringView));
MOCK_METHOD(SourceTimeStamps, valuesReturnSourceTimeStamps, (std::size_t), ());
MOCK_METHOD(SourceTimeStamps, valuesReturnSourceTimeStamps, (std::size_t, int sourcePathId), ());
MOCK_METHOD(Utils::optional<PrecompiledHeaderTimeStamps>,
valuesReturnPrecompiledHeaderTimeStamps,
(int projectPartId));
template<typename ResultType, typename... QueryTypes>
auto value(const QueryTypes &...queryValues)
{
if constexpr (std::is_same_v<ResultType, Sqlite::ByteArrayBlob>)
return valueReturnBlob(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::ProjectPartId>)
return valueReturnProjectPartId(queryValues...);
else if constexpr (std::is_same_v<ResultType, int>)
return valueReturnInt32(queryValues...);
else if constexpr (std::is_same_v<ResultType, long long>)
return valueReturnInt64(queryValues...);
else if constexpr (std::is_same_v<ResultType, Utils::PathString>)
return valueReturnPathString(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::FilePath>)
return valueReturnFilePath(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::ProjectPartArtefact>)
return valueReturnProjectPartArtefact(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::ProjectPartContainer>)
return valueReturnProjectPartContainer(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::ProjectPartPch>)
return valueReturnProjectPartPch(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::PchPaths>)
return valueReturnPchPaths(queryValues...);
else if constexpr (std::is_same_v<ResultType, Utils::SmallString>)
return valueReturnSmallString(queryValues...);
else if constexpr (std::is_same_v<ResultType, SourceLocation>)
return valueReturnSourceLocation(queryValues...);
else if constexpr (std::is_same_v<ResultType, Sources::SourceNameAndDirectoryId>)
return valueReturnSourceNameAndDirectoryId(queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::PrecompiledHeaderTimeStamps>)
return valuesReturnPrecompiledHeaderTimeStamps(queryValues...);
else
static_assert(!std::is_same_v<ResultType, ResultType>,
"SqliteReadStatementMock::value does not handle result type!");
}
template<typename ResultType, typename... QueryType>
auto values(std::size_t reserveSize, const QueryType &...queryValues)
{
if constexpr (std::is_same_v<ResultType, Utils::SmallString>)
return valuesReturnStringVector(reserveSize);
else if constexpr (std::is_same_v<ResultType, long long>)
return valuesReturnRowIds(reserveSize);
else if constexpr (std::is_same_v<ResultType, SourceLocation>)
return valuesReturnSourceLocations(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, CppTools::Usage>)
return valuesReturnSourceUsages(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, Symbol>)
return valuesReturnSymbols(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::UsedMacro>)
return valuesReturnUsedMacros(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::FilePathId>)
return valuesReturnFilePathIds(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::FilePath>)
return valuesReturnFilePaths(reserveSize);
else if constexpr (std::is_same_v<ResultType, Sources::Directory>)
return valuesReturnStdVectorDirectory(reserveSize);
else if constexpr (std::is_same_v<ResultType, Sources::Source>)
return valuesReturnStdVectorSource(reserveSize);
else if constexpr (std::is_same_v<ResultType, ProjectPartNameId>)
return valuesReturnProjectPartNameIds(reserveSize);
else if constexpr (std::is_same_v<ResultType, ClangBackEnd::ProjectPartContainer>)
return valuesReturnProjectPartContainers(reserveSize);
else if constexpr (std::is_same_v<ResultType, SourceEntry>)
return valuesReturnSourceEntries(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, SourceTimeStamp>)
return valuesReturnSourceTimeStamps(reserveSize, queryValues...);
else
static_assert(!std::is_same_v<ResultType, ResultType>,
"SqliteReadStatementMock::values does not handle result type!");
}
public:
Utils::SmallString sqlStatement;
};
template<>
std::vector<Utils::SmallString> SqliteReadStatementMock::values<Utils::SmallString>(
std::size_t reserveSize);
template<>
std::vector<long long> SqliteReadStatementMock::values<long long>(std::size_t reserveSize);
template<>
Utils::optional<long long> SqliteReadStatementMock::value<long long>();
template<>
Utils::optional<Sqlite::ByteArrayBlob> SqliteReadStatementMock::value<Sqlite::ByteArrayBlob>(
const Utils::SmallStringView &name, const long long &blob);
template<int ResultCount>
class SqliteReadStatementMock : public SqliteReadStatementMockBase
{
public:
using SqliteReadStatementMockBase::SqliteReadStatementMockBase;
};

View File

@@ -124,8 +124,8 @@ class Sessions : public testing::Test
protected:
Sessions() { sessions.setAttachedTables({"data", "tags"}); }
std::vector<Data> fetchData() { return selectData.values<Data, 3>(8); }
std::vector<Tag> fetchTags() { return selectTags.values<Tag, 2>(8); }
std::vector<Data> fetchData() { return selectData.values<Data>(8); }
std::vector<Tag> fetchTags() { return selectTags.values<Tag>(8); }
protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
@@ -150,10 +150,10 @@ protected:
"DELETE FROM tags WHERE dataId=(SELECT id FROM data WHERE name=?)", database};
Sqlite::WriteStatement insertTag{
"INSERT INTO tags(dataId, tag) VALUES ((SELECT id FROM data WHERE name=?1), ?2) ", database};
Sqlite::ReadStatement selectData{"SELECT name, number, value FROM data", database};
Sqlite::ReadStatement selectTags{"SELECT name, tag FROM tags JOIN data ON data.id=tags.dataId",
database};
Sqlite::ReadStatement selectChangeSets{"SELECT changeset FROM testsessions", database};
Sqlite::ReadStatement<3> selectData{"SELECT name, number, value FROM data", database};
Sqlite::ReadStatement<2> selectTags{
"SELECT name, tag FROM tags JOIN data ON data.id=tags.dataId", database};
Sqlite::ReadStatement<1> selectChangeSets{"SELECT changeset FROM testsessions", database};
};
TEST_F(Sessions, DontThrowForCommittingWithoutSessionStart)

View File

@@ -121,12 +121,12 @@ struct Output
TEST_F(SqliteStatement, ThrowsStatementHasErrorForWrongSqlStatement)
{
ASSERT_THROW(ReadStatement("blah blah blah", database), Sqlite::StatementHasError);
ASSERT_THROW(ReadStatement<0>("blah blah blah", database), Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, ThrowsNotReadOnlySqlStatementForWritableSqlStatementInReadStatement)
{
ASSERT_THROW(ReadStatement("INSERT INTO test(name, number) VALUES (?, ?)", database),
ASSERT_THROW(ReadStatement<0>("INSERT INTO test(name, number) VALUES (?, ?)", database),
Sqlite::NotReadOnlySqlStatement);
}
@@ -143,7 +143,7 @@ TEST_F(SqliteStatement, CountRows)
while (statement.next())
++nextCount;
int sqlCount = ReadStatement::toValue<int>("SELECT count(*) FROM test", database);
int sqlCount = ReadStatement<1>::toValue<int>("SELECT count(*) FROM test", database);
ASSERT_THAT(nextCount, sqlCount);
}
@@ -174,24 +174,28 @@ TEST_F(SqliteStatement, Value)
TEST_F(SqliteStatement, ToIntegerValue)
{
auto value = ReadStatement::toValue<int>("SELECT number FROM test WHERE name='foo'", database);
auto value = ReadStatement<1>::toValue<int>("SELECT number FROM test WHERE name='foo'", database);
ASSERT_THAT(value, 23);
}
TEST_F(SqliteStatement, ToLongIntegerValue)
{
ASSERT_THAT(ReadStatement::toValue<qint64>("SELECT number FROM test WHERE name='foo'", database), Eq(23));
ASSERT_THAT(ReadStatement<1>::toValue<qint64>("SELECT number FROM test WHERE name='foo'", database),
Eq(23));
}
TEST_F(SqliteStatement, ToDoubleValue)
{
ASSERT_THAT(ReadStatement::toValue<double>("SELECT number FROM test WHERE name='foo'", database), 23.3);
ASSERT_THAT(ReadStatement<1>::toValue<double>("SELECT number FROM test WHERE name='foo'", database),
23.3);
}
TEST_F(SqliteStatement, ToStringValue)
{
ASSERT_THAT(ReadStatement::toValue<Utils::SmallString>("SELECT name FROM test WHERE name='foo'", database), "foo");
ASSERT_THAT(ReadStatement<1>::toValue<Utils::SmallString>(
"SELECT name FROM test WHERE name='foo'", database),
"foo");
}
TEST_F(SqliteStatement, BindNull)
@@ -544,16 +548,15 @@ TEST_F(SqliteStatement, CannotReadFromClosedDatabase)
{
database.close();
ASSERT_THROW(ReadStatement("SELECT * FROM test", database),
Sqlite::DatabaseIsNotOpen);
ASSERT_THROW(ReadStatement<3>("SELECT * FROM test", database), Sqlite::DatabaseIsNotOpen);
}
TEST_F(SqliteStatement, GetTupleValuesWithoutArguments)
{
using Tuple = std::tuple<Utils::SmallString, double, int>;
ReadStatement statement("SELECT name, number, value FROM test", database);
ReadStatement<3> statement("SELECT name, number, value FROM test", database);
auto values = statement.values<Tuple, 3>(3);
auto values = statement.values<Tuple>(3);
ASSERT_THAT(values,
UnorderedElementsAre(Tuple{"bar", 0, 1}, Tuple{"foo", 23.3, 2}, Tuple{"poo", 40.0, 3}));
@@ -561,7 +564,7 @@ TEST_F(SqliteStatement, GetTupleValuesWithoutArguments)
TEST_F(SqliteStatement, GetSingleValuesWithoutArguments)
{
ReadStatement statement("SELECT name FROM test", database);
ReadStatement<1> statement("SELECT name FROM test", database);
std::vector<Utils::SmallString> values = statement.values<Utils::SmallString>(3);
@@ -586,7 +589,7 @@ public:
TEST_F(SqliteStatement, GetSingleSqliteValuesWithoutArguments)
{
ReadStatement statement("SELECT number FROM test", database);
ReadStatement<1> statement("SELECT number FROM test", database);
database.execute("INSERT INTO test VALUES (NULL, NULL, NULL)");
std::vector<FooValue> values = statement.values<FooValue>(3);
@@ -596,9 +599,9 @@ TEST_F(SqliteStatement, GetSingleSqliteValuesWithoutArguments)
TEST_F(SqliteStatement, GetStructValuesWithoutArguments)
{
ReadStatement statement("SELECT name, number, value FROM test", database);
ReadStatement<3> statement("SELECT name, number, value FROM test", database);
auto values = statement.values<Output, 3>(3);
auto values = statement.values<Output>(3);
ASSERT_THAT(values,
UnorderedElementsAre(Output{"bar", "blah", 1},
@@ -608,7 +611,7 @@ TEST_F(SqliteStatement, GetStructValuesWithoutArguments)
TEST_F(SqliteStatement, GetValuesForSingleOutputWithBindingMultipleTimes)
{
ReadStatement statement("SELECT name FROM test WHERE number=?", database);
ReadStatement<1> statement("SELECT name FROM test WHERE number=?", database);
statement.values<Utils::SmallString>(3, 40);
std::vector<Utils::SmallString> values = statement.values<Utils::SmallString>(3, 40);
@@ -616,56 +619,13 @@ TEST_F(SqliteStatement, GetValuesForSingleOutputWithBindingMultipleTimes)
ASSERT_THAT(values, ElementsAre("poo"));
}
TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndContainerQueryValues)
{
using Tuple = std::tuple<Utils::SmallString, double, double>;
std::vector<double> queryValues = {40, 23.3};
ReadStatement statement("SELECT name, number, value FROM test WHERE number=?", database);
auto values = statement.values<Tuple, 3>(3, queryValues);
ASSERT_THAT(values, UnorderedElementsAre(Tuple{"poo", 40, 3.}, Tuple{"foo", 23.3, 2.}));
}
TEST_F(SqliteStatement, GetValuesForSingleOutputValuesAndContainerQueryValues)
{
std::vector<double> queryValues = {40, 23.3};
ReadStatement statement("SELECT name FROM test WHERE number=?", database);
std::vector<Utils::SmallString> values = statement.values<Utils::SmallString>(3, queryValues);
ASSERT_THAT(values, UnorderedElementsAre("poo", "foo"));
}
TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndContainerQueryTupleValues)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, int>;
using ResultTuple = std::tuple<Utils::SmallString, double, int>;
std::vector<Tuple> queryValues = {{"poo", "40", 3}, {"bar", "blah", 1}};
ReadStatement statement("SELECT name, number, value FROM test WHERE name= ? AND number=? AND value=?", database);
auto values = statement.values<ResultTuple, 3>(3, queryValues);
ASSERT_THAT(values, UnorderedElementsAre(ResultTuple{"poo", 40, 3}, ResultTuple{"bar", 0, 1}));
}
TEST_F(SqliteStatement, GetValuesForSingleOutputValuesAndContainerQueryTupleValues)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString>;
std::vector<Tuple> queryValues = {{"poo", "40"}, {"bar", "blah"}};
ReadStatement statement("SELECT name FROM test WHERE name= ? AND number=?", database);
std::vector<Utils::SmallString> values = statement.values<Utils::SmallString>(3, queryValues);
ASSERT_THAT(values, UnorderedElementsAre("poo", "bar"));
}
TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndMultipleQueryValue)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>;
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
ReadStatement<3> statement(
"SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
auto values = statement.values<Tuple, 3>(3, "bar", "blah", 1);
auto values = statement.values<Tuple>(3, "bar", "blah", 1);
ASSERT_THAT(values, ElementsAre(Tuple{"bar", "blah", 1}));
}
@@ -673,49 +633,29 @@ TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndMultipleQueryValue)
TEST_F(SqliteStatement, CallGetValuesForMultipleOutputValuesAndMultipleQueryValueMultipleTimes)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>;
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=?", database);
statement.values<Tuple, 3>(3, "bar", "blah");
ReadStatement<3> statement("SELECT name, number, value FROM test WHERE name=? AND number=?",
database);
statement.values<Tuple>(3, "bar", "blah");
auto values = statement.values<Tuple, 3>(3, "bar", "blah");
auto values = statement.values<Tuple>(3, "bar", "blah");
ASSERT_THAT(values, ElementsAre(Tuple{"bar", "blah", 1}));
}
TEST_F(SqliteStatement, GetStructOutputValuesAndMultipleQueryValue)
{
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
ReadStatement<3> statement(
"SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
auto values = statement.values<Output, 3>(3, "bar", "blah", 1);
auto values = statement.values<Output>(3, "bar", "blah", 1);
ASSERT_THAT(values, ElementsAre(Output{"bar", "blah", 1}));
}
TEST_F(SqliteStatement, GetStructOutputValuesAndContainerQueryValues)
{
std::vector<double> queryValues = {40, 23.3};
ReadStatement statement("SELECT name, number, value FROM test WHERE number=?", database);
auto values = statement.values<Output, 3>(3, queryValues);
ASSERT_THAT(values, ElementsAre(Output{"poo", "40", 3},
Output{"foo", "23.3", 2}));
}
TEST_F(SqliteStatement, GetStructOutputValuesAndContainerQueryTupleValues)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, int>;
std::vector<Tuple> queryValues = {{"poo", "40", 3}, {"bar", "blah", 1}};
ReadStatement statement("SELECT name, number, value FROM test WHERE name= ? AND number=? AND value=?", database);
auto values = statement.values<Output, 3>(3, queryValues);
ASSERT_THAT(values, UnorderedElementsAre(Output{"poo", "40", 3}, Output{"bar", "blah", 1}));
}
TEST_F(SqliteStatement, GetBlobValues)
{
database.execute("INSERT INTO test VALUES ('blob', 40, x'AABBCCDD')");
ReadStatement statement("SELECT value FROM test WHERE name='blob'", database);
ReadStatement<1> statement("SELECT value FROM test WHERE name='blob'", database);
const int value = 0xDDCCBBAA;
auto bytePointer = reinterpret_cast<const Sqlite::byte *>(&value);
Sqlite::BlobView bytes{bytePointer, 4};
@@ -727,7 +667,7 @@ TEST_F(SqliteStatement, GetBlobValues)
TEST_F(SqliteStatement, GetEmptyBlobValueForInteger)
{
ReadStatement statement("SELECT value FROM test WHERE name='poo'", database);
ReadStatement<1> statement("SELECT value FROM test WHERE name='poo'", database);
auto value = statement.value<Sqlite::Blob>();
@@ -736,7 +676,7 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForInteger)
TEST_F(SqliteStatement, GetEmptyBlobValueForFloat)
{
ReadStatement statement("SELECT number FROM test WHERE name='foo'", database);
ReadStatement<1> statement("SELECT number FROM test WHERE name='foo'", database);
auto value = statement.value<Sqlite::Blob>();
@@ -745,7 +685,7 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForFloat)
TEST_F(SqliteStatement, GetEmptyBlobValueForText)
{
ReadStatement statement("SELECT number FROM test WHERE name='bar'", database);
ReadStatement<1> statement("SELECT number FROM test WHERE name='bar'", database);
auto value = statement.value<Sqlite::Blob>();
@@ -754,7 +694,8 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForText)
TEST_F(SqliteStatement, GetOptionalSingleValueAndMultipleQueryValue)
{
ReadStatement statement("SELECT name FROM test WHERE name=? AND number=? AND value=?", database);
ReadStatement<1> statement("SELECT name FROM test WHERE name=? AND number=? AND value=?",
database);
auto value = statement.value<Utils::SmallString>("bar", "blah", 1);
@@ -763,9 +704,10 @@ TEST_F(SqliteStatement, GetOptionalSingleValueAndMultipleQueryValue)
TEST_F(SqliteStatement, GetOptionalOutputValueAndMultipleQueryValue)
{
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
ReadStatement<3> statement(
"SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
auto value = statement.value<Output, 3>("bar", "blah", 1);
auto value = statement.value<Output>("bar", "blah", 1);
ASSERT_THAT(value.value(), Eq(Output{"bar", "blah", 1}));
}
@@ -773,9 +715,10 @@ TEST_F(SqliteStatement, GetOptionalOutputValueAndMultipleQueryValue)
TEST_F(SqliteStatement, GetOptionalTupleValueAndMultipleQueryValue)
{
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>;
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
ReadStatement<3> statement(
"SELECT name, number, value FROM test WHERE name=? AND number=? AND value=?", database);
auto value = statement.value<Tuple, 3>("bar", "blah", 1);
auto value = statement.value<Tuple>("bar", "blah", 1);
ASSERT_THAT(value.value(), Eq(Tuple{"bar", "blah", 1}));
}
@@ -837,65 +780,6 @@ TEST_F(SqliteStatement, GetValuesWithSimpleArgumentsCallsResetIfExceptionIsThrow
EXPECT_THROW(mockStatement.values<int>(3, "foo", "bar"), Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, GetValuesWithVectorArgumentsCallsReset)
{
MockSqliteStatement mockStatement;
EXPECT_CALL(mockStatement, reset()).Times(2);
mockStatement.values<int>(3, std::vector<Utils::SmallString>{"bar", "foo"});
}
TEST_F(SqliteStatement, GetValuesWithVectorArgumentCallsResetIfExceptionIsThrown)
{
MockSqliteStatement mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
EXPECT_CALL(mockStatement, reset());
EXPECT_THROW(mockStatement.values<int>(3, std::vector<Utils::SmallString>{"bar", "foo"}),
Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, GetValuesWithTupleArgumentsCallsReset)
{
MockSqliteStatement mockStatement;
EXPECT_CALL(mockStatement, reset()).Times(2);
mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}});
}
TEST_F(SqliteStatement, GetValuesWithTupleArgumentsCallsResetIfExceptionIsThrown)
{
MockSqliteStatement mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
EXPECT_CALL(mockStatement, reset());
EXPECT_THROW(mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}}),
Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, DoubleThrowExceptionsInReset)
{
MockSqliteStatement mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
ON_CALL(mockStatement, reset()).WillByDefault(Throw(Sqlite::StatementHasError("")));
ASSERT_THROW(mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}}),
Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, ThrowExceptionOnlyInReset)
{
MockSqliteStatement mockStatement;
ON_CALL(mockStatement, reset()).WillByDefault(Throw(Sqlite::StatementHasError("")));
ASSERT_THROW(mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}}),
Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, ResetIfWriteIsThrowingException)
{
MockSqliteStatement mockStatement;
@@ -917,138 +801,101 @@ TEST_F(SqliteStatement, ResetIfExecuteThrowsException)
ASSERT_ANY_THROW(mockStatement.execute());
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForValue)
TEST_F(SqliteStatement, ReadStatementThrowsColumnCountDoesNotMatch)
{
SqliteTestStatement statement("SELECT name, number FROM test", database);
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView)> callbackMock;
ASSERT_THROW(statement.value<int>(), Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForValues)
{
SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.values<int>(1), Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForValuesWithArguments)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE name=?", database);
ASSERT_THROW(statement.values<int>(1, 2), Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForValuesWithVectorArguments)
{
SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.values<int>(1, std::vector<int>{}), Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForValuesWithTupleArguments)
{
SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.values<int>(1, std::vector<std::tuple<int>>{}),
ASSERT_THROW(ReadStatement<1> statement("SELECT name, number FROM test", database),
Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForToValues)
TEST_F(SqliteStatement, ReadWriteStatementThrowsColumnCountDoesNotMatch)
{
ASSERT_THROW(SqliteTestStatement::toValue<int>("SELECT name, number FROM test", database),
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView)> callbackMock;
ASSERT_THROW(ReadWriteStatement<1> statement("SELECT name, number FROM test", database),
Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ReadCallback)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
ReadStatement statement("SELECT name, value FROM test", database);
ReadStatement<2> statement("SELECT name, value FROM test", database);
EXPECT_CALL(callbackMock, Call(Eq("bar"), Eq(1)));
EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2)));
EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3)));
statement.readCallback<2>(callbackMock.AsStdFunction());
statement.readCallback(callbackMock.AsStdFunction());
}
TEST_F(SqliteStatement, ReadCallbackCalledWithArguments)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
ReadStatement statement("SELECT name, value FROM test WHERE value=?", database);
ReadStatement<2> statement("SELECT name, value FROM test WHERE value=?", database);
EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2)));
statement.readCallback<2>(callbackMock.AsStdFunction(), 2);
statement.readCallback(callbackMock.AsStdFunction(), 2);
}
TEST_F(SqliteStatement, ReadCallbackAborts)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
ReadStatement statement("SELECT name, value FROM test ORDER BY name", database);
ReadStatement<2> statement("SELECT name, value FROM test ORDER BY name", database);
EXPECT_CALL(callbackMock, Call(Eq("bar"), Eq(1)));
EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2))).WillOnce(Return(Sqlite::CallbackControl::Abort));
EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3))).Times(0);
statement.readCallback<2>(callbackMock.AsStdFunction());
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForReadCallback)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView)> callbackMock;
SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.readCallback<1>(callbackMock.AsStdFunction()),
Sqlite::ColumnCountDoesNotMatch);
statement.readCallback(callbackMock.AsStdFunction());
}
TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacks)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement;
MockSqliteStatement<2> mockStatement;
EXPECT_CALL(mockStatement, reset());
mockStatement.readCallback<2>(callbackMock.AsStdFunction());
mockStatement.readCallback(callbackMock.AsStdFunction());
}
TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacksAborts)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement;
MockSqliteStatement<2> mockStatement;
ON_CALL(callbackMock, Call(_, _)).WillByDefault(Return(Sqlite::CallbackControl::Abort));
EXPECT_CALL(mockStatement, reset());
mockStatement.readCallback<2>(callbackMock.AsStdFunction());
mockStatement.readCallback(callbackMock.AsStdFunction());
}
TEST_F(SqliteStatement, ReadCallbackThrowsForError)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement;
MockSqliteStatement<2> mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
ASSERT_THROW(mockStatement.readCallback<2>(callbackMock.AsStdFunction()),
Sqlite::StatementHasError);
ASSERT_THROW(mockStatement.readCallback(callbackMock.AsStdFunction()), Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, ReadCallbackCallsResetIfExceptionIsThrown)
{
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement;
MockSqliteStatement<2> mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
EXPECT_CALL(mockStatement, reset());
EXPECT_THROW(mockStatement.readCallback<2>(callbackMock.AsStdFunction()),
Sqlite::StatementHasError);
EXPECT_THROW(mockStatement.readCallback(callbackMock.AsStdFunction()), Sqlite::StatementHasError);
}
TEST_F(SqliteStatement, ReadToContainer)
{
std::deque<FooValue> values;
ReadStatement statement("SELECT number FROM test", database);
ReadStatement<1> statement("SELECT number FROM test", database);
statement.readTo<1>(values);
@@ -1058,21 +905,13 @@ TEST_F(SqliteStatement, ReadToContainer)
TEST_F(SqliteStatement, ReadToContainerCallCallbackWithArguments)
{
std::deque<FooValue> values;
ReadStatement statement("SELECT number FROM test WHERE value=?", database);
ReadStatement<1> statement("SELECT number FROM test WHERE value=?", database);
statement.readTo(values, 2);
ASSERT_THAT(values, ElementsAre(Eq(23.3)));
}
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForToManyArgumentsForReadTo)
{
std::deque<FooValue> values;
SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.readTo<1>(values, 2), Sqlite::ColumnCountDoesNotMatch);
}
TEST_F(SqliteStatement, ReadToCallsResetAfterPushingAllValuesBack)
{
std::deque<FooValue> values;

View File

@@ -27,7 +27,7 @@
#include "spydummy.h"
#include <sqlitecolumn.h>
#include <mocksqlitedatabase.h>
#include <sqlitedatabasemock.h>
#include <sqlitetable.h>
namespace {
@@ -45,7 +45,7 @@ using Sqlite::OpenMode;
class SqliteTable : public ::testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
NiceMock<SqliteDatabaseMock> databaseMock;
Sqlite::Table table;
Utils::SmallString tableName = "testTable";
};
@@ -93,9 +93,9 @@ TEST_F(SqliteTable, InitializeTable)
table.addColumn("name");
table.addColumn("value");
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE IF NOT EXISTS testTable(name NUMERIC, value NUMERIC) WITHOUT ROWID")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE IF NOT EXISTS testTable(name NUMERIC, value NUMERIC) WITHOUT ROWID")));
table.initialize(mockDatabase);
table.initialize(databaseMock);
}
TEST_F(SqliteTable, InitializeTableWithIndex)
@@ -107,11 +107,11 @@ TEST_F(SqliteTable, InitializeTableWithIndex)
table.addIndex({column});
table.addIndex({column2});
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE testTable(name NUMERIC, value NUMERIC)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_name ON testTable(name)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_value ON testTable(value)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE testTable(name NUMERIC, value NUMERIC)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_name ON testTable(name)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_testTable_value ON testTable(value)")));
table.initialize(mockDatabase);
table.initialize(databaseMock);
}
TEST_F(SqliteTable, AddForeignKeyColumnWithTableCalls)
@@ -125,11 +125,11 @@ TEST_F(SqliteTable, AddForeignKeyColumnWithTableCalls)
ForeignKeyAction::Cascade,
Enforment::Deferred);
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(Eq("CREATE TABLE testTable(name INTEGER REFERENCES foreignTable ON UPDATE "
"SET NULL ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)")));
table.initialize(mockDatabase);
table.initialize(databaseMock);
}
TEST_F(SqliteTable, AddForeignKeyColumnWithColumnCalls)
@@ -145,12 +145,12 @@ TEST_F(SqliteTable, AddForeignKeyColumnWithColumnCalls)
Enforment::Deferred);
EXPECT_CALL(
mockDatabase,
databaseMock,
execute(
Eq("CREATE TABLE testTable(name TEXT REFERENCES foreignTable(foreignColumn) ON UPDATE "
"SET DEFAULT ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED)")));
table.initialize(mockDatabase);
table.initialize(databaseMock);
}
TEST_F(SqliteTable, AddColumn)
@@ -299,10 +299,10 @@ TEST_F(SqliteTable, AddPrimaryTableContraint)
const auto &nameColumn = table.addColumn("name");
table.addPrimaryKeyContraint({idColumn, nameColumn});
EXPECT_CALL(mockDatabase,
EXPECT_CALL(databaseMock,
execute(
Eq("CREATE TABLE testTable(id NUMERIC, name NUMERIC, PRIMARY KEY(id, name))")));
table.initialize(mockDatabase);
table.initialize(databaseMock);
}
} // namespace

View File

@@ -27,11 +27,13 @@
#include <sqlitebasestatement.h>
class SqliteTestStatement : public Sqlite::StatementImplementation<Sqlite::BaseStatement>
class SqliteTestStatement : public Sqlite::StatementImplementation<Sqlite::BaseStatement, 1>
{
using Base = Sqlite::StatementImplementation<Sqlite::BaseStatement, 1>;
public:
explicit SqliteTestStatement(Utils::SmallStringView sqlStatement, Sqlite::Database &database)
: Sqlite::StatementImplementation<Sqlite::BaseStatement>(sqlStatement, database)
: Base(sqlStatement, database)
{}
};

View File

@@ -27,9 +27,9 @@
#include "mocksqlitetransactionbackend.h"
#include <sqlitetransaction.h>
#include <sqlitedatabasemock.h>
#include <sqliteexception.h>
#include <mocksqlitedatabase.h>
#include <sqlitetransaction.h>
namespace {

View File

@@ -74,8 +74,35 @@ public:
Utils::SmallStringView,
Utils::SmallStringView),
());
MOCK_METHOD(void,
write,
(int,
Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView,
Utils::SmallStringView,
int,
int,
int),
());
MOCK_METHOD(void, write, (void *, long long), ());
MOCK_METHOD(void, write, (int), ());
MOCK_METHOD(void, write, (int, long long), ());
MOCK_METHOD(void, write, (int, int), ());
MOCK_METHOD(void, write, (uint, uint, uint), ());
MOCK_METHOD(void, write, (int, off_t, time_t), ());
MOCK_METHOD(void, write, (uint, uint), ());
MOCK_METHOD(void, write, (uchar, int), ());
MOCK_METHOD(void, write, (int, int, uchar, uchar), ());
MOCK_METHOD(void, write, (long long, int), ());
MOCK_METHOD(void, write, (uint, Utils::SmallStringView, Utils::SmallStringView, uint), ());
MOCK_METHOD(void, write, (uint, uint, uint, uint), ());
MOCK_METHOD(void, write, (long long, int, int, int), ());
MOCK_METHOD(void, write, (long long, int, int, int, int), ());
MOCK_METHOD(void, write, (uint, Utils::SmallStringView), ());
MOCK_METHOD(void, write, (int, Utils::SmallStringView), ());
MOCK_METHOD(void, write, (int, Utils::SmallStringView, long long), ());
Utils::SmallString sqlStatement;
};

View File

@@ -27,7 +27,7 @@
#include "mockfilepathstorage.h"
#include "mockmutex.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <stringcache.h>
@@ -86,8 +86,8 @@ protected:
}
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
NiceMock<MockFilePathStorage> mockStorage{mockDatabase};
NiceMock<SqliteDatabaseMock> databaseMock;
NiceMock<MockFilePathStorage> mockStorage{databaseMock};
StorageIdFunction mockStorageFetchDirectyId;
StorageStringFunction mockStorageFetchDirectyPath;
Cache cache;

View File

@@ -263,7 +263,7 @@ protected:
mockProjectPartsStorage,
mockModifiedTimeChecker,
testEnvironment};
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
SymbolIndexerTaskQueue indexerQueue{indexerScheduler, progressCounter, mockSqliteDatabase};
Scheduler indexerScheduler{collectorManger,
indexerQueue,

View File

@@ -25,7 +25,7 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include "mocktaskscheduler.h"
#include <symbolindexertaskqueue.h>
@@ -55,7 +55,7 @@ protected:
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
NiceMock<MockTaskScheduler<Callable>> mockTaskScheduler;
NiceMock<MockSqliteDatabase> mockSqliteDatabase;
NiceMock<SqliteDatabaseMock> mockSqliteDatabase;
ClangBackEnd::SymbolIndexerTaskQueue queue{mockTaskScheduler, progressCounter, mockSqliteDatabase};
};

View File

@@ -54,7 +54,7 @@ using ClangRefactoring::QuerySqliteStatementFactory;
using Utils::PathString;
using SL = ClangRefactoring::SourceLocations;
using StatementFactory = QuerySqliteStatementFactory<Database, ReadStatement>;
using StatementFactory = QuerySqliteStatementFactory<Database>;
using Query = SymbolQuery<StatementFactory>;
MATCHER_P3(IsLocation, filePathId, line, column,

View File

@@ -25,8 +25,7 @@
#include "googletest.h"
#include "mocksqlitedatabase.h"
#include "mocksqlitereadstatement.h"
#include "sqlitedatabasemock.h"
#include <querysqlitestatementfactory.h>
#include <refactoringdatabaseinitializer.h>
@@ -42,28 +41,32 @@ using ClangRefactoring::QuerySqliteStatementFactory;
using Sqlite::Database;
using ClangBackEnd::SourceLocationKind;
using ClangBackEnd::SymbolKind;
using MockStatementFactory = QuerySqliteStatementFactory<MockSqliteDatabase,
MockSqliteReadStatement>;
using MockStatementFactory = QuerySqliteStatementFactory<SqliteDatabaseMock>;
using MockQuery = ClangRefactoring::SymbolQuery<MockStatementFactory>;
using RealStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
Sqlite::ReadStatement>;
using RealStatementFactory = QuerySqliteStatementFactory<Sqlite::Database>;
using RealQuery = ClangRefactoring::SymbolQuery<RealStatementFactory>;
class SymbolQuery : public testing::Test
{
template<int ResultCount>
using ReadStatement = typename SqliteDatabaseMock::template ReadStatement<ResultCount>;
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
MockStatementFactory mockStatementFactory{mockDatabase};
MockSqliteReadStatement &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation;
MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = mockStatementFactory.selectSourceUsagesForSymbolLocation;
MockSqliteReadStatement &selectSymbolsForKindAndStartsWith = mockStatementFactory.selectSymbolsForKindAndStartsWith;
MockSqliteReadStatement &selectSymbolsForKindAndStartsWith2 = mockStatementFactory.selectSymbolsForKindAndStartsWith2;
MockSqliteReadStatement &selectSymbolsForKindAndStartsWith3 = mockStatementFactory.selectSymbolsForKindAndStartsWith3;
MockSqliteReadStatement &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol;
MockSqliteReadStatement &selectSourceUsagesOrderedForSymbolLocation = mockStatementFactory
NiceMock<SqliteDatabaseMock> databaseMock;
MockStatementFactory mockStatementFactory{databaseMock};
ReadStatement<3> &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation;
ReadStatement<3> &selectSourceUsagesForSymbolLocation = mockStatementFactory
.selectSourceUsagesForSymbolLocation;
ReadStatement<3> &selectSymbolsForKindAndStartsWith = mockStatementFactory.selectSymbolsForKindAndStartsWith;
ReadStatement<3> &selectSymbolsForKindAndStartsWith2 = mockStatementFactory
.selectSymbolsForKindAndStartsWith2;
ReadStatement<3> &selectSymbolsForKindAndStartsWith3 = mockStatementFactory
.selectSymbolsForKindAndStartsWith3;
ReadStatement<3> &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol;
ReadStatement<3> &selectSourceUsagesOrderedForSymbolLocation = mockStatementFactory
.selectSourceUsagesOrderedForSymbolLocation;
MockSqliteReadStatement &selectSourceUsagesByLocationKindForSymbolLocation
ReadStatement<3> &selectSourceUsagesByLocationKindForSymbolLocation
= mockStatementFactory.selectSourceUsagesByLocationKindForSymbolLocation;
SourceLocations locations{{1, 1, 1}, {1, 2, 3}, {2, 1, 1}, {2, 3, 1}, {4, 1, 1}, {4, 1, 3}};
MockQuery query{mockStatementFactory};

View File

@@ -26,7 +26,7 @@
#include "googletest.h"
#include "mockfilepathcaching.h"
#include "mocksqlitedatabase.h"
#include "sqlitedatabasemock.h"
#include <builddependenciesstorage.h>
#include <refactoringdatabaseinitializer.h>
@@ -52,23 +52,27 @@ using Sqlite::Database;
using Sqlite::Table;
using Utils::PathString;
using Storage = ClangBackEnd::SymbolStorage<MockSqliteDatabase>;
using Storage = ClangBackEnd::SymbolStorage<SqliteDatabaseMock>;
using DatabaseType = Database;
template<int ResultCount>
using ReadStatement = typename SqliteDatabaseMock::template ReadStatement<ResultCount>;
using WriteStatement = typename SqliteDatabaseMock::WriteStatement;
class SymbolStorage : public testing::Test
{
protected:
NiceMock<MockSqliteDatabase> mockDatabase;
Storage storage{mockDatabase};
MockSqliteWriteStatement &insertSymbolsToNewSymbolsStatement = storage.insertSymbolsToNewSymbolsStatement;
MockSqliteWriteStatement &insertLocationsToNewLocationsStatement = storage.insertLocationsToNewLocationsStatement;
MockSqliteReadStatement &selectNewSourceIdsStatement = storage.selectNewSourceIdsStatement;
MockSqliteWriteStatement &addNewSymbolsToSymbolsStatement = storage.addNewSymbolsToSymbolsStatement;
MockSqliteWriteStatement &syncNewSymbolsFromSymbolsStatement = storage.syncNewSymbolsFromSymbolsStatement;
MockSqliteWriteStatement &syncSymbolsIntoNewLocationsStatement = storage.syncSymbolsIntoNewLocationsStatement;
MockSqliteWriteStatement &deleteAllLocationsFromUpdatedFilesStatement = storage.deleteAllLocationsFromUpdatedFilesStatement;
MockSqliteWriteStatement &insertNewLocationsInLocationsStatement = storage.insertNewLocationsInLocationsStatement;
MockSqliteWriteStatement &deleteNewSymbolsTableStatement = storage.deleteNewSymbolsTableStatement;
MockSqliteWriteStatement &deleteNewLocationsTableStatement = storage.deleteNewLocationsTableStatement;
NiceMock<SqliteDatabaseMock> databaseMock;
Storage storage{databaseMock};
WriteStatement &insertSymbolsToNewSymbolsStatement = storage.insertSymbolsToNewSymbolsStatement;
WriteStatement &insertLocationsToNewLocationsStatement = storage.insertLocationsToNewLocationsStatement;
ReadStatement<1> &selectNewSourceIdsStatement = storage.selectNewSourceIdsStatement;
WriteStatement &addNewSymbolsToSymbolsStatement = storage.addNewSymbolsToSymbolsStatement;
WriteStatement &syncNewSymbolsFromSymbolsStatement = storage.syncNewSymbolsFromSymbolsStatement;
WriteStatement &syncSymbolsIntoNewLocationsStatement = storage.syncSymbolsIntoNewLocationsStatement;
WriteStatement &deleteAllLocationsFromUpdatedFilesStatement = storage.deleteAllLocationsFromUpdatedFilesStatement;
WriteStatement &insertNewLocationsInLocationsStatement = storage.insertNewLocationsInLocationsStatement;
WriteStatement &deleteNewSymbolsTableStatement = storage.deleteNewSymbolsTableStatement;
WriteStatement &deleteNewLocationsTableStatement = storage.deleteNewLocationsTableStatement;
SymbolEntries symbolEntries{{1, {"functionUSR", "function", SymbolKind::Function}},
{2, {"function2USR", "function2", SymbolKind::Function}}};
SourceLocationEntries sourceLocations{{1, 3, {42, 23}, SourceLocationKind::Declaration},
@@ -156,9 +160,9 @@ 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)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
storage.createNewSymbolsTable();
}
@@ -167,8 +171,8 @@ 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)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
storage.createNewLocationsTable();
}
@@ -177,15 +181,15 @@ 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());
EXPECT_CALL(databaseMock, immediateBegin());
EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)")));
EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)")));
EXPECT_CALL(databaseMock, commit());
Storage storage{mockDatabase};
Storage storage{databaseMock};
}
} // namespace

View File

@@ -97,7 +97,6 @@ SOURCES += \
unittests-main.cpp \
utf8-test.cpp \
symbolstorage-test.cpp \
mocksqlitereadstatement.cpp \
symbolquery-test.cpp \
sqliteindex-test.cpp \
sqlitetransaction-test.cpp \
@@ -191,6 +190,8 @@ SOURCES += \
unsavedfiles-test.cpp \
unsavedfile-test.cpp \
utf8positionfromlinecolumn-test.cpp \
clangreferencescollector-test.cpp \
clangdocumentsuspenderresumer-test.cpp \
readexporteddiagnostics-test.cpp
!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):SOURCE += \
@@ -203,11 +204,9 @@ SOURCES += \
!isEmpty(LIBTOOLING_LIBS) {
SOURCES += \
gtest-llvm-printing.cpp \
clangdocumentsuspenderresumer-test.cpp \
clangquerygatherer-test.cpp \
clangqueryprojectfindfilter-test.cpp \
clangquery-test.cpp \
clangreferencescollector-test.cpp \
pchcreator-test.cpp \
refactoringclientserverinprocess-test.cpp \
refactoringclient-test.cpp \
@@ -275,9 +274,6 @@ HEADERS += \
testenvironment.h \
mocksymbolscollector.h \
mocksymbolstorage.h \
mocksqlitewritestatement.h \
mocksqlitedatabase.h \
mocksqlitereadstatement.h \
google-using-declarations.h \
mocksymbolindexing.h \
sqliteteststatement.h \

View File

@@ -263,12 +263,8 @@ Project {
"mocksearch.h",
"mocksearchhandle.h",
"mocksearchresult.h",
"mocksqlitedatabase.h",
"mocksqlitereadstatement.cpp",
"mocksqlitereadstatement.h",
"mocksqlitestatement.h",
"mocksqlitetransactionbackend.h",
"mocksqlitewritestatement.h",
"mocksymbolindexertaskqueue.h",
"mocksymbolindexing.h",
"mocksymbolquery.h",