| 
									
										
										
										
											2015-10-01 12:45:06 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** 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 | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							|  |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | ** information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | #include "mockclangcodemodelclient.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | #include "testutils.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | #include <clangcodemodelserver.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | #include <highlightingmarkcontainer.h>
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | #include <clangcodemodelclientproxy.h>
 | 
					
						
							|  |  |  | #include <clangcodemodelserverproxy.h>
 | 
					
						
							| 
									
										
										
										
											2016-06-09 12:55:42 +02:00
										 |  |  | #include <requestdocumentannotations.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <translationunitdoesnotexistexception.h>
 | 
					
						
							|  |  |  | #include <translationunitparseerrorexception.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 12:36:43 +02:00
										 |  |  | #include <cmbcompletecodemessage.h>
 | 
					
						
							| 
									
										
										
										
											2015-08-31 14:36:58 +02:00
										 |  |  | #include <cmbregisterprojectsforeditormessage.h>
 | 
					
						
							|  |  |  | #include <cmbregistertranslationunitsforeditormessage.h>
 | 
					
						
							|  |  |  | #include <cmbunregisterprojectsforeditormessage.h>
 | 
					
						
							|  |  |  | #include <cmbunregistertranslationunitsforeditormessage.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QFile>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 12:38:04 +02:00
										 |  |  | #include <gmock/gmock.h>
 | 
					
						
							|  |  |  | #include <gmock/gmock-matchers.h>
 | 
					
						
							|  |  |  | #include <gtest/gtest.h>
 | 
					
						
							| 
									
										
										
										
											2015-07-01 14:50:35 +02:00
										 |  |  | #include "gtest-qt-printing.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | using testing::Property; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | using testing::Not; | 
					
						
							|  |  |  | using testing::Eq; | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | using testing::PrintToString; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | using testing::_; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | using namespace ClangBackEnd; | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 13:31:46 +01:00
										 |  |  | MATCHER_P5(HasDirtyTranslationUnit, | 
					
						
							|  |  |  |            filePath, | 
					
						
							|  |  |  |            projectPartId, | 
					
						
							|  |  |  |            documentRevision, | 
					
						
							|  |  |  |            isNeedingReparse, | 
					
						
							|  |  |  |            hasNewDiagnostics, | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |            std::string(negation ? "isn't" : "is") | 
					
						
							|  |  |  |            + " translation unit with file path "+ PrintToString(filePath) | 
					
						
							|  |  |  |            + " and project " + PrintToString(projectPartId) | 
					
						
							|  |  |  |            + " and document revision " + PrintToString(documentRevision) | 
					
						
							| 
									
										
										
										
											2015-11-23 13:31:46 +01:00
										 |  |  |            + " and isNeedingReparse = " + PrintToString(isNeedingReparse) | 
					
						
							|  |  |  |            + " and hasNewDiagnostics = " + PrintToString(hasNewDiagnostics) | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto &&translationUnits = arg.translationUnitsForTestOnly(); | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         auto translationUnit = translationUnits.translationUnit(filePath, projectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (translationUnit.documentRevision() == documentRevision) { | 
					
						
							| 
									
										
										
										
											2015-11-23 13:31:46 +01:00
										 |  |  |             if (translationUnit.isNeedingReparse() && !isNeedingReparse) { | 
					
						
							|  |  |  |                 *result_listener << "isNeedingReparse is true"; | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } else if (!translationUnit.isNeedingReparse() && isNeedingReparse) { | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |                 *result_listener << "isNeedingReparse is false"; | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 13:31:46 +01:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         *result_listener << "revision number is " << PrintToString(translationUnit.documentRevision()); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } catch (...) { | 
					
						
							|  |  |  |         *result_listener << "has no translation unit"; | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | class ClangClangCodeModelServer : public ::testing::Test | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     void TearDown() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     bool waitUntilAllJobsFinished(int timeOutInMs = 10000); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void registerProjectPart(); | 
					
						
							|  |  |  |     void changeProjectPartArguments(); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     void unregisterProject(const Utf8String &projectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void registerProjectAndFile(const Utf8String &filePath, | 
					
						
							|  |  |  |                                 int expectedDocumentAnnotationsChangedMessages = 1); | 
					
						
							|  |  |  |     void registerProjectAndFileAndWaitForFinished(const Utf8String &filePath, | 
					
						
							|  |  |  |                                                   int expectedDocumentAnnotationsChangedMessages = 1); | 
					
						
							|  |  |  |     void registerProjectAndFilesAndWaitForFinished(int expectedDocumentAnnotationsChangedMessages = 2); | 
					
						
							|  |  |  |     void registerFile(const Utf8String &filePath, const Utf8String &projectFilePath); | 
					
						
							|  |  |  |     void registerFile(const Utf8String &filePath, | 
					
						
							|  |  |  |                       int expectedDocumentAnnotationsChangedMessages = 1); | 
					
						
							|  |  |  |     void registerFiles(int expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  |     void registerFileWithUnsavedContent(const Utf8String &filePath, const Utf8String &content); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void updateUnsavedContent(const Utf8String &filePath, | 
					
						
							|  |  |  |                               const Utf8String &fileContent, | 
					
						
							|  |  |  |                               quint32 revisionNumber); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void unregisterFile(const Utf8String &filePath); | 
					
						
							|  |  |  |     void unregisterFile(const Utf8String &filePath, const Utf8String &projectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void removeUnsavedFile(const Utf8String &filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  |     void updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void requestDocumentAnnotations(const Utf8String &filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void completeCode(const Utf8String &filePath, uint line = 1, uint column = 1, | 
					
						
							|  |  |  |                       const Utf8String &projectPartId = Utf8String()); | 
					
						
							|  |  |  |     void completeCodeInFileA(); | 
					
						
							|  |  |  |     void completeCodeInFileB(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void expectDocumentAnnotationsChanged(int count); | 
					
						
							|  |  |  |     void expectCompletion(const CodeCompletion &completion); | 
					
						
							|  |  |  |     void expectCompletionFromFileA(); | 
					
						
							|  |  |  |     void expectCompletionFromFileBEnabledByMacro(); | 
					
						
							|  |  |  |     void expectCompletionFromFileAUnsavedMethodVersion1(); | 
					
						
							|  |  |  |     void expectCompletionFromFileAUnsavedMethodVersion2(); | 
					
						
							|  |  |  |     void expectCompletionWithTicketNumber(quint64 ticketNumber); | 
					
						
							|  |  |  |     void expectNoCompletionWithUnsavedMethod(); | 
					
						
							|  |  |  |     void expectTranslationUnitDoesNotExist(const Utf8String &filePath); | 
					
						
							|  |  |  |     void expectProjectPartsDoNoExist(const Utf8StringVector &projectFilePaths); | 
					
						
							|  |  |  |     void expectDocumentAnnotationsChangedForFileBWithSpecificHighlightingMark(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     static const Utf8String unsavedContent(const QString &unsavedFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  |     MockClangCodeModelClient mockClangCodeModelClient; | 
					
						
							|  |  |  |     ClangBackEnd::ClangCodeModelServer clangServer; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  |     const ClangBackEnd::TranslationUnits &translationUnits = clangServer.translationUnitsForTestOnly(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro"); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const Utf8String filePathA = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"); | 
					
						
							|  |  |  |     const QString filePathAUnsavedVersion1 | 
					
						
							|  |  |  |         = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved.cpp"); | 
					
						
							|  |  |  |     const QString filePathAUnsavedVersion2 | 
					
						
							|  |  |  |         = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved_2.cpp"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Utf8String filePathB = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Utf8String aFilePath = Utf8StringLiteral("afile.cpp"); | 
					
						
							|  |  |  |     const Utf8String anExistingFilePath | 
					
						
							|  |  |  |         = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp"); | 
					
						
							|  |  |  |     const Utf8String aProjectPartId = Utf8StringLiteral("aproject.pro"); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetCodeCompletion) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFile(filePathA); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectCompletionFromFileA(); | 
					
						
							|  |  |  |     completeCodeInFileA(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-09 12:55:42 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, RequestDocumentAnnotations) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFileAndWaitForFinished(filePathB); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectDocumentAnnotationsChangedForFileBWithSpecificHighlightingMark(); | 
					
						
							|  |  |  |     requestDocumentAnnotations(filePathB); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, NoInitialDocumentAnnotationsForClosedDocument) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const int expectedDocumentAnnotationsChangedCount = 0; | 
					
						
							|  |  |  |     registerProjectAndFile(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unregisterFile(filePathA); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, NoDocumentAnnotationsForClosedDocument) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const int expectedDocumentAnnotationsChangedCount = 1; // Only for registration.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  |     updateUnsavedContent(filePathA, Utf8String(), 1); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     unregisterFile(filePathA); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangClangCodeModelServer, NoInitialDocumentAnnotationsForOutdatedDocumentRevision) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const int expectedDocumentAnnotationsChangedCount = 1; // Only for registration.
 | 
					
						
							|  |  |  |     registerProjectAndFile(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     updateUnsavedContent(filePathA, Utf8String(), 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangClangCodeModelServer, NoCompletionsForClosedDocument) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const int expectedDocumentAnnotationsChangedCount = 1; // Only for registration.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  |     completeCodeInFileA(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unregisterFile(filePathA); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangClangCodeModelServer, CodeCompletionDependingOnProject) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const int expectedDocumentAnnotationsChangedCount = 2; // For registration and due to project change.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathB, expectedDocumentAnnotationsChangedCount); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectCompletionFromFileBEnabledByMacro(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     changeProjectPartArguments(); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     completeCodeInFileB(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForEditorOnNonExistingTranslationUnit) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectTranslationUnitDoesNotExist(aFilePath); | 
					
						
							|  |  |  |     completeCode(aFilePath); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForCompletingUnregisteredFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectTranslationUnitDoesNotExist(anExistingFilePath); | 
					
						
							|  |  |  |     completeCode(anExistingFilePath, 20, 1); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetCodeCompletionForUnsavedFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							|  |  |  |     expectDocumentAnnotationsChanged(1); | 
					
						
							|  |  |  |     registerFileWithUnsavedContent(filePathA, unsavedContent(filePathAUnsavedVersion1)); | 
					
						
							|  |  |  |     expectCompletionFromFileAUnsavedMethodVersion1(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     completeCodeInFileA(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetNoCodeCompletionAfterRemovingUnsavedFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const int expectedDocumentAnnotationsChangedCount = 2; // For registration and update/removal.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  |     removeUnsavedFile(filePathA); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectNoCompletionWithUnsavedMethod(); | 
					
						
							|  |  |  |     completeCodeInFileA(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetNewCodeCompletionAfterUpdatingUnsavedFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const int expectedDocumentAnnotationsChangedCount = 2; // For registration and update/removal.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  |     updateUnsavedContent(filePathA, unsavedContent(filePathAUnsavedVersion2), 1); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectCompletionFromFileAUnsavedMethodVersion2(); | 
					
						
							|  |  |  |     completeCodeInFileA(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForUnregisterTranslationUnitWithWrongFilePath) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectTranslationUnitDoesNotExist(aFilePath); | 
					
						
							|  |  |  |     unregisterFile(aFilePath); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, UnregisterTranslationUnitAndTestFailingCompletion) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const int expectedDocumentAnnotationsChangedCount = 1; // Only for registration.
 | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, expectedDocumentAnnotationsChangedCount); | 
					
						
							|  |  |  |     unregisterFile(filePathA); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectTranslationUnitDoesNotExist(filePathA); | 
					
						
							|  |  |  |     completeCodeInFileA(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistUnregisterProjectPartInexistingProjectPart) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectProjectPartsDoNoExist({aProjectPartId}); | 
					
						
							|  |  |  |     unregisterProject(aProjectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistRegisterTranslationUnitWithInexistingProjectPart) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectProjectPartsDoNoExist({aProjectPartId}); | 
					
						
							|  |  |  |     registerFile(filePathB, aProjectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistUnregisterTranslationUnitWithInexistingProjectPart) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectProjectPartsDoNoExist({aProjectPartId}); | 
					
						
							|  |  |  |     unregisterFile(filePathB, aProjectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistForCompletingProjectPartFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFile(filePathB, 1); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectProjectPartsDoNoExist({aProjectPartId}); | 
					
						
							|  |  |  |     completeCode(filePathB, 1, 1, aProjectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistForCompletingUnregisteredFile) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectTranslationUnitDoesNotExist(anExistingFilePath); | 
					
						
							|  |  |  |     completeCode(anExistingFilePath); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, TicketNumberIsForwarded) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFile(filePathA, 1); | 
					
						
							|  |  |  |     const CompleteCodeMessage message(filePathA, 20, 1, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     expectCompletionWithTicketNumber(message.ticketNumber()); | 
					
						
							|  |  |  |     clangServer.completeCode(message); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, TranslationUnitAfterCreationIsNotDirty) | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFile(filePathA, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(clangServer, HasDirtyTranslationUnit(filePathA, projectPartId, 0U, false, false)); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-23 13:31:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, SetCurrentAndVisibleEditor) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFilesAndWaitForFinished(); | 
					
						
							|  |  |  |     auto functionTranslationUnit = translationUnits.translationUnit(filePathA, projectPartId); | 
					
						
							|  |  |  |     auto variableTranslationUnit = translationUnits.translationUnit(filePathB, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     updateVisibilty(filePathB, filePathA); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     ASSERT_TRUE(variableTranslationUnit.isUsedByCurrentEditor()); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  |     ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor()); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     ASSERT_TRUE(functionTranslationUnit.isVisibleInEditor()); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, IsNotCurrentCurrentAndVisibleEditorAnymore) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectAndFilesAndWaitForFinished(); | 
					
						
							|  |  |  |     auto functionTranslationUnit = translationUnits.translationUnit(filePathA, projectPartId); | 
					
						
							|  |  |  |     auto variableTranslationUnit = translationUnits.translationUnit(filePathB, projectPartId); | 
					
						
							|  |  |  |     updateVisibilty(filePathB, filePathA); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     updateVisibilty(filePathB, Utf8String()); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(functionTranslationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  |     ASSERT_FALSE(functionTranslationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  |     ASSERT_TRUE(variableTranslationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  |     ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | TEST_F(ClangClangCodeModelServer, TranslationUnitAfterUpdateNeedsReparse) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     registerProjectAndFileAndWaitForFinished(filePathA, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     updateUnsavedContent(filePathA, unsavedContent(filePathAUnsavedVersion1), 1U); | 
					
						
							|  |  |  |     ASSERT_THAT(clangServer, HasDirtyTranslationUnit(filePathA, projectPartId, 1U, true, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | void ClangClangCodeModelServer::SetUp() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-04 16:14:42 +02:00
										 |  |  |     clangServer.setClient(&mockClangCodeModelClient); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     clangServer.setUpdateDocumentAnnotationsTimeOutInMsForTestsOnly(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::TearDown() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_TRUE(waitUntilAllJobsFinished()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ClangClangCodeModelServer::waitUntilAllJobsFinished(int timeOutInMs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const auto noJobsRunningAnymore = [this]() { | 
					
						
							|  |  |  |         return clangServer.jobsForTestOnly().runningJobs() == 0 | 
					
						
							|  |  |  |             && clangServer.jobsForTestOnly().queue().size() == 0 | 
					
						
							|  |  |  |             && !clangServer.isTimerRunningForTestOnly(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return TestUtils::processEventsUntilTrue(noJobsRunningAnymore, timeOutInMs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::registerProjectAndFilesAndWaitForFinished( | 
					
						
							|  |  |  |         int expectedDocumentAnnotationsChangedMessages) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  |     registerProjectPart(); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerFiles(expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(waitUntilAllJobsFinished()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::registerFile(const Utf8String &filePath, | 
					
						
							|  |  |  |                                   int expectedDocumentAnnotationsChangedMessages) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainer(filePath, projectPartId); | 
					
						
							|  |  |  |     const RegisterTranslationUnitForEditorMessage message({fileContainer}, filePath, {filePath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectDocumentAnnotationsChanged(expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::registerFiles(int expectedDocumentAnnotationsChangedMessages) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainerA(filePathA, projectPartId); | 
					
						
							|  |  |  |     const FileContainer fileContainerB(filePathB, projectPartId); | 
					
						
							|  |  |  |     const RegisterTranslationUnitForEditorMessage message({fileContainerA, | 
					
						
							|  |  |  |                                                            fileContainerB}, | 
					
						
							|  |  |  |                                                            filePathA, | 
					
						
							|  |  |  |                                                            {filePathA, filePathB}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectDocumentAnnotationsChanged(expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerTranslationUnitsForEditor(message); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::expectDocumentAnnotationsChanged(int count) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     EXPECT_CALL(mockClangCodeModelClient, documentAnnotationsChanged(_)).Times(count); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-02 13:31:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::registerFile(const Utf8String &filePath, const Utf8String &projectFilePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainer(filePath, projectFilePath); | 
					
						
							|  |  |  |     const RegisterTranslationUnitForEditorMessage message({fileContainer}, filePath, {filePath}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::registerFileWithUnsavedContent(const Utf8String &filePath, | 
					
						
							|  |  |  |                                                     const Utf8String &unsavedContent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainer(filePath, projectPartId, unsavedContent, true); | 
					
						
							|  |  |  |     const RegisterTranslationUnitForEditorMessage message({fileContainer}, filePath, {filePath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::completeCode(const Utf8String &filePath, | 
					
						
							|  |  |  |                                   uint line, | 
					
						
							|  |  |  |                                   uint column, | 
					
						
							|  |  |  |                                   const Utf8String &projectPartId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Utf8String theProjectPartId = projectPartId; | 
					
						
							|  |  |  |     if (theProjectPartId.isEmpty()) | 
					
						
							|  |  |  |         theProjectPartId = this->projectPartId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const CompleteCodeMessage message(filePath, line, column, theProjectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.completeCode(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::completeCodeInFileA() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     completeCode(filePathA, 20, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::completeCodeInFileB() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     completeCode(filePathB, 35, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletion(const CodeCompletion &completion) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, | 
					
						
							|  |  |  |                 codeCompleted(Property(&CodeCompletedMessage::codeCompletions, | 
					
						
							|  |  |  |                                        Contains(completion)))) | 
					
						
							|  |  |  |             .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletionFromFileBEnabledByMacro() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const CodeCompletion completion(Utf8StringLiteral("ArgumentDefinitionVariable"), | 
					
						
							|  |  |  |                                     34, | 
					
						
							|  |  |  |                                     CodeCompletion::VariableCompletionKind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectCompletion(completion); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletionFromFileAUnsavedMethodVersion1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const CodeCompletion completion(Utf8StringLiteral("Method2"), | 
					
						
							|  |  |  |                                     34, | 
					
						
							|  |  |  |                                     CodeCompletion::FunctionCompletionKind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectCompletion(completion); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletionFromFileAUnsavedMethodVersion2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const CodeCompletion completion(Utf8StringLiteral("Method3"), | 
					
						
							|  |  |  |                                     34, | 
					
						
							|  |  |  |                                     CodeCompletion::FunctionCompletionKind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectCompletion(completion); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletionWithTicketNumber(quint64 ticketNumber) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, | 
					
						
							|  |  |  |                 codeCompleted(Property(&CodeCompletedMessage::ticketNumber, | 
					
						
							|  |  |  |                                        Eq(ticketNumber)))) | 
					
						
							|  |  |  |         .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectNoCompletionWithUnsavedMethod() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const CodeCompletion completion(Utf8StringLiteral("Method2"), | 
					
						
							|  |  |  |                                     34, | 
					
						
							|  |  |  |                                     CodeCompletion::FunctionCompletionKind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, | 
					
						
							|  |  |  |                 codeCompleted(Property(&CodeCompletedMessage::codeCompletions, | 
					
						
							|  |  |  |                                        Not(Contains(completion))))) | 
					
						
							|  |  |  |             .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectTranslationUnitDoesNotExist(const Utf8String &filePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const TranslationUnitDoesNotExistMessage message(filePath, projectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(message)) | 
					
						
							|  |  |  |         .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectCompletionFromFileA() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const CodeCompletion completion(Utf8StringLiteral("Function"), | 
					
						
							|  |  |  |                                     34, | 
					
						
							|  |  |  |                                     CodeCompletion::FunctionCompletionKind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectCompletion(completion); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::requestDocumentAnnotations(const Utf8String &filePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const RequestDocumentAnnotationsMessage message({filePath, projectPartId}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.requestDocumentAnnotations(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectDocumentAnnotationsChangedForFileBWithSpecificHighlightingMark() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     HighlightingTypes types; | 
					
						
							|  |  |  |     types.mainHighlightingType = ClangBackEnd::HighlightingType::Function; | 
					
						
							|  |  |  |     types.mixinHighlightingTypes.push_back(ClangBackEnd::HighlightingType::Declaration); | 
					
						
							|  |  |  |     const HighlightingMarkContainer highlightingMark(1, 6, 8, types); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, | 
					
						
							|  |  |  |                 documentAnnotationsChanged( | 
					
						
							|  |  |  |                     Property(&DocumentAnnotationsChangedMessage::highlightingMarks, | 
					
						
							|  |  |  |                              Contains(highlightingMark)))) | 
					
						
							|  |  |  |         .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::updateUnsavedContent(const Utf8String &filePath, | 
					
						
							|  |  |  |                                               const Utf8String &fileContent, | 
					
						
							|  |  |  |                                               quint32 revisionNumber) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainer(filePath, projectPartId, fileContent, true, revisionNumber); | 
					
						
							|  |  |  |     const UpdateTranslationUnitsForEditorMessage message({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.updateTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::removeUnsavedFile(const Utf8String &filePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74); | 
					
						
							|  |  |  |     const UpdateTranslationUnitsForEditorMessage message({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.updateTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::unregisterFile(const Utf8String &filePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QVector<FileContainer> fileContainers = {FileContainer(filePath, projectPartId)}; | 
					
						
							|  |  |  |     const UnregisterTranslationUnitsForEditorMessage message(fileContainers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.unregisterTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::unregisterFile(const Utf8String &filePath, const Utf8String &projectPartId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QVector<FileContainer> fileContainers = {FileContainer(filePath, projectPartId)}; | 
					
						
							|  |  |  |     const UnregisterTranslationUnitsForEditorMessage message(fileContainers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.unregisterTranslationUnitsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::unregisterProject(const Utf8String &projectPartId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const UnregisterProjectPartsForEditorMessage message({projectPartId}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.unregisterProjectPartsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangClangCodeModelServer::expectProjectPartsDoNoExist(const Utf8StringVector &projectFilePaths) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPartsDoNotExistMessage message(projectFilePaths); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangCodeModelClient, projectPartsDoNotExist(message)) | 
					
						
							|  |  |  |         .Times(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | void ClangClangCodeModelServer::registerProjectPart() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerProjectPartsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::registerProjectAndFile(const Utf8String &filePath, | 
					
						
							|  |  |  |                                                        int expectedDocumentAnnotationsChangedMessages) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     registerProjectPart(); | 
					
						
							|  |  |  |     registerFile(filePath, expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::registerProjectAndFileAndWaitForFinished( | 
					
						
							|  |  |  |         const Utf8String &filePath, | 
					
						
							|  |  |  |         int expectedDocumentAnnotationsChangedMessages) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     registerProjectAndFile(filePath, expectedDocumentAnnotationsChangedMessages); | 
					
						
							|  |  |  |     ASSERT_TRUE(waitUntilAllJobsFinished()); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::changeProjectPartArguments() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const ProjectPartContainer projectPartContainer(projectPartId, | 
					
						
							|  |  |  |                                                     {Utf8StringLiteral("-DArgumentDefinition")}); | 
					
						
							|  |  |  |     const RegisterProjectPartsForEditorMessage message({projectPartContainer}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     clangServer.registerProjectPartsForEditor(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | void ClangClangCodeModelServer::updateVisibilty(const Utf8String ¤tEditor, | 
					
						
							|  |  |  |                                      const Utf8String &additionalVisibleEditor) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const UpdateVisibleTranslationUnitsMessage message(currentEditor, | 
					
						
							|  |  |  |                                                        {currentEditor, additionalVisibleEditor}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     clangServer.updateVisibleTranslationUnits(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 16:49:56 +02:00
										 |  |  | const Utf8String ClangClangCodeModelServer::unsavedContent(const QString &unsavedFilePath) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QFile unsavedFileContentFile(unsavedFilePath); | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  |     const bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:29:28 +01:00
										 |  |  |     if (!isOpen) | 
					
						
							|  |  |  |         ADD_FAILURE() << "File with the unsaved content cannot be opened!"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Utf8String::fromByteArray(unsavedFileContentFile.readAll()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | } // anonymous
 |