| 
									
										
										
										
											2015-10-01 12:45:06 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). | 
					
						
							|  |  |  | ** Contact: http://www.qt.io/licensing
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Digia.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://www.qt.io/licensing.  For further information
 | 
					
						
							|  |  |  | ** use the contact form at http://www.qt.io/contact-us.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 or version 3 as published by the Free | 
					
						
							|  |  |  | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | 
					
						
							|  |  |  | ** LICENSE.LGPLv3 included in the packaging of this file.  Please review the | 
					
						
							|  |  |  | ** following information to ensure the GNU Lesser General Public License | 
					
						
							|  |  |  | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
 | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							|  |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 13:10:28 +02:00
										 |  |  | #include <diagnosticset.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <filecontainer.h>
 | 
					
						
							|  |  |  | #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-06-16 12:38:04 +02:00
										 |  |  | #include <translationunit.h>
 | 
					
						
							|  |  |  | #include <translationunitisnullexception.h>
 | 
					
						
							|  |  |  | #include <translationunits.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | #include <utf8string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <clang-c/Index.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  | #include "mocksenddiagnosticscallback.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-11-25 15:21:24 +01:00
										 |  |  | using ClangBackEnd::DiagnosticsChangedMessage; | 
					
						
							|  |  |  | using ClangBackEnd::DiagnosticSendState; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:21:24 +01:00
										 |  |  |     void sendAllDiagnostics(); | 
					
						
							|  |  |  |     void sendAllCurrentEditorDiagnostics(); | 
					
						
							|  |  |  |     void sendAllVisibleEditorsDiagnostics(); | 
					
						
							| 
									
										
										
										
											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-25 15:21:24 +01:00
										 |  |  |     MockSendDiagnosticCallback mockSendDiagnosticCallback; | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							|  |  |  |     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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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-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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, Update) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 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()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setCurrentEditor(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotCurrentEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setCurrentEditor(headerPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotCurrentEditorAfterBeingCurrent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnits.setCurrentEditor(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setCurrentEditor(headerPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isUsedByCurrentEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsVisibleEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setVisibleEditors({filePath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotVisibleEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setVisibleEditors({headerPath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, IsNotVisibleEditorAfterBeingVisible) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnits.setVisibleEditors({filePath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.setVisibleEditors({headerPath}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(translationUnit.isVisibleInEditor()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotSendDiagnosticsIfThereIsNothingToSend) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, SendDiagnosticsAfterTranslationUnitCreation) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotSendDiagnosticsAfterGettingDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.diagnostics(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, SendDiagnosticsForCurrentEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.setIsUsedByCurrentEditor(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllCurrentEditorDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotSendDiagnosticsForCurrentEditorIfThereIsNoCurrentEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllCurrentEditorDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotSendDiagnosticsForCurrentEditorAfterGettingDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto translationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     translationUnit.setIsUsedByCurrentEditor(true); | 
					
						
							|  |  |  |     translationUnit.diagnostics(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllCurrentEditorDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, DoNotSendDiagnosticsForVisibleEditorIfThereAreNoVisibleEditors) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     translationUnits.sendChangedDiagnosticsForVisibleEditors(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, SendDiagnosticsForVisibleEditors) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     fileTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     auto headerTranslationUnit = translationUnits.translationUnit(headerContainer); | 
					
						
							|  |  |  |     headerTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllVisibleEditorsDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(TranslationUnits, SendOnlyOneDiagnosticsForVisibleEditor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     translationUnits.create({fileContainer, headerContainer}); | 
					
						
							|  |  |  |     auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); | 
					
						
							|  |  |  |     fileTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     auto headerTranslationUnit = translationUnits.translationUnit(headerContainer); | 
					
						
							|  |  |  |     headerTranslationUnit.setIsVisibleInEditor(true); | 
					
						
							|  |  |  |     headerTranslationUnit.diagnostics(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSendDiagnosticCallback, sendDiagnostic()).Times(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendAllVisibleEditorsDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslationUnits::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     projects.createOrUpdate({ClangBackEnd::ProjectPartContainer(projectPartId)}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto callback = [&] (const DiagnosticsChangedMessage &) { mockSendDiagnosticCallback.sendDiagnostic(); }; | 
					
						
							|  |  |  |     translationUnits.setSendChangeDiagnosticsCallback(callback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslationUnits::sendAllDiagnostics() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto diagnosticSendState = DiagnosticSendState::MaybeThereAreMoreDiagnostics; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (diagnosticSendState == DiagnosticSendState::MaybeThereAreMoreDiagnostics) | 
					
						
							|  |  |  |         diagnosticSendState = translationUnits.sendChangedDiagnostics(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslationUnits::sendAllCurrentEditorDiagnostics() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto diagnosticSendState = DiagnosticSendState::MaybeThereAreMoreDiagnostics; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (diagnosticSendState == DiagnosticSendState::MaybeThereAreMoreDiagnostics) | 
					
						
							|  |  |  |         diagnosticSendState = translationUnits.sendChangedDiagnosticsForCurrentEditor(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslationUnits::sendAllVisibleEditorsDiagnostics() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto diagnosticSendState = DiagnosticSendState::MaybeThereAreMoreDiagnostics; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (diagnosticSendState == DiagnosticSendState::MaybeThereAreMoreDiagnostics) | 
					
						
							|  |  |  |         diagnosticSendState = translationUnits.sendChangedDiagnosticsForVisibleEditors(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 12:54:22 +02:00
										 |  |  | } |