logic: File Manager
* added FileManager that keeps track of the files analyzed by the project. It therefore checks if files get added, updated or deleted from the source- and include folders. * refactored ASTVisitor::hasValidLocation() and implemented one version that search for the location in the currently parsed file and one that searches in all the project's source files. * quickfix: switched order in FileManager so that header files are parsed first. * created folder for helper classes used in tests. * added test code for FileManager * adjusted test code for Parser Tests.
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
add_files(
|
||||
TEST_FILES
|
||||
|
||||
helper/TestFileManager.cpp
|
||||
helper/TestFileManager.h
|
||||
helper/TestStorage.cpp
|
||||
helper/TestStorage.h
|
||||
|
||||
TestSuiteFixture.cpp
|
||||
TestSuiteFixture.h
|
||||
|
||||
TestStorage.cpp
|
||||
TestStorage.h
|
||||
|
||||
ConfigManagerTestSuite.h
|
||||
CxxParserTestSuite.h
|
||||
DataTypeTestSuite.h
|
||||
DictionaryTestSuite.h
|
||||
FileManagerTestSuite.h
|
||||
FileSystemTestSuite.h
|
||||
GraphTestSuite.h
|
||||
GraphFilterTestSuite.h
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "helper/TestFileManager.h"
|
||||
|
||||
class CxxParserTestSuite: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
@@ -1531,8 +1533,9 @@ public:
|
||||
|
||||
void test_cxx_parser_parses_multiple_files()
|
||||
{
|
||||
TestFileManager fm;
|
||||
TestParserClient client;
|
||||
CxxParser parser(&client);
|
||||
CxxParser parser(&client, &fm);
|
||||
|
||||
std::vector<std::string> filePaths;
|
||||
filePaths.push_back("data/CxxParserTestSuite/header.h");
|
||||
@@ -1839,8 +1842,9 @@ private:
|
||||
|
||||
std::shared_ptr<TestParserClient> parseCode(std::string code) const
|
||||
{
|
||||
TestFileManager fm;
|
||||
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
|
||||
CxxParser parser(client.get());
|
||||
CxxParser parser(client.get(), &fm);
|
||||
parser.parseFile(TextAccess::createFromString(code));
|
||||
return client;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "utility/file/FileManager.h"
|
||||
|
||||
class FileManagerTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_file_manager_is_created_empty()
|
||||
{
|
||||
std::vector<std::string> sourcePaths;
|
||||
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
|
||||
std::vector<std::string> includePaths;
|
||||
includePaths.push_back("./data/FileManagerTestSuite/include/");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
|
||||
std::vector<std::string> addedFilePaths = fm.getAddedFilePaths();
|
||||
std::vector<std::string> updatedFilePaths = fm.getUpdatedFilePaths();
|
||||
std::vector<std::string> removedFilePaths = fm.getRemovedFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(addedFilePaths.size(), 0);
|
||||
TS_ASSERT_EQUALS(updatedFilePaths.size(), 0);
|
||||
TS_ASSERT_EQUALS(removedFilePaths.size(), 0);
|
||||
}
|
||||
|
||||
void test_file_manager_has_added_file_paths_after_first_fetch()
|
||||
{
|
||||
std::vector<std::string> sourcePaths;
|
||||
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
|
||||
std::vector<std::string> includePaths;
|
||||
includePaths.push_back("./data/FileManagerTestSuite/include/");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
std::vector<std::string> addedFilePaths = fm.getAddedFilePaths();
|
||||
std::vector<std::string> updatedFilePaths = fm.getUpdatedFilePaths();
|
||||
std::vector<std::string> removedFilePaths = fm.getRemovedFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(addedFilePaths.size(), 4);
|
||||
}
|
||||
|
||||
void test_file_manager_has_no_added_file_paths_after_second_fetch()
|
||||
{
|
||||
std::vector<std::string> sourcePaths;
|
||||
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
|
||||
std::vector<std::string> includePaths;
|
||||
includePaths.push_back("./data/FileManagerTestSuite/include/");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
fm.fetchFilePaths();
|
||||
|
||||
std::vector<std::string> addedFilePaths = fm.getAddedFilePaths();
|
||||
std::vector<std::string> updatedFilePaths = fm.getUpdatedFilePaths();
|
||||
std::vector<std::string> removedFilePaths = fm.getRemovedFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(addedFilePaths.size(), 0);
|
||||
}
|
||||
|
||||
void test_file_manager_has_updated_file_paths_after_second_fetch()
|
||||
{
|
||||
std::vector<std::string> sourcePaths;
|
||||
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
|
||||
std::vector<std::string> includePaths;
|
||||
includePaths.push_back("./data/FileManagerTestSuite/include/");
|
||||
std::vector<std::string> sourceExtensions;
|
||||
sourceExtensions.push_back(".cpp");
|
||||
sourceExtensions.push_back(".c");
|
||||
std::vector<std::string> includeExtensions;
|
||||
includeExtensions.push_back(".hpp");
|
||||
includeExtensions.push_back(".h");
|
||||
|
||||
FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions);
|
||||
fm.fetchFilePaths();
|
||||
|
||||
std::fstream fileStream;
|
||||
fileStream.open("./data/FileManagerTestSuite/include/c.h");
|
||||
fileStream << "update";
|
||||
fileStream.close();
|
||||
|
||||
fm.fetchFilePaths();
|
||||
|
||||
std::vector<std::string> addedFilePaths = fm.getAddedFilePaths();
|
||||
std::vector<std::string> updatedFilePaths = fm.getUpdatedFilePaths();
|
||||
std::vector<std::string> removedFilePaths = fm.getRemovedFilePaths();
|
||||
|
||||
TS_ASSERT_EQUALS(addedFilePaths.size(), 0);
|
||||
TS_ASSERT_EQUALS(updatedFilePaths.size(), 1);
|
||||
TS_ASSERT_EQUALS(removedFilePaths.size(), 0);
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
class FileSystemTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
@@ -71,6 +71,22 @@ public:
|
||||
TS_ASSERT_EQUALS(sourceFiles[0], "data/FileSystemTestSuite/update.c");
|
||||
}
|
||||
|
||||
void test_find_file_infos()
|
||||
{
|
||||
std::vector<std::string> extensions;
|
||||
extensions.push_back(".h");
|
||||
extensions.push_back(".hpp");
|
||||
extensions.push_back(".cpp");
|
||||
|
||||
std::vector<std::string> directoryPaths;
|
||||
directoryPaths.push_back("./data/FileSystemTestSuite");
|
||||
|
||||
std::vector<FileInfo> files =
|
||||
FileSystem::getFileInfosFromDirectoryPaths(directoryPaths, extensions);
|
||||
|
||||
TS_ASSERT_EQUALS(files.size(), 5);
|
||||
}
|
||||
|
||||
void test_filesystem_finds_existing_files()
|
||||
{
|
||||
TS_ASSERT(FileSystem::exists("data/FileSystemTestSuite"));
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "data/graph/filter/GraphFilterConductor.h"
|
||||
#include "data/query/QueryTree.h"
|
||||
#include "TestStorage.h"
|
||||
|
||||
#include "helper/TestStorage.h"
|
||||
|
||||
class GraphFilterConductorTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "data/graph/filter/GraphFilter.h"
|
||||
#include "data/graph/filter/GraphFilterImplementations.h"
|
||||
#include "TestStorage.h"
|
||||
|
||||
#include "helper/TestStorage.h"
|
||||
|
||||
class GraphFilterTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "TestFileManager.h"
|
||||
|
||||
TestFileManager::TestFileManager()
|
||||
: FileManager(
|
||||
std::vector<std::string>(),
|
||||
std::vector<std::string>(),
|
||||
std::vector<std::string>(),
|
||||
std::vector<std::string>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
bool TestFileManager::hasFilePath(const std::string& filePath) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef TEST_FILE_MANAGER_H
|
||||
#define TEST_FILE_MANAGER_H
|
||||
|
||||
#include "utility/file/FileManager.h"
|
||||
|
||||
class TestFileManager: public FileManager
|
||||
{
|
||||
public:
|
||||
TestFileManager();
|
||||
virtual bool hasFilePath(const std::string& filePath) const;
|
||||
};
|
||||
|
||||
#endif // TEST_FILE_MANAGER_H
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "TestFileManager.h"
|
||||
|
||||
void TestStorage::parseCxxCode(std::string code)
|
||||
{
|
||||
clear();
|
||||
CxxParser parser(this);
|
||||
TestFileManager fm;
|
||||
CxxParser parser(this, &fm);
|
||||
parser.parseFile(TextAccess::createFromString(code));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user