| 
									
										
										
										
											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
										 |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  | #include <diagnosticset.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <filecontainer.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | #include <highlightingchangedmessage.h>
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  | #include <highlightingmarks.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <projectpartcontainer.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-16 12:38:04 +02:00
										 |  |  | #include <projectpart.h>
 | 
					
						
							|  |  |  | #include <projectpartsdonotexistexception.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <projects.h>
 | 
					
						
							|  |  |  | #include <translationunitdoesnotexistexception.h>
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | #include <translationunitalreadyexistsexception.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <translationunitfilenotexitexception.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-24 11:17:18 +01:00
										 |  |  | #include <clangtranslationunit.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-16 12:38:04 +02:00
										 |  |  | #include <translationunitisnullexception.h>
 | 
					
						
							|  |  |  | #include <translationunits.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | #include <utf8string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 15:31:49 +02:00
										 |  |  | #include <QTemporaryFile>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 12:38:04 +02:00
										 |  |  | #include <clang-c/Index.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | #include "mocksenddocumentannotationscallback.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  | using ClangBackEnd::TranslationUnit; | 
					
						
							|  |  |  | using ClangBackEnd::UnsavedFiles; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPart; | 
					
						
							| 
									
										
										
										
											2015-12-07 13:37:02 +01:00
										 |  |  | using ClangBackEnd::ProjectPartContainer; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | using ClangBackEnd::DiagnosticsChangedMessage; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | using ClangBackEnd::HighlightingChangedMessage; | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | using ClangBackEnd::DocumentAnnotationsSendState; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | using testing::IsNull; | 
					
						
							|  |  |  | using testing::NotNull; | 
					
						
							|  |  |  | using testing::Gt; | 
					
						
							|  |  |  | using testing::Not; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ::testing::PrintToString; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | MATCHER_P3(IsTranslationUnit, filePath, projectPartId, documentRevision, | 
					
						
							|  |  |  |            std::string(negation ? "isn't" : "is") | 
					
						
							|  |  |  |            + " translation unit with file path "+ PrintToString(filePath) | 
					
						
							|  |  |  |            + " and project " + PrintToString(projectPartId) | 
					
						
							|  |  |  |            + " and document revision " + PrintToString(documentRevision) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     return arg.filePath() == filePath | 
					
						
							|  |  |  |         && arg.projectPartId() == projectPartId | 
					
						
							|  |  |  |         && arg.documentRevision() == documentRevision; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TranslationUnits : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							| 
									
										
										
										
											2016-04-22 15:31:49 +02:00
										 |  |  |     void createDirtyTranslationUnitAndDeleteFile(); | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     void sendAllDocumentAnnotations(); | 
					
						
							|  |  |  |     void sendAllDocumentAnnotationsForCurrentEditor(); | 
					
						
							|  |  |  |     void sendAllDocumentAnnotationsForVisibleEditors(); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							|  |  |  |     ClangBackEnd::UnsavedFiles unsavedFiles; | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     MockSendDocumentAnnotationsCallback mockSendDocumentAnnotationsCallback; | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp"); | 
					
						
							|  |  |  |     const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"); | 
					
						
							|  |  |  |     const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp"); | 
					
						
							|  |  |  |     const Utf8String projectPartId = Utf8StringLiteral("projectPartId"); | 
					
						
							| 
									
										
										
										
											2016-06-06 12:32:45 +02:00
										 |  |  |     const Utf8String otherProjectPartId = Utf8StringLiteral("otherProjectPartId"); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     const Utf8String nonExistingProjectPartId = Utf8StringLiteral("nonExistingProjectPartId"); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  |     const ClangBackEnd::FileContainer fileContainer{filePath, projectPartId}; | 
					
						
							|  |  |  |     const ClangBackEnd::FileContainer headerContainer{headerPath, projectPartId}; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForGettingWithWrongFilePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ASSERT_THROW(translationUnits.translationUnit(nonExistingFilePath, projectPartId), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::TranslationUnitDoesNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForGettingWithWrongProjectPartFilePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ASSERT_THROW(translationUnits.translationUnit(filePath, nonExistingProjectPartId), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::ProjectPartDoNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForAddingNonExistingFile) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     ASSERT_THROW(translationUnits.create({fileContainer}), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::TranslationUnitFileNotExitsException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotThrowForAddingNonExistingFileWithUnsavedContent) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId, Utf8String(), true); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     ASSERT_NO_THROW(translationUnits.create({fileContainer})); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 15:31:49 +02:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForVanishedMainFile) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     createDirtyTranslationUnitAndDeleteFile(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllDocumentAnnotations(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | TEST_F(TranslationUnits, Add) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |                 IsTranslationUnit(filePath, projectPartId, 74u)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 13:31:07 +01:00
										 |  |  | TEST_F(TranslationUnits, AddAndTestCreatedTranslationUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto createdTranslationUnits = translationUnits.create({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(createdTranslationUnits.front(), | 
					
						
							|  |  |  |                 IsTranslationUnit(filePath, projectPartId, 74u)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | TEST_F(TranslationUnits, ThrowForCreatingAnExistingTranslationUnit) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THROW(translationUnits.create({fileContainer}), | 
					
						
							|  |  |  |                  ClangBackEnd::TranslationUnitAlreadyExistsException); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForUpdatingANonExistingTranslationUnit) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     ASSERT_THROW(translationUnits.update({fileContainer}), | 
					
						
							|  |  |  |                  ClangBackEnd::TranslationUnitDoesNotExistException); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-06 12:32:45 +02:00
										 |  |  | TEST_F(TranslationUnits, UpdateSingle) | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({createFileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.update({updateFileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), | 
					
						
							|  |  |  |                 IsTranslationUnit(filePath, projectPartId, 75u)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-06 12:32:45 +02:00
										 |  |  | TEST_F(TranslationUnits, UpdateMultiple) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, otherProjectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer updatedFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u); | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, fileContainerWithOtherProject}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.update({updatedFileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), | 
					
						
							|  |  |  |                 IsTranslationUnit(filePath, projectPartId, 75u)); | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.translationUnit(filePath, otherProjectPartId), | 
					
						
							|  |  |  |                 IsTranslationUnit(filePath, otherProjectPartId, 75u)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     translationUnits.translationUnit(filePath, projectPartId).cxTranslationUnit(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.update({headerContainerWithUnsavedContent}); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).isNeedingReparse()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  | TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  |     ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  |     translationUnits.translationUnit(filePath, projectPartId).diagnostics(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.update({headerContainerWithUnsavedContent}); | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewDiagnostics()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  |     ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  |     translationUnits.translationUnit(filePath, projectPartId).diagnostics(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.remove({headerContainerWithUnsavedContent}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewDiagnostics()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  | TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForHighlightingMarks) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     translationUnits.translationUnit(filePath, projectPartId).highlightingMarks(); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.update({headerContainerWithUnsavedContent}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewHighlightingMarks()); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  | TEST_F(TranslationUnits, RemoveFileAndCheckForHighlightingMarks) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     translationUnits.translationUnit(filePath, projectPartId).highlightingMarks(); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.remove({headerContainerWithUnsavedContent}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewHighlightingMarks()); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | TEST_F(TranslationUnits, DontGetNewerFileContainerIfRevisionIsTheSame) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto newerFileContainers = translationUnits.newerFileContainers({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(newerFileContainers.size(), 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, GetNewerFileContainerIfRevisionIsDifferent) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u); | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer newerContainer(filePath, projectPartId, Utf8StringVector(), 75u); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto newerFileContainers = translationUnits.newerFileContainers({newerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(newerFileContainers.size(), 1); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForRemovingWithWrongFilePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THROW(translationUnits.remove({fileContainer}), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::TranslationUnitDoesNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectPartFilePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, nonExistingProjectPartId); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THROW(translationUnits.remove({fileContainer}), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::ProjectPartDoNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, Remove) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.remove({fileContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THROW(translationUnits.translationUnit(filePath, projectPartId), | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |                  ClangBackEnd::TranslationUnitDoesNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({fileContainer}); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ASSERT_THROW(translationUnits.remove({ClangBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro"), projectPartId), fileContainer}), | 
					
						
							|  |  |  |                  ClangBackEnd::TranslationUnitDoesNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.translationUnits(), | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |                 Not(Contains(TranslationUnit(filePath, | 
					
						
							|  |  |  |                                              projects.project(projectPartId), | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |                                              Utf8StringVector(), | 
					
						
							| 
									
										
										
										
											2015-08-31 12:40:14 +02:00
										 |  |  |                                              translationUnits)))); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 12:54:22 +02:00
										 |  |  | TEST_F(TranslationUnits, HasTranslationUnit) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-13 15:56:41 +02:00
										 |  |  |     translationUnits.create({{filePath, projectPartId}}); | 
					
						
							| 
									
										
										
										
											2015-10-13 12:54:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnits.hasTranslationUnit(filePath)); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 12:54:22 +02:00
										 |  |  | TEST_F(TranslationUnits, HasNotTranslationUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnits.hasTranslationUnit(filePath)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | TEST_F(TranslationUnits, isUsedByCurrentEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setUsedByCurrentEditor(filePath); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotCurrentEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setUsedByCurrentEditor(headerPath); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotCurrentEditorAfterBeingCurrent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setUsedByCurrentEditor(filePath); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setUsedByCurrentEditor(headerPath); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsVisibleEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setVisibleInEditors({filePath}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotVisibleEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setVisibleInEditors({headerPath}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotVisibleEditorAfterBeingVisible) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setVisibleInEditors({filePath}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 16:33:01 +01:00
										 |  |  |     translationUnits.setVisibleInEditors({headerPath}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsIfThereIsNothingToSend) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotations(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 14:08:37 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsAfterTranslationUnitCreation) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 14:08:37 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotations(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsAfterGettingDocumentAnnotations) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							| 
									
										
										
										
											2015-12-01 14:08:37 +01:00
										 |  |  |     translationUnit.setIsVisibleInEditor(true); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     translationUnit.diagnostics(); // Reset
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     translationUnit.highlightingMarks(); // Reset
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 14:08:37 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotations(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, SendDocumentAnnotationsForCurrentEditor) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.setIsUsedByCurrentEditor(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotationsForCurrentEditor(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForCurrentEditorIfThereIsNoCurrentEditor) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotationsForCurrentEditor(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForCurrentEditorAfterGettingDocumentAnnotations) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.setIsUsedByCurrentEditor(true); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     translationUnit.diagnostics(); // Reset
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     translationUnit.highlightingMarks(); // Reset
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotationsForCurrentEditor(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForVisibleEditorIfThereAreNoVisibleEditors) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     translationUnits.sendDocumentAnnotationsForVisibleEditors(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, SendDocumentAnnotationsForVisibleEditors) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     fileTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     auto headerTranslationUnit = translationUnits.translationUnit(headerContainer); | 
					
						
							|  |  |  |     headerTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(2); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotationsForVisibleEditors(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | TEST_F(TranslationUnits, SendDocumentAnnotationsOnlyOnceForVisibleEditor) | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     fileTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     auto headerTranslationUnit = translationUnits.translationUnit(headerContainer); | 
					
						
							|  |  |  |     headerTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     headerTranslationUnit.diagnostics(); // Reset
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     headerTranslationUnit.highlightingMarks(); // Reset
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     sendAllDocumentAnnotationsForVisibleEditors(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:37:02 +01:00
										 |  |  | TEST_F(TranslationUnits, SendDocumentAnnotationsAfterProjectPartChange) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     fileTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     fileTranslationUnit.diagnostics(); // Reset
 | 
					
						
							| 
									
										
										
										
											2016-02-29 13:09:39 +01:00
										 |  |  |     fileTranslationUnit.highlightingMarks(); // Reset
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:37:02 +01:00
										 |  |  |     projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})}); | 
					
						
							|  |  |  |     translationUnits.setTranslationUnitsDirtyIfProjectPartChanged(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllDocumentAnnotationsForVisibleEditors(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | void TranslationUnits::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-12-07 13:37:02 +01:00
										 |  |  |     projects.createOrUpdate({ProjectPartContainer(projectPartId)}); | 
					
						
							| 
									
										
										
										
											2016-06-06 12:32:45 +02:00
										 |  |  |     projects.createOrUpdate({ProjectPartContainer(otherProjectPartId)}); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     auto callback = [&] (const DiagnosticsChangedMessage &, const HighlightingChangedMessage &) { | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |         mockSendDocumentAnnotationsCallback.sendDocumentAnnotations(); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     translationUnits.setSendDocumentAnnotationsCallback(callback); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 15:31:49 +02:00
										 |  |  | void TranslationUnits::createDirtyTranslationUnitAndDeleteFile() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTemporaryFile temporaryFile(QLatin1String("XXXXXX.cpp")); | 
					
						
							|  |  |  |     EXPECT_TRUE(temporaryFile.open()); | 
					
						
							|  |  |  |     const QString temporaryFilePath = Utf8String::fromString(temporaryFile.fileName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ClangBackEnd::FileContainer fileContainer(temporaryFilePath, | 
					
						
							|  |  |  |                                               projectPartId, Utf8String(), true); | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.setIsUsedByCurrentEditor(true); | 
					
						
							|  |  |  |     translationUnit.setDirtyIfDependencyIsMet(translationUnit.filePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | void TranslationUnits::sendAllDocumentAnnotations() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations) | 
					
						
							|  |  |  |         sendState = translationUnits.sendDocumentAnnotations(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | void TranslationUnits::sendAllDocumentAnnotationsForCurrentEditor() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations) | 
					
						
							|  |  |  |         sendState = translationUnits.sendDocumentAnnotationsForCurrentEditor(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  | void TranslationUnits::sendAllDocumentAnnotationsForVisibleEditors() | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 15:15:28 +01:00
										 |  |  |     while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations) | 
					
						
							|  |  |  |         sendState = translationUnits.sendDocumentAnnotationsForVisibleEditors(); | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 12:54:22 +02:00
										 |  |  | } |