add catch2 based test setup including some basic test cases

This commit is contained in:
mlangkabel
2018-12-10 20:26:32 +01:00
parent a69232afed
commit 4d5b97b7e6
19 changed files with 15389 additions and 126 deletions
+43 -16
View File
@@ -19,9 +19,19 @@
#include <memory>
#include <string>
#include <vector>
#include "sqlite/CppSQLite3.h"
#include "StorageEdge.h"
#include "StorageError.h"
#include "StorageFile.h"
#include "StorageLocalSymbol.h"
#include "StorageNode.h"
#include "StorageOccurrence.h"
#include "StorageSourceLocation.h"
#include "StorageSymbol.h"
namespace sourcetrail
{
/**
@@ -49,25 +59,23 @@ namespace sourcetrail
void rollbackTransaction();
void optimizeDatabaseMemory();
int addNode(const std::string& serializedNameHierarchy);
void addSymbol(int symbolId, int definitionKind);
void addFile(int nodeId, const std::string& filePath);
int addEdge(int sourceId, int targetId, int edgeKind);
int addLocalSymbol(const std::string& name);
int addSourceLocation(
int fileId,
int startLineNumber,
int startColumnNumber,
int endLineNumber,
int endColumnNumber,
int locationKind);
void addOccurrence(int elementId, int sourceLocationId);
int addError(
const std::string& message,
bool fatal);
int addNode(const StorageNodeData& storageNodeData);
void addSymbol(const StorageSymbol& storageSymbol);
void addFile(const StorageFile& storageFile);
int addEdge(const StorageEdgeData& storageEdgeData);
int addLocalSymbol(const StorageLocalSymbolData& storageLocalSymbolData);
int addSourceLocation(const StorageSourceLocationData& storageSourceLocationData);
void addOccurrence(const StorageOccurrence& storageOccurrence);
int addError(const StorageErrorData& storageErrorData);
void setNodeType(int nodeId, int nodeKind);
template <typename ResultType>
std::vector<ResultType> getAll() const
{
return doGetAll<ResultType>("");
}
private:
DatabaseStorage() = default;
@@ -77,9 +85,28 @@ namespace sourcetrail
CppSQLite3Query executeQuery(const std::string& query) const;
CppSQLite3Query executeQuery(CppSQLite3Statement& statement) const;
template <typename ResultType>
std::vector<ResultType> doGetAll(const std::string& query) const;
mutable CppSQLite3DB m_database;
};
template <>
std::vector<StorageEdge> DatabaseStorage::doGetAll<StorageEdge>(const std::string& query) const;
template <>
std::vector<StorageNode> DatabaseStorage::doGetAll<StorageNode>(const std::string& query) const;
template <>
std::vector<StorageSymbol> DatabaseStorage::doGetAll<StorageSymbol>(const std::string& query) const;
template <>
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const;
template <>
std::vector<StorageLocalSymbol> DatabaseStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
template <>
std::vector<StorageSourceLocation> DatabaseStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
template <>
std::vector<StorageOccurrence> DatabaseStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
template <>
std::vector<StorageError> DatabaseStorage::doGetAll<StorageError>(const std::string& query) const;
}
#endif // SOURCETRAIL_DATABASE_STORAGE_H
+9 -12
View File
@@ -20,18 +20,17 @@
#include <memory>
#include <string>
#include "DefinitionKind.h"
#include "EdgeKind.h"
#include "LocationKind.h"
#include "NameHierarchy.h"
#include "ReferenceKind.h"
#include "SourceRange.h"
#include "SymbolKind.h"
namespace sourcetrail
{
class DatabaseStorage;
struct SourceRange;
struct NameHierarchy;
enum DefinitionKind;
enum EdgeKind;
enum LocationKind;
enum ReferenceKind;
enum SymbolKind;
class DatabaseStorage; // forward declaration prevents leakage of sqlite include dependency to users of the SourcetrailDBWriter
/**
* Class wrapping the main interface for writing data to a Sourcetrail project database.
@@ -89,8 +88,6 @@ namespace sourcetrail
private:
static std::string serializeNameHierarchy(const NameHierarchy& nameHierarchy);
std::string getProjectFilePath() const;
std::string getDatabaseFilePath() const;
void openDatabase();
void closeDatabase();
void setupDatabaseTables();
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_EDGE_H
#define SOURCETRAIL_STORAGE_EDGE_H
namespace sourcetrail
{
struct StorageEdgeData
{
StorageEdgeData()
: sourceNodeId(0)
, targetNodeId(0)
, edgeKind(0)
{}
StorageEdgeData(int sourceNodeId, int targetNodeId, int edgeKind)
: sourceNodeId(sourceNodeId)
, targetNodeId(targetNodeId)
, edgeKind(edgeKind)
{}
int sourceNodeId;
int targetNodeId;
int edgeKind;
};
struct StorageEdge : public StorageEdgeData
{
StorageEdge()
: StorageEdgeData()
, id(0)
{}
StorageEdge(int id, const StorageEdgeData& data)
: StorageEdgeData(data)
, id(id)
{}
StorageEdge(int id, int sourceNodeId, int targetNodeId, int edgeKind)
: StorageEdgeData(sourceNodeId, targetNodeId, edgeKind)
, id(id)
{}
int id;
};
}
#endif // SOURCETRAIL_STORAGE_EDGE_H
+84
View File
@@ -0,0 +1,84 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_ERROR_H
#define SOURCETRAIL_STORAGE_ERROR_H
#include <string>
namespace sourcetrail
{
struct StorageErrorData
{
StorageErrorData()
: message("")
, translationUnit("")
, fatal(0)
, indexed(0)
{}
StorageErrorData(
std::string message,
std::string translationUnit,
bool fatal,
bool indexed
)
: message(std::move(message))
, translationUnit(std::move(translationUnit))
, fatal(fatal)
, indexed(indexed)
{}
std::string message;
std::string translationUnit;
bool fatal;
bool indexed;
};
struct StorageError : public StorageErrorData
{
StorageError()
: StorageErrorData()
, id(0)
{}
StorageError(int id, const StorageErrorData& data)
: StorageErrorData(data)
, id(id)
{}
StorageError(
int id,
std::string message,
std::string translationUnit,
bool fatal,
bool indexed
)
: StorageErrorData(
std::move(message),
std::move(translationUnit),
fatal,
indexed
)
, id(id)
{}
int id;
};
}
#endif // SOURCETRAIL_STORAGE_ERROR_H
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_FILE_H
#define SOURCETRAIL_STORAGE_FILE_H
#include <string>
namespace sourcetrail
{
struct StorageFile
{
StorageFile()
: id(0)
, filePath("")
, modificationTime("")
, indexed(true)
, complete(true)
{}
StorageFile(int id, std::string filePath, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, modificationTime("")
, indexed(indexed)
, complete(complete)
{}
StorageFile(int id, std::string filePath, std::string modificationTime, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, modificationTime(std::move(modificationTime))
, indexed(indexed)
, complete(complete)
{}
int id;
std::string filePath;
std::string modificationTime;
bool indexed;
bool complete;
};
}
#endif // SOURCETRAIL_STORAGE_FILE_H
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
#define SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
#include <string>
namespace sourcetrail
{
struct StorageLocalSymbolData
{
StorageLocalSymbolData()
: name("")
{}
StorageLocalSymbolData(std::string name)
: name(std::move(name))
{}
std::string name;
};
struct StorageLocalSymbol : public StorageLocalSymbolData
{
StorageLocalSymbol()
: StorageLocalSymbolData()
, id(0)
{}
StorageLocalSymbol(int id, const StorageLocalSymbolData& data)
: StorageLocalSymbolData(data)
, id(id)
{}
StorageLocalSymbol(int id, std::string name)
: StorageLocalSymbolData(std::move(name))
, id(id)
{}
int id;
};
}
#endif // SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_NODE_H
#define SOURCETRAIL_STORAGE_NODE_H
#include <string>
namespace sourcetrail
{
struct StorageNodeData
{
StorageNodeData()
: nodeKind(0)
, serializedName("")
{}
StorageNodeData(int nodeKind, std::string serializedName)
: nodeKind(nodeKind)
, serializedName(std::move(serializedName))
{}
int nodeKind;
std::string serializedName;
};
struct StorageNode : public StorageNodeData
{
StorageNode()
: StorageNodeData()
, id(0)
{}
StorageNode(int id, int nodeKind, std::string serializedName)
: StorageNodeData(nodeKind, std::move(serializedName))
, id(id)
{}
StorageNode(int id, const StorageNodeData& data)
: StorageNodeData(data)
, id(id)
{}
int id;
};
}
#endif // SOURCETRAIL_STORAGE_NODE_H
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_OCCURRENCE_H
#define SOURCETRAIL_STORAGE_OCCURRENCE_H
namespace sourcetrail
{
struct StorageOccurrence
{
StorageOccurrence()
: elementId(0)
, sourceLocationId(0)
{}
StorageOccurrence(int elementId, int sourceLocationId)
: elementId(elementId)
, sourceLocationId(sourceLocationId)
{}
int elementId;
int sourceLocationId;
};
}
#endif // SOURCETRAIL_STORAGE_OCCURRENCE_H
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
#define SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
namespace sourcetrail
{
struct StorageSourceLocationData
{
StorageSourceLocationData()
: fileNodeId(0)
, startLineNumber(-1)
, startColumnNumber(-1)
, endLineNumber(-1)
, endColumnNumber(-1)
, locationKind(0)
{}
StorageSourceLocationData(int fileNodeId, int startLineNumber, int startColumnNumber, int endLineNumber, int endColumnNumber, int locationKind)
: fileNodeId(fileNodeId)
, startLineNumber(startLineNumber)
, startColumnNumber(startColumnNumber)
, endLineNumber(endLineNumber)
, endColumnNumber(endColumnNumber)
, locationKind(locationKind)
{}
int fileNodeId;
int startLineNumber;
int startColumnNumber;
int endLineNumber;
int endColumnNumber;
int locationKind;
};
struct StorageSourceLocation : public StorageSourceLocationData
{
StorageSourceLocation()
: StorageSourceLocationData()
, id(0)
{}
StorageSourceLocation(int id, const StorageSourceLocationData& data)
: StorageSourceLocationData(data)
, id(id)
{}
StorageSourceLocation(int id, int fileNodeId, int startLineNumber, int startColumnNumber, int endLineNumber, int endColumnNumber, int locationKind)
: StorageSourceLocationData(fileNodeId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber, locationKind)
, id(id)
{}
int id;
};
}
#endif // SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_SYMBOL_H
#define SOURCETRAIL_STORAGE_SYMBOL_H
#include "DefinitionKind.h"
namespace sourcetrail
{
struct StorageSymbol
{
StorageSymbol()
: id(0)
, definitionKind(definitionKindToInt(DEFINITION_EXPLICIT))
{}
StorageSymbol(int id, int definitionKind)
: id(id)
, definitionKind(definitionKind)
{}
int id;
int definitionKind;
};
}
#endif // SOURCETRAIL_STORAGE_SYMBOL_H
-1
View File
@@ -26,7 +26,6 @@ namespace sourcetrail
{
bool getFileExists(const std::string& filePath);
std::string getFileContent(const std::string& filePath);
time_t getFileModificationTime(const std::string& filePath);
std::string getDateTimeString(const time_t& time);
int getLineCount(const std::string s);
}