Sqlite: Make the statement conversion operator id aware

Before you had to use an constructor which is has an integer as
parameter. Like

struct Foo
{
  Foo{long long id} : id{id} {}
  Foo{TypeId id} : id{id} {}

  TypeId id;
}

Now you can write:

struct Foo
{
  TypeId id;
}

With C++ 20 we can even remove more contructors.

Change-Id: I374505a037a71339b672f5f3a57b06dcf443b4bf
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2022-07-19 14:33:00 +02:00
parent fdcb02d5e2
commit 93d0b5a1d3
15 changed files with 194 additions and 198 deletions

View File

@@ -96,10 +96,10 @@ public:
void bind(int index, ValueView value); void bind(int index, ValueView value);
void bind(int index, BlobView blobView); void bind(int index, BlobView blobView);
template<auto Type, typename InternalIntergerType> template<typename Type, typename = std::enable_if_t<Type::IsBasicId::value>>
void bind(int index, BasicId<Type, InternalIntergerType> id) void bind(int index, Type id)
{ {
bind(index, id.id); bind(index, &id);
} }
void bind(int index, uint value) { bind(index, static_cast<long long>(value)); } void bind(int index, uint value) { bind(index, static_cast<long long>(value)); }
@@ -452,14 +452,24 @@ private:
, column(column) , column(column)
{} {}
operator int() { return statement.fetchIntValue(column); } operator int() const { return statement.fetchIntValue(column); }
operator long() { return statement.fetchLongValue(column); } operator long() const { return statement.fetchLongValue(column); }
operator long long() { return statement.fetchLongLongValue(column); } operator long long() const { return statement.fetchLongLongValue(column); }
operator double() { return statement.fetchDoubleValue(column); } operator double() const { return statement.fetchDoubleValue(column); }
operator Utils::SmallStringView() { return statement.fetchSmallStringViewValue(column); } operator Utils::SmallStringView() { return statement.fetchSmallStringViewValue(column); }
operator BlobView() { return statement.fetchBlobValue(column); } operator BlobView() { return statement.fetchBlobValue(column); }
operator ValueView() { return statement.fetchValueView(column); } operator ValueView() { return statement.fetchValueView(column); }
template<typename ConversionType,
typename = std::enable_if_t<ConversionType::IsBasicId::value>>
constexpr operator ConversionType()
{
if constexpr (std::is_same_v<typename ConversionType::DatabaseType, int>)
return ConversionType::create(statement.fetchIntValue(column));
else
return ConversionType::create(statement.fetchLongLongValue(column));
}
StatementImplementation &statement; StatementImplementation &statement;
int column; int column;
}; };
@@ -491,7 +501,7 @@ private:
template<typename ResultType, int... ColumnIndices> template<typename ResultType, int... ColumnIndices>
ResultType createValue(std::integer_sequence<int, ColumnIndices...>) ResultType createValue(std::integer_sequence<int, ColumnIndices...>)
{ {
return ResultType{ValueGetter(*this, ColumnIndices)...}; return ResultType(ValueGetter(*this, ColumnIndices)...);
} }
template<typename ResultType> template<typename ResultType>

View File

