Commit 0bc18df6 authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Do not work on unspecified values in ProjectParts::remove



Change-Id: Icc322bc64988cbc1b5ec4e6d6474b1b6b956c667
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 7bc397b1
......@@ -46,11 +46,16 @@ void ProjectParts::remove(const Utf8StringVector &projectPartIds)
{
Utf8StringVector processedProjectPartFilePaths = projectPartIds;
auto removeBeginIterator = std::remove_if(projects_.begin(), projects_.end(), [&processedProjectPartFilePaths] (const ProjectPart &project) {
return processedProjectPartFilePaths.removeFast(project.projectPartId());
const auto removeBeginIterator = std::remove_if(projects_.begin(), projects_.end(),
[&processedProjectPartFilePaths] (ProjectPart &project) {
const bool isRemoved = processedProjectPartFilePaths.removeFast(project.projectPartId());
if (isRemoved)
project.clearProjectPartId();
return isRemoved;
});
std::for_each(removeBeginIterator, projects_.end(), [](ProjectPart &project) { project.clearProjectPartId(); });
projects_.erase(removeBeginIterator, projects_.end());
if (!processedProjectPartFilePaths.isEmpty())
......
......@@ -153,7 +153,7 @@ TEST(ProjectPart, ProjectPartProjectPartIdIsEmptyfterRemoving)
ASSERT_TRUE(project.projectPartId().isEmpty());
}
TEST(Project, ThrowsForNotExistingProjectPartButRemovesAllExistingProject)
TEST(ProjectPart, ThrowsForNotExistingProjectPartButRemovesAllExistingProject)
{
ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"));
ClangBackEnd::ProjectParts projects;
......@@ -165,6 +165,18 @@ TEST(Project, ThrowsForNotExistingProjectPartButRemovesAllExistingProject)
ASSERT_THAT(projects.projects(), Not(Contains(project)));
}
TEST(ProjectPart, ProjectPartIdIsEmptyAfterRemove)
{
ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"));
ClangBackEnd::ProjectParts projects;
projects.createOrUpdate({projectContainer});
ClangBackEnd::ProjectPart project = *projects.findProjectPart(projectContainer.projectPartId());
projects.remove({projectContainer.projectPartId()});
ASSERT_THAT(project.projectPartId(), Utf8String());
}
TEST(ProjectPart, HasProjectPart)
{
ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment