aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2018-08-07 19:01:01 +0200
committerMarco Bubke <marco.bubke@qt.io>2018-08-14 12:47:03 +0000
commit4195fce68f06a1b0ed86cd1f36cddab160f3bf29 (patch)
tree087e3ce65d82c184097beea14d6bf0d72bab0122 /tests
parentf6b228842c7d605d59f08e31bcdc090524d53ccf (diff)
ClangRefactoring: Integrate generated files
This is an intermediate step to handle the indexing of the project parts completely. The generated files are now independently handled from the project parts. We still not handle the case the a file is indexed but the generated file is not provided. This will be done in a different patch. All provided data is now sorted too to improve merging. Change-Id: I09712b99217a881ec0a233d09aea8659fb787324 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/gtest-creator-printing.cpp16
-rw-r--r--tests/unit/unittest/gtest-creator-printing.h6
-rw-r--r--tests/unit/unittest/projectupdater-test.cpp97
3 files changed, 100 insertions, 19 deletions
diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp
index 73184a17af..28cbf6b788 100644
--- a/tests/unit/unittest/gtest-creator-printing.cpp
+++ b/tests/unit/unittest/gtest-creator-printing.cpp
@@ -143,6 +143,11 @@ std::ostream &operator<<(std::ostream &out, const LineColumn &lineColumn)
return out << "(" << lineColumn.line << ", " << lineColumn.column << ")";
}
+void PrintTo(Utils::SmallStringView text, ::std::ostream *os)
+{
+ *os << text;
+}
+
void PrintTo(const Utils::SmallString &text, ::std::ostream *os)
{
*os << text;
@@ -981,6 +986,16 @@ std::ostream &operator<<(std::ostream &out, SymbolTags symbolTags)
return out;
}
+std::ostream &operator<<(std::ostream &out, const UpdateGeneratedFilesMessage &message)
+{
+ return out << "(" << message.generatedFiles << ")";
+}
+
+std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &message)
+{
+ return out << "(" << message.generatedFiles << ")";
+}
+
void PrintTo(const FilePath &filePath, ::std::ostream *os)
{
*os << filePath;
@@ -1020,6 +1035,7 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe
<< container.projectPartId << ", "
<< container.arguments << ", "
<< container.headerPathIds << ", "
+ << container.sourcePathIds << ", "
<< container.compilerMacros << ", "
<< container.includeSearchPaths << ")";
diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h
index a7c200daad..91c1e7fd37 100644
--- a/tests/unit/unittest/gtest-creator-printing.h
+++ b/tests/unit/unittest/gtest-creator-printing.h
@@ -67,6 +67,7 @@ std::ostream &operator<<(std::ostream &out, const Macro &macro);
namespace Utils {
class LineColumn;
+class SmallStringView;
std::ostream &operator<<(std::ostream &out, const LineColumn &lineColumn);
@@ -85,6 +86,7 @@ void PrintTo(const Utils::optional<Type> &optional, ::std::ostream *os)
*os << optional;
}
+void PrintTo(Utils::SmallStringView text, ::std::ostream *os);
void PrintTo(const Utils::SmallString &text, ::std::ostream *os);
void PrintTo(const Utils::PathString &text, ::std::ostream *os);
@@ -165,6 +167,8 @@ class SymbolEntry;
enum class SymbolKind : uchar;
enum class SymbolTag : uchar;
using SymbolTags = Utils::SizedArray<SymbolTag, 7>;
+class UpdateGeneratedFilesMessage;
+class RemoveGeneratedFilesMessage;
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
@@ -242,6 +246,8 @@ std::ostream &operator<<(std::ostream &out, const SymbolEntry &symbolEntry);
std::ostream &operator<<(std::ostream &out, SymbolKind symbolKind);
std::ostream &operator<<(std::ostream &out, SymbolTag symbolTag);
std::ostream &operator<<(std::ostream &out, SymbolTags symbolTags);
+std::ostream &operator<<(std::ostream &out, const UpdateGeneratedFilesMessage &message);
+std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &message);
void PrintTo(const FilePath &filePath, ::std::ostream *os);
void PrintTo(const FilePathView &filePathView, ::std::ostream *os);
diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp
index 4e43d6b577..0dd63c2558 100644
--- a/tests/unit/unittest/projectupdater-test.cpp
+++ b/tests/unit/unittest/projectupdater-test.cpp
@@ -83,11 +83,19 @@ protected:
projectPart.files.push_back(source1ProjectFile);
projectPart.files.push_back(source2ProjectFile);
projectPart.displayName = QString(projectPartId);
- projectPart.projectMacros.push_back({"DEFINE", "1"});
+ projectPart.projectMacros = {{"FOO", "2"}, {"BAR", "1"}};
+ projectPart2.files.push_back(header2ProjectFile);
+ projectPart2.files.push_back(header1ProjectFile);
+ projectPart2.files.push_back(source2ProjectFile);
+ projectPart2.files.push_back(source1ProjectFile);
+ projectPart2.displayName = QString(projectPartId2);
+ projectPart2.projectMacros = {{"BAR", "1"}, {"FOO", "2"}};
Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments(
&projectPart)};
+ Utils::SmallStringVector arguments2{ClangPchManager::ProjectUpdater::compilerArguments(
+ &projectPart2)};
expectedContainer = {projectPartId.clone(),
arguments.clone(),
@@ -95,6 +103,12 @@ protected:
{},
{filePathId(headerPaths[1])},
{filePathIds(sourcePaths)}};
+ expectedContainer2 = {projectPartId2.clone(),
+ arguments2.clone(),
+ Utils::clone(compilerMacros),
+ {},
+ {filePathId(headerPaths[1])},
+ {filePathIds(sourcePaths)}};
}
protected:
@@ -110,34 +124,73 @@ protected:
Utils::SmallString projectPartId2{"project2"};
Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"};
- ClangBackEnd::CompilerMacros compilerMacros = {{"DEFINE", "1"}};
+ ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1"}, {"FOO", "2"}};
CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader};
CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader};
CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource};
CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), CppTools::ProjectFile::CXXSource};
CppTools::ProjectPart projectPart;
+ CppTools::ProjectPart projectPart2;
ProjectPartContainer expectedContainer;
+ ProjectPartContainer expectedContainer2;
FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}};
+ FileContainer generatedFile2{{"/path/to2", "header1.h"}, "content", {}};
+ FileContainer generatedFile3{{"/path/to", "header2.h"}, "content", {}};
};
TEST_F(ProjectUpdater, CallUpdateProjectParts)
{
- std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart};
- ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()}};
+ std::vector<CppTools::ProjectPart*> projectParts = {&projectPart2, &projectPart};
+ ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer2.clone()}};
+ updater.updateGeneratedFiles({generatedFile});
EXPECT_CALL(mockPchManagerServer, updateProjectParts(message));
- updater.updateProjectParts(projectParts, {generatedFile});
+ updater.updateProjectParts(projectParts);
}
-TEST_F(ProjectUpdater, CallUpdateGeneratedFiles)
+TEST_F(ProjectUpdater, CallUpdateGeneratedFilesWithSortedEntries)
{
- std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart};
- ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile}};
+ ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile, generatedFile3, generatedFile2}};
EXPECT_CALL(mockPchManagerServer, updateGeneratedFiles(message));
- updater.updateProjectParts(projectParts, {generatedFile});
+ updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
+}
+
+TEST_F(ProjectUpdater, GeneratedFilesAddedAreSorted)
+{
+ updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
+
+ ASSERT_THAT(updater.generatedFiles().fileContainers(),
+ ElementsAre(generatedFile, generatedFile3, generatedFile2));
+}
+
+TEST_F(ProjectUpdater, GeneratedFilesAddedToExcludePaths)
+{
+ updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
+
+ ASSERT_THAT(updater.excludedPaths(), ElementsAre(generatedFile.filePath,
+ generatedFile3.filePath,
+ generatedFile2.filePath));
+}
+
+TEST_F(ProjectUpdater, CallRemoveGeneratedFiles)
+{
+ ClangBackEnd::RemoveGeneratedFilesMessage message{{{"/path/to/header1.h"}}};
+
+ EXPECT_CALL(mockPchManagerServer, removeGeneratedFiles(message));
+
+ updater.removeGeneratedFiles({{"/path/to/header1.h"}});
+}
+
+TEST_F(ProjectUpdater, GeneratedFilesRemovedFromExcludePaths)
+{
+ updater.updateGeneratedFiles({generatedFile});
+
+ updater.removeGeneratedFiles({generatedFile.filePath});
+
+ ASSERT_THAT(updater.excludedPaths(), IsEmpty());
}
TEST_F(ProjectUpdater, CallRemoveProjectParts)
@@ -153,6 +206,7 @@ TEST_F(ProjectUpdater, CallPrecompiledHeaderRemovedInPchManagerProjectUpdater)
{
ClangPchManager::PchManagerProjectUpdater pchUpdater{mockPchManagerServer, pchManagerClient, filePathCache};
ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}};
+ EXPECT_CALL(mockPrecompiledHeaderStorage, deletePrecompiledHeader(_)).Times(AnyNumber());
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString()));
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2.toQString()));
@@ -176,29 +230,34 @@ TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLike
ASSERT_THAT(containers, SizeIs(2));
}
-TEST_F(ProjectUpdater, CreateExcludedPaths)
+TEST_F(ProjectUpdater, CreateSortedExcludedPaths)
{
- auto excludedPaths = updater.createExcludedPaths({generatedFile});
+ auto excludedPaths = updater.createExcludedPaths({generatedFile2, generatedFile3, generatedFile});
- ASSERT_THAT(excludedPaths, ElementsAre("/path/to/header1.h"));
+ ASSERT_THAT(excludedPaths, ElementsAre(ClangBackEnd::FilePath{"/path/to/header1.h"},
+ ClangBackEnd::FilePath{"/path/to/header2.h"},
+ ClangBackEnd::FilePath{"/path/to2/header1.h"}));
}
-TEST_F(ProjectUpdater, CreateCompilerMacros)
+TEST_F(ProjectUpdater, CreateSortedCompilerMacros)
{
- auto paths = updater.createCompilerMacros({{"DEFINE", "1"}});
+ auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}});
- ASSERT_THAT(paths, ElementsAre(CompilerMacro{"DEFINE", "1"}));
+ ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1"},
+ CompilerMacro{"FOO", "2"},
+ CompilerMacro{"DEFINE", "1"}));
}
-TEST_F(ProjectUpdater, CreateIncludeSearchPaths)
+TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths)
{
- ProjectPartHeaderPath includePath{"/to/path", ProjectPartHeaderPath::IncludePath};
+ ProjectPartHeaderPath includePath{"/to/path1", ProjectPartHeaderPath::IncludePath};
+ ProjectPartHeaderPath includePath2{"/to/path2", ProjectPartHeaderPath::IncludePath};
ProjectPartHeaderPath invalidPath;
ProjectPartHeaderPath frameworkPath{"/framework/path", ProjectPartHeaderPath::FrameworkPath};
- auto paths = updater.createIncludeSearchPaths({includePath, invalidPath, frameworkPath});
+ auto paths = updater.createIncludeSearchPaths({frameworkPath, includePath2, includePath, invalidPath});
- ASSERT_THAT(paths, ElementsAre(includePath.path, frameworkPath.path));
+ ASSERT_THAT(paths, ElementsAre(includePath.path, includePath2.path, frameworkPath.path));
}
}