diff options
| author | Marco Bubke <marco.bubke@theqtcompany.com> | 2015-04-29 15:37:01 +0200 |
|---|---|---|
| committer | Marco Bubke <marco.bubke@theqtcompany.com> | 2015-04-30 14:19:34 +0000 |
| commit | 083f935115fe0fc90a052c079ece96bcb8bd4672 (patch) | |
| tree | 77aba1899646985c27f35f2859aa6a5399e0b774 | |
| parent | d931553739f51ee22d4f1bfcfce00acc4a406d08 (diff) | |
| download | qt-creator-083f935115fe0fc90a052c079ece96bcb8bd4672.tar.gz | |
catch the exceptions
Change-Id: I09158de96027c380d811de6bb7ece8864aef170f
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
36 files changed, 680 insertions, 118 deletions
diff --git a/src/libs/codemodelbackendipc/source/cmbcommands.cpp b/src/libs/codemodelbackendipc/source/cmbcommands.cpp index 10dc01b127..61219b7911 100644 --- a/src/libs/codemodelbackendipc/source/cmbcommands.cpp +++ b/src/libs/codemodelbackendipc/source/cmbcommands.cpp @@ -39,6 +39,7 @@ #include <cmbunregisterprojectsforcodecompletioncommand.h> #include <cmbcompletecodecommand.h> #include <cmbcodecompletedcommand.h> +#include <translationunitdoesnotexistscommand.h> namespace CodeModelBackEnd { @@ -90,6 +91,10 @@ void Commands::registerCommands() qRegisterMetaType<UnregisterProjectsForCodeCompletionCommand>(); qRegisterMetaTypeStreamOperators<UnregisterProjectsForCodeCompletionCommand>(); QMetaType::registerComparators<UnregisterProjectsForCodeCompletionCommand>(); + + qRegisterMetaType<TranslationUnitDoesNotExistsCommand>(); + qRegisterMetaTypeStreamOperators<TranslationUnitDoesNotExistsCommand>(); + QMetaType::registerComparators<TranslationUnitDoesNotExistsCommand>(); } } // namespace CodeModelBackEnd diff --git a/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.cpp b/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.cpp index 6e0ab73b87..5af2884f15 100644 --- a/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.cpp +++ b/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.cpp @@ -55,18 +55,18 @@ QDebug operator <<(QDebug debug, const UnregisterFilesForCodeCompletionCommand & return debug; } - +#ifdef CODEMODELBACKEND_TESTS void PrintTo(const UnregisterFilesForCodeCompletionCommand &command, ::std::ostream* os) { *os << "UnregisterFileForCodeCompletion("; -#ifdef CODEMODELBACKEND_TESTS for (const FileContainer &fileContainer : command.fileContainers()) *os << ::testing::PrintToString(fileContainer) << ", "; -#endif *os << ")"; } +#endif + } // namespace CodeModelBackEnd diff --git a/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.h b/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.h index edc83f75e7..85b2fcfcb5 100644 --- a/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.h +++ b/src/libs/codemodelbackendipc/source/cmbunregisterfilesforcodecompletioncommand.h @@ -34,7 +34,9 @@ CMBIPC_EXPORT bool operator == (const UnregisterFilesForCodeCompletionCommand &f CMBIPC_EXPORT bool operator < (const UnregisterFilesForCodeCompletionCommand &first, const UnregisterFilesForCodeCompletionCommand &second); CMBIPC_EXPORT QDebug operator <<(QDebug debug, const UnregisterFilesForCodeCompletionCommand &command); +#ifdef CODEMODELBACKEND_TESTS void PrintTo(const UnregisterFilesForCodeCompletionCommand &command, ::std::ostream* os); +#endif } // namespace CodeModelBackEnd Q_DECLARE_METATYPE(CodeModelBackEnd::UnregisterFilesForCodeCompletionCommand) diff --git a/src/libs/codemodelbackendipc/source/codemodelbackendipc-source.pri b/src/libs/codemodelbackendipc/source/codemodelbackendipc-source.pri index 616961adf0..3e36348d66 100644 --- a/src/libs/codemodelbackendipc/source/codemodelbackendipc-source.pri +++ b/src/libs/codemodelbackendipc/source/codemodelbackendipc-source.pri @@ -31,7 +31,8 @@ SOURCES += ipcserverinterface.cpp \ codemodelbackendipc_global.cpp \ $$PWD/projectcontainer.cpp \ $$PWD/cmbregisterprojectsforcodecompletioncommand.cpp \ - $$PWD/cmbunregisterprojectsforcodecompletioncommand.cpp + $$PWD/cmbunregisterprojectsforcodecompletioncommand.cpp \ + translationunitdoesnotexistscommand.cpp HEADERS += codemodelbackendipc_global.h \ @@ -58,4 +59,5 @@ HEADERS += codemodelbackendipc_global.h \ codecompletion.h \ $$PWD/projectcontainer.h \ $$PWD/cmbregisterprojectsforcodecompletioncommand.h \ - $$PWD/cmbunregisterprojectsforcodecompletioncommand.h + $$PWD/cmbunregisterprojectsforcodecompletioncommand.h \ + translationunitdoesnotexistscommand.h diff --git a/src/libs/codemodelbackendipc/source/connectionclient.h b/src/libs/codemodelbackendipc/source/connectionclient.h index fb667b8118..7caa2212b1 100644 --- a/src/libs/codemodelbackendipc/source/connectionclient.h +++ b/src/libs/codemodelbackendipc/source/connectionclient.h @@ -66,7 +66,7 @@ public: void sendCompleteCodeCommand(const Utf8String &fileName, quint32 line, quint32 column, - const Utf8String &commandLine); + const Utf8String &projectFilePath); void resetProcessAliveTimer(); void setProcessAliveTimerInterval(int processTimerInterval); diff --git a/src/libs/codemodelbackendipc/source/ipcclientdispatcher.cpp b/src/libs/codemodelbackendipc/source/ipcclientdispatcher.cpp index 9138fe6ce8..9377adbe05 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientdispatcher.cpp +++ b/src/libs/codemodelbackendipc/source/ipcclientdispatcher.cpp @@ -62,5 +62,11 @@ void IpcClientDispatcher::codeCompleted(const CodeCompletedCommand &command) client->codeCompleted(command); } +void IpcClientDispatcher::translationUnitDoesNotExists(const TranslationUnitDoesNotExistsCommand &command) +{ + for (auto *client : clients) + client->translationUnitDoesNotExists(command); +} + } // namespace CodeModelBackEnd diff --git a/src/libs/codemodelbackendipc/source/ipcclientdispatcher.h b/src/libs/codemodelbackendipc/source/ipcclientdispatcher.h index fe6aa3e78e..a09c367153 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientdispatcher.h +++ b/src/libs/codemodelbackendipc/source/ipcclientdispatcher.h @@ -44,10 +44,9 @@ public: void removeClient(IpcClientInterface *client); void alive() override; - void echo(const EchoCommand &command) override; - void codeCompleted(const CodeCompletedCommand &command) override; + void translationUnitDoesNotExists(const TranslationUnitDoesNotExistsCommand &command) override; private: QVector<IpcClientInterface*> clients; diff --git a/src/libs/codemodelbackendipc/source/ipcclientinterface.cpp b/src/libs/codemodelbackendipc/source/ipcclientinterface.cpp index d5afbe81c1..95299a2a9f 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientinterface.cpp +++ b/src/libs/codemodelbackendipc/source/ipcclientinterface.cpp @@ -35,6 +35,7 @@ #include "cmbechocommand.h" #include "cmbcodecompletedcommand.h" +#include "translationunitdoesnotexistscommand.h" namespace CodeModelBackEnd { @@ -44,6 +45,7 @@ void IpcClientInterface::dispatch(const QVariant &command) static const int aliveCommandType = QMetaType::type("CodeModelBackEnd::AliveCommand"); static const int echoCommandType = QMetaType::type("CodeModelBackEnd::EchoCommand"); static const int codeCompletedCommandType = QMetaType::type("CodeModelBackEnd::CodeCompletedCommand"); + static const int translationUnitDoesNotExistsCommand = QMetaType::type("CodeModelBackEnd::TranslationUnitDoesNotExistsCommand"); int type = command.userType(); @@ -53,6 +55,8 @@ void IpcClientInterface::dispatch(const QVariant &command) echo(command.value<EchoCommand>()); else if (type == codeCompletedCommandType) codeCompleted(command.value<CodeCompletedCommand>()); + else if (type == translationUnitDoesNotExistsCommand) + translationUnitDoesNotExists(command.value<TranslationUnitDoesNotExistsCommand>()); else qWarning() << "Unknown IpcClientCommand"; } diff --git a/src/libs/codemodelbackendipc/source/ipcclientinterface.h b/src/libs/codemodelbackendipc/source/ipcclientinterface.h index 4411bf3267..d9cb0b171c 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientinterface.h +++ b/src/libs/codemodelbackendipc/source/ipcclientinterface.h @@ -43,6 +43,7 @@ class UnregisterProjectsForCodeCompletionCommand; class EchoCommand; class CompleteCodeCommand; class CodeCompletedCommand; +class TranslationUnitDoesNotExistsCommand; class CMBIPC_EXPORT IpcClientInterface : public IpcInterface { @@ -52,6 +53,7 @@ public: virtual void alive() = 0; virtual void echo(const EchoCommand &command) = 0; virtual void codeCompleted(const CodeCompletedCommand &command) = 0; + virtual void translationUnitDoesNotExists(const TranslationUnitDoesNotExistsCommand &command) = 0; }; } // namespace CodeModelBackEnd diff --git a/src/libs/codemodelbackendipc/source/ipcclientproxy.cpp b/src/libs/codemodelbackendipc/source/ipcclientproxy.cpp index bf205bc856..7f7f1bfe77 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientproxy.cpp +++ b/src/libs/codemodelbackendipc/source/ipcclientproxy.cpp @@ -41,6 +41,7 @@ #include "cmbechocommand.h" #include "cmbregisterfilesforcodecompletioncommand.h" #include "cmbcodecompletedcommand.h" +#include "translationunitdoesnotexistscommand.h" namespace CodeModelBackEnd { @@ -68,6 +69,11 @@ void IpcClientProxy::codeCompleted(const CodeCompletedCommand &command) writeCommandBlock.write(QVariant::fromValue(command)); } +void IpcClientProxy::translationUnitDoesNotExists(const TranslationUnitDoesNotExistsCommand &command) +{ + writeCommandBlock.write(QVariant::fromValue(command)); +} + void IpcClientProxy::readCommands() { for (const QVariant &command : readCommandBlock.readAll()) diff --git a/src/libs/codemodelbackendipc/source/ipcclientproxy.h b/src/libs/codemodelbackendipc/source/ipcclientproxy.h index 635483b393..72510c1345 100644 --- a/src/libs/codemodelbackendipc/source/ipcclientproxy.h +++ b/src/libs/codemodelbackendipc/source/ipcclientproxy.h @@ -61,6 +61,7 @@ public: void alive() override; void echo(const EchoCommand &command) override; void codeCompleted(const CodeCompletedCommand &command) override; + void translationUnitDoesNotExists(const TranslationUnitDoesNotExistsCommand &command) override; void readCommands(); diff --git a/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.cpp b/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.cpp new file mode 100644 index 0000000000..ab64e389b9 --- /dev/null +++ b/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitdoesnotexistscommand.h" + +#include <QDebug> + +namespace CodeModelBackEnd { + +TranslationUnitDoesNotExistsCommand::TranslationUnitDoesNotExistsCommand(const FileContainer &fileContainer) + : fileContainer_(fileContainer) +{ +} + +TranslationUnitDoesNotExistsCommand::TranslationUnitDoesNotExistsCommand(const Utf8String filePath, const Utf8String projectFilePath) + : fileContainer_(filePath, projectFilePath) +{ +} + +const FileContainer &TranslationUnitDoesNotExistsCommand::fileContainer() const +{ + return fileContainer_; +} + +const Utf8String &TranslationUnitDoesNotExistsCommand::filePath() const +{ + return fileContainer_.filePath(); +} + +const Utf8String &TranslationUnitDoesNotExistsCommand::projectFilePath() const +{ + return fileContainer_.projectFilePath(); +} + +QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistsCommand &command) +{ + out << command.fileContainer_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistsCommand &command) +{ + in >> command.fileContainer_; + + return in; +} + +bool operator == (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second) +{ + return first.fileContainer_ == second.fileContainer_; +} + +bool operator < (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second) +{ + return first.fileContainer_ < second.fileContainer_; +} + +QDebug operator <<(QDebug debug, const TranslationUnitDoesNotExistsCommand &command) +{ + debug.nospace() << "TranslationUnitDoesNotExistsCommand("; + + debug.nospace() << command.fileContainer_; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const TranslationUnitDoesNotExistsCommand &command, ::std::ostream* os) +{ + QString output; + QDebug debug(&output); + + debug << command; + + *os << output.toUtf8().constData(); +} + +} // namespace CodeModelBackEnd + diff --git a/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.h b/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.h new file mode 100644 index 0000000000..6424333beb --- /dev/null +++ b/src/libs/codemodelbackendipc/source/translationunitdoesnotexistscommand.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H +#define CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H + +#include <QMetaType> + +#include "filecontainer.h" + +namespace CodeModelBackEnd { + +class CMBIPC_EXPORT TranslationUnitDoesNotExistsCommand +{ + friend QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistsCommand &command); + friend QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistsCommand &command); + friend bool operator == (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second); + friend bool operator < (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second); + friend QDebug operator <<(QDebug debug, const TranslationUnitDoesNotExistsCommand &command); + friend void PrintTo(const TranslationUnitDoesNotExistsCommand &command, ::std::ostream* os); +public: + TranslationUnitDoesNotExistsCommand() = default; + TranslationUnitDoesNotExistsCommand(const FileContainer &fileContainer); + TranslationUnitDoesNotExistsCommand(const Utf8String filePath, const Utf8String projectFilePath); + + const FileContainer &fileContainer() const; + const Utf8String &filePath() const; + const Utf8String &projectFilePath() const; + +private: + FileContainer fileContainer_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const TranslationUnitDoesNotExistsCommand &command); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, TranslationUnitDoesNotExistsCommand &command); +CMBIPC_EXPORT bool operator == (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second); +CMBIPC_EXPORT bool operator < (const TranslationUnitDoesNotExistsCommand &first, const TranslationUnitDoesNotExistsCommand &second); + +CMBIPC_EXPORT QDebug operator <<(QDebug debug, const TranslationUnitDoesNotExistsCommand &command); +void PrintTo(const TranslationUnitDoesNotExistsCommand &command, ::std::ostream* os); + +} // namespace CodeModelBackEnd + +Q_DECLARE_METATYPE(CodeModelBackEnd::TranslationUnitDoesNotExistsCommand) + +#endif // CODEMODELBACKEND_TRANSLATIONUNITDOESNOTEXISTSCOMMAND_H diff --git a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp b/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp index 781c859f1d..b37bd4aba9 100644 --- a/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp +++ b/src/tools/codemodelbackend/ipcsource/clangipcserver.cpp @@ -8,10 +8,15 @@ #include <cmbunregisterprojectsforcodecompletioncommand.h> #include <cmbcodecompletedcommand.h> #include <cmbcompletecodecommand.h> +#include <translationunitdoesnotexistscommand.h> #include "translationunits.h" #include "codecompleter.h" -#include "translationunitdonotexistsexception.h" +#include "translationunitdoesnotexistsexception.h" +#include "translationunitisnullexception.h" +#include "translationunitfilenotexitsexception.h" +#include "projectdonotexistsexception.h" +#include "translationunitparseerrorexception.h" #include <QDebug> @@ -29,30 +34,72 @@ void ClangIpcServer::end() void ClangIpcServer::registerFilesForCodeCompletion(const CodeModelBackEnd::RegisterFilesForCodeCompletionCommand &command) { - translationUnits.createOrUpdate(command.fileContainers()); - unsavedFiles.createOrUpdate(command.fileContainers()); + try { + translationUnits.createOrUpdate(command.fileContainers()); + unsavedFiles.createOrUpdate(command.fileContainers()); + } catch (const TranslationUnitFileNotExitsException &exception) { + qWarning() << "Error in ClangIpcServer::registerFilesForCodeCompletion: Tried to access a null TranslationUnit!"; + } catch (const TranslationUnitIsNullException &exception) { + qWarning() << "Error in ClangIpcServer::registerFilesForCodeCompletion: File for TranslationUnit doesn't exits!"; + } catch (const ProjectDoNotExistsException &exception) { + qWarning() << "Error in ClangIpcServer::registerFilesForCodeCompletion: Project" << exception.projectFilePath() << "doesn't exits!"; + } } void ClangIpcServer::unregisterFilesForCodeCompletion(const CodeModelBackEnd::UnregisterFilesForCodeCompletionCommand &command) { - translationUnits.remove(command.fileContainers()); + try { + translationUnits.remove(command.fileContainers()); + } catch (const TranslationUnitDoesNotExistsException &exception) { + client()->translationUnitDoesNotExists(TranslationUnitDoesNotExistsCommand(exception.fileContainer())); + } catch(const TranslationUnitIsNullException &exception) { + qWarning() << "Error in ClangIpcServer::unregisterFilesForCodeCompletion: Tried to access a null TranslationUnit!"; + } catch (const ProjectDoNotExistsException &exception) { + qWarning() << "Error in ClangIpcServer::unregisterFilesForCodeCompletion: Project" << exception.projectFilePath() << "doesn't exits!"; + } } void ClangIpcServer::registerProjectsForCodeCompletion(const RegisterProjectsForCodeCompletionCommand &command) { - projects.createOrUpdate(command.projectContainers()); + try { + projects.createOrUpdate(command.projectContainers()); + } catch (const TranslationUnitIsNullException &exception) { + qWarning() << "Error in ClangIpcServer::registerProjectsForCodeCompletion: Tried to access a null TranslationUnit!"; + } } void ClangIpcServer::unregisterProjectsForCodeCompletion(const UnregisterProjectsForCodeCompletionCommand &command) { - projects.remove(command.filePaths()); + try { + projects.remove(command.filePaths()); + } catch (const TranslationUnitIsNullException &exception) { + qWarning() << "Error in ClangIpcServer::unregisterProjectsForCodeCompletion: Tried to access a null TranslationUnit!"; + } catch (const ProjectDoNotExistsException &exception) { + qWarning() << "Error in ClangIpcServer::unregisterProjectsForCodeCompletion: Project" << exception.projectFilePath() << "doesn't exits!"; + } } void ClangIpcServer::completeCode(const CodeModelBackEnd::CompleteCodeCommand &command) { - CodeCompleter codeCompleter(translationUnits.translationUnit(command.filePath(), command.projectFilePath())); + try { + CodeCompleter codeCompleter(translationUnits.translationUnit(command.filePath(), command.projectFilePath())); - client()->codeCompleted(CodeCompletedCommand(codeCompleter.complete(command.line(), command.column()))); + const auto codeCompletions = codeCompleter.complete(command.line(), command.column()); + + client()->codeCompleted(CodeCompletedCommand(codeCompletions)); + } catch (const TranslationUnitDoesNotExistsException &exception) { + client()->translationUnitDoesNotExists(TranslationUnitDoesNotExistsCommand(exception.fileContainer())); + } catch (const TranslationUnitIsNullException &exception) { + qWarning() << "Error in ClangIpcServer::completeCode: Tried to access a null TranslationUnit!"; + } catch (const ProjectDoNotExistsException &exception) { + qWarning() << "Error in ClangIpcServer::completeCode: Project" << exception.projectFilePath() << "doesn't exits!"; + } catch (const TranslationUnitParseErrorException &exception) { + qWarning() << "Error in ClangIpcServer::completeCode: Parse error for file" + << exception.filePath() + << " in project" + << exception.projectFilePath() + << "!"; + } } } diff --git a/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri b/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri index 69b713cb83..60bf8b8aef 100644 --- a/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri +++ b/src/tools/codemodelbackend/ipcsource/codemodelbackendclangipc-source.pri @@ -15,7 +15,8 @@ HEADERS += clangipcserver.h \ $$PWD/projects.h \ $$PWD/projectdonotexistsexception.h \ $$PWD/translationunits.h \ - $$PWD/translationunitdonotexistsexception.h + $$PWD/translationunitparseerrorexception.h \ + $$PWD/translationunitdoesnotexistsexception.h SOURCES += clangipcserver.cpp \ codecompleter.cpp \ @@ -31,4 +32,5 @@ SOURCES += clangipcserver.cpp \ $$PWD/projects.cpp \ $$PWD/projectdonotexistsexception.cpp \ $$PWD/translationunits.cpp \ - $$PWD/translationunitdonotexistsexception.cpp + $$PWD/translationunitparseerrorexception.cpp \ + $$PWD/translationunitdoesnotexistsexception.cpp diff --git a/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.cpp b/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.cpp index 08c858518a..bd746f0ee1 100644 --- a/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.cpp +++ b/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.cpp @@ -32,5 +32,15 @@ namespace CodeModelBackEnd { +ProjectDoNotExistsException::ProjectDoNotExistsException(const Utf8String &projectFilePath) + : projectFilePath_(projectFilePath) +{ +} + +const Utf8String ProjectDoNotExistsException::projectFilePath() const +{ + return projectFilePath_; +} + } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.h b/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.h index 8c1a6d457a..6a3d5e4730 100644 --- a/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.h +++ b/src/tools/codemodelbackend/ipcsource/projectdonotexistsexception.h @@ -31,13 +31,19 @@ #ifndef CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H #define CODEMODELBACKEND_PROJECTDONOTEXISTSEXCEPTION_H +#include <utf8string.h> namespace CodeModelBackEnd { class ProjectDoNotExistsException { public: + ProjectDoNotExistsException(const Utf8String &projectFilePath); + const Utf8String projectFilePath() const; + +private: + Utf8String projectFilePath_; }; } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/projects.cpp b/src/tools/codemodelbackend/ipcsource/projects.cpp index dde2cf9d33..ca13ff961a 100644 --- a/src/tools/codemodelbackend/ipcsource/projects.cpp +++ b/src/tools/codemodelbackend/ipcsource/projects.cpp @@ -52,7 +52,7 @@ void Projects::remove(const Utf8StringVector &projectFilePaths) }); if (removeBeginIterator == lastRemoveBeginIterator) - throw ProjectDoNotExistsException(); + throw ProjectDoNotExistsException(projectFilePath); lastRemoveBeginIterator = removeBeginIterator; } @@ -66,7 +66,7 @@ const Project &Projects::project(const Utf8String &projectFilePath) const const auto findIterator = findProject(projectFilePath); if (findIterator == projects.cend()) - throw ProjectDoNotExistsException(); + throw ProjectDoNotExistsException(projectFilePath); return *findIterator; } diff --git a/src/tools/codemodelbackend/ipcsource/translationunit.cpp b/src/tools/codemodelbackend/ipcsource/translationunit.cpp index ecf2862ae5..b0bf10599a 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunit.cpp +++ b/src/tools/codemodelbackend/ipcsource/translationunit.cpp @@ -38,6 +38,7 @@ #include "translationunitisnullexception.h" #include "translationunitfilenotexitsexception.h" +#include "translationunitparseerrorexception.h" #include "unsavedfiles.h" #include "project.h" @@ -81,7 +82,7 @@ TranslationUnit::TranslationUnit(const Utf8String &filePath, const Project &project) : d(std::make_shared<TranslationUnitData>(filePath, unsavedFiles, project)) { - checkIfFileNotExists(); + checkIfFileExists(); } bool TranslationUnit::isNull() const @@ -108,24 +109,9 @@ CXTranslationUnit TranslationUnit::cxTranslationUnit() const { checkIfNull(); - const auto options = CXTranslationUnit_DetailedPreprocessingRecord - | CXTranslationUnit_CacheCompletionResults - | CXTranslationUnit_PrecompiledPreamble - | CXTranslationUnit_SkipFunctionBodies; - removeOutdatedTranslationUnit(); - if (!d->translationUnit) { - d->translationUnit = clang_parseTranslationUnit(index(), - d->filePath.constData(), - d->project.cxArguments(), - d->project.argumentCount(), - d->unsavedFiles.cxUnsavedFiles(), - d->unsavedFiles.count(), - options); - updateLastChangeTimePoint(); - } - + createTranslationUnitIfNeeded(); return d->translationUnit; } @@ -155,7 +141,7 @@ void TranslationUnit::checkIfNull() const throw TranslationUnitIsNullException(); } -void TranslationUnit::checkIfFileNotExists() const +void TranslationUnit::checkIfFileExists() const { if (!QFileInfo::exists(d->filePath.toString())) throw TranslationUnitFileNotExitsException(); @@ -174,6 +160,38 @@ void TranslationUnit::removeOutdatedTranslationUnit() const } } +void TranslationUnit::createTranslationUnitIfNeeded() const +{ + const auto options = CXTranslationUnit_DetailedPreprocessingRecord + | CXTranslationUnit_CacheCompletionResults + | CXTranslationUnit_PrecompiledPreamble + | CXTranslationUnit_SkipFunctionBodies; + + if (!d->translationUnit) { + d->translationUnit = CXTranslationUnit(); + CXErrorCode errorCode = clang_parseTranslationUnit2(index(), + d->filePath.constData(), + d->project.cxArguments(), + d->project.argumentCount(), + d->unsavedFiles.cxUnsavedFiles(), + d->unsavedFiles.count(), + options, + &d->translationUnit); + + checkTranslationUnitErrorCode(errorCode); + + updateLastChangeTimePoint(); + } +} + +void TranslationUnit::checkTranslationUnitErrorCode(CXErrorCode errorCode) const +{ + switch (errorCode) { + case CXError_Success: break; + default: throw TranslationUnitParseErrorException(d->filePath, d->project.projectFilePath()); + } +} + uint TranslationUnit::unsavedFilesCount() const { return d->unsavedFiles.count(); diff --git a/src/tools/codemodelbackend/ipcsource/translationunit.h b/src/tools/codemodelbackend/ipcsource/translationunit.h index 6dda19b08d..f4e94b4b45 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunit.h +++ b/src/tools/codemodelbackend/ipcsource/translationunit.h @@ -78,9 +78,11 @@ public: private: void checkIfNull() const; - void checkIfFileNotExists() const; + void checkIfFileExists() const; void updateLastChangeTimePoint() const; void removeOutdatedTranslationUnit() const; + void createTranslationUnitIfNeeded() const; + void checkTranslationUnitErrorCode(CXErrorCode errorCode) const; private: mutable std::shared_ptr<TranslationUnitData> d; diff --git a/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistsexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistsexception.cpp new file mode 100644 index 0000000000..6edb999139 --- /dev/null +++ b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistsexception.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitdoesnotexistsexception.h" + +namespace CodeModelBackEnd { + +TranslationUnitDoesNotExistsException::TranslationUnitDoesNotExistsException(const FileContainer &fileContainer) + : fileContainer_(fileContainer) +{ +} + +TranslationUnitDoesNotExistsException::TranslationUnitDoesNotExistsException(const Utf8String filePath, const Utf8String projectFilePath) + : fileContainer_(filePath, projectFilePath) +{ +} + +const FileContainer TranslationUnitDoesNotExistsException::fileContainer() const +{ + return fileContainer_; +} + +} // namespace CodeModelBackEnd + diff --git a/src/tools/codemodelbackend/ipcsource/translationunitdonotexistsexception.h b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistsexception.h index 20e8a213f5..11f1754df6 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunitdonotexistsexception.h +++ b/src/tools/codemodelbackend/ipcsource/translationunitdoesnotexistsexception.h @@ -31,11 +31,20 @@ #ifndef CODEMODELBACKEND_TRANSLATIONUNITDONOTEXISTS_H #define CODEMODELBACKEND_TRANSLATIONUNITDONOTEXISTS_H +#include <filecontainer.h> namespace CodeModelBackEnd { -class TranslationUnitDoNotExistsException +class TranslationUnitDoesNotExistsException { +public: + TranslationUnitDoesNotExistsException(const FileContainer &fileContainer); + TranslationUnitDoesNotExistsException(const Utf8String filePath, const Utf8String projectFilePath); + + const FileContainer fileContainer() const; + +private: + FileContainer fileContainer_; }; } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp index 7d4fb29d3a..e33ef4ff34 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp +++ b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.cpp @@ -32,10 +32,6 @@ namespace CodeModelBackEnd { -TranslationUnitIsNullException::TranslationUnitIsNullException() -{ - -} } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h index 80d3619b0c..1d6de1a0c3 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h +++ b/src/tools/codemodelbackend/ipcsource/translationunitisnullexception.h @@ -36,8 +36,6 @@ namespace CodeModelBackEnd { class TranslationUnitIsNullException { -public: - TranslationUnitIsNullException(); }; } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/translationunitdonotexistsexception.cpp b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp index 4024acaf31..ae660e5913 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunitdonotexistsexception.cpp +++ b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.cpp @@ -28,10 +28,25 @@ ** ****************************************************************************/ -#include "translationunitdonotexistsexception.h" +#include "translationunitparseerrorexception.h" namespace CodeModelBackEnd { +TranslationUnitParseErrorException::TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectFilePath) + : filePath_(filePath), + projectFilePath_(projectFilePath) +{ +} + +const Utf8String &TranslationUnitParseErrorException::filePath() const +{ + return filePath_; +} + +const Utf8String &TranslationUnitParseErrorException::projectFilePath() const +{ + return projectFilePath_; +} } // namespace CodeModelBackEnd diff --git a/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h new file mode 100644 index 0000000000..12b9b43c55 --- /dev/null +++ b/src/tools/codemodelbackend/ipcsource/translationunitparseerrorexception.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H +#define CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H + +#include <utf8string.h> + + + +namespace CodeModelBackEnd { + +class TranslationUnitParseErrorException +{ +public: + TranslationUnitParseErrorException(const Utf8String &filePath, const Utf8String &projectFilePath); + + const Utf8String &filePath() const; + const Utf8String &projectFilePath() const; + +private: + Utf8String filePath_; + Utf8String projectFilePath_; +}; + +} // namespace CodeModelBackEnd + +#endif // CODEMODELBACKEND_TRANSLATIONUNITPARSEERROREXCEPTION_H diff --git a/src/tools/codemodelbackend/ipcsource/translationunits.cpp b/src/tools/codemodelbackend/ipcsource/translationunits.cpp index d769a09eff..3f7c1e53dd 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunits.cpp +++ b/src/tools/codemodelbackend/ipcsource/translationunits.cpp @@ -31,7 +31,7 @@ #include "translationunits.h" #include <projects.h> -#include <translationunitdonotexistsexception.h> +#include <translationunitdoesnotexistsexception.h> namespace CodeModelBackEnd { @@ -57,7 +57,7 @@ void TranslationUnits::remove(const QVector<FileContainer> &fileContainers) }); if (removeBeginIterator == lastRemoveBeginIterator) - throw TranslationUnitDoNotExistsException(); + throw TranslationUnitDoesNotExistsException(fileContainer); lastRemoveBeginIterator = removeBeginIterator; } @@ -70,7 +70,7 @@ const TranslationUnit &TranslationUnits::translationUnit(const Utf8String &fileP auto findIterator = findTranslationUnit(filePath, projectFilePath); if (findIterator == translationUnits.end()) - throw TranslationUnitDoNotExistsException(); + throw TranslationUnitDoesNotExistsException(FileContainer(filePath, projectFilePath)); return *findIterator; } diff --git a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp b/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp index f695b23e1e..1fdc684adb 100644 --- a/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp +++ b/tests/unit/codemodelbackend/unittest/clangipcservertest.cpp @@ -37,7 +37,8 @@ #include <ipcclientproxy.h> #include <ipcserverproxy.h> #include <clangipcserver.h> -#include <translationunitdonotexistsexception.h> +#include <translationunitdoesnotexistsexception.h> +#include <translationunitparseerrorexception.h> #include <cmbcodecompletedcommand.h> #include <cmbcompletecodecommand.h> @@ -46,10 +47,13 @@ #include <cmbunregisterfilesforcodecompletioncommand.h> #include <cmbregisterprojectsforcodecompletioncommand.h> #include <cmbunregisterprojectsforcodecompletioncommand.h> +#include <translationunitdoesnotexistscommand.h> #include <QBuffer> #include <QFile> +#include "mockipclient.h" + using testing::Property; using testing::Contains; using testing::Not; @@ -65,16 +69,7 @@ using CodeModelBackEnd::CodeCompletedCommand; using CodeModelBackEnd::CodeCompletion; using CodeModelBackEnd::FileContainer; using CodeModelBackEnd::ProjectContainer; - -class MockIpcClient : public CodeModelBackEnd::IpcClientInterface { - public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(echo, - void(const CodeModelBackEnd::EchoCommand &command)); - MOCK_METHOD1(codeCompleted, - void(const CodeModelBackEnd::CodeCompletedCommand &command)); -}; +using CodeModelBackEnd::TranslationUnitDoesNotExistsCommand; class ClangIpcServer : public ::testing::Test @@ -85,6 +80,7 @@ protected: void registerFiles(); void registerProject(); void changeProjectArguments(); + void changeProjectArgumentsToWrongValues(); static const Utf8String unsavedContent(const QString &unsavedFilePath); protected: @@ -95,6 +91,7 @@ protected: const Utf8String variableTestFilePath = Utf8StringLiteral("data/complete_extractor_variable.cpp"); const QString unsavedTestFilePath = QStringLiteral("data/complete_extractor_function_unsaved.cpp"); const QString updatedUnsavedTestFilePath = QStringLiteral("data/complete_extractor_function_unsaved_2.cpp"); + const Utf8String parseErrorTestFilePath = Utf8StringLiteral("data/complete_translationunit_parse_error.cpp"); }; @@ -125,7 +122,13 @@ void ClangIpcServer::changeProjectArguments() RegisterProjectsForCodeCompletionCommand command({ProjectContainer(projectFilePath, {Utf8StringLiteral("-DArgumentDefinition")})}); clangServer.registerProjectsForCodeCompletion(command); +} +void ClangIpcServer::changeProjectArgumentsToWrongValues() +{ + RegisterProjectsForCodeCompletionCommand command({ProjectContainer(projectFilePath, {Utf8StringLiteral("-blah")})}); + + clangServer.registerProjectsForCodeCompletion(command); } const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath) @@ -175,14 +178,33 @@ TEST_F(ClangIpcServer, GetCodeCompletionDependingOnArgumets) clangServer.completeCode(completeCodeCommand); } -TEST_F(ClangIpcServer, ThrowExceptionForCodeCompletionOnNonExistingTranslationUnit) +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistsForCodeCompletionOnNonExistingTranslationUnit) { CompleteCodeCommand completeCodeCommand(Utf8StringLiteral("dontexists.cpp"), 34, 1, Utf8String()); + TranslationUnitDoesNotExistsCommand translationUnitDoesNotExistsCommand(Utf8StringLiteral("dontexists.cpp"), Utf8String()); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(translationUnitDoesNotExistsCommand)) + .Times(1); + + clangServer.completeCode(completeCodeCommand); +} + + +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistsForCompletingUnregisteredFile) +{ + CompleteCodeCommand completeCodeCommand(parseErrorTestFilePath, + 20, + 1, + projectFilePath); + TranslationUnitDoesNotExistsCommand translationUnitDoesNotExistsCommand(parseErrorTestFilePath, projectFilePath); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(translationUnitDoesNotExistsCommand)) + .Times(1); - ASSERT_THROW(clangServer.completeCode(completeCodeCommand), CodeModelBackEnd::TranslationUnitDoNotExistsException); + clangServer.completeCode(completeCodeCommand); } TEST_F(ClangIpcServer, GetCodeCompletionForUnsavedFile) @@ -244,30 +266,45 @@ TEST_F(ClangIpcServer, GetNewCodeCompletionAfterUpdatingUnsavedFile) clangServer.completeCode(completeCodeCommand); } -TEST_F(ClangIpcServer, ThrowExceptionForUnregisterTranslationUnitWithWrongFilePath) +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistsForUnregisterTranslationUnitWithWrongFilePath) { - UnregisterFilesForCodeCompletionCommand command({FileContainer(Utf8StringLiteral("foo.cpp"), projectFilePath)}); + FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectFilePath); + UnregisterFilesForCodeCompletionCommand command({fileContainer}); + TranslationUnitDoesNotExistsCommand translationUnitDoesNotExistsCommand(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(translationUnitDoesNotExistsCommand)) + .Times(1); - ASSERT_THROW(clangServer.unregisterFilesForCodeCompletion(command), CodeModelBackEnd::TranslationUnitDoNotExistsException); + clangServer.unregisterFilesForCodeCompletion(command); } -TEST_F(ClangIpcServer, ThrowExceptionForUnregisterTranslationUnitWithWrongProjectFilePath) +TEST_F(ClangIpcServer, GetTranslationUnitDoesNotExistsForUnregisterTranslationUnitWithWrongProjectFilePath) { - UnregisterFilesForCodeCompletionCommand command({FileContainer(functionTestFilePath, Utf8StringLiteral("bar.pro"))}); + FileContainer fileContainer(functionTestFilePath, Utf8StringLiteral("bar.pro")); + UnregisterFilesForCodeCompletionCommand command({fileContainer}); + TranslationUnitDoesNotExistsCommand translationUnitDoesNotExistsCommand(fileContainer); - ASSERT_THROW(clangServer.unregisterFilesForCodeCompletion(command), CodeModelBackEnd::TranslationUnitDoNotExistsException); + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(translationUnitDoesNotExistsCommand)) + .Times(1); + + clangServer.unregisterFilesForCodeCompletion(command); } TEST_F(ClangIpcServer, UnregisterTranslationUnitAndTestFailingCompletion) { - UnregisterFilesForCodeCompletionCommand command({FileContainer(functionTestFilePath, projectFilePath)}); + FileContainer fileContainer(functionTestFilePath, projectFilePath); + UnregisterFilesForCodeCompletionCommand command({fileContainer}); clangServer.unregisterFilesForCodeCompletion(command); CompleteCodeCommand completeCodeCommand(functionTestFilePath, 20, 1, projectFilePath); + TranslationUnitDoesNotExistsCommand translationUnitDoesNotExistsCommand(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(translationUnitDoesNotExistsCommand)) + .Times(1); - ASSERT_THROW(clangServer.completeCode(completeCodeCommand), CodeModelBackEnd::TranslationUnitDoNotExistsException); + clangServer.completeCode(completeCodeCommand); } TEST_F(ClangIpcServer, UnregisterProjectAndCompletionIsStillWorking) @@ -290,4 +327,15 @@ TEST_F(ClangIpcServer, UnregisterProjectAndCompletionIsStillWorking) clangServer.completeCode(completeCodeCommand); } +//TEST_F(ClangIpcServer, ThrowForTranslationUnitParsingError) +//{ +// changeProjectArgumentsToWrongValues(); + +// CompleteCodeCommand completeCodeCommand(functionTestFilePath, +// 20, +// 1, +// projectFilePath); + +// ASSERT_THROW(clangServer.completeCode(completeCodeCommand), CodeModelBackEnd::TranslationUnitParseErrorException); +//} } diff --git a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp b/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp index c5945c679b..54affed20e 100644 --- a/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp +++ b/tests/unit/codemodelbackend/unittest/clientserverinprocesstest.cpp @@ -33,6 +33,7 @@ #include "gmock/gmock.h" #include "gtest-qt-printing.h" +#include "translationunitdoesnotexistscommand.h" #include <QString> #include <QBuffer> @@ -55,35 +56,12 @@ #include <ipcserverproxy.h> #include <ipcclientproxy.h> -using namespace CodeModelBackEnd; +#include "mockipclient.h" +#include "mockipcserver.h" -class MockIpcClient : public IpcClientInterface { - public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(echo, - void(const EchoCommand &command)); - MOCK_METHOD1(codeCompleted, - void(const CodeCompletedCommand &command)); -}; +using namespace CodeModelBackEnd; -class MockIpcServer : public IpcServerInterface { - public: - MOCK_METHOD0(end, - void()); - MOCK_METHOD1(registerFilesForCodeCompletion, - void(const RegisterFilesForCodeCompletionCommand &command)); - MOCK_METHOD1(unregisterFilesForCodeCompletion, - void(const UnregisterFilesForCodeCompletionCommand &command)); - MOCK_METHOD1(registerProjectsForCodeCompletion, - void(const RegisterProjectsForCodeCompletionCommand &command)); - MOCK_METHOD1(unregisterProjectsForCodeCompletion, - void(const UnregisterProjectsForCodeCompletionCommand &command)); - MOCK_METHOD1(completeCode, - void(const CompleteCodeCommand &command)); -}; - class ClientServerInProcess : public ::testing::Test { protected: @@ -193,6 +171,19 @@ TEST_F(ClientServerInProcess, SendUnregisterProjectsForCodeCompletionCommand) scheduleServerCommands(); } +TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistsCommand) +{ + CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("data/complete_extractor_function.cpp"), + Utf8StringLiteral("pathToProject.pro")); + CodeModelBackEnd::TranslationUnitDoesNotExistsCommand command(fileContainer); + + EXPECT_CALL(mockIpcClient, translationUnitDoesNotExists(command)) + .Times(1); + + clientProxy.translationUnitDoesNotExists(command); + scheduleClientCommands(); +} + ClientServerInProcess::ClientServerInProcess() : serverProxy(&mockIpcClient, &buffer), clientProxy(&mockIpcServer, &buffer) diff --git a/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp b/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp index b37cbad6de..66bdf079ae 100644 --- a/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp +++ b/tests/unit/codemodelbackend/unittest/clientserveroutsideprocess.cpp @@ -53,24 +53,15 @@ #include <cmbcompletecodecommand.h> #include <writecommandblock.h> #include <readcommandblock.h> - #include <connectionclient.h> +#include <translationunitdoesnotexistscommand.h> + +#include <mockipclient.h> using namespace CodeModelBackEnd; using ::testing::Eq; -class MockIpcClient : public IpcClientInterface { - public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(echo, - void(const EchoCommand &command)); - MOCK_METHOD1(codeCompleted, - void(const CodeCompletedCommand &command)); -}; - - class ClientServerOutsideProcess : public ::testing::Test { protected: diff --git a/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp b/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp new file mode 100644 index 0000000000..288cef2a33 --- /dev/null +++ b/tests/unit/codemodelbackend/unittest/data/complete_translationunit_parse_error.cpp @@ -0,0 +1,2 @@ +NAMESPACE { + diff --git a/tests/unit/codemodelbackend/unittest/mockipclient.h b/tests/unit/codemodelbackend/unittest/mockipclient.h new file mode 100644 index 0000000000..6b42dda8ff --- /dev/null +++ b/tests/unit/codemodelbackend/unittest/mockipclient.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MOCKIPCLIENT_H +#define MOCKIPCLIENT_H + +class MockIpcClient : public CodeModelBackEnd::IpcClientInterface { + public: + MOCK_METHOD0(alive, + void()); + MOCK_METHOD1(echo, + void(const CodeModelBackEnd::EchoCommand &command)); + MOCK_METHOD1(codeCompleted, + void(const CodeModelBackEnd::CodeCompletedCommand &command)); + MOCK_METHOD1(translationUnitDoesNotExists, + void(const CodeModelBackEnd::TranslationUnitDoesNotExistsCommand &command)); +}; + +#endif // MOCKIPCLIENT_H + diff --git a/tests/unit/codemodelbackend/unittest/mockipcserver.h b/tests/unit/codemodelbackend/unittest/mockipcserver.h new file mode 100644 index 0000000000..0c45e4cfd5 --- /dev/null +++ b/tests/unit/codemodelbackend/unittest/mockipcserver.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef MOCKIPCSERVER_H +#define MOCKIPCSERVER_H + +#include <ipcserverinterface.h> + +class MockIpcServer : public CodeModelBackEnd::IpcServerInterface { + public: + MOCK_METHOD0(end, + void()); + MOCK_METHOD1(registerFilesForCodeCompletion, + void(const CodeModelBackEnd::RegisterFilesForCodeCompletionCommand &command)); + MOCK_METHOD1(unregisterFilesForCodeCompletion, + void(const CodeModelBackEnd::UnregisterFilesForCodeCompletionCommand &command)); + MOCK_METHOD1(registerProjectsForCodeCompletion, + void(const CodeModelBackEnd::RegisterProjectsForCodeCompletionCommand &command)); + MOCK_METHOD1(unregisterProjectsForCodeCompletion, + void(const CodeModelBackEnd::UnregisterProjectsForCodeCompletionCommand &command)); + MOCK_METHOD1(completeCode, + void(const CodeModelBackEnd::CompleteCodeCommand &command)); +}; + +#endif // MOCKIPCSERVER_H + diff --git a/tests/unit/codemodelbackend/unittest/translationunitstest.cpp b/tests/unit/codemodelbackend/unittest/translationunitstest.cpp index 130696bde9..cd82a07246 100644 --- a/tests/unit/codemodelbackend/unittest/translationunitstest.cpp +++ b/tests/unit/codemodelbackend/unittest/translationunitstest.cpp @@ -42,7 +42,7 @@ #include <filecontainer.h> #include <projectcontainer.h> #include <projects.h> -#include <translationunitdonotexistsexception.h> +#include <translationunitdoesnotexistsexception.h> #include <translationunitisnullexception.h> #include <translationunitfilenotexitsexception.h> @@ -98,14 +98,14 @@ void TranslationUnits::SetUp() TEST_F(TranslationUnits, ThrowForGettingWithWrongFilePath) { ASSERT_THROW(translationUnits.translationUnit(Utf8StringLiteral("foo.cpp"), projectFilePath), - CodeModelBackEnd::TranslationUnitDoNotExistsException); + CodeModelBackEnd::TranslationUnitDoesNotExistsException); } TEST_F(TranslationUnits, ThrowForGettingWithWrongProjectFilePath) { ASSERT_THROW(translationUnits.translationUnit(filePath, Utf8StringLiteral("foo.pro")), - CodeModelBackEnd::TranslationUnitDoNotExistsException); + CodeModelBackEnd::TranslationUnitDoesNotExistsException); } @@ -125,7 +125,7 @@ TEST_F(TranslationUnits, ThrowForRemovingWithWrongFilePath) CodeModelBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectFilePath); ASSERT_THROW(translationUnits.remove({fileContainer}), - CodeModelBackEnd::TranslationUnitDoNotExistsException); + CodeModelBackEnd::TranslationUnitDoesNotExistsException); } TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectFilePath) @@ -133,7 +133,7 @@ TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectFilePath) CodeModelBackEnd::FileContainer fileContainer(filePath, Utf8StringLiteral("foo.pro")); ASSERT_THROW(translationUnits.remove({fileContainer}), - CodeModelBackEnd::TranslationUnitDoNotExistsException); + CodeModelBackEnd::TranslationUnitDoesNotExistsException); } TEST_F(TranslationUnits, Remove) @@ -144,7 +144,7 @@ TEST_F(TranslationUnits, Remove) translationUnits.remove({fileContainer}); ASSERT_THROW(translationUnits.translationUnit(filePath, projectFilePath), - CodeModelBackEnd::TranslationUnitDoNotExistsException); + CodeModelBackEnd::TranslationUnitDoesNotExistsException); } } diff --git a/tests/unit/codemodelbackend/unittest/translationunittest.cpp b/tests/unit/codemodelbackend/unittest/translationunittest.cpp index 8e66ce8907..a79c23c471 100644 --- a/tests/unit/codemodelbackend/unittest/translationunittest.cpp +++ b/tests/unit/codemodelbackend/unittest/translationunittest.cpp @@ -41,9 +41,10 @@ #include <translationunits.h> #include <filecontainer.h> #include <projects.h> -#include <translationunitdonotexistsexception.h> +#include <translationunitdoesnotexistsexception.h> #include <translationunitisnullexception.h> #include <translationunitfilenotexitsexception.h> +#include <translationunitparseerrorexception.h> using CodeModelBackEnd::TranslationUnit; using CodeModelBackEnd::UnsavedFiles; @@ -130,4 +131,13 @@ TEST(TranslationUnit, TimeStampIsUpdatedAsNewCxTranslationUnitIsGenerated) ASSERT_THAT(translationUnit.lastChangeTimePoint(), Gt(lastChangeTimePoint)); } +//TEST(TranslationUnit, ThrowParseErrorForWrongArguments) +//{ +// Project project(Utf8StringLiteral("/path/to/projectfile")); +// project.setArguments({Utf8StringLiteral("-fblah")}); +// TranslationUnit translationUnit(Utf8StringLiteral("data/complete_testfile_1.cpp"), UnsavedFiles(), project); + +// ASSERT_THROW(translationUnit.cxTranslationUnit(), CodeModelBackEnd::TranslationUnitParseErrorException); +//} + } diff --git a/tests/unit/codemodelbackend/unittest/unittest.pro b/tests/unit/codemodelbackend/unittest/unittest.pro index 97bd41c321..763136b6fd 100644 --- a/tests/unit/codemodelbackend/unittest/unittest.pro +++ b/tests/unit/codemodelbackend/unittest/unittest.pro @@ -61,7 +61,9 @@ SOURCES += main.cpp \ HEADERS += \ gtest-qt-printing.h \ spydummy.h \ - ../../../../src/libs/utils/qtcassert.h + ../../../../src/libs/utils/qtcassert.h \ + mockipclient.h \ + mockipcserver.h OTHER_FILES += data/complete_testfile_1.cpp \ data/complete_completer.cpp \ @@ -73,7 +75,8 @@ OTHER_FILES += data/complete_testfile_1.cpp \ data/complete_extractor_class.cpp \ data/complete_extractor_namespace.cpp \ data/complete_extractor_enumeration.cpp \ - data/complete_extractor_constructor.cpp + data/complete_extractor_constructor.cpp \ + data/complete_translationunit_parse_error.cpp DEFINES += QT_NO_CAST_FROM_ASCII DEFINES += CODEMODELBACKEND_TESTS |
