diff --git a/src/libs/clangbackendipc/clangbackendipc-lib.pri b/src/libs/clangbackendipc/clangbackendipc-lib.pri index cc11840a043..3084a13761b 100644 --- a/src/libs/clangbackendipc/clangbackendipc-lib.pri +++ b/src/libs/clangbackendipc/clangbackendipc-lib.pri @@ -46,7 +46,8 @@ SOURCES += $$PWD/ipcserverinterface.cpp \ $$PWD/requestdiagnosticsmessage.cpp \ $$PWD/registerunsavedfilesforeditormessage.cpp \ $$PWD/unregisterunsavedfilesforeditormessage.cpp \ - $$PWD/updatetranslationunitsforeditormessage.cpp + $$PWD/updatetranslationunitsforeditormessage.cpp \ + $$PWD/updatevisibletranslationunitsmessage.cpp HEADERS += \ $$PWD/ipcserverinterface.h \ @@ -87,6 +88,7 @@ HEADERS += \ $$PWD/requestdiagnosticsmessage.h \ $$PWD/registerunsavedfilesforeditormessage.h \ $$PWD/unregisterunsavedfilesforeditormessage.h \ - $$PWD/updatetranslationunitsforeditormessage.h + $$PWD/updatetranslationunitsforeditormessage.h \ + $$PWD/updatevisibletranslationunitsmessage.h contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols diff --git a/src/libs/clangbackendipc/cmbmessages.cpp b/src/libs/clangbackendipc/cmbmessages.cpp index 04af03c5e7d..d275de5353d 100644 --- a/src/libs/clangbackendipc/cmbmessages.cpp +++ b/src/libs/clangbackendipc/cmbmessages.cpp @@ -49,6 +49,7 @@ #include "translationunitdoesnotexistmessage.h" #include "unregisterunsavedfilesforeditormessage.h" #include "updatetranslationunitsforeditormessage.h" +#include "updatevisibletranslationunitsmessage.h" #include @@ -82,6 +83,8 @@ void Messages::registerMessages() registerMetaType(); registerMetaType(); + registerMetaType(); + registerMetaType(); registerMetaType(); registerMetaType(); diff --git a/src/libs/clangbackendipc/ipcclientinterface.h b/src/libs/clangbackendipc/ipcclientinterface.h index 32d17e4c60d..5600e130763 100644 --- a/src/libs/clangbackendipc/ipcclientinterface.h +++ b/src/libs/clangbackendipc/ipcclientinterface.h @@ -50,6 +50,7 @@ class DiagnosticsChangedMessage; class RequestDiagnosticsMessage; class RegisterUnsavedFilesForEditorMessage; class UnregisterUnsavedFilesForEditorMessage; +class UpdateVisibleTranslationUnitsMessage; class CMBIPC_EXPORT IpcClientInterface : public IpcInterface { diff --git a/src/libs/clangbackendipc/ipcserverinterface.cpp b/src/libs/clangbackendipc/ipcserverinterface.cpp index 92ba85a6de7..93717dfa33a 100644 --- a/src/libs/clangbackendipc/ipcserverinterface.cpp +++ b/src/libs/clangbackendipc/ipcserverinterface.cpp @@ -39,6 +39,7 @@ #include "requestdiagnosticsmessage.h" #include "unregisterunsavedfilesforeditormessage.h" #include "updatetranslationunitsforeditormessage.h" +#include "updatevisibletranslationunitsmessage.h" #include #include @@ -57,6 +58,8 @@ void IpcServerInterface::dispatch(const QVariant &message) static const int unregisterUnsavedFilesForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterUnsavedFilesForEditorMessage"); static const int completeCodeMessageType = QMetaType::type("ClangBackEnd::CompleteCodeMessage"); static const int requestDiagnosticsMessageType = QMetaType::type("ClangBackEnd::RequestDiagnosticsMessage"); + static const int updateVisibleTranslationUnitsMessageType = QMetaType::type("ClangBackEnd::UpdateVisibleTranslationUnitsMessage"); + int type = message.userType(); @@ -80,6 +83,8 @@ void IpcServerInterface::dispatch(const QVariant &message) completeCode(message.value()); else if (type == requestDiagnosticsMessageType) requestDiagnostics(message.value()); + else if (type == updateVisibleTranslationUnitsMessageType) + updateVisibleTranslationUnits(message.value()); else qWarning() << "Unknown IpcServerMessage"; } diff --git a/src/libs/clangbackendipc/ipcserverinterface.h b/src/libs/clangbackendipc/ipcserverinterface.h index 0682970412c..98d1441c0d5 100644 --- a/src/libs/clangbackendipc/ipcserverinterface.h +++ b/src/libs/clangbackendipc/ipcserverinterface.h @@ -54,6 +54,7 @@ public: virtual void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) = 0; virtual void completeCode(const CompleteCodeMessage &message) = 0; virtual void requestDiagnostics(const RequestDiagnosticsMessage &message) = 0; + virtual void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) = 0; void addClient(IpcClientInterface *client); void removeClient(IpcClientInterface *client); diff --git a/src/libs/clangbackendipc/ipcserverproxy.cpp b/src/libs/clangbackendipc/ipcserverproxy.cpp index a1d9d978be5..fa5777267c8 100644 --- a/src/libs/clangbackendipc/ipcserverproxy.cpp +++ b/src/libs/clangbackendipc/ipcserverproxy.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -119,5 +120,10 @@ void IpcServerProxy::requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMe writeMessageBlock.write(QVariant::fromValue(message)); } +void IpcServerProxy::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) +{ + writeMessageBlock.write(QVariant::fromValue(message)); +} + } // namespace ClangBackEnd diff --git a/src/libs/clangbackendipc/ipcserverproxy.h b/src/libs/clangbackendipc/ipcserverproxy.h index a3f52ff128c..d4c42887f4f 100644 --- a/src/libs/clangbackendipc/ipcserverproxy.h +++ b/src/libs/clangbackendipc/ipcserverproxy.h @@ -65,7 +65,7 @@ public: void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override; void completeCode(const CompleteCodeMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override; - + void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override; void readMessages(); void resetCounter(); diff --git a/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.cpp b/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.cpp new file mode 100644 index 00000000000..8e383fa86c1 --- /dev/null +++ b/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** 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 The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#include "updatevisibletranslationunitsmessage.h" + +#include "container_common.h" + +#include +#include + +#include +#include +#include + +namespace ClangBackEnd { + +UpdateVisibleTranslationUnitsMessage::UpdateVisibleTranslationUnitsMessage( + const Utf8String ¤tEditorFilePath, + const Utf8StringVector &visibleEditorFilePaths) + : currentEditorFilePath_(currentEditorFilePath), + visibleEditorFilePaths_(visibleEditorFilePaths) +{ +} + +const Utf8String &UpdateVisibleTranslationUnitsMessage::currentEditorFilePath() const +{ + return currentEditorFilePath_; +} + +const Utf8StringVector &UpdateVisibleTranslationUnitsMessage::visibleEditorFilePaths() const +{ + return visibleEditorFilePaths_; +} + +QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message) +{ + out << message.currentEditorFilePath_; + out << message.visibleEditorFilePaths_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message) +{ + in >> message.currentEditorFilePath_; + in >> message.visibleEditorFilePaths_; + + return in; +} + +bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second) +{ + return first.currentEditorFilePath_ == second.currentEditorFilePath_ + && first.visibleEditorFilePaths_ == second.visibleEditorFilePaths_; +} + +bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second) +{ + return first.currentEditorFilePath_ < second.currentEditorFilePath_ + && compareContainer(first.visibleEditorFilePaths_, second.visibleEditorFilePaths_); +} + +QDebug operator<<(QDebug debug, const UpdateVisibleTranslationUnitsMessage &message) +{ + debug.nospace() << "UpdateVisibleTranslationUnitsMessage("; + + debug.nospace() << message.currentEditorFilePath() << ", "; + + for (const Utf8String &visibleEditorFilePath : message.visibleEditorFilePaths()) + debug.nospace() << visibleEditorFilePath << ", "; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const UpdateVisibleTranslationUnitsMessage &message, ::std::ostream* os) +{ + *os << "UpdateVisibleTranslationUnitsMessage("; + + *os << message.currentEditorFilePath().constData() << ", "; + + auto visiblePaths = message.visibleEditorFilePaths(); + + std::copy(visiblePaths.cbegin(), visiblePaths.cend(), std::ostream_iterator(*os, ", ")); + + *os << ")"; +} + +} // namespace ClangBackEnd diff --git a/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.h b/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.h new file mode 100644 index 00000000000..3383ccc616f --- /dev/null +++ b/src/libs/clangbackendipc/updatevisibletranslationunitsmessage.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** 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 The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef CLANGBACKEND_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H +#define CLANGBACKEND_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H + +#include + +#include + +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT UpdateVisibleTranslationUnitsMessage +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message); + friend CMBIPC_EXPORT bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second); + friend CMBIPC_EXPORT bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second); + +public: + UpdateVisibleTranslationUnitsMessage() = default; + UpdateVisibleTranslationUnitsMessage(const Utf8String ¤tEditorFilePath, + const Utf8StringVector &visibleEditorFilePaths); + + const Utf8String ¤tEditorFilePath() const; + const Utf8StringVector &visibleEditorFilePaths() const; + +private: + Utf8String currentEditorFilePath_; + Utf8StringVector visibleEditorFilePaths_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message); +CMBIPC_EXPORT bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second); +CMBIPC_EXPORT bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdateVisibleTranslationUnitsMessage &message); +void PrintTo(const UpdateVisibleTranslationUnitsMessage &message, ::std::ostream* os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::UpdateVisibleTranslationUnitsMessage) + +#endif // CLANGBACKEND_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H diff --git a/src/libs/sqlite/utf8string.cpp b/src/libs/sqlite/utf8string.cpp index c8cbaea2230..9fb92b5d39d 100644 --- a/src/libs/sqlite/utf8string.cpp +++ b/src/libs/sqlite/utf8string.cpp @@ -269,6 +269,14 @@ void PrintTo(const Utf8String &text, ::std::ostream* os) *os << "\"" << text.toByteArray().data() << "\""; } +std::ostream& operator<<(std::ostream &os, const Utf8String &utf8String) +{ + using std::ostream; + os << utf8String.constData(); + + return os; +} + uint qHash(const Utf8String &utf8String) { return qHash(utf8String.byteArray); diff --git a/src/libs/sqlite/utf8string.h b/src/libs/sqlite/utf8string.h index c6adfc93716..6158f8b690d 100644 --- a/src/libs/sqlite/utf8string.h +++ b/src/libs/sqlite/utf8string.h @@ -36,6 +36,8 @@ #include #include +#include + class Utf8StringVector; class Utf8String; @@ -120,6 +122,7 @@ SQLITE_EXPORT QDataStream &operator<<(QDataStream &datastream, const Utf8String SQLITE_EXPORT QDataStream &operator>>(QDataStream &datastream, Utf8String &text); SQLITE_EXPORT QDebug operator<<(QDebug debug, const Utf8String &text); SQLITE_EXPORT void PrintTo(const Utf8String &text, ::std::ostream* os); +SQLITE_EXPORT std::ostream& operator<<(std::ostream &os, const Utf8String &utf8String); SQLITE_EXPORT uint qHash(const Utf8String &utf8String); diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.cpp b/src/tools/clangbackend/ipcsource/clangipcserver.cpp index 320c982c88e..31c3ae481f3 100644 --- a/src/tools/clangbackend/ipcsource/clangipcserver.cpp +++ b/src/tools/clangbackend/ipcsource/clangipcserver.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,18 @@ void ClangIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message } } +void ClangIpcServer::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) +{ + TIME_SCOPE_DURATION("ClangIpcServer::updateVisibleTranslationUnits"); + + try { + translationUnits.setCurrentEditor(message.currentEditorFilePath()); + translationUnits.setVisibleEditors(message.visibleEditorFilePaths()); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::updateVisibleTranslationUnits:" << exception.what(); + } +} + const TranslationUnits &ClangIpcServer::translationUnitsForTestOnly() const { return translationUnits; diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.h b/src/tools/clangbackend/ipcsource/clangipcserver.h index d4e5c6442ac..bfb1313e64f 100644 --- a/src/tools/clangbackend/ipcsource/clangipcserver.h +++ b/src/tools/clangbackend/ipcsource/clangipcserver.h @@ -61,6 +61,7 @@ public: void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override; void completeCode(const CompleteCodeMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override; + void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override; const TranslationUnits &translationUnitsForTestOnly() const; diff --git a/tests/unit/echoserver/echoipcserver.cpp b/tests/unit/echoserver/echoipcserver.cpp index c9dbfb42e88..fe1e79180f3 100644 --- a/tests/unit/echoserver/echoipcserver.cpp +++ b/tests/unit/echoserver/echoipcserver.cpp @@ -43,6 +43,7 @@ #include "requestdiagnosticsmessage.h" #include "unregisterunsavedfilesforeditormessage.h" #include "updatetranslationunitsforeditormessage.h" +#include "updatevisibletranslationunitsmessage.h" #include #include @@ -106,6 +107,11 @@ void EchoIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message) echoMessage(QVariant::fromValue(message)); } +void EchoIpcServer::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) +{ + echoMessage(QVariant::fromValue(message)); +} + void EchoIpcServer::echoMessage(const QVariant &message) { client()->echo(EchoMessage(message)); diff --git a/tests/unit/echoserver/echoipcserver.h b/tests/unit/echoserver/echoipcserver.h index cb3c55d2bb4..f7710f6f3dc 100644 --- a/tests/unit/echoserver/echoipcserver.h +++ b/tests/unit/echoserver/echoipcserver.h @@ -49,6 +49,7 @@ public: void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override; void completeCode(const CompleteCodeMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override; + void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override; private: void echoMessage(const QVariant &message); diff --git a/tests/unit/unittest/clangipcservertest.cpp b/tests/unit/unittest/clangipcservertest.cpp index be19eab6eed..2f0711832b0 100644 --- a/tests/unit/unittest/clangipcservertest.cpp +++ b/tests/unit/unittest/clangipcservertest.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -76,6 +77,7 @@ using ClangBackEnd::ProjectPartContainer; using ClangBackEnd::TranslationUnitDoesNotExistMessage; using ClangBackEnd::ProjectPartsDoNotExistMessage; using ClangBackEnd::UpdateTranslationUnitsForEditorMessage; +using ClangBackEnd::UpdateVisibleTranslationUnitsMessage; MATCHER_P5(HasDirtyTranslationUnit, filePath, @@ -135,11 +137,13 @@ protected: void registerProjectPart(); void changeProjectPartArguments(); void changeProjectPartArgumentsToWrongValues(); + void updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor); static const Utf8String unsavedContent(const QString &unsavedFilePath); protected: MockIpcClient mockIpcClient; ClangBackEnd::ClangIpcServer clangServer; + const ClangBackEnd::TranslationUnits &translationUnits = clangServer.translationUnitsForTestOnly(); const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro"); const Utf8String functionTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"); const Utf8String variableTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"); @@ -148,53 +152,6 @@ protected: const Utf8String parseErrorTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp"); }; - -void ClangIpcServer::SetUp() -{ - clangServer.addClient(&mockIpcClient); - registerProjectPart(); - registerFiles(); -} - -void ClangIpcServer::registerFiles() -{ - RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true), - FileContainer(variableTestFilePath, projectPartId)}); - - clangServer.registerTranslationUnitsForEditor(message); -} - -void ClangIpcServer::registerProjectPart() -{ - RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)}); - - clangServer.registerProjectPartsForEditor(message); -} - -void ClangIpcServer::changeProjectPartArguments() -{ - RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})}); - - clangServer.registerProjectPartsForEditor(message); -} - -void ClangIpcServer::changeProjectPartArgumentsToWrongValues() -{ - RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})}); - - clangServer.registerProjectPartsForEditor(message); -} - -const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath) -{ - QFile unsavedFileContentFile(unsavedFilePath); - bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); - if (!isOpen) - ADD_FAILURE() << "File with the unsaved content cannot be opened!"; - - return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); -} - TEST_F(ClangIpcServer, GetCodeCompletion) { CompleteCodeMessage completeCodeMessage(functionTestFilePath, @@ -426,6 +383,86 @@ TEST_F(ClangIpcServer, TranslationUnitAfterCreationNeedsNoReparseAndHasNewDiagno ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0U, false, true)); } +TEST_F(ClangIpcServer, SetCurrentAndVisibleEditor) +{ + auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId); + auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId); + + updateVisibilty(functionTestFilePath, variableTestFilePath); + + ASSERT_TRUE(functionTranslationUnit.isUsedByCurrentEditor()); + ASSERT_TRUE(functionTranslationUnit.isVisibleInEditor()); + ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor()); +} + +TEST_F(ClangIpcServer, IsNotCurrentCurrentAndVisibleEditorAnymore) +{ + auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId); + auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId); + updateVisibilty(functionTestFilePath, variableTestFilePath); + + updateVisibilty(variableTestFilePath, Utf8String()); + + ASSERT_FALSE(functionTranslationUnit.isUsedByCurrentEditor()); + ASSERT_FALSE(functionTranslationUnit.isVisibleInEditor()); + ASSERT_TRUE(variableTranslationUnit.isUsedByCurrentEditor()); + ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor()); +} + +void ClangIpcServer::SetUp() +{ + clangServer.addClient(&mockIpcClient); + registerProjectPart(); + registerFiles(); +} + +void ClangIpcServer::registerFiles() +{ + RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true), + FileContainer(variableTestFilePath, projectPartId)}); + + clangServer.registerTranslationUnitsForEditor(message); +} + +void ClangIpcServer::registerProjectPart() +{ + RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)}); + + clangServer.registerProjectPartsForEditor(message); +} + +void ClangIpcServer::changeProjectPartArguments() +{ + RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})}); + + clangServer.registerProjectPartsForEditor(message); +} + +void ClangIpcServer::changeProjectPartArgumentsToWrongValues() +{ + RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})}); + + clangServer.registerProjectPartsForEditor(message); +} + +void ClangIpcServer::updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor) +{ + UpdateVisibleTranslationUnitsMessage message(currentEditor, + {currentEditor, additionalVisibleEditor}); + + clangServer.updateVisibleTranslationUnits(message); +} + +const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath) +{ + QFile unsavedFileContentFile(unsavedFilePath); + bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); + if (!isOpen) + ADD_FAILURE() << "File with the unsaved content cannot be opened!"; + + return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); +} + TEST_F(ClangIpcServer, TranslationUnitAfterUpdateNeedsReparseAndHasNewDiagnostics) { const auto fileContainer = FileContainer(functionTestFilePath, projectPartId,unsavedContent(unsavedTestFilePath), true, 1); diff --git a/tests/unit/unittest/clientserverinprocesstest.cpp b/tests/unit/unittest/clientserverinprocesstest.cpp index 87632e2c069..0b5bb27d114 100644 --- a/tests/unit/unittest/clientserverinprocesstest.cpp +++ b/tests/unit/unittest/clientserverinprocesstest.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -232,6 +233,19 @@ TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForEditorMessage) scheduleServerMessages(); } +TEST_F(ClientServerInProcess, UpdateVisibleTranslationUnitsMessage) +{ + ClangBackEnd::UpdateVisibleTranslationUnitsMessage message(Utf8StringLiteral(TESTDATA_DIR"/fileone.cpp"), + {Utf8StringLiteral(TESTDATA_DIR"/fileone.cpp"), + Utf8StringLiteral(TESTDATA_DIR"/filetwo.cpp")}); + + EXPECT_CALL(mockIpcServer, updateVisibleTranslationUnits(message)) + .Times(1); + + serverProxy.updateVisibleTranslationUnits(message); + scheduleServerMessages(); +} + TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistMessage) { ClangBackEnd::TranslationUnitDoesNotExistMessage message(fileContainer); diff --git a/tests/unit/unittest/mockipcserver.h b/tests/unit/unittest/mockipcserver.h index 31591c28c0d..83f9870b4d6 100644 --- a/tests/unit/unittest/mockipcserver.h +++ b/tests/unit/unittest/mockipcserver.h @@ -60,6 +60,8 @@ public: void(const ClangBackEnd::CompleteCodeMessage &message)); MOCK_METHOD1(requestDiagnostics, void(const ClangBackEnd::RequestDiagnosticsMessage &message)); + MOCK_METHOD1(updateVisibleTranslationUnits, + void(const ClangBackEnd::UpdateVisibleTranslationUnitsMessage &message)); }; #endif // MOCKIPCSERVER_H