* replaced the implementation of the search index. the search index now uses a search-trie. edges have gates that can be used to check if a character can be matched when following the edge. * SearchMatches now have a text and a list of NameHierarchies that share this node (instead of Ids, so that nodes must be found by names (which makes sure that SearchMatches are still valid after refresh). * when parsing a project's description the CodeController now looks for NameHierarchies instead of SearchNode names to find ids of linked elements.
295 lines
9.3 KiB
C++
295 lines
9.3 KiB
C++
#include "cxxtest/TestSuite.h"
|
|
|
|
#include "utility/utilityString.h"
|
|
|
|
#include "data/graph/token_component/TokenComponentAbstraction.h"
|
|
#include "data/graph/token_component/TokenComponentAccess.h"
|
|
#include "data/graph/token_component/TokenComponentStatic.h"
|
|
#include "data/location/TokenLocation.h"
|
|
#include "data/parser/ParseLocation.h"
|
|
#include "data/Storage.h"
|
|
#include "data/type/DataType.h"
|
|
#include "data/type/NamedDataType.h"
|
|
|
|
class StorageTestSuite: public CxxTest::TestSuite
|
|
{
|
|
public:
|
|
void setUp()
|
|
{
|
|
m_filePath = "file.cpp";
|
|
}
|
|
|
|
void test_storage_saves_file()
|
|
{
|
|
TestStorage storage;
|
|
|
|
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
|
Id id = intermetiateStorage->addFile("test.h", "path/to/test.h", "someTime");
|
|
|
|
storage.injectData(intermetiateStorage);
|
|
|
|
TS_ASSERT_EQUALS(storage.getNameHierarchyForNodeWithId(id).getQualifiedNameWithSignature(), "test.h");
|
|
TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_FILE);
|
|
|
|
}
|
|
void test_storage_saves_node()
|
|
{
|
|
NameHierarchy a = createNameHierarchy("type");
|
|
|
|
TestStorage storage;
|
|
|
|
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
|
Id id = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), a, true);
|
|
|
|
storage.injectData(intermetiateStorage);
|
|
|
|
Id storedId = storage.getIdForNodeWithNameHierarchy(a);
|
|
|
|
TS_ASSERT(storedId != 0);
|
|
TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(storedId), Node::NODE_TYPEDEF);
|
|
}
|
|
|
|
|
|
void test_storage_saves_field_as_member()
|
|
{
|
|
NameHierarchy a = createNameHierarchy("Struct");
|
|
NameHierarchy b = createNameHierarchy("Struct::m_field");
|
|
|
|
TestStorage storage;
|
|
|
|
std::shared_ptr<IntermediateStorage> intermetiateStorage = std::make_shared<IntermediateStorage>();
|
|
Id aId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_STRUCT), a, true);
|
|
Id bId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FIELD), b, true);
|
|
intermetiateStorage->addEdge(Edge::typeToInt(Edge::EDGE_MEMBER), aId, bId);
|
|
|
|
storage.injectData(intermetiateStorage);
|
|
|
|
TS_ASSERT(storage.getIdForEdge(Edge::EDGE_MEMBER, a, b) != 0);
|
|
}
|
|
|
|
|
|
void test_storage_saves_method_static()
|
|
{
|
|
//TestStorage storage;
|
|
//Id id = storage.onMethodParsed(
|
|
// validLocation(1),
|
|
// ParseFunction(typeUsage("void"), createNameHierarchy("isMethod"), parameters("bool"), true),
|
|
// ParserClient::ACCESS_NONE,
|
|
// ParserClient::ABSTRACTION_NONE,
|
|
// validLocation(4)
|
|
//);
|
|
|
|
//Node* node = storage.getNodeWithId(id);
|
|
//TS_ASSERT(node);
|
|
//TS_ASSERT_EQUALS(node->getQualifiedNameWithSignature(), "isMethod");
|
|
//TS_ASSERT_EQUALS(node->getType(), Node::NODE_METHOD);
|
|
//TS_ASSERT(node->getComponent<TokenComponentStatic>());
|
|
}
|
|
|
|
void test_storage_clears_single_file_data_of_single_file_storage()
|
|
{
|
|
/*TestStorage storage;
|
|
storage.onFunctionParsed(
|
|
validLocation(), ParseFunction(typeUsage("bool"), createNameHierarchy("isTrue"),
|
|
parameters("char")), validLocation()
|
|
);
|
|
|
|
TS_ASSERT_EQUALS(storage.getNodeCount(), 3);
|
|
TS_ASSERT_EQUALS(storage.getEdgeCount(), 2);
|
|
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 4);
|
|
|
|
std::set<FilePath> files;
|
|
files.insert(FilePath(m_filePath));
|
|
storage.clearFileData(files);
|
|
|
|
TS_ASSERT_EQUALS(storage.getNodeCount(), 0);
|
|
TS_ASSERT_EQUALS(storage.getEdgeCount(), 0);
|
|
TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 0);*/
|
|
}
|
|
|
|
void test_storage_clears_unreferenced_single_file_data_of_multi_file_storage()
|
|
{
|
|
//m_filePath = "file.h";
|
|
|
|
//TestStorage storage;
|
|
|
|
//ParseFunction isTrue = ParseFunction(typeUsage("bool"), createNameHierarchy("isTrue"), parameters("char"));
|
|
//storage.onFunctionParsed(validLocation(), isTrue, validLocation());
|
|
|
|
//m_filePath = "file.cpp";
|
|
|
|
//ParseFunction main = ParseFunction(typeUsage("int"), createNameHierarchy("main"), parameters("void"));
|
|
//storage.onFunctionParsed(validLocation(), main, validLocation());
|
|
|
|
//storage.onCallParsed(validLocation(), main, isTrue);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 6);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 5);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
|
|
|
|
//std::set<FilePath> files;
|
|
//files.insert(FilePath("file.cpp"));
|
|
//storage.clearFileData(files);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 3);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 2);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 4);*/
|
|
}
|
|
|
|
void test_storage_clears_referenced_single_file_data_of_multi_file_storage()
|
|
{
|
|
//m_filePath = "file.h";
|
|
|
|
//TestStorage storage;
|
|
|
|
//ParseFunction isTrue = ParseFunction(typeUsage("bool"), createNameHierarchy("isTrue"), parameters("void"));
|
|
//storage.onFunctionParsed(validLocation(), isTrue, validLocation());
|
|
|
|
//m_filePath = "file.cpp";
|
|
|
|
//ParseFunction main = ParseFunction(typeUsage("int"), createNameHierarchy("main"), parameters("void"));
|
|
//storage.onFunctionParsed(validLocation(), main, validLocation());
|
|
|
|
//storage.onCallParsed(validLocation(), main, isTrue);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 5);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 5);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
|
|
|
|
//std::set<FilePath> files;
|
|
//files.insert(FilePath("file.h"));
|
|
//storage.clearFileData(files);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 4);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 3);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 5);
|
|
}
|
|
|
|
void test_storage_clears_multi_file_data_of_multi_file_storage()
|
|
{
|
|
//m_filePath = "file.h";
|
|
|
|
//TestStorage storage;
|
|
|
|
//ParseFunction isTrue = ParseFunction(typeUsage("bool"), createNameHierarchy("isTrue"), parameters("void"));
|
|
//storage.onFunctionParsed(validLocation(), isTrue, validLocation());
|
|
|
|
//m_filePath = "file.cpp";
|
|
|
|
//ParseFunction main = ParseFunction(typeUsage("int"), createNameHierarchy("main"), parameters("void"));
|
|
//storage.onFunctionParsed(validLocation(), main, validLocation());
|
|
|
|
//storage.onCallParsed(validLocation(), main, isTrue);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 5);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 5);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 9);
|
|
|
|
//std::set<FilePath> filePaths;
|
|
//filePaths.insert(FilePath("file.cpp"));
|
|
//filePaths.insert(FilePath("file.h"));
|
|
//storage.clearFileData(filePaths);
|
|
|
|
//TS_ASSERT_EQUALS(storage.getNodeCount(), 0);
|
|
//TS_ASSERT_EQUALS(storage.getEdgeCount(), 0);
|
|
//TS_ASSERT_EQUALS(storage.tokenLocationCollection().getTokenLocations().size(), 0);
|
|
}
|
|
|
|
void test_storage_finds_and_removes_depending_file_nodes()
|
|
{
|
|
//TestStorage storage;
|
|
|
|
//Id id1 = storage.onFileParsed("f.h");
|
|
//Id id2 = storage.onFileParsed("file.h");
|
|
//Id id3 = storage.onFileParsed("file.cpp");
|
|
//Id id4 = storage.onFileIncludeParsed(validLocation(), "file.h", "f.h");
|
|
//Id id5 = storage.onFileIncludeParsed(validLocation(), "file.cpp", "file.h");
|
|
|
|
//std::string name1 = storage.getNodeWithId(id2)->getQualifiedNameWithSignature();
|
|
//std::string name2 = storage.getNodeWithId(id3)->getQualifiedNameWithSignature();
|
|
|
|
//std::set<FilePath> filePaths;
|
|
//filePaths.insert(FilePath(name1));
|
|
//std::set<FilePath> dependingFilePaths = storage.getDependingFilePathsAndRemoveFileNodes(filePaths);
|
|
|
|
//TS_ASSERT_EQUALS(dependingFilePaths.size(), 1);
|
|
//TS_ASSERT_EQUALS(dependingFilePaths.begin()->str(), name2);
|
|
|
|
//TS_ASSERT(storage.getNodeWithId(id1));
|
|
//TS_ASSERT(!storage.getNodeWithId(id2));
|
|
//TS_ASSERT(!storage.getNodeWithId(id3));
|
|
//TS_ASSERT(!storage.getEdgeWithId(id4));
|
|
//TS_ASSERT(!storage.getEdgeWithId(id5));
|
|
}
|
|
|
|
private:
|
|
class TestStorage
|
|
: public Storage
|
|
{
|
|
public:
|
|
TestStorage()
|
|
: Storage("data/test.sqlite")
|
|
{
|
|
clear();
|
|
}
|
|
|
|
std::shared_ptr<TokenLocationCollection> getLocationCollectionForTokenId(Id id) const
|
|
{
|
|
std::vector<Id> tokenIds;
|
|
tokenIds.push_back(id);
|
|
return getTokenLocationsForTokenIds(tokenIds);
|
|
}
|
|
|
|
//const size_t getNodeCount() const
|
|
//{
|
|
// return getGraph().getNodeCount();
|
|
//}
|
|
|
|
//const size_t getEdgeCount() const
|
|
//{
|
|
// return getGraph().getEdgeCount();
|
|
//}
|
|
|
|
Id getEdgeId(Edge::EdgeType type, const NameHierarchy& fromName, const NameHierarchy& toName) const
|
|
{
|
|
NameHierarchy from;
|
|
|
|
return getIdForEdge(type, fromName, toName);
|
|
}
|
|
};
|
|
|
|
ParseLocation validLocation(Id locationId = 0) const
|
|
{
|
|
return ParseLocation(m_filePath, 1, locationId, 1, locationId);
|
|
}
|
|
|
|
bool isValidLocation(TokenLocation* location, Id locationId) const
|
|
{
|
|
return
|
|
location->getFilePath() == m_filePath &&
|
|
location->getLineNumber() == 1 &&
|
|
location->getColumnNumber() == locationId;
|
|
}
|
|
|
|
NameHierarchy createFunctionNameHierarchy(std::string ret, std::string name, std::string parameters) const
|
|
{
|
|
NameHierarchy nameHierarchy = createNameHierarchy(name);
|
|
std::string lastName = nameHierarchy.back()->getName();
|
|
nameHierarchy.pop();
|
|
nameHierarchy.push(std::make_shared<NameElement>(lastName, NameElement::Signature(ret, parameters)));
|
|
return nameHierarchy;
|
|
}
|
|
|
|
NameHierarchy createNameHierarchy(std::string s) const
|
|
{
|
|
NameHierarchy nameHierarchy;
|
|
for (std::string element: utility::splitToVector(s, "::"))
|
|
{
|
|
nameHierarchy.push(std::make_shared<NameElement>(element, NameElement::Signature()));
|
|
}
|
|
return nameHierarchy;
|
|
}
|
|
|
|
std::string m_filePath;
|
|
};
|