| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** 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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 17:41:41 +02:00
										 |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  | #include <clangclock.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <clangfilepath.h>
 | 
					
						
							|  |  |  | #include <clangtranslationunitupdater.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  | #include <clangtranslationunits.h>
 | 
					
						
							|  |  |  | #include <clangtranslationunit.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <commandlinearguments.h>
 | 
					
						
							|  |  |  | #include <diagnosticset.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | #include <tokenprocessor.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <filecontainer.h>
 | 
					
						
							|  |  |  | #include <projectpart.h>
 | 
					
						
							|  |  |  | #include <projectpartcontainer.h>
 | 
					
						
							|  |  |  | #include <projects.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-09 14:25:59 +02:00
										 |  |  | #include <clangexceptions.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <clangdocument.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  | #include <clangtranslationunit.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <clangdocuments.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | #include <utf8string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <clang-c/Index.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QTemporaryFile>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <thread>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  | using ClangBackEnd::Clock; | 
					
						
							|  |  |  | using ClangBackEnd::Duration; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | using ClangBackEnd::FileContainer; | 
					
						
							|  |  |  | using ClangBackEnd::FilePath; | 
					
						
							|  |  |  | using ClangBackEnd::Document; | 
					
						
							|  |  |  | using ClangBackEnd::UnsavedFiles; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPart; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPartContainer; | 
					
						
							|  |  |  | using ClangBackEnd::Documents; | 
					
						
							|  |  |  | using ClangBackEnd::TranslationUnitUpdateResult; | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  | using ClangBackEnd::TranslationUnit; | 
					
						
							|  |  |  | using ClangBackEnd::TranslationUnits; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | using testing::IsNull; | 
					
						
							|  |  |  | using testing::NotNull; | 
					
						
							|  |  |  | using testing::Eq; | 
					
						
							|  |  |  | using testing::Gt; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | using testing::EndsWith; | 
					
						
							|  |  |  | using testing::AllOf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Document : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							|  |  |  |     ::Document createDocumentAndDeleteFile(); | 
					
						
							|  |  |  |     QByteArray readContentFromDocumentFile() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							|  |  |  |     Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")}; | 
					
						
							|  |  |  |     ProjectPart projectPart; | 
					
						
							|  |  |  |     Utf8String documentFilePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp"); | 
					
						
							|  |  |  |     ClangBackEnd::UnsavedFiles unsavedFiles; | 
					
						
							|  |  |  |     ClangBackEnd::Documents documents{projects, unsavedFiles}; | 
					
						
							|  |  |  |     ::Document document; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | using DocumentSlowTest = Document; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | TEST_F(Document, DefaultDocumentIsInvalid) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ::Document document; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(document.isNull()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, DefaultDocumentIsNotIntact) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ::Document document; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(document.isIntact()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ThrowExceptionForNonExistingFilePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-03 09:36:37 +02:00
										 |  |  |     ASSERT_THROW(::Document(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), | 
					
						
							|  |  |  |                             documents), | 
					
						
							| 
									
										
										
										
											2016-09-09 14:42:35 +02:00
										 |  |  |                  ClangBackEnd::DocumentFileDoesNotExistException); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ThrowNoExceptionForNonExistingFilePathIfDoNotCheckIfFileExistsIsSet) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-03 09:36:37 +02:00
										 |  |  |     ASSERT_NO_THROW(::Document(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), | 
					
						
							|  |  |  |                                documents, ::Document::FileExistsCheck::DoNotCheck)); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, DocumentIsValid) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_FALSE(document.isNull()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ThrowExceptionForGettingIndexForInvalidUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ::Document document; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 14:42:35 +02:00
										 |  |  |     ASSERT_THROW(document.translationUnit().cxIndex(), ClangBackEnd::DocumentIsNullException); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ::Document document; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 14:42:35 +02:00
										 |  |  |     ASSERT_THROW(document.translationUnit().cxIndex(), ClangBackEnd::DocumentIsNullException); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, CxTranslationUnitGetterIsNonNullForParsedUnit) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  |     ASSERT_THAT(document.translationUnit().cxIndex(), NotNull()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ThrowExceptionIfGettingFilePathForNullUnit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    ::Document document; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 14:42:35 +02:00
										 |  |  |     ASSERT_THROW(document.filePath(), ClangBackEnd::DocumentIsNullException); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, ResettedDocumentIsNull) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     document.reset(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(document.isNull()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, LastCommandLineArgumentIsFilePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const Utf8String nativeFilePath = FilePath::toNativeSeparators(documentFilePath); | 
					
						
							|  |  |  |     const auto arguments = document.createUpdater().commandLineArguments(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(nativeFilePath)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     auto lastChangeTimePoint = document.lastProjectPartChangeTimePoint(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     std::this_thread::sleep_for(Duration(1)); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(document.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ProjectPart projectPart = document.projectPart(); | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  |     auto lastChangeTimePoint = document.lastProjectPartChangeTimePoint(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     std::this_thread::sleep_for(Duration(1)); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     projectPart.clear(); | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(document.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, DocumentRevisionInFileContainerGetter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     document.setDocumentRevision(74); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 18:25:23 +02:00
										 |  |  |     ASSERT_THAT(document.fileContainer().documentRevision, 74); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, DependedFilePaths) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(document.dependedFilePaths(), | 
					
						
							|  |  |  |                 AllOf(Contains(documentFilePath), | 
					
						
							|  |  |  |                       Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, DeletedFileShouldNotNeedReparsing) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto document = createDocumentAndDeleteFile(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(document.filePath()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, NeedsNoReparseAfterCreation) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NeedsReparseAfterChangeOfMainFile) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(documentFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NoNeedForReparsingForIndependendFile) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NeedsReparsingForDependendFile) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NeedsNoReparsingAfterReparsing) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.reparse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, IsIntactAfterParsing) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(document.isIntact()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, IsNotIntactForDeletedFile) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto document = createDocumentAndDeleteFile(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(document.isIntact()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterParse) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NeedsReparseAfterMainFileChanged) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(documentFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, NeedsReparseAfterIncludedFileChanged) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterNotIncludedFileChanged) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, DoesNotNeedReparseAfterReparse) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(documentFilePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.reparse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, SetDirtyIfProjectPartIsOutdated) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     projects.createOrUpdate({ProjectPartContainer(projectPartId)}); | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  |     projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 15:48:44 +02:00
										 |  |  |     const bool wasOutdated = document.setDirtyIfProjectPartIsOutdated(); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 15:48:44 +02:00
										 |  |  |     ASSERT_TRUE(wasOutdated); | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentSlowTest, SetNotDirtyIfProjectPartIsNotOutdated) | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     document.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 15:48:44 +02:00
										 |  |  |     const bool wasOutdated = document.setDirtyIfProjectPartIsOutdated(); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 15:48:44 +02:00
										 |  |  |     ASSERT_FALSE(wasOutdated); | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, IncorporateUpdaterResultResetsDirtyness) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(document.filePath()); | 
					
						
							|  |  |  |     TranslationUnitUpdateResult result; | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     result.reparseTimePoint = Clock::now(); | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     result.needsToBeReparsedChangeTimePoint = document.isDirtyTimeChangePoint(); | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |     result.translationUnitId = document.translationUnit().id(); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     document.incorporateUpdaterResult(result); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_FALSE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(Document, IncorporateUpdaterResultDoesNotResetDirtynessIfItWasChanged) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     TranslationUnitUpdateResult result; | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     result.reparseTimePoint = Clock::now(); | 
					
						
							|  |  |  |     result.needsToBeReparsedChangeTimePoint = Clock::now(); | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |     result.translationUnitId = document.translationUnit().id(); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |     document.setDirtyIfDependencyIsMet(document.filePath()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.incorporateUpdaterResult(result); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 10:10:50 +02:00
										 |  |  |     ASSERT_TRUE(document.isDirty()); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  | TEST_F(Document, IncorporateUpdaterResultUpdatesTranslationUnitsReparseTimePoint) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     TranslationUnits &translationUnits = document.translationUnits(); | 
					
						
							|  |  |  |     const TranslationUnit initialTranslationUnit = translationUnits.get(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     translationUnits.updateParseTimePoint(initialTranslationUnit.id(), Clock::now()); | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |     const TranslationUnit alternativeTranslationUnit = translationUnits.createAndAppend(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     translationUnits.updateParseTimePoint(alternativeTranslationUnit.id(), Clock::now()); | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |     TranslationUnitUpdateResult result; | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     result.reparseTimePoint = Clock::now(); | 
					
						
							|  |  |  |     result.needsToBeReparsedChangeTimePoint = Clock::now(); | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |     result.translationUnitId = initialTranslationUnit.id(); | 
					
						
							|  |  |  |     document.setDirtyIfDependencyIsMet(document.filePath()); | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.get().id(), Eq(alternativeTranslationUnit.id())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     document.incorporateUpdaterResult(result); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(translationUnits.get().id(), Eq(initialTranslationUnit.id())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | void Document::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     projects.createOrUpdate({ProjectPartContainer(projectPartId)}); | 
					
						
							|  |  |  |     projectPart = *projects.findProjectPart(projectPartId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QVector<FileContainer> fileContainer{FileContainer(documentFilePath, projectPartId)}; | 
					
						
							|  |  |  |     const auto createdDocuments = documents.create(fileContainer); | 
					
						
							|  |  |  |     document = createdDocuments.front(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ::Document Document::createDocumentAndDeleteFile() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTemporaryFile temporaryFile; | 
					
						
							|  |  |  |     EXPECT_TRUE(temporaryFile.open()); | 
					
						
							|  |  |  |     EXPECT_TRUE(temporaryFile.write(readContentFromDocumentFile())); | 
					
						
							|  |  |  |     ::Document document(temporaryFile.fileName(), | 
					
						
							|  |  |  |                         projectPart, | 
					
						
							|  |  |  |                         Utf8StringVector(), | 
					
						
							|  |  |  |                         documents); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return document; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray Document::readContentFromDocumentFile() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QFile contentFile(documentFilePath); | 
					
						
							|  |  |  |     EXPECT_TRUE(contentFile.open(QIODevice::ReadOnly)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return contentFile.readAll(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |