summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@theqtcompany.com>2015-05-06 14:16:36 +0200
committerMarco Bubke <marco.bubke@theqtcompany.com>2015-05-07 15:46:50 +0000
commitcdb95947dc899f26d61d912bf7aeadb023f2d52e (patch)
treee2f18ed5d59e99632b4dcd111c774f0ca2686f31
parent82322f3c7a10909bfff3a7648e9e82e112f5bd24 (diff)
downloadqt-creator-cdb95947dc899f26d61d912bf7aeadb023f2d52e.tar.gz
Improve testing that projects not exists
Change-Id: Id23b6e0e07b7a1d214fa670de5aea3e845632139 Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
-rw-r--r--src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.cpp18
-rw-r--r--src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.h8
-rw-r--r--src/tools/codemodelbackend/ipcsource/clangipcserver.cpp8
-rw-r--r--src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.cpp12
-rw-r--r--src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.h8
-rw-r--r--src/tools/codemodelbackend/ipcsource/projects.cpp22
-rw-r--r--tests/unit/codemodelbackend/unittest/clangipcservertest.cpp8
-rw-r--r--tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp2
8 files changed, 41 insertions, 45 deletions
diff --git a/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.cpp b/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.cpp
index 84600e15a3..9109db2f8e 100644
--- a/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.cpp
+++ b/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.cpp
@@ -36,46 +36,46 @@
namespace CodeModelBackEnd {
-ProjectDoesNotExistCommand::ProjectDoesNotExistCommand(const Utf8String &projectFilePath)
- : projectFilePath_(projectFilePath)
+ProjectDoesNotExistCommand::ProjectDoesNotExistCommand(const Utf8StringVector &projectFilePaths)
+ : projectFilePaths_(projectFilePaths)
{
}
-const Utf8String &ProjectDoesNotExistCommand::projectFilePath() const
+const Utf8StringVector &ProjectDoesNotExistCommand::projectFilePaths() const
{
- return projectFilePath_;
+ return projectFilePaths_;
}
QDataStream &operator<<(QDataStream &out, const ProjectDoesNotExistCommand &command)
{
- out << command.projectFilePath_;
+ out << command.projectFilePaths_;
return out;
}
QDataStream &operator>>(QDataStream &in, ProjectDoesNotExistCommand &command)
{
- in >> command.projectFilePath_;
+ in >> command.projectFilePaths_;
return in;
}
bool operator == (const ProjectDoesNotExistCommand &first, const ProjectDoesNotExistCommand &second)
{
- return first.projectFilePath_ == second.projectFilePath_;
+ return first.projectFilePaths_ == second.projectFilePaths_;
}
bool operator < (const ProjectDoesNotExistCommand &first, const ProjectDoesNotExistCommand &second)
{
- return first.projectFilePath_ < second.projectFilePath_;
+ return first.projectFilePaths_ < second.projectFilePaths_;
}
QDebug operator <<(QDebug debug, const ProjectDoesNotExistCommand &command)
{
debug.nospace() << "ProjectDoesNotExistCommand(";
- debug.nospace() << command.projectFilePath_;
+ debug.nospace() << command.projectFilePaths_;
debug.nospace() << ")";
diff --git a/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.h b/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.h
index 578e4dc4b1..be40d3a96c 100644
--- a/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.h
+++ b/src/libs/codemodelbackendipc/source/projectdoesnotexistscommand.h
@@ -33,7 +33,7 @@
#include <QMetaType>
-#include <utf8string.h>
+#include <utf8stringvector.h>
#include "codemodelbackendipc_global.h"
@@ -49,12 +49,12 @@ class CMBIPC_EXPORT ProjectDoesNotExistCommand
friend void PrintTo(const ProjectDoesNotExistCommand &command, ::std::ostream* os);
public:
ProjectDoesNotExistCommand() = default;
- ProjectDoesNotExistCommand(const Utf8String &projectFilePath);
+ ProjectDoesNotExistCommand(const Utf8StringVector &projectFilePaths);
- const Utf8String &projectFilePath() const;
+ const Utf8StringVector &projectFilePaths() const;
private:
- Utf8String projectFilePath_;
+ Utf8StringVector projectFilePaths_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const ProjectDoesNotExistCommand &command);
diff --git a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp b/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp
index ac10112d1e..e1c9622c5b 100644
--- a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp
+++ b/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp
@@ -39,7 +39,7 @@ void ClangIpcServer::registerTranslationUnitsForCodeCompletion(const CodeModelBa
translationUnits.createOrUpdate(command.fileContainers());
unsavedFiles.createOrUpdate(command.fileContainers());
} catch (const ProjectDoesNotExistException &exception) {
- client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePath()));
+ client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePaths()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::registerTranslationUnitsForCodeCompletion:" << exception.what();
}
@@ -52,7 +52,7 @@ void ClangIpcServer::unregisterTranslationUnitsForCodeCompletion(const CodeModel
} catch (const TranslationUnitDoesNotExistException &exception) {
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer()));
} catch (const ProjectDoesNotExistException &exception) {
- client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePath()));
+ client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePaths()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::unregisterTranslationUnitsForCodeCompletion:" << exception.what();
}
@@ -72,7 +72,7 @@ void ClangIpcServer::unregisterProjectsForCodeCompletion(const UnregisterProject
try {
projects.remove(command.filePaths());
} catch (const ProjectDoesNotExistException &exception) {
- client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePath()));
+ client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePaths()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::unregisterProjectsForCodeCompletion:" << exception.what();
}
@@ -89,7 +89,7 @@ void ClangIpcServer::completeCode(const CodeModelBackEnd::CompleteCodeCommand &c
} catch (const TranslationUnitDoesNotExistException &exception) {
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistCommand(exception.fileContainer()));
} catch (const ProjectDoesNotExistException &exception) {
- client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePath()));
+ client()->projectDoesNotExist(ProjectDoesNotExistCommand(exception.projectFilePaths()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::unregisterProjectsForCodeCompletion:" << exception.what();
}
diff --git a/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.cpp b/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.cpp
index b4229538fa..e71593aea8 100644
--- a/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.cpp
+++ b/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.cpp
@@ -32,21 +32,21 @@
namespace CodeModelBackEnd {
-ProjectDoesNotExistException::ProjectDoesNotExistException(const Utf8String &projectFilePath)
- : projectFilePath_(projectFilePath)
+ProjectDoesNotExistException::ProjectDoesNotExistException(const Utf8StringVector &projectFilePaths)
+ : projectFilePaths_(projectFilePaths)
{
}
-const Utf8String &ProjectDoesNotExistException::projectFilePath() const
+const Utf8StringVector &ProjectDoesNotExistException::projectFilePaths() const
{
- return projectFilePath_;
+ return projectFilePaths_;
}
const char *ProjectDoesNotExistException::what() const Q_DECL_NOEXCEPT
{
if (what_.isEmpty())
- what_ += Utf8StringLiteral("Project file ")
- + projectFilePath()
+ what_ += Utf8StringLiteral("Project files ")
+ + projectFilePaths().join(Utf8StringLiteral(", "))
+ Utf8StringLiteral(" does not exist!");
return what_.constData();
diff --git a/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.h b/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.h
index ebc3980d3f..5543472b04 100644
--- a/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.h
+++ b/src/tools/codemodelbackend/ipcsource/projectdoesnotexistsexception.h
@@ -31,7 +31,7 @@
#ifndef CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H
#define CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H
-#include <utf8string.h>
+#include <utf8stringvector.h>
#include <exception>
@@ -40,14 +40,14 @@ namespace CodeModelBackEnd {
class ProjectDoesNotExistException : public std::exception
{
public:
- ProjectDoesNotExistException(const Utf8String &projectFilePath);
+ ProjectDoesNotExistException(const Utf8StringVector &projectFilePaths);
- const Utf8String &projectFilePath() const;
+ const Utf8StringVector &projectFilePaths() const;
const char *what() const Q_DECL_NOEXCEPT override;
private:
- Utf8String projectFilePath_;
+ Utf8StringVector projectFilePaths_;
mutable Utf8String what_;
};
diff --git a/src/tools/codemodelbackend/ipcsource/projects.cpp b/src/tools/codemodelbackend/ipcsource/projects.cpp
index 525921e421..1887f6bfd0 100644
--- a/src/tools/codemodelbackend/ipcsource/projects.cpp
+++ b/src/tools/codemodelbackend/ipcsource/projects.cpp
@@ -44,21 +44,17 @@ void Projects::createOrUpdate(const QVector<ProjectContainer> &projectContainers
void Projects::remove(const Utf8StringVector &projectFilePaths)
{
- auto lastRemoveBeginIterator = projects.end();
+ Utf8StringVector processedProjectFilePaths = projectFilePaths;
- for (const Utf8String &projectFilePath : projectFilePaths) {
- auto removeBeginIterator = std::remove_if(projects.begin(), lastRemoveBeginIterator, [projectFilePath] (const Project &project) {
- return project.projectFilePath() == projectFilePath;
- });
-
- if (removeBeginIterator == lastRemoveBeginIterator)
- throw ProjectDoesNotExistException(projectFilePath);
+ auto removeBeginIterator = std::remove_if(projects.begin(), projects.end(), [&processedProjectFilePaths] (const Project &project) {
+ return processedProjectFilePaths.removeOne(project.projectFilePath());
+ });
- lastRemoveBeginIterator = removeBeginIterator;
- }
+ if (!processedProjectFilePaths.isEmpty())
+ throw ProjectDoesNotExistException(processedProjectFilePaths);
- std::for_each(lastRemoveBeginIterator, projects.end(), [](Project &project) { project.clearProjectFilePath(); });
- projects.erase(lastRemoveBeginIterator, projects.end());
+ std::for_each(removeBeginIterator, projects.end(), [](Project &project) { project.clearProjectFilePath(); });
+ projects.erase(removeBeginIterator, projects.end());
}
const Project &Projects::project(const Utf8String &projectFilePath) const
@@ -66,7 +62,7 @@ const Project &Projects::project(const Utf8String &projectFilePath) const
const auto findIterator = findProject(projectFilePath);
if (findIterator == projects.cend())
- throw ProjectDoesNotExistException(projectFilePath);
+ throw ProjectDoesNotExistException({projectFilePath});
return *findIterator;
}
diff --git a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp b/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp
index 46407c88c0..b2cd536891 100644
--- a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp
+++ b/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp
@@ -299,7 +299,7 @@ TEST_F(ClangIpcServer, UnregisterTranslationUnitAndTestFailingCompletion)
TEST_F(ClangIpcServer, GetProjectDoesNotExistUnregisterProjectInexistingProject)
{
- Utf8String inexistingProjectFilePath = Utf8StringLiteral("projectdoesnotexists.pro");
+ Utf8StringVector inexistingProjectFilePath = {Utf8StringLiteral("projectdoesnotexists.pro"), Utf8StringLiteral("project2doesnotexists.pro")};
UnregisterProjectsForCodeCompletionCommand unregisterProjectsForCodeCompletionCommand({inexistingProjectFilePath});
ProjectDoesNotExistCommand projectDoesNotExistCommand(inexistingProjectFilePath);
@@ -313,7 +313,7 @@ TEST_F(ClangIpcServer, GetProjectDoesNotExistRegisterTranslationUnitWithInexisti
{
Utf8String inexistingProjectFilePath = Utf8StringLiteral("projectdoesnotexists.pro");
RegisterTranslationUnitForCodeCompletionCommand registerFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectFilePath)});
- ProjectDoesNotExistCommand projectDoesNotExistCommand(inexistingProjectFilePath);
+ ProjectDoesNotExistCommand projectDoesNotExistCommand({inexistingProjectFilePath});
EXPECT_CALL(mockIpcClient, projectDoesNotExist(projectDoesNotExistCommand))
.Times(1);
@@ -325,7 +325,7 @@ TEST_F(ClangIpcServer, GetProjectDoesNotExistUnregisterTranslationUnitWithInexis
{
Utf8String inexistingProjectFilePath = Utf8StringLiteral("projectdoesnotexists.pro");
UnregisterTranslationUnitsForCodeCompletionCommand unregisterFileForCodeCompletionCommand({FileContainer(variableTestFilePath, inexistingProjectFilePath)});
- ProjectDoesNotExistCommand projectDoesNotExistCommand(inexistingProjectFilePath);
+ ProjectDoesNotExistCommand projectDoesNotExistCommand({inexistingProjectFilePath});
EXPECT_CALL(mockIpcClient, projectDoesNotExist(projectDoesNotExistCommand))
.Times(1);
@@ -340,7 +340,7 @@ TEST_F(ClangIpcServer, GetProjectDoesNotExistForCompletingProjectFile)
20,
1,
inexistingProjectFilePath);
- ProjectDoesNotExistCommand projectDoesNotExistCommand(inexistingProjectFilePath);
+ ProjectDoesNotExistCommand projectDoesNotExistCommand({inexistingProjectFilePath});
EXPECT_CALL(mockIpcClient, projectDoesNotExist(projectDoesNotExistCommand))
.Times(1);
diff --git a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp b/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp
index f3a55bf839..dc4a25b641 100644
--- a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp
+++ b/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp
@@ -193,7 +193,7 @@ TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistCommand)
TEST_F(ClientServerInProcess, SendProjectDoesNotExistCommand)
{
- CodeModelBackEnd::ProjectDoesNotExistCommand command(Utf8StringLiteral("pathToProject.pro"));
+ CodeModelBackEnd::ProjectDoesNotExistCommand command({Utf8StringLiteral("pathToProject.pro")});
EXPECT_CALL(mockIpcClient, projectDoesNotExist(command))
.Times(1);