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> template <typename StatementFactory>
class FilePathStorage class FilePathStorage
{ {
using ReadStatement = typename StatementFactory::ReadStatement; template<int ResultCount>
using ReadStatement = typename StatementFactory::template ReadStatement<ResultCount>;
using WriteStatement = typename StatementFactory::WriteStatement; using WriteStatement = typename StatementFactory::WriteStatement;
using Database = typename StatementFactory::Database; using Database = typename StatementFactory::Database;
@@ -84,7 +85,7 @@ public:
Utils::optional<int> readDirectoryId(Utils::SmallStringView directoryPath) Utils::optional<int> readDirectoryId(Utils::SmallStringView directoryPath)
{ {
ReadStatement &statement = m_statementFactory.selectDirectoryIdFromDirectoriesByDirectoryPath; auto &statement = m_statementFactory.selectDirectoryIdFromDirectoriesByDirectoryPath;
return statement.template value<int>(directoryPath); return statement.template value<int>(directoryPath);
} }
@@ -103,7 +104,7 @@ public:
try { try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database}; Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectDirectoryPathFromDirectoriesByDirectoryId; auto &statement = m_statementFactory.selectDirectoryPathFromDirectoriesByDirectoryId;
auto optionalDirectoryPath = statement.template value<Utils::PathString>(directoryPathId); auto optionalDirectoryPath = statement.template value<Utils::PathString>(directoryPathId);
@@ -123,9 +124,9 @@ public:
try { try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database}; 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(); transaction.commit();
@@ -164,7 +165,7 @@ public:
int writeSourceId(int directoryId, Utils::SmallStringView sourceName) int writeSourceId(int directoryId, Utils::SmallStringView sourceName)
{ {
WriteStatement &statement = m_statementFactory.insertIntoSources; auto &statement = m_statementFactory.insertIntoSources;
statement.write(directoryId, sourceName); statement.write(directoryId, sourceName);
@@ -173,7 +174,7 @@ public:
Utils::optional<int> readSourceId(int directoryId, Utils::SmallStringView sourceName) 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); return statement.template value<int>(directoryId, sourceName);
} }
@@ -183,9 +184,10 @@ public:
try { try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database}; 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) if (!optionalSourceName)
throw SourceNameIdDoesNotExists(); throw SourceNameIdDoesNotExists();
@@ -203,7 +205,7 @@ public:
try { try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database}; Sqlite::DeferredTransaction transaction{m_statementFactory.database};
ReadStatement &statement = m_statementFactory.selectDirectoryIdFromSourcesBySourceId; auto &statement = m_statementFactory.selectDirectoryIdFromSourcesBySourceId;
auto optionalDirectoryId = statement.template value<int>(sourceId); auto optionalDirectoryId = statement.template value<int>(sourceId);
@@ -223,9 +225,9 @@ public:
try { try {
Sqlite::DeferredTransaction transaction{m_statementFactory.database}; 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(); transaction.commit();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -128,7 +128,9 @@ sqlite3 *DatabaseBackend::sqliteDatabaseHandle() const
void DatabaseBackend::setPragmaValue(Utils::SmallStringView pragmaKey, Utils::SmallStringView newPragmaValue) 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); Utils::SmallString pragmeValueInDatabase = toValue<Utils::SmallString>("PRAGMA " + pragmaKey);
checkPragmaValue(pragmeValueInDatabase, newPragmaValue); checkPragmaValue(pragmeValueInDatabase, newPragmaValue);
@@ -172,7 +174,7 @@ void DatabaseBackend::setLastInsertedRowId(int64_t rowId)
void DatabaseBackend::execute(Utils::SmallStringView sqlStatement) void DatabaseBackend::execute(Utils::SmallStringView sqlStatement)
{ {
try { try {
ReadWriteStatement statement(sqlStatement, m_database); ReadWriteStatement<0> statement(sqlStatement, m_database);
statement.execute(); statement.execute();
} catch (StatementIsBusy &) { } catch (StatementIsBusy &) {
execute(sqlStatement); execute(sqlStatement);
@@ -454,7 +456,7 @@ template <typename Type>
Type DatabaseBackend::toValue(Utils::SmallStringView sqlStatement) Type DatabaseBackend::toValue(Utils::SmallStringView sqlStatement)
{ {
try { try {
ReadWriteStatement statement(sqlStatement, m_database); ReadWriteStatement<1> statement(sqlStatement, m_database);
statement.next(); 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 { namespace Sqlite {
class SQLITE_EXPORT ReadStatement final : protected StatementImplementation<BaseStatement> template<int ResultCount>
class ReadStatement final : protected StatementImplementation<BaseStatement, ResultCount>
{ {
public: using Base = StatementImplementation<BaseStatement, ResultCount>;
explicit ReadStatement(Utils::SmallStringView sqlStatement, Database &database);
using StatementImplementation::readCallback; public:
using StatementImplementation::readTo; ReadStatement(Utils::SmallStringView sqlStatement, Database &database)
using StatementImplementation::toValue; : Base{sqlStatement, database}
using StatementImplementation::value; {
using StatementImplementation::values; checkIsReadOnlyStatement();
Base::checkColumnCount(ResultCount);
}
using Base::readCallback;
using Base::readTo;
using Base::toValue;
using Base::value;
using Base::values;
protected: 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 } // 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 { namespace Sqlite {
class SQLITE_EXPORT ReadWriteStatement final : protected StatementImplementation<BaseStatement> template<int ResultCount = 0>
class ReadWriteStatement final : protected StatementImplementation<BaseStatement, ResultCount>
{ {
friend class DatabaseBackend; friend class DatabaseBackend;
using Base = StatementImplementation<BaseStatement, ResultCount>;
public: public:
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database); ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database)
: Base{sqlStatement, database}
{
Base::checkColumnCount(ResultCount);
}
using StatementImplementation::execute; using Base::execute;
using StatementImplementation::readCallback; using Base::readCallback;
using StatementImplementation::readTo; using Base::readTo;
using StatementImplementation::toValue; using Base::toValue;
using StatementImplementation::value; using Base::value;
using StatementImplementation::values; using Base::values;
using StatementImplementation::write; using Base::write;
}; };
} // namespace Sqlite } // namespace Sqlite

View File

@@ -127,7 +127,7 @@ void Internal::SessionsBase::createSessionTable(Database &database)
void Sessions::revert() void Sessions::revert()
{ {
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ", ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName, sessionsTableName,
" ORDER BY id DESC"}, " ORDER BY id DESC"},
database}; database};
@@ -151,7 +151,7 @@ void Sessions::revert()
void Sessions::apply() void Sessions::apply()
{ {
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ", ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName, sessionsTableName,
" ORDER BY id"}, " ORDER BY id"},
database}; database};
@@ -187,7 +187,7 @@ void Sessions::deleteAll()
SessionChangeSets Sessions::changeSets() const SessionChangeSets Sessions::changeSets() const
{ {
ReadStatement selectChangeSets{Utils::PathString{"SELECT changeset FROM ", ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
sessionsTableName, sessionsTableName,
" ORDER BY id DESC"}, " ORDER BY id DESC"},
database}; 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 { namespace Sqlite {
class SQLITE_EXPORT WriteStatement : protected StatementImplementation<BaseStatement> class WriteStatement : protected StatementImplementation<BaseStatement, -1>
{ {
public: using Base = StatementImplementation<BaseStatement, -1>;
explicit WriteStatement(Utils::SmallStringView sqlStatement, Database &database);
public:
WriteStatement(Utils::SmallStringView sqlStatement, Database &database)
: StatementImplementation(sqlStatement, database)
{
checkIsWritableStatement();
}
using StatementImplementation::execute;
using StatementImplementation::database; using StatementImplementation::database;
using StatementImplementation::execute;
using StatementImplementation::write; using StatementImplementation::write;
protected: protected:
void checkIsWritableStatement(); void checkIsWritableStatement()
{
if (Base::isReadOnlyStatement())
throw NotWriteSqlStatement(
"SqliteStatement::SqliteWriteStatement: is not a writable statement!");
}
}; };
} // namespace Sqlite } // namespace Sqlite

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -27,15 +27,15 @@
#include "googletest.h" #include "googletest.h"
#include "mocksqlitedatabase.h" #include "sqlitedatabasemock.h"
#include <filepathstoragesources.h> #include <filepathstoragesources.h>
class MockFilePathStorage class MockFilePathStorage
{ {
public: public:
MockFilePathStorage(MockSqliteDatabase &mockDatabase) MockFilePathStorage(SqliteDatabaseMock &databaseMock)
: mockDatabase{mockDatabase} : databaseMock{databaseMock}
{} {}
MOCK_METHOD1(fetchDirectoryId, int(Utils::SmallStringView directoryPath)); MOCK_METHOD1(fetchDirectoryId, int(Utils::SmallStringView directoryPath));
@@ -50,8 +50,8 @@ public:
MOCK_METHOD0(fetchAllDirectories, std::vector<ClangBackEnd::Sources::Directory>()); MOCK_METHOD0(fetchAllDirectories, std::vector<ClangBackEnd::Sources::Directory>());
MOCK_METHOD0(fetchAllSources, std::vector<ClangBackEnd::Sources::Source>()); 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(prepare, void(Utils::SmallStringView sqlStatement));
MOCK_METHOD1(checkColumnCount, void(int)); MOCK_METHOD1(checkColumnCount, void(int));
MOCK_CONST_METHOD0(isReadOnlyStatement, bool());
}; };
template<> template<>
@@ -96,13 +98,12 @@ Utils::PathString BaseMockSqliteStatement::fetchValue<Utils::PathString>(int col
return fetchPathStringValue(column); return fetchPathStringValue(column);
} }
class MockSqliteStatement : public Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>> template<int ResultCount = 1>
class MockSqliteStatement
: public Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>, ResultCount>
{ {
public: public:
explicit MockSqliteStatement() explicit MockSqliteStatement() {}
: Sqlite::StatementImplementation<NiceMock<BaseMockSqliteStatement>>()
{}
protected: protected:
void checkIsWritableStatement(); 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 "googletest.h"
#include "mocksqlitedatabase.h" #include "sqlitedatabasemock.h"
#include <symbolstorageinterface.h> #include <symbolstorageinterface.h>

View File

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

View File

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

View File

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

View File

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

View File

@@ -27,34 +27,9 @@
#include "sqlitedatabasemock.h" #include "sqlitedatabasemock.h"
SqliteReadStatementMock::SqliteReadStatementMock(Utils::SmallStringView sqlStatement, SqliteReadStatementMockBase::SqliteReadStatementMockBase(Utils::SmallStringView sqlStatement,
SqliteDatabaseMock &databaseMock) SqliteDatabaseMock &databaseMock)
: sqlStatement(sqlStatement) : sqlStatement(sqlStatement)
{ {
databaseMock.prepare(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 "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 <sqliteblob.h>
#include <stringcachefwd.h>
#include <symbol.h>
#include <usedmacro.h>
#include <utils/optional.h> #include <utils/optional.h>
#include <utils/smallstring.h> #include <utils/smallstring.h>
@@ -37,57 +49,196 @@
#include <tuple> #include <tuple>
#include <vector> #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 SqliteDatabaseMock;
class SqliteReadStatementMock class SqliteReadStatementMockBase
{ {
public: public:
SqliteReadStatementMock() = default; SqliteReadStatementMockBase() = default;
SqliteReadStatementMock(Utils::SmallStringView sqlStatement, SqliteDatabaseMock &databaseMock); SqliteReadStatementMockBase(Utils::SmallStringView sqlStatement, SqliteDatabaseMock &databaseMock);
MOCK_METHOD(std::vector<Utils::SmallString>, valuesReturnStringVector, (std::size_t), ()); MOCK_METHOD(std::vector<Utils::SmallString>, valuesReturnStringVector, (std::size_t), ());
MOCK_METHOD(std::vector<long long>, valuesReturnRowIds, (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>, MOCK_METHOD(Utils::optional<Sqlite::ByteArrayBlob>,
valueReturnBlob, valueReturnBlob,
(Utils::SmallStringView, long long), (Utils::SmallStringView, long long),
()); ());
template<typename ResultType, int ResultTypeCount = 1, typename... QueryType> MOCK_METHOD(SourceLocations, valuesReturnSourceLocations, (std::size_t, int, int, int), ());
std::vector<ResultType> values(std::size_t reserveSize, const QueryType &... queryValues);
template <typename ResultType, MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int), ());
int ResultTypeCount = 1,
typename... QueryType>
std::vector<ResultType> values(std::size_t reserveSize);
template <typename ResultType, MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int, int), ());
int ResultTypeCount = 1,
template <typename...> class QueryContainerType,
typename QueryElementType>
std::vector<ResultType> values(std::size_t reserveSize,
const QueryContainerType<QueryElementType> &queryValues);
template <typename ResultType, MOCK_METHOD(std::vector<Sources::Directory>, valuesReturnStdVectorDirectory, (std::size_t), ());
int ResultTypeCount = 1,
typename... QueryTypes> MOCK_METHOD(std::vector<Sources::Source>, valuesReturnStdVectorSource, (std::size_t), ());
Utils::optional<ResultType> value(const QueryTypes&... queryValues);
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: public:
Utils::SmallString sqlStatement; Utils::SmallString sqlStatement;
}; };
template<> template<int ResultCount>
std::vector<Utils::SmallString> SqliteReadStatementMock::values<Utils::SmallString>( class SqliteReadStatementMock : public SqliteReadStatementMockBase
std::size_t reserveSize); {
public:
template<> using SqliteReadStatementMockBase::SqliteReadStatementMockBase;
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);

View File

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

View File

@@ -121,12 +121,12 @@ struct Output
TEST_F(SqliteStatement, ThrowsStatementHasErrorForWrongSqlStatement) 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) 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); Sqlite::NotReadOnlySqlStatement);
} }
@@ -143,7 +143,7 @@ TEST_F(SqliteStatement, CountRows)
while (statement.next()) while (statement.next())
++nextCount; ++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); ASSERT_THAT(nextCount, sqlCount);
} }
@@ -174,24 +174,28 @@ TEST_F(SqliteStatement, Value)
TEST_F(SqliteStatement, ToIntegerValue) 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); ASSERT_THAT(value, 23);
} }
TEST_F(SqliteStatement, ToLongIntegerValue) 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) 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) 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) TEST_F(SqliteStatement, BindNull)
@@ -544,16 +548,15 @@ TEST_F(SqliteStatement, CannotReadFromClosedDatabase)
{ {
database.close(); database.close();
ASSERT_THROW(ReadStatement("SELECT * FROM test", database), ASSERT_THROW(ReadStatement<3>("SELECT * FROM test", database), Sqlite::DatabaseIsNotOpen);
Sqlite::DatabaseIsNotOpen);
} }
TEST_F(SqliteStatement, GetTupleValuesWithoutArguments) TEST_F(SqliteStatement, GetTupleValuesWithoutArguments)
{ {
using Tuple = std::tuple<Utils::SmallString, double, int>; 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, ASSERT_THAT(values,
UnorderedElementsAre(Tuple{"bar", 0, 1}, Tuple{"foo", 23.3, 2}, Tuple{"poo", 40.0, 3})); 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) 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); std::vector<Utils::SmallString> values = statement.values<Utils::SmallString>(3);
@@ -586,7 +589,7 @@ public:
TEST_F(SqliteStatement, GetSingleSqliteValuesWithoutArguments) 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)"); database.execute("INSERT INTO test VALUES (NULL, NULL, NULL)");
std::vector<FooValue> values = statement.values<FooValue>(3); std::vector<FooValue> values = statement.values<FooValue>(3);
@@ -596,9 +599,9 @@ TEST_F(SqliteStatement, GetSingleSqliteValuesWithoutArguments)
TEST_F(SqliteStatement, GetStructValuesWithoutArguments) 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, ASSERT_THAT(values,
UnorderedElementsAre(Output{"bar", "blah", 1}, UnorderedElementsAre(Output{"bar", "blah", 1},
@@ -608,7 +611,7 @@ TEST_F(SqliteStatement, GetStructValuesWithoutArguments)
TEST_F(SqliteStatement, GetValuesForSingleOutputWithBindingMultipleTimes) 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); statement.values<Utils::SmallString>(3, 40);
std::vector<Utils::SmallString> values = 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")); 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) TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndMultipleQueryValue)
{ {
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>; 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})); ASSERT_THAT(values, ElementsAre(Tuple{"bar", "blah", 1}));
} }
@@ -673,49 +633,29 @@ TEST_F(SqliteStatement, GetValuesForMultipleOutputValuesAndMultipleQueryValue)
TEST_F(SqliteStatement, CallGetValuesForMultipleOutputValuesAndMultipleQueryValueMultipleTimes) TEST_F(SqliteStatement, CallGetValuesForMultipleOutputValuesAndMultipleQueryValueMultipleTimes)
{ {
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>; using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>;
ReadStatement statement("SELECT name, number, value FROM test WHERE name=? AND number=?", database); ReadStatement<3> statement("SELECT name, number, value FROM test WHERE name=? AND number=?",
statement.values<Tuple, 3>(3, "bar", "blah"); 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})); ASSERT_THAT(values, ElementsAre(Tuple{"bar", "blah", 1}));
} }
TEST_F(SqliteStatement, GetStructOutputValuesAndMultipleQueryValue) 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})); 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) TEST_F(SqliteStatement, GetBlobValues)
{ {
database.execute("INSERT INTO test VALUES ('blob', 40, x'AABBCCDD')"); 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; const int value = 0xDDCCBBAA;
auto bytePointer = reinterpret_cast<const Sqlite::byte *>(&value); auto bytePointer = reinterpret_cast<const Sqlite::byte *>(&value);
Sqlite::BlobView bytes{bytePointer, 4}; Sqlite::BlobView bytes{bytePointer, 4};
@@ -727,7 +667,7 @@ TEST_F(SqliteStatement, GetBlobValues)
TEST_F(SqliteStatement, GetEmptyBlobValueForInteger) 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>(); auto value = statement.value<Sqlite::Blob>();
@@ -736,7 +676,7 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForInteger)
TEST_F(SqliteStatement, GetEmptyBlobValueForFloat) 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>(); auto value = statement.value<Sqlite::Blob>();
@@ -745,7 +685,7 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForFloat)
TEST_F(SqliteStatement, GetEmptyBlobValueForText) 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>(); auto value = statement.value<Sqlite::Blob>();
@@ -754,7 +694,8 @@ TEST_F(SqliteStatement, GetEmptyBlobValueForText)
TEST_F(SqliteStatement, GetOptionalSingleValueAndMultipleQueryValue) 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); auto value = statement.value<Utils::SmallString>("bar", "blah", 1);
@@ -763,9 +704,10 @@ TEST_F(SqliteStatement, GetOptionalSingleValueAndMultipleQueryValue)
TEST_F(SqliteStatement, GetOptionalOutputValueAndMultipleQueryValue) 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})); ASSERT_THAT(value.value(), Eq(Output{"bar", "blah", 1}));
} }
@@ -773,9 +715,10 @@ TEST_F(SqliteStatement, GetOptionalOutputValueAndMultipleQueryValue)
TEST_F(SqliteStatement, GetOptionalTupleValueAndMultipleQueryValue) TEST_F(SqliteStatement, GetOptionalTupleValueAndMultipleQueryValue)
{ {
using Tuple = std::tuple<Utils::SmallString, Utils::SmallString, long long>; 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})); 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); 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) TEST_F(SqliteStatement, ResetIfWriteIsThrowingException)
{ {
MockSqliteStatement mockStatement; MockSqliteStatement mockStatement;
@@ -917,138 +801,101 @@ TEST_F(SqliteStatement, ResetIfExecuteThrowsException)
ASSERT_ANY_THROW(mockStatement.execute()); 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); ASSERT_THROW(ReadStatement<1> statement("SELECT name, number FROM test", database),
}
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>>{}),
Sqlite::ColumnCountDoesNotMatch); 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); Sqlite::ColumnCountDoesNotMatch);
} }
TEST_F(SqliteStatement, ReadCallback) TEST_F(SqliteStatement, ReadCallback)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; 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("bar"), Eq(1)));
EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2))); EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2)));
EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3))); EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3)));
statement.readCallback<2>(callbackMock.AsStdFunction()); statement.readCallback(callbackMock.AsStdFunction());
} }
TEST_F(SqliteStatement, ReadCallbackCalledWithArguments) TEST_F(SqliteStatement, ReadCallbackCalledWithArguments)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; 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))); EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2)));
statement.readCallback<2>(callbackMock.AsStdFunction(), 2); statement.readCallback(callbackMock.AsStdFunction(), 2);
} }
TEST_F(SqliteStatement, ReadCallbackAborts) TEST_F(SqliteStatement, ReadCallbackAborts)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; 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("bar"), Eq(1)));
EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2))).WillOnce(Return(Sqlite::CallbackControl::Abort)); EXPECT_CALL(callbackMock, Call(Eq("foo"), Eq(2))).WillOnce(Return(Sqlite::CallbackControl::Abort));
EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3))).Times(0); EXPECT_CALL(callbackMock, Call(Eq("poo"), Eq(3))).Times(0);
statement.readCallback<2>(callbackMock.AsStdFunction()); statement.readCallback(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);
} }
TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacks) TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacks)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement; MockSqliteStatement<2> mockStatement;
EXPECT_CALL(mockStatement, reset()); EXPECT_CALL(mockStatement, reset());
mockStatement.readCallback<2>(callbackMock.AsStdFunction()); mockStatement.readCallback(callbackMock.AsStdFunction());
} }
TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacksAborts) TEST_F(SqliteStatement, ReadCallbackCallsResetAfterCallbacksAborts)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement; MockSqliteStatement<2> mockStatement;
ON_CALL(callbackMock, Call(_, _)).WillByDefault(Return(Sqlite::CallbackControl::Abort)); ON_CALL(callbackMock, Call(_, _)).WillByDefault(Return(Sqlite::CallbackControl::Abort));
EXPECT_CALL(mockStatement, reset()); EXPECT_CALL(mockStatement, reset());
mockStatement.readCallback<2>(callbackMock.AsStdFunction()); mockStatement.readCallback(callbackMock.AsStdFunction());
} }
TEST_F(SqliteStatement, ReadCallbackThrowsForError) TEST_F(SqliteStatement, ReadCallbackThrowsForError)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement; MockSqliteStatement<2> mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError(""))); ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
ASSERT_THROW(mockStatement.readCallback<2>(callbackMock.AsStdFunction()), ASSERT_THROW(mockStatement.readCallback(callbackMock.AsStdFunction()), Sqlite::StatementHasError);
Sqlite::StatementHasError);
} }
TEST_F(SqliteStatement, ReadCallbackCallsResetIfExceptionIsThrown) TEST_F(SqliteStatement, ReadCallbackCallsResetIfExceptionIsThrown)
{ {
MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock; MockFunction<Sqlite::CallbackControl(Utils::SmallStringView, long long)> callbackMock;
MockSqliteStatement mockStatement; MockSqliteStatement<2> mockStatement;
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError(""))); ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
EXPECT_CALL(mockStatement, reset()); EXPECT_CALL(mockStatement, reset());
EXPECT_THROW(mockStatement.readCallback<2>(callbackMock.AsStdFunction()), EXPECT_THROW(mockStatement.readCallback(callbackMock.AsStdFunction()), Sqlite::StatementHasError);
Sqlite::StatementHasError);
} }
TEST_F(SqliteStatement, ReadToContainer) TEST_F(SqliteStatement, ReadToContainer)
{ {
std::deque<FooValue> values; std::deque<FooValue> values;
ReadStatement statement("SELECT number FROM test", database); ReadStatement<1> statement("SELECT number FROM test", database);
statement.readTo<1>(values); statement.readTo<1>(values);
@@ -1058,21 +905,13 @@ TEST_F(SqliteStatement, ReadToContainer)
TEST_F(SqliteStatement, ReadToContainerCallCallbackWithArguments) TEST_F(SqliteStatement, ReadToContainerCallCallbackWithArguments)
{ {
std::deque<FooValue> values; 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); statement.readTo(values, 2);
ASSERT_THAT(values, ElementsAre(Eq(23.3))); 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) TEST_F(SqliteStatement, ReadToCallsResetAfterPushingAllValuesBack)
{ {
std::deque<FooValue> values; std::deque<FooValue> values;

View File

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

View File

@@ -27,11 +27,13 @@
#include <sqlitebasestatement.h> #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: public:
explicit SqliteTestStatement(Utils::SmallStringView sqlStatement, Sqlite::Database &database) 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 "mocksqlitetransactionbackend.h"
#include <sqlitetransaction.h> #include <sqlitedatabasemock.h>
#include <sqliteexception.h> #include <sqliteexception.h>
#include <mocksqlitedatabase.h> #include <sqlitetransaction.h>
namespace { namespace {

View File

@@ -74,8 +74,35 @@ public:
Utils::SmallStringView, Utils::SmallStringView,
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, (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; Utils::SmallString sqlStatement;
}; };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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