@@ -27,6 +27,7 @@
#include <utils/span.h> #include <utils/span.h>
#include <type_traits>
#include <vector> #include <vector>
namespace Sqlite { namespace Sqlite {
@@ -35,15 +36,19 @@ template<auto Type, typename InternalIntegerType = long long>
class BasicId class BasicId
{ {
public: public:
using IsBasicId = std::true_type;
using DatabaseType = InternalIntegerType; using DatabaseType = InternalIntegerType;
constexpr explicit BasicId() = default; constexpr explicit BasicId() = default;
constexpr BasicId(const char *) = delete; constexpr BasicId(const char *) = delete;
constexpr explicit BasicId(InternalIntegerType id) static constexpr BasicId create(InternalIntegerType idNumber)
: id{id} {
{} BasicId id;
id.id = idNumber;
return id;
}
constexpr friend bool operator==(BasicId first, BasicId second) constexpr friend bool operator==(BasicId first, BasicId second)
{ {
@@ -71,7 +76,7 @@ public:
InternalIntegerType operator&() const { return id; } InternalIntegerType operator&() const { return id; }
public: private:
InternalIntegerType id = -1; InternalIntegerType id = -1;
}; };

View File

@@ -41,12 +41,6 @@ public:
, lastModified{lastModified} , lastModified{lastModified}
{} {}
explicit FileStatus(int sourceId, long long size, long long lastModified)
: sourceId{sourceId}
, size{size}
, lastModified{lastModified}
{}
friend bool operator==(const FileStatus &first, const FileStatus &second) friend bool operator==(const FileStatus &first, const FileStatus &second)
{ {
return first.sourceId == second.sourceId && first.size == second.size return first.sourceId == second.sourceId && first.size == second.size

View File

@@ -519,14 +519,6 @@ private:
, importedTypeNameId{std::move(importedTypeNameId)} , importedTypeNameId{std::move(importedTypeNameId)}
{} {}
explicit PropertyDeclaration(long long typeId,
long long propertyDeclarationId,
long long importedTypeNameId)
: typeId{typeId}
, propertyDeclarationId{propertyDeclarationId}
, importedTypeNameId{importedTypeNameId}
{}
friend bool operator<(const PropertyDeclaration &first, const PropertyDeclaration &second) friend bool operator<(const PropertyDeclaration &first, const PropertyDeclaration &second)
{ {
return std::tie(first.typeId, first.propertyDeclarationId) return std::tie(first.typeId, first.propertyDeclarationId)
@@ -876,15 +868,15 @@ private:
void handleAliasPropertyDeclarationsWithPropertyType( void handleAliasPropertyDeclarationsWithPropertyType(
TypeId typeId, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations) TypeId typeId, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations)
{ {
auto callback = [&](long long typeId, auto callback = [&](TypeId typeId,
long long propertyDeclarationId, PropertyDeclarationId propertyDeclarationId,
long long propertyImportedTypeNameId, ImportedTypeNameId propertyImportedTypeNameId,
long long aliasPropertyDeclarationId, PropertyDeclarationId aliasPropertyDeclarationId,
long long aliasPropertyDeclarationTailId) { PropertyDeclarationId aliasPropertyDeclarationTailId) {
auto aliasPropertyName = selectPropertyNameStatement.template value<Utils::SmallString>( auto aliasPropertyName = selectPropertyNameStatement.template value<Utils::SmallString>(
aliasPropertyDeclarationId); aliasPropertyDeclarationId);
Utils::SmallString aliasPropertyNameTail; Utils::SmallString aliasPropertyNameTail;
if (aliasPropertyDeclarationTailId != -1) if (aliasPropertyDeclarationTailId)
aliasPropertyNameTail = selectPropertyNameStatement.template value<Utils::SmallString>( aliasPropertyNameTail = selectPropertyNameStatement.template value<Utils::SmallString>(
aliasPropertyDeclarationTailId); aliasPropertyDeclarationTailId);
@@ -901,7 +893,7 @@ private:
}; };
selectAliasPropertiesDeclarationForPropertiesWithTypeIdStatement.readCallback(callback, selectAliasPropertiesDeclarationForPropertiesWithTypeIdStatement.readCallback(callback,
&typeId); typeId);
} }
void handlePropertyDeclarationWithPropertyType(TypeId typeId, void handlePropertyDeclarationWithPropertyType(TypeId typeId,
@@ -913,8 +905,8 @@ private:
void handlePrototypes(TypeId prototypeId, Prototypes &relinkablePrototypes) void handlePrototypes(TypeId prototypeId, Prototypes &relinkablePrototypes)
{ {
auto callback = [&](long long typeId, long long prototypeNameId) { auto callback = [&](TypeId typeId, ImportedTypeNameId prototypeNameId) {
relinkablePrototypes.emplace_back(TypeId{typeId}, ImportedTypeNameId{prototypeNameId}); relinkablePrototypes.emplace_back(typeId, prototypeNameId);
return Sqlite::CallbackControl::Continue; return Sqlite::CallbackControl::Continue;
}; };
@@ -1017,9 +1009,9 @@ private:
Prototypes &relinkablePrototypes, Prototypes &relinkablePrototypes,
TypeIds &deletedTypeIds) TypeIds &deletedTypeIds)
{ {
auto callback = [&](long long typeId) { auto callback = [&](TypeId typeId) {
deletedTypeIds.push_back(TypeId{typeId}); deletedTypeIds.push_back(typeId);
deleteType(TypeId{typeId}, deleteType(typeId,
relinkableAliasPropertyDeclarations, relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes); relinkablePrototypes);
@@ -1030,7 +1022,7 @@ private:
toIntegers(updatedSourceIds), toIntegers(updatedSourceIds),
toIntegers(updatedTypeIds)); toIntegers(updatedTypeIds));
for (TypeId typeIdToBeDeleted : typeIdsToBeDeleted) for (TypeId typeIdToBeDeleted : typeIdsToBeDeleted)
callback(&typeIdToBeDeleted); callback(typeIdToBeDeleted);
} }
void relink(AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, void relink(AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
@@ -1207,9 +1199,9 @@ private:
SourceId sourceId, SourceId sourceId,
TypeId typeId) TypeId typeId)
{ {
auto callback = [&](long long propertyDeclarationId) { auto callback = [&](PropertyDeclarationId propertyDeclarationId) {
insertedAliasPropertyDeclarations.emplace_back(typeId, insertedAliasPropertyDeclarations.emplace_back(typeId,
PropertyDeclarationId{propertyDeclarationId}, propertyDeclarationId,
fetchImportedTypeNameId(value.typeName, fetchImportedTypeNameId(value.typeName,
sourceId), sourceId),
value.aliasPropertyName, value.aliasPropertyName,
@@ -1365,8 +1357,8 @@ private:
{ {
public: public:
explicit AliasPropertyDeclarationView(Utils::SmallStringView name, explicit AliasPropertyDeclarationView(Utils::SmallStringView name,
long long id, PropertyDeclarationId id,
long long aliasId) PropertyDeclarationId aliasId)
: name{name} : name{name}
, id{id} , id{id}
, aliasId{aliasId} , aliasId{aliasId}
@@ -1481,12 +1473,12 @@ private:
auto insert = [&](const Storage::Synchronization::Import &import) { auto insert = [&](const Storage::Synchronization::Import &import) {
insertDocumentImport(import, importKind, import.moduleId, ModuleExportedImportId{}); insertDocumentImport(import, importKind, import.moduleId, ModuleExportedImportId{});
auto callback = [&](int exportedModuleId, auto callback = [&](ModuleId exportedModuleId,
int majorVersion, int majorVersion,
int minorVersion, int minorVersion,
long long moduleExportedImportId) { ModuleExportedImportId moduleExportedImportId) {
Storage::Synchronization::Import additionImport{ Storage::Synchronization::Import additionImport{
ModuleId{exportedModuleId}, exportedModuleId,
Storage::Synchronization::Version{majorVersion, minorVersion}, Storage::Synchronization::Version{majorVersion, minorVersion},
import.sourceId}; import.sourceId};
@@ -1497,7 +1489,7 @@ private:
insertDocumentImport(additionImport, insertDocumentImport(additionImport,
exportedImportKind, exportedImportKind,
import.moduleId, import.moduleId,
ModuleExportedImportId{moduleExportedImportId}); moduleExportedImportId);
return Sqlite::CallbackControl::Continue; return Sqlite::CallbackControl::Continue;
}; };
@@ -1812,7 +1804,7 @@ private:
class TypeWithDefaultPropertyView class TypeWithDefaultPropertyView
{ {
public: public:
TypeWithDefaultPropertyView(long long typeId, long long defaultPropertyId) TypeWithDefaultPropertyView(TypeId typeId, PropertyDeclarationId defaultPropertyId)
: typeId{typeId} : typeId{typeId}
, defaultPropertyId{defaultPropertyId} , defaultPropertyId{defaultPropertyId}
{} {}
@@ -1893,8 +1885,8 @@ private:
void checkForPrototypeChainCycle(TypeId typeId) const void checkForPrototypeChainCycle(TypeId typeId) const
{ {
auto callback = [=](long long currentTypeId) { auto callback = [=](TypeId currentTypeId) {
if (typeId == TypeId{currentTypeId}) if (typeId == currentTypeId)
throw PrototypeChainCycle{}; throw PrototypeChainCycle{};
return Sqlite::CallbackControl::Continue; return Sqlite::CallbackControl::Continue;
@@ -1905,8 +1897,8 @@ private:
void checkForAliasChainCycle(PropertyDeclarationId propertyDeclarationId) const void checkForAliasChainCycle(PropertyDeclarationId propertyDeclarationId) const
{ {
auto callback = [=](long long currentPropertyDeclarationId) { auto callback = [=](PropertyDeclarationId currentPropertyDeclarationId) {
if (propertyDeclarationId == PropertyDeclarationId{currentPropertyDeclarationId}) if (propertyDeclarationId == currentPropertyDeclarationId)
throw AliasChainCycle{}; throw AliasChainCycle{};
return Sqlite::CallbackControl::Continue; return Sqlite::CallbackControl::Continue;
@@ -2032,8 +2024,8 @@ private:
class FetchPropertyDeclarationResult class FetchPropertyDeclarationResult
{ {
public: public:
FetchPropertyDeclarationResult(long long propertyTypeId, FetchPropertyDeclarationResult(TypeId propertyTypeId,
long long propertyDeclarationId, PropertyDeclarationId propertyDeclarationId,
long long propertyTraits) long long propertyTraits)
: propertyTypeId{propertyTypeId} : propertyTypeId{propertyTypeId}
, propertyDeclarationId{propertyDeclarationId} , propertyDeclarationId{propertyDeclarationId}
@@ -2087,14 +2079,14 @@ private:
{ {
insertIntoSourceContextsStatement.write(sourceContextPath); insertIntoSourceContextsStatement.write(sourceContextPath);
return SourceContextId(database.lastInsertedRowId()); return SourceContextId::create(database.lastInsertedRowId());
} }
SourceId writeSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName) SourceId writeSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName)
{ {
insertIntoSourcesStatement.write(sourceContextId, sourceName); insertIntoSourcesStatement.write(sourceContextId, sourceName);
return SourceId(database.lastInsertedRowId()); return SourceId::create(database.lastInsertedRowId());
} }
SourceId readSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName) SourceId readSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName)
@@ -2121,7 +2113,7 @@ private:
auto callback = [&](Utils::SmallStringView name, auto callback = [&](Utils::SmallStringView name,
Utils::SmallStringView returnType, Utils::SmallStringView returnType,
long long functionDeclarationId) { FunctionDeclarationId functionDeclarationId) {
auto &functionDeclaration = functionDeclarations.emplace_back(name, returnType); auto &functionDeclaration = functionDeclarations.emplace_back(name, returnType);
functionDeclaration.parameters = selectFunctionParameterDeclarationsStatement.template values< functionDeclaration.parameters = selectFunctionParameterDeclarationsStatement.template values<
Storage::Synchronization::ParameterDeclaration>(8, functionDeclarationId); Storage::Synchronization::ParameterDeclaration>(8, functionDeclarationId);
@@ -2138,7 +2130,7 @@ private:
{ {
Storage::Synchronization::SignalDeclarations signalDeclarations; Storage::Synchronization::SignalDeclarations signalDeclarations;
auto callback = [&](Utils::SmallStringView name, long long signalDeclarationId) { auto callback = [&](Utils::SmallStringView name, SignalDeclarationId signalDeclarationId) {
auto &signalDeclaration = signalDeclarations.emplace_back(name); auto &signalDeclaration = signalDeclarations.emplace_back(name);
signalDeclaration.parameters = selectSignalParameterDeclarationsStatement.template values< signalDeclaration.parameters = selectSignalParameterDeclarationsStatement.template values<
Storage::Synchronization::ParameterDeclaration>(8, signalDeclarationId); Storage::Synchronization::ParameterDeclaration>(8, signalDeclarationId);
@@ -2155,7 +2147,8 @@ private:
{ {
Storage::Synchronization::EnumerationDeclarations enumerationDeclarations; Storage::Synchronization::EnumerationDeclarations enumerationDeclarations;
auto callback = [&](Utils::SmallStringView name, long long enumerationDeclarationId) { auto callback = [&](Utils::SmallStringView name,
EnumerationDeclarationId enumerationDeclarationId) {
enumerationDeclarations.emplace_back( enumerationDeclarations.emplace_back(
name, name,
selectEnumeratorDeclarationStatement.template values< selectEnumeratorDeclarationStatement.template values<

View File

@@ -174,7 +174,7 @@ public:
, sourceId{sourceId} , sourceId{sourceId}
{} {}
explicit Import(int moduleId, int majorVersion, int minorVersion, int sourceId) explicit Import(ModuleId moduleId, int majorVersion, int minorVersion, SourceId sourceId)
: version{majorVersion, minorVersion} : version{majorVersion, minorVersion}
, moduleId{moduleId} , moduleId{moduleId}
, sourceId{sourceId} , sourceId{sourceId}
@@ -205,7 +205,8 @@ class ImportView
public: public:
explicit ImportView() = default; explicit ImportView() = default;
explicit ImportView(long long importId, int sourceId, int moduleId, int majorVersion, int minorVersion) explicit ImportView(
ImportId importId, SourceId sourceId, ModuleId moduleId, int majorVersion, int minorVersion)
: importId{importId} : importId{importId}
, sourceId{sourceId} , sourceId{sourceId}
, moduleId{moduleId} , moduleId{moduleId}
@@ -272,9 +273,9 @@ class ModuleExportedImportView
public: public:
explicit ModuleExportedImportView() = default; explicit ModuleExportedImportView() = default;
explicit ModuleExportedImportView(long long moduleExportedImportId, explicit ModuleExportedImportView(ModuleExportedImportId moduleExportedImportId,
int moduleId, ModuleId moduleId,
int exportedModuleId, ModuleId exportedModuleId,
int majorVersion, int majorVersion,
int minorVersion, int minorVersion,
int isAutoVersion) int isAutoVersion)
@@ -360,7 +361,7 @@ public:
, moduleId{moduleId} , moduleId{moduleId}
{} {}
explicit ExportedType(int moduleId, Utils::SmallStringView name, int majorVersion, int minorVersion) explicit ExportedType(ModuleId moduleId, Utils::SmallStringView name, int majorVersion, int minorVersion)
: name{name} : name{name}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
, moduleId{moduleId} , moduleId{moduleId}
@@ -395,12 +396,12 @@ public:
, version{version} , version{version}
, moduleId{moduleId} , moduleId{moduleId}
{} {}
explicit ExportedTypeView(int moduleId, explicit ExportedTypeView(ModuleId moduleId,
Utils::SmallStringView name, Utils::SmallStringView name,
int majorVersion, int majorVersion,
int minorVersion, int minorVersion,
int typeId, TypeId typeId,
long long exportedTypeNameId) ExportedTypeNameId exportedTypeNameId)
: name{name} : name{name}
, version{majorVersion, minorVersion} , version{majorVersion, minorVersion}
, typeId{typeId} , typeId{typeId}
@@ -475,7 +476,7 @@ public:
explicit EnumerationDeclarationView() = default; explicit EnumerationDeclarationView() = default;
explicit EnumerationDeclarationView(Utils::SmallStringView name, explicit EnumerationDeclarationView(Utils::SmallStringView name,
Utils::SmallStringView enumeratorDeclarations, Utils::SmallStringView enumeratorDeclarations,
long long id) EnumerationDeclarationId id)
: name{name} : name{name}
, enumeratorDeclarations{std::move(enumeratorDeclarations)} , enumeratorDeclarations{std::move(enumeratorDeclarations)}
, id{id} , id{id}
@@ -550,7 +551,7 @@ public:
explicit SignalDeclarationView() = default; explicit SignalDeclarationView() = default;
explicit SignalDeclarationView(Utils::SmallStringView name, explicit SignalDeclarationView(Utils::SmallStringView name,
Utils::SmallStringView signature, Utils::SmallStringView signature,
long long id) SignalDeclarationId id)
: name{name} : name{name}
, signature{signature} , signature{signature}
, id{id} , id{id}
@@ -601,7 +602,7 @@ public:
explicit FunctionDeclarationView(Utils::SmallStringView name, explicit FunctionDeclarationView(Utils::SmallStringView name,
Utils::SmallStringView returnTypeName, Utils::SmallStringView returnTypeName,
Utils::SmallStringView signature, Utils::SmallStringView signature,
long long id) FunctionDeclarationId id)
: name{name} : name{name}
, returnTypeName{returnTypeName} , returnTypeName{returnTypeName}
, signature{signature} , signature{signature}
@@ -667,7 +668,7 @@ public:
{} {}
explicit PropertyDeclaration(Utils::SmallStringView name, explicit PropertyDeclaration(Utils::SmallStringView name,
long long propertyTypeId, TypeId propertyTypeId,
int traits, int traits,
Utils::SmallStringView aliasPropertyName, Utils::SmallStringView aliasPropertyName,
Utils::SmallStringView aliasPropertyNameTail = {}) Utils::SmallStringView aliasPropertyNameTail = {})
@@ -718,10 +719,10 @@ class PropertyDeclarationView
public: public:
explicit PropertyDeclarationView(Utils::SmallStringView name, explicit PropertyDeclarationView(Utils::SmallStringView name,
int traits, int traits,
long long typeId, TypeId typeId,
long long typeNameId, ImportedTypeNameId typeNameId,
long long id, PropertyDeclarationId id,
long long aliasId) PropertyDeclarationId aliasId)
: name{name} : name{name}
, traits{static_cast<PropertyDeclarationTraits>(traits)} , traits{static_cast<PropertyDeclarationTraits>(traits)}
, typeId{typeId} , typeId{typeId}
@@ -794,7 +795,7 @@ public:
explicit Type(Utils::SmallStringView typeName, explicit Type(Utils::SmallStringView typeName,
Utils::SmallStringView prototype, Utils::SmallStringView prototype,
int accessSemantics, int accessSemantics,
int sourceId) SourceId sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{ImportedType{prototype}} , prototype{ImportedType{prototype}}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)} , accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
@@ -802,10 +803,10 @@ public:
{} {}
explicit Type(int sourceId, explicit Type(SourceId sourceId,
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
long long typeId, TypeId typeId,
long long prototypeId, TypeId prototypeId,
int accessSemantics, int accessSemantics,
Utils::SmallStringView defaultPropertyName) Utils::SmallStringView defaultPropertyName)
: typeName{typeName} : typeName{typeName}
@@ -855,7 +856,7 @@ public:
, fileType{fileType} , fileType{fileType}
{} {}
ProjectData(int projectSourceId, int sourceId, int moduleId, int fileType) ProjectData(SourceId projectSourceId, SourceId sourceId, ModuleId moduleId, int fileType)
: projectSourceId{projectSourceId} : projectSourceId{projectSourceId}
, sourceId{sourceId} , sourceId{sourceId}
, moduleId{moduleId} , moduleId{moduleId}
@@ -938,10 +939,7 @@ namespace QmlDesigner::Storage::Info {
class PropertyDeclaration class PropertyDeclaration
{ {
public: public:
PropertyDeclaration(long long typeId, PropertyDeclaration(TypeId typeId, Utils::SmallStringView name, long long traits, TypeId propertyTypeId)
Utils::SmallStringView name,
long long traits,
long long propertyTypeId)
: typeId{typeId} : typeId{typeId}
, name{name} , name{name}
, traits{static_cast<PropertyDeclarationTraits>(traits)} , traits{static_cast<PropertyDeclarationTraits>(traits)}
@@ -967,11 +965,6 @@ public:
class Type class Type
{ {
public: public:
Type(long long defaultPropertyId)
: defaultPropertyId{defaultPropertyId}
{}
Type(PropertyDeclarationId defaultPropertyId) Type(PropertyDeclarationId defaultPropertyId)
: defaultPropertyId{defaultPropertyId} : defaultPropertyId{defaultPropertyId}
{} {}

View File

@@ -57,11 +57,6 @@ public:
class SourceNameEntry class SourceNameEntry
{ {
public: public:
SourceNameEntry(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(Utils::SmallStringView sourceName, SourceContextId sourceContextId) SourceNameEntry(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName(sourceName) : sourceName(sourceName)
, sourceContextId(sourceContextId) , sourceContextId(sourceContextId)
@@ -129,10 +124,6 @@ public:
: Base{{sourceName, sourceContextId}, sourceId} : Base{{sourceName, sourceContextId}, sourceId}
{} {}
Source(Utils::SmallStringView sourceName, int sourceContextId, int sourceId)
: Base{{sourceName, SourceContextId{sourceContextId}}, SourceId{sourceId}}
{}
friend bool operator==(const Source &first, const Source &second) friend bool operator==(const Source &first, const Source &second)
{ {
return first.id == second.id && first.value == second.value; return first.id == second.id && first.value == second.value;
@@ -145,10 +136,7 @@ class SourceNameAndSourceContextId
{ {
public: public:
constexpr SourceNameAndSourceContextId() = default; constexpr SourceNameAndSourceContextId() = default;
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, SourceContextId sourceContextId) SourceNameAndSourceContextId(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName{sourceName} : sourceName{sourceName}
, sourceContextId{sourceContextId} , sourceContextId{sourceContextId}

View File

@@ -269,7 +269,7 @@ public:
{ {
std::shared_lock<Mutex> sharedLock(m_mutex); std::shared_lock<Mutex> sharedLock(m_mutex);
if (IndexType{static_cast<IndexDatabaseType>(m_indices.size())} > id) { if (IndexType::create(static_cast<IndexDatabaseType>(m_indices.size())) > id) {
if (auto indirectionIndex = m_indices.at(static_cast<std::size_t>(id)); if (auto indirectionIndex = m_indices.at(static_cast<std::size_t>(id));
indirectionIndex.isValid()) indirectionIndex.isValid())
return m_entries.at(static_cast<std::size_t>(indirectionIndex)).value; return m_entries.at(static_cast<std::size_t>(indirectionIndex)).value;

View File

@@ -36,11 +36,6 @@ public:
, id(id) , id(id)
{} {}
StorageCacheEntry(ViewType value, typename IndexType::DatabaseType id)
: value(value)
, id{id}
{}
operator ViewType() const noexcept { return value; } operator ViewType() const noexcept { return value; }
friend bool operator==(const StorageCacheEntry &first, const StorageCacheEntry &second) friend bool operator==(const StorageCacheEntry &first, const StorageCacheEntry &second)
{ {

View File

@@ -47,8 +47,8 @@ protected:
NiceMock<MockFunction<void(const SourceContextIds &sourceContextIds)>> mockCompressorCallback; NiceMock<MockFunction<void(const SourceContextIds &sourceContextIds)>> mockCompressorCallback;
QmlDesigner::DirectoryPathCompressor<NiceMock<MockTimer>> compressor; QmlDesigner::DirectoryPathCompressor<NiceMock<MockTimer>> compressor;
NiceMock<MockTimer> &mockTimer = compressor.timer(); NiceMock<MockTimer> &mockTimer = compressor.timer();
SourceContextId sourceContextId1{1}; SourceContextId sourceContextId1{SourceContextId::create(1)};
SourceContextId sourceContextId2{2}; SourceContextId sourceContextId2{SourceContextId::create(2)};
}; };
TEST_F(DirectoryPathCompressor, AddFilePath) TEST_F(DirectoryPathCompressor, AddFilePath)

View File

@@ -57,10 +57,10 @@ protected:
protected: protected:
NiceMock<FileSystemMock> fileSystem; NiceMock<FileSystemMock> fileSystem;
QmlDesigner::FileStatusCache cache{fileSystem}; QmlDesigner::FileStatusCache cache{fileSystem};
SourceId header{1}; SourceId header{SourceId::create(1)};
SourceId source{2}; SourceId source{SourceId::create(2)};
SourceId header2{3}; SourceId header2{SourceId::create(3)};
SourceId source2{4}; SourceId source2{SourceId::create(4)};
SourceIds entries{header, source, header2, source2}; SourceIds entries{header, source, header2, source2};
long long headerLastModifiedTime = 100; long long headerLastModifiedTime = 100;
long long headerLastModifiedTime2 = 110; long long headerLastModifiedTime2 = 110;

View File

@@ -1024,7 +1024,7 @@ TEST_F(ProjectStorage, FetchSourceContextPath)
TEST_F(ProjectStorage, FetchUnknownSourceContextPathThrows) TEST_F(ProjectStorage, FetchUnknownSourceContextPathThrows)
{ {
ASSERT_THROW(storage.fetchSourceContextPath(SourceContextId{323}), ASSERT_THROW(storage.fetchSourceContextPath(SourceContextId::create(323)),
QmlDesigner::SourceContextIdDoesNotExists); QmlDesigner::SourceContextIdDoesNotExists);
} }
@@ -1096,13 +1096,13 @@ TEST_F(ProjectStorage, FetchSourceIdWithDifferentNameAreNotEqual)
TEST_F(ProjectStorage, FetchSourceIdWithNonExistingSourceContextIdThrows) TEST_F(ProjectStorage, FetchSourceIdWithNonExistingSourceContextIdThrows)
{ {
ASSERT_THROW(storage.fetchSourceId(SourceContextId{42}, "foo"), ASSERT_THROW(storage.fetchSourceId(SourceContextId::create(42), "foo"),
Sqlite::ConstraintPreventsModification); Sqlite::ConstraintPreventsModification);
} }
TEST_F(ProjectStorage, FetchSourceNameAndSourceContextIdForNonExistingSourceId) TEST_F(ProjectStorage, FetchSourceNameAndSourceContextIdForNonExistingSourceId)
{ {
ASSERT_THROW(storage.fetchSourceNameAndSourceContextId(SourceId{212}), ASSERT_THROW(storage.fetchSourceNameAndSourceContextId(SourceId::create(212)),
QmlDesigner::SourceIdDoesNotExists); QmlDesigner::SourceIdDoesNotExists);
} }
@@ -1119,7 +1119,8 @@ TEST_F(ProjectStorage, FetchSourceNameAndSourceContextIdForNonExistingEntry)
TEST_F(ProjectStorage, FetchSourceContextIdForNonExistingSourceId) TEST_F(ProjectStorage, FetchSourceContextIdForNonExistingSourceId)
{ {
ASSERT_THROW(storage.fetchSourceContextId(SourceId{212}), QmlDesigner::SourceIdDoesNotExists); ASSERT_THROW(storage.fetchSourceContextId(SourceId::create(212)),
QmlDesigner::SourceIdDoesNotExists);
} }
TEST_F(ProjectStorage, FetchSourceContextIdForExistingSourceId) TEST_F(ProjectStorage, FetchSourceContextIdForExistingSourceId)
@@ -1194,7 +1195,7 @@ TEST_F(ProjectStorage, FetchSourceIdUnguardedWithNonExistingSourceContextIdThrow
{ {
std::lock_guard lock{database}; std::lock_guard lock{database};
ASSERT_THROW(storage.fetchSourceIdUnguarded(SourceContextId{42}, "foo"), ASSERT_THROW(storage.fetchSourceIdUnguarded(SourceContextId::create(42), "foo"),
Sqlite::ConstraintPreventsModification); Sqlite::ConstraintPreventsModification);
} }
@@ -1261,7 +1262,7 @@ TEST_F(ProjectStorage, SynchronizeTypesAddsNewTypesWithMissingModule)
Storage::Synchronization::ImportedType{}, Storage::Synchronization::ImportedType{},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
sourceId3, sourceId3,
{Storage::Synchronization::ExportedType{ModuleId{22}, "Object2"}, {Storage::Synchronization::ExportedType{ModuleId::create(22), "Object2"},
Storage::Synchronization::ExportedType{pathToModuleId, "Obj2"}}}); Storage::Synchronization::ExportedType{pathToModuleId, "Obj2"}}});
ASSERT_THROW(storage.synchronize(std::move(package)), QmlDesigner::ExportedTypeCannotBeInserted); ASSERT_THROW(storage.synchronize(std::move(package)), QmlDesigner::ExportedTypeCannotBeInserted);
@@ -4475,7 +4476,7 @@ TEST_F(ProjectStorage, ModuleNameThrowsIfIdIsInvalid)
TEST_F(ProjectStorage, ModuleNameThrowsIfIdDoesNotExists) TEST_F(ProjectStorage, ModuleNameThrowsIfIdDoesNotExists)
{ {
ASSERT_THROW(storage.moduleName(ModuleId{222}), QmlDesigner::ModuleDoesNotExists); ASSERT_THROW(storage.moduleName(ModuleId::create(222)), QmlDesigner::ModuleDoesNotExists);
} }
TEST_F(ProjectStorage, GetModuleName) TEST_F(ProjectStorage, GetModuleName)

View File

@@ -117,9 +117,9 @@ protected:
NiceMock<FileSystemMock> mockFileSystem; NiceMock<FileSystemMock> mockFileSystem;
Watcher watcher{sourcePathCacheMock, mockFileSystem, &notifier}; Watcher watcher{sourcePathCacheMock, mockFileSystem, &notifier};
NiceMock<MockQFileSytemWatcher> &mockQFileSytemWatcher = watcher.fileSystemWatcher(); NiceMock<MockQFileSytemWatcher> &mockQFileSytemWatcher = watcher.fileSystemWatcher();
ProjectChunkId id1{ProjectPartId{2}, SourceType::Qml}; ProjectChunkId id1{ProjectPartId::create(2), SourceType::Qml};
ProjectChunkId id2{ProjectPartId{2}, SourceType::QmlUi}; ProjectChunkId id2{ProjectPartId::create(2), SourceType::QmlUi};
ProjectChunkId id3{ProjectPartId{4}, SourceType::QmlTypes}; ProjectChunkId id3{ProjectPartId::create(4), SourceType::QmlTypes};
SourcePathView path1{"/path/path1"}; SourcePathView path1{"/path/path1"};
SourcePathView path2{"/path/path2"}; SourcePathView path2{"/path/path2"};
SourcePathView path3{"/path2/path1"}; SourcePathView path3{"/path2/path1"};
@@ -132,8 +132,14 @@ protected:
QString sourceContextPath3 = "/path3"; QString sourceContextPath3 = "/path3";
Utils::PathString sourceContextPathString = sourceContextPath; Utils::PathString sourceContextPathString = sourceContextPath;
Utils::PathString sourceContextPathString2 = sourceContextPath2; Utils::PathString sourceContextPathString2 = sourceContextPath2;
SourceIds pathIds = {SourceId{1}, SourceId{2}, SourceId{3}, SourceId{4}, SourceId{5}}; SourceIds pathIds = {SourceId::create(1),
SourceContextIds sourceContextIds = {SourceContextId{1}, SourceContextId{2}, SourceContextId{3}}; SourceId::create(2),
SourceId::create(3),
SourceId::create(4),
SourceId::create(5)};
SourceContextIds sourceContextIds = {SourceContextId::create(1),
SourceContextId::create(2),
SourceContextId::create(3)};
ProjectChunkIds ids{id1, id2, id3}; ProjectChunkIds ids{id1, id2, id3};
WatcherEntry watcherEntry1{id1, sourceContextIds[0], pathIds[0]}; WatcherEntry watcherEntry1{id1, sourceContextIds[0], pathIds[0]};
WatcherEntry watcherEntry2{id2, sourceContextIds[0], pathIds[0]}; WatcherEntry watcherEntry2{id2, sourceContextIds[0], pathIds[0]};
@@ -273,7 +279,7 @@ TEST_F(ProjectStoragePathWatcher, RemoveEntriesWithId)
{id2, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1]}},
{id3, {pathIds[1], pathIds[3]}}}); {id3, {pathIds[1], pathIds[3]}}});
watcher.removeIds({ProjectPartId{2}}); watcher.removeIds({ProjectPartId::create(2)});
ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry5, watcherEntry8)); ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry5, watcherEntry8));
} }
@@ -370,9 +376,9 @@ TEST_F(ProjectStoragePathWatcher, TwoNotifyFileChanges)
.WillByDefault(Return(FileStatus{pathIds[3], 1, 2})); .WillByDefault(Return(FileStatus{pathIds[3], 1, 2}));
EXPECT_CALL(notifier, EXPECT_CALL(notifier,
pathsWithIdsChanged( pathsWithIdsChanged(ElementsAre(
ElementsAre(IdPaths{id1, {SourceId{1}, SourceId{2}}}, IdPaths{id1, {SourceId::create(1), SourceId::create(2)}},
IdPaths{id2, {SourceId{1}, SourceId{2}, SourceId{4}}}))); IdPaths{id2, {SourceId::create(1), SourceId::create(2), SourceId::create(4)}})));
mockQFileSytemWatcher.directoryChanged(sourceContextPath); mockQFileSytemWatcher.directoryChanged(sourceContextPath);
mockQFileSytemWatcher.directoryChanged(sourceContextPath2); mockQFileSytemWatcher.directoryChanged(sourceContextPath2);

View File

@@ -47,32 +47,33 @@ protected:
SourcePathCache() SourcePathCache()
{ {
ON_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))) ON_CALL(storageMock, fetchSourceContextId(Eq("/path/to")))
.WillByDefault(Return(SourceContextId{5})); .WillByDefault(Return(SourceContextId::create(5)));
ON_CALL(storageMock, fetchSourceContextId(Eq("/path2/to"))) ON_CALL(storageMock, fetchSourceContextId(Eq("/path2/to")))
.WillByDefault(Return(SourceContextId{6})); .WillByDefault(Return(SourceContextId::create(6)));
ON_CALL(storageMock, fetchSourceId(SourceContextId{5}, Eq("file.cpp"))) ON_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")))
.WillByDefault(Return(SourceId{42})); .WillByDefault(Return(SourceId::create(42)));
ON_CALL(storageMock, fetchSourceId(SourceContextId{5}, Eq("file2.cpp"))) ON_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file2.cpp")))
.WillByDefault(Return(SourceId{63})); .WillByDefault(Return(SourceId::create(63)));
ON_CALL(storageMock, fetchSourceId(SourceContextId{6}, Eq("file.cpp"))) ON_CALL(storageMock, fetchSourceId(SourceContextId::create(6), Eq("file.cpp")))
.WillByDefault(Return(SourceId{72})); .WillByDefault(Return(SourceId::create(72)));
ON_CALL(storageMock, fetchSourceContextPath(SourceContextId{5})) ON_CALL(storageMock, fetchSourceContextPath(SourceContextId::create(5)))
.WillByDefault(Return(Utils::PathString("/path/to"))); .WillByDefault(Return(Utils::PathString("/path/to")));
ON_CALL(storageMock, fetchSourceNameAndSourceContextId(SourceId{42})) ON_CALL(storageMock, fetchSourceNameAndSourceContextId(SourceId::create(42)))
.WillByDefault(Return(SourceNameAndSourceContextId("file.cpp", SourceContextId{5}))); .WillByDefault(
Return(SourceNameAndSourceContextId("file.cpp", SourceContextId::create(5))));
ON_CALL(storageMockFilled, fetchAllSources()) ON_CALL(storageMockFilled, fetchAllSources())
.WillByDefault(Return(std::vector<QmlDesigner::Cache::Source>({ .WillByDefault(Return(std::vector<QmlDesigner::Cache::Source>({
{"file.cpp", SourceContextId{6}, SourceId{72}}, {"file.cpp", SourceContextId::create(6), SourceId::create(72)},
{"file2.cpp", SourceContextId{5}, SourceId{63}}, {"file2.cpp", SourceContextId::create(5), SourceId::create(63)},
{"file.cpp", SourceContextId{5}, SourceId{42}}, {"file.cpp", SourceContextId::create(5), SourceId::create(42)},
}))); })));
ON_CALL(storageMockFilled, fetchAllSourceContexts()) ON_CALL(storageMockFilled, fetchAllSourceContexts())
.WillByDefault(Return(std::vector<QmlDesigner::Cache::SourceContext>( .WillByDefault(Return(std::vector<QmlDesigner::Cache::SourceContext>(
{{"/path2/to", SourceContextId{6}}, {"/path/to", SourceContextId{5}}}))); {{"/path2/to", SourceContextId::create(6)}, {"/path/to", SourceContextId::create(5)}})));
ON_CALL(storageMockFilled, fetchSourceContextId(Eq("/path/to"))) ON_CALL(storageMockFilled, fetchSourceContextId(Eq("/path/to")))
.WillByDefault(Return(SourceContextId{5})); .WillByDefault(Return(SourceContextId::create(5)));
ON_CALL(storageMockFilled, fetchSourceId(SourceContextId{5}, Eq("file.cpp"))) ON_CALL(storageMockFilled, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")))
.WillByDefault(Return(SourceId{42})); .WillByDefault(Return(SourceId::create(42)));
} }
protected: protected:
@@ -91,7 +92,7 @@ TEST_F(SourcePathCache, SourceIdWithOutAnyEntryCallSourceContextId)
TEST_F(SourcePathCache, SourceIdWithOutAnyEntryCalls) TEST_F(SourcePathCache, SourceIdWithOutAnyEntryCalls)
{ {
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId{5}, Eq("file.cpp"))); EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")));
cache.sourceId(SourcePathView("/path/to/file.cpp")); cache.sourceId(SourcePathView("/path/to/file.cpp"));
} }
@@ -100,7 +101,7 @@ TEST_F(SourcePathCache, SourceIdOfSourceIdWithOutAnyEntry)
{ {
auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp")); auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
ASSERT_THAT(sourceId, SourceId{42}); ASSERT_THAT(sourceId, SourceId::create(42));
} }
TEST_F(SourcePathCache, SourceIdWithSourceContextIdAndSourceName) TEST_F(SourcePathCache, SourceIdWithSourceContextIdAndSourceName)
@@ -109,7 +110,7 @@ TEST_F(SourcePathCache, SourceIdWithSourceContextIdAndSourceName)
auto sourceId = cache.sourceId(sourceContextId, "file.cpp"_sv); auto sourceId = cache.sourceId(sourceContextId, "file.cpp"_sv);
ASSERT_THAT(sourceId, SourceId{42}); ASSERT_THAT(sourceId, SourceId::create(42));
} }
TEST_F(SourcePathCache, IfEntryExistsDontCallInStrorage) TEST_F(SourcePathCache, IfEntryExistsDontCallInStrorage)
@@ -117,7 +118,7 @@ TEST_F(SourcePathCache, IfEntryExistsDontCallInStrorage)
cache.sourceId(SourcePathView("/path/to/file.cpp")); cache.sourceId(SourcePathView("/path/to/file.cpp"));
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0); EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0);
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId{5}, Eq("file.cpp"))).Times(0); EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp"))).Times(0);
cache.sourceId(SourcePathView("/path/to/file.cpp")); cache.sourceId(SourcePathView("/path/to/file.cpp"));
} }
@@ -127,7 +128,7 @@ TEST_F(SourcePathCache, IfDirectoryEntryExistsDontCallFetchSourceContextIdButSti
cache.sourceId(SourcePathView("/path/to/file2.cpp")); cache.sourceId(SourcePathView("/path/to/file2.cpp"));
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0); EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0);
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId{5}, Eq("file.cpp"))); EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")));
cache.sourceId(SourcePathView("/path/to/file.cpp")); cache.sourceId(SourcePathView("/path/to/file.cpp"));
} }
@@ -138,7 +139,7 @@ TEST_F(SourcePathCache, GetSourceIdWithCachedValue)
auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp")); auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
ASSERT_THAT(sourceId, SourceId{42}); ASSERT_THAT(sourceId, SourceId::create(42));
} }
TEST_F(SourcePathCache, GetSourceIdWithSourceContextIdCached) TEST_F(SourcePathCache, GetSourceIdWithSourceContextIdCached)
@@ -147,7 +148,7 @@ TEST_F(SourcePathCache, GetSourceIdWithSourceContextIdCached)
auto sourceId = cache.sourceId(SourcePathView("/path/to/file2.cpp")); auto sourceId = cache.sourceId(SourcePathView("/path/to/file2.cpp"));
ASSERT_THAT(sourceId, SourceId{63}); ASSERT_THAT(sourceId, SourceId::create(63));
} }
TEST_F(SourcePathCache, ThrowForGettingAFilePathWithAnInvalidId) TEST_F(SourcePathCache, ThrowForGettingAFilePathWithAnInvalidId)
@@ -168,7 +169,7 @@ TEST_F(SourcePathCache, GetAFilePath)
TEST_F(SourcePathCache, GetAFilePathWithCachedSourceId) TEST_F(SourcePathCache, GetAFilePathWithCachedSourceId)
{ {
SourceId sourceId{42}; SourceId sourceId{SourceId::create(42)};
auto sourcePath = cache.sourcePath(sourceId); auto sourcePath = cache.sourcePath(sourceId);
@@ -220,7 +221,7 @@ TEST_F(SourcePathCache, SourceContextId)
{ {
auto id = cache.sourceContextId(Utils::SmallString("/path/to")); auto id = cache.sourceContextId(Utils::SmallString("/path/to"));
ASSERT_THAT(id, Eq(SourceContextId{5})); ASSERT_THAT(id, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCache) TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCache)
@@ -269,7 +270,7 @@ TEST_F(SourcePathCache, ThrowForGettingADirectoryPathWithAnInvalidId)
TEST_F(SourcePathCache, GetADirectoryPath) TEST_F(SourcePathCache, GetADirectoryPath)
{ {
SourceContextId sourceContextId{5}; SourceContextId sourceContextId{SourceContextId::create(5)};
auto sourceContextPath = cache.sourceContextPath(sourceContextId); auto sourceContextPath = cache.sourceContextPath(sourceContextId);
@@ -278,7 +279,7 @@ TEST_F(SourcePathCache, GetADirectoryPath)
TEST_F(SourcePathCache, GetADirectoryPathWithCachedSourceContextId) TEST_F(SourcePathCache, GetADirectoryPathWithCachedSourceContextId)
{ {
SourceContextId sourceContextId{5}; SourceContextId sourceContextId{SourceContextId::create(5)};
cache.sourceContextPath(sourceContextId); cache.sourceContextPath(sourceContextId);
auto sourceContextPath = cache.sourceContextPath(sourceContextId); auto sourceContextPath = cache.sourceContextPath(sourceContextId);
@@ -288,18 +289,18 @@ TEST_F(SourcePathCache, GetADirectoryPathWithCachedSourceContextId)
TEST_F(SourcePathCache, DirectoryPathCallsFetchDirectoryPath) TEST_F(SourcePathCache, DirectoryPathCallsFetchDirectoryPath)
{ {
EXPECT_CALL(storageMock, fetchSourceContextPath(Eq(SourceContextId{5}))); EXPECT_CALL(storageMock, fetchSourceContextPath(Eq(SourceContextId::create(5))));
cache.sourceContextPath(SourceContextId{5}); cache.sourceContextPath(SourceContextId::create(5));
} }
TEST_F(SourcePathCache, SecondDirectoryPathCallsNotFetchDirectoryPath) TEST_F(SourcePathCache, SecondDirectoryPathCallsNotFetchDirectoryPath)
{ {
cache.sourceContextPath(SourceContextId{5}); cache.sourceContextPath(SourceContextId::create(5));
EXPECT_CALL(storageMock, fetchSourceContextPath(_)).Times(0); EXPECT_CALL(storageMock, fetchSourceContextPath(_)).Times(0);
cache.sourceContextPath(SourceContextId{5}); cache.sourceContextPath(SourceContextId::create(5));
} }
TEST_F(SourcePathCache, ThrowForGettingASourceContextIdWithAnInvalidSourceId) TEST_F(SourcePathCache, ThrowForGettingASourceContextIdWithAnInvalidSourceId)
@@ -311,36 +312,36 @@ TEST_F(SourcePathCache, ThrowForGettingASourceContextIdWithAnInvalidSourceId)
TEST_F(SourcePathCache, FetchSourceContextIdBySourceId) TEST_F(SourcePathCache, FetchSourceContextIdBySourceId)
{ {
auto sourceContextId = cache.sourceContextId(SourceId{42}); auto sourceContextId = cache.sourceContextId(SourceId::create(42));
ASSERT_THAT(sourceContextId, Eq(SourceContextId{5})); ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, FetchSourceContextIdBySourceIdCached) TEST_F(SourcePathCache, FetchSourceContextIdBySourceIdCached)
{ {
cache.sourceContextId(SourceId{42}); cache.sourceContextId(SourceId::create(42));
auto sourceContextId = cache.sourceContextId(SourceId{42}); auto sourceContextId = cache.sourceContextId(SourceId::create(42));
ASSERT_THAT(sourceContextId, Eq(SourceContextId{5})); ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, FetchFilePathAfterFetchingSourceContextIdBySourceId) TEST_F(SourcePathCache, FetchFilePathAfterFetchingSourceContextIdBySourceId)
{ {
cache.sourceContextId(SourceId{42}); cache.sourceContextId(SourceId::create(42));
auto sourcePath = cache.sourcePath(SourceId{42}); auto sourcePath = cache.sourcePath(SourceId::create(42));
ASSERT_THAT(sourcePath, Eq("/path/to/file.cpp")); ASSERT_THAT(sourcePath, Eq("/path/to/file.cpp"));
} }
TEST_F(SourcePathCache, FetchSourceContextIdAfterFetchingFilePathBySourceId) TEST_F(SourcePathCache, FetchSourceContextIdAfterFetchingFilePathBySourceId)
{ {
cache.sourcePath(SourceId{42}); cache.sourcePath(SourceId::create(42));
auto sourceContextId = cache.sourceContextId(SourceId{42}); auto sourceContextId = cache.sourceContextId(SourceId::create(42));
ASSERT_THAT(sourceContextId, Eq(SourceContextId{5})); ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, FetchAllSourceContextsAndSourcesAtCreation) TEST_F(SourcePathCache, FetchAllSourceContextsAndSourcesAtCreation)
@@ -357,23 +358,23 @@ TEST_F(SourcePathCache, GetFileIdInFilledCache)
auto id = cacheFilled.sourceId("/path2/to/file.cpp"); auto id = cacheFilled.sourceId("/path2/to/file.cpp");
ASSERT_THAT(id, Eq(SourceId{72})); ASSERT_THAT(id, Eq(SourceId::create(72)));
} }
TEST_F(SourcePathCache, GetSourceContextIdInFilledCache) TEST_F(SourcePathCache, GetSourceContextIdInFilledCache)
{ {
Cache cacheFilled{storageMockFilled}; Cache cacheFilled{storageMockFilled};
auto id = cacheFilled.sourceContextId(SourceId{42}); auto id = cacheFilled.sourceContextId(SourceId::create(42));
ASSERT_THAT(id, Eq(SourceContextId{5})); ASSERT_THAT(id, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, GetDirectoryPathInFilledCache) TEST_F(SourcePathCache, GetDirectoryPathInFilledCache)
{ {
Cache cacheFilled{storageMockFilled}; Cache cacheFilled{storageMockFilled};
auto path = cacheFilled.sourceContextPath(SourceContextId{5}); auto path = cacheFilled.sourceContextPath(SourceContextId::create(5));
ASSERT_THAT(path, Eq("/path/to")); ASSERT_THAT(path, Eq("/path/to"));
} }
@@ -382,7 +383,7 @@ TEST_F(SourcePathCache, GetFilePathInFilledCache)
{ {
Cache cacheFilled{storageMockFilled}; Cache cacheFilled{storageMockFilled};
auto path = cacheFilled.sourcePath(SourceId{42}); auto path = cacheFilled.sourcePath(SourceId::create(42));
ASSERT_THAT(path, Eq("/path/to/file.cpp")); ASSERT_THAT(path, Eq("/path/to/file.cpp"));
} }
@@ -393,7 +394,7 @@ TEST_F(SourcePathCache, GetFileIdInAfterPopulateIfEmpty)
auto id = cacheNotFilled.sourceId("/path2/to/file.cpp"); auto id = cacheNotFilled.sourceId("/path2/to/file.cpp");
ASSERT_THAT(id, Eq(SourceId{72})); ASSERT_THAT(id, Eq(SourceId::create(72)));
} }
TEST_F(SourcePathCache, DontPopulateIfNotEmpty) TEST_F(SourcePathCache, DontPopulateIfNotEmpty)
@@ -410,16 +411,16 @@ TEST_F(SourcePathCache, GetSourceContextIdAfterPopulateIfEmpty)
{ {
cacheNotFilled.populateIfEmpty(); cacheNotFilled.populateIfEmpty();
auto id = cacheNotFilled.sourceContextId(SourceId{42}); auto id = cacheNotFilled.sourceContextId(SourceId::create(42));
ASSERT_THAT(id, Eq(SourceContextId{5})); ASSERT_THAT(id, Eq(SourceContextId::create(5)));
} }
TEST_F(SourcePathCache, GetDirectoryPathAfterPopulateIfEmpty) TEST_F(SourcePathCache, GetDirectoryPathAfterPopulateIfEmpty)
{ {
cacheNotFilled.populateIfEmpty(); cacheNotFilled.populateIfEmpty();
auto path = cacheNotFilled.sourceContextPath(SourceContextId{5}); auto path = cacheNotFilled.sourceContextPath(SourceContextId::create(5));
ASSERT_THAT(path, Eq("/path/to")); ASSERT_THAT(path, Eq("/path/to"));
} }
@@ -428,7 +429,7 @@ TEST_F(SourcePathCache, GetFilePathAfterPopulateIfEmptye)
{ {
cacheNotFilled.populateIfEmpty(); cacheNotFilled.populateIfEmpty();
auto path = cacheNotFilled.sourcePath(SourceId{42}); auto path = cacheNotFilled.sourcePath(SourceId::create(42));
ASSERT_THAT(path, Eq("/path/to/file.cpp")); ASSERT_THAT(path, Eq("/path/to/file.cpp"));
} }

View File

@@ -1162,6 +1162,11 @@ TEST_F(SqliteStatement, GetValueCallsReset)
{ {
struct Value struct Value
{ {
Value() = default;
Value(int x)
: x(x)
{}
int x = 0; int x = 0;
}; };
MockSqliteStatement<1, 1> mockStatement{databaseMock}; MockSqliteStatement<1, 1> mockStatement{databaseMock};
@@ -1175,6 +1180,11 @@ TEST_F(SqliteStatement, GetValueCallsResetIfExceptionIsThrown)
{ {
struct Value struct Value
{ {
Value() = default;
Value(int x)
: x(x)
{}
int x = 0; int x = 0;
}; };
MockSqliteStatement<1, 1> mockStatement{databaseMock}; MockSqliteStatement<1, 1> mockStatement{databaseMock};

View File

@@ -112,16 +112,16 @@ protected:
Utils::PathString filePath5{"/file/pathFife"}; Utils::PathString filePath5{"/file/pathFife"};
Utils::PathStringVector filePaths{filePath1, filePath2, filePath3, filePath4, filePath5}; Utils::PathStringVector filePaths{filePath1, filePath2, filePath3, filePath4, filePath5};
Utils::PathStringVector reverseFilePaths{filePath1, filePath2, filePath3, filePath4, filePath5}; Utils::PathStringVector reverseFilePaths{filePath1, filePath2, filePath3, filePath4, filePath5};
SourceContextId id1{0}; SourceContextId id1{SourceContextId::create(0)};
SourceContextId id2{1}; SourceContextId id2{SourceContextId::create(1)};
SourceContextId id3{2}; SourceContextId id3{SourceContextId::create(2)};
SourceContextId id4{3}; SourceContextId id4{SourceContextId::create(3)};
SourceContextId id5{4}; SourceContextId id5{SourceContextId::create(4)};
SourceContextId id41{41}; SourceContextId id41{SourceContextId::create(41)};
SourceContextId id42{42}; SourceContextId id42{SourceContextId::create(42)};
SourceContextId id43{43}; SourceContextId id43{SourceContextId::create(43)};
SourceContextId id44{44}; SourceContextId id44{SourceContextId::create(44)};
SourceContextId id45{45}; SourceContextId id45{SourceContextId::create(45)};
}; };
using CacheTypes = ::testing::Types<CacheWithMockLocking, CacheWithoutLocking>; using CacheTypes = ::testing::Types<CacheWithMockLocking, CacheWithoutLocking>;
@@ -240,7 +240,7 @@ TYPED_TEST(StorageCache, IsNotEmptyAfterPopulateWithSomeEntries)
typename TypeParam::CacheEntries entries{{this->filePath1.clone(), this->id1}, typename TypeParam::CacheEntries entries{{this->filePath1.clone(), this->id1},
{this->filePath2.clone(), this->id4}, {this->filePath2.clone(), this->id4},
{this->filePath3.clone(), this->id3}, {this->filePath3.clone(), this->id3},
{this->filePath4.clone(), SourceContextId{5}}}; {this->filePath4.clone(), SourceContextId::create(5)}};
ON_CALL(this->mockStorage, fetchAllSourceContexts()).WillByDefault(Return(entries)); ON_CALL(this->mockStorage, fetchAllSourceContexts()).WillByDefault(Return(entries));
this->cache.uncheckedPopulate(); this->cache.uncheckedPopulate();
@@ -252,12 +252,12 @@ TYPED_TEST(StorageCache, GetEntryAfterPopulateWithSomeEntries)
{ {
typename TypeParam::CacheEntries entries{{this->filePath1.clone(), this->id1}, typename TypeParam::CacheEntries entries{{this->filePath1.clone(), this->id1},
{this->filePath2.clone(), this->id2}, {this->filePath2.clone(), this->id2},
{this->filePath3.clone(), SourceContextId{7}}, {this->filePath3.clone(), SourceContextId::create(7)},
{this->filePath4.clone(), this->id4}}; {this->filePath4.clone(), this->id4}};
ON_CALL(this->mockStorage, fetchAllSourceContexts()).WillByDefault(Return(entries)); ON_CALL(this->mockStorage, fetchAllSourceContexts()).WillByDefault(Return(entries));
this->cache.uncheckedPopulate(); this->cache.uncheckedPopulate();
auto value = this->cache.value(SourceContextId{7}); auto value = this->cache.value(SourceContextId::create(7));
ASSERT_THAT(value, this->filePath3); ASSERT_THAT(value, this->filePath3);
} }
@@ -442,7 +442,7 @@ TYPED_TEST(StorageCache, GetEntryByIndexAfterInsertingByCustomIndex)
TYPED_TEST(StorageCache, CallFetchSourceContextPathForLowerIndex) TYPED_TEST(StorageCache, CallFetchSourceContextPathForLowerIndex)
{ {
auto index = this->cache.id("foo"); auto index = this->cache.id("foo");
SourceContextId lowerIndex{&index - 1}; SourceContextId lowerIndex{SourceContextId::create(&index - 1)};
EXPECT_CALL(this->mockStorage, fetchSourceContextPath(Eq(lowerIndex))); EXPECT_CALL(this->mockStorage, fetchSourceContextPath(Eq(lowerIndex)));