| 
									
										
										
										
											2016-08-04 15:26:53 +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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 19:53:32 +02:00
										 |  |  | #include "filesystem-utilities.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | #include "mockrefactoringclient.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | #include "mocksymbolindexing.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | #include "sourcerangecontainer-matcher.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | #include <clangrefactoringmessages.h>
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | #include <filepathcaching.h>
 | 
					
						
							|  |  |  | #include <refactoringdatabaseinitializer.h>
 | 
					
						
							|  |  |  | #include <refactoringserver.h>
 | 
					
						
							|  |  |  | #include <sqlitedatabase.h>
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 17:44:38 +01:00
										 |  |  | #include <utils/temporarydirectory.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | #include <QTemporaryFile>
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::AllOf; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  | using testing::Field; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | using testing::IsEmpty; | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | using testing::NiceMock; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  | using testing::Not; | 
					
						
							| 
									
										
										
										
											2016-08-08 15:58:48 +02:00
										 |  |  | using testing::Pair; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | using testing::PrintToString; | 
					
						
							|  |  |  | using testing::Property; | 
					
						
							| 
									
										
										
										
											2016-08-08 15:58:48 +02:00
										 |  |  | using testing::_; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | using ClangBackEnd::FilePath; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::IncludeSearchPaths; | 
					
						
							|  |  |  | using ClangBackEnd::IncludeSearchPathType; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | using ClangBackEnd::RequestSourceLocationsForRenamingMessage; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | using ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | using ClangBackEnd::RequestSourceRangesForQueryMessage; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | using ClangBackEnd::SourceLocationsContainer; | 
					
						
							|  |  |  | using ClangBackEnd::SourceLocationsForRenamingMessage; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | using ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage; | 
					
						
							|  |  |  | using ClangBackEnd::SourceRangesContainer; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::SourceRangesForQueryMessage; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | using ClangBackEnd::V2::FileContainer; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | using ClangBackEnd::V2::FileContainers; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::ProjectPartContainer; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPartContainers; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | MATCHER_P2(IsSourceLocation, line, column, | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |            std::string(negation ? "isn't " : "is ") | 
					
						
							|  |  |  |            + "(" + PrintToString(line) | 
					
						
							|  |  |  |            + ", " + PrintToString(column) | 
					
						
							|  |  |  |            + ")" | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |     return arg.line == uint(line) | 
					
						
							|  |  |  |         && arg.column == uint(column); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RefactoringServer : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  |     void SetUp() override; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     void TearDown() override; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     ClangBackEnd::FilePathId filePathId(Utils::SmallStringView string) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return filePathCache.filePathId(ClangBackEnd::FilePathView{string}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  |     NiceMock<MockRefactoringClient> mockRefactoringClient; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  |     NiceMock<MockSymbolIndexing> mockSymbolIndexing; | 
					
						
							| 
									
										
										
										
											2017-10-18 13:34:05 +02:00
										 |  |  |     Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; | 
					
						
							|  |  |  |     ClangBackEnd::FilePathCaching filePathCache{database}; | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  |     ClangBackEnd::GeneratedFiles generatedFiles; | 
					
						
							|  |  |  |     ClangBackEnd::RefactoringServer refactoringServer{mockSymbolIndexing, filePathCache, generatedFiles}; | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  |     Utils::SmallString sourceContent{"void f()\n {}"}; | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, sourceContent.clone(), {"cc"}}; | 
					
						
							| 
									
										
										
										
											2019-01-31 10:30:58 +01:00
										 |  |  |     QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath() | 
					
						
							|  |  |  |                                  + "/clangQuery-XXXXXX.cpp"}; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     int processingSlotCount = 2; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | using RefactoringServerSlowTest = RefactoringServer; | 
					
						
							|  |  |  | using RefactoringServerVerySlowTest = RefactoringServer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringServerSlowTest, RequestSourceLocationsForRenamingMessage) | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     RequestSourceLocationsForRenamingMessage message{ | 
					
						
							|  |  |  |         {TESTDATA_DIR, "renamevariable.cpp"}, 1, 5, "int v;\n\nint x = v + 3;\n", {"cc"}, 1}; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceLocationsForRenamingMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     AllOf(Field(&SourceLocationsForRenamingMessage::textDocumentRevision, 1), | 
					
						
							|  |  |  |                           Field(&SourceLocationsForRenamingMessage::symbolName, "v"), | 
					
						
							|  |  |  |                           Field(&SourceLocationsForRenamingMessage::sourceLocations, | 
					
						
							|  |  |  |                                 Property(&SourceLocationsContainer::sourceLocationContainers, | 
					
						
							|  |  |  |                                          AllOf(Contains(IsSourceLocation(1, 5)), | 
					
						
							|  |  |  |                                                Contains(IsSourceLocation(3, 9)))))))); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceLocationsForRenamingMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(RefactoringServerSlowTest, RequestSingleSourceRangesForQueryMessage) | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                {source.clone()}, | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(RefactoringServerSlowTest, RequestSingleSourceRangesAndDiagnosticsWithUnsavedContentForQueryMessage) | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Utils::SmallString unsavedContent{"void f();"}; | 
					
						
							|  |  |  |     FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, | 
					
						
							|  |  |  |                          "#include \"query_simplefunction.h\"", | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |                          {"cc"}}; | 
					
						
							|  |  |  |     FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, unsavedContent.clone(), {}}; | 
					
						
							|  |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", {source.clone()}, {unsaved.clone()}}; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Contains(IsSourceRangeWithText(1, 1, 1, 9, unsavedContent)))))); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(RefactoringServerSlowTest, RequestTwoSourceRangesForQueryMessage) | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                {source.clone(), source.clone()}, | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Not(Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent))))))); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(RefactoringServerVerySlowTest, RequestManySourceRangesForQueryMessage) | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  |     std::vector<FileContainer> sources; | 
					
						
							|  |  |  |     std::fill_n(std::back_inserter(sources), | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                 processingSlotCount + 3, | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  |                 source.clone()); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                std::move(sources), | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 Not(Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent))))))) | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |             .Times(processingSlotCount + 2); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | TEST_F(RefactoringServer, CancelJobs) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     std::vector<FileContainer> sources; | 
					
						
							|  |  |  |     std::fill_n(std::back_inserter(sources), | 
					
						
							|  |  |  |                 std::thread::hardware_concurrency() + 3, | 
					
						
							|  |  |  |                 source.clone()); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                std::move(sources), | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  |     refactoringServer.cancel(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(refactoringServer.isCancelingJobs()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | TEST_F(RefactoringServer, PollTimerIsActiveAfterStart) | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                {source}, | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(refactoringServer.pollTimerIsActive()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringServer, PollTimerIsNotActiveAfterFinishing) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                {source}, | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.waitThatSourceRangesForQueryMessagesAreFinished(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(refactoringServer.pollTimerIsActive()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | TEST_F(RefactoringServer, PollTimerNotIsActiveAfterCanceling) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceRangesForQueryMessage message{"functionDecl()", | 
					
						
							|  |  |  |                                                {source}, | 
					
						
							|  |  |  |                                                {}}; | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     refactoringServer.cancel(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(refactoringServer.pollTimerIsActive()); | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()", | 
					
						
							|  |  |  |                                                              {FilePath(temporaryFile.fileName()), | 
					
						
							|  |  |  |                                                               "void f() {}", | 
					
						
							|  |  |  |                                                               {"cc"}}); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceRangesAndDiagnosticsForQueryMessage( | 
					
						
							|  |  |  |                     AllOf( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                         Field(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                               Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                     Contains(IsSourceRangeWithText(1, 1, 1, 12, "void f() {}")))), | 
					
						
							|  |  |  |                         Field(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, | 
					
						
							|  |  |  |                               IsEmpty())))); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     RequestSourceRangesAndDiagnosticsForQueryMessage message("func()", | 
					
						
							|  |  |  |                                                              {FilePath(temporaryFile.fileName()), | 
					
						
							|  |  |  |                                                               "void f() {}", | 
					
						
							|  |  |  |                                                               {"cc"}}); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceRangesAndDiagnosticsForQueryMessage( | 
					
						
							|  |  |  |                     AllOf( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                         Field(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                               Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                     IsEmpty())), | 
					
						
							|  |  |  |                         Field(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, | 
					
						
							|  |  |  |                               Not(IsEmpty()))))); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | TEST_F(RefactoringServer, UpdateGeneratedFilesSetMemberWhichIsUsedForSymbolIndexing) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, | 
					
						
							|  |  |  |                             "void f();", | 
					
						
							|  |  |  |                             {}}}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  |     refactoringServer.updateGeneratedFiles(Utils::clone(unsaved)); | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  |     ASSERT_THAT(generatedFiles.fileContainers(), ElementsAre(unsaved.front())); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  | TEST_F(RefactoringServer, RemoveGeneratedFilesSetMemberWhichIsUsedForSymbolIndexing) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, | 
					
						
							|  |  |  |                             "void f();", | 
					
						
							|  |  |  |                             {}}}; | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     refactoringServer.updateGeneratedFiles(Utils::clone(unsaved)); | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.removeGeneratedFiles({{{TESTDATA_DIR, "query_simplefunction.h"}}}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(generatedFiles.fileContainers(), IsEmpty()); | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | TEST_F(RefactoringServer, UpdateProjectPartsCallsSymbolIndexingUpdateProjectParts) | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |     ProjectPartContainers projectParts{ | 
					
						
							|  |  |  |         {{"projectPartId", | 
					
						
							|  |  |  |           {"-I", TESTDATA_DIR}, | 
					
						
							|  |  |  |           {{"DEFINE", "1", 1}}, | 
					
						
							|  |  |  |           IncludeSearchPaths{{"/includes", 1, IncludeSearchPathType::BuiltIn}, | 
					
						
							|  |  |  |                              {"/other/includes", 2, IncludeSearchPathType::System}}, | 
					
						
							|  |  |  |           IncludeSearchPaths{{"/project/includes", 1, IncludeSearchPathType::User}, | 
					
						
							|  |  |  |                              {"/other/project/includes", 2, IncludeSearchPathType::User}}, | 
					
						
							|  |  |  |           {filePathId("header1.h")}, | 
					
						
							|  |  |  |           {filePathId("main.cpp")}, | 
					
						
							|  |  |  |           Utils::Language::C, | 
					
						
							|  |  |  |           Utils::LanguageVersion::C11, | 
					
						
							|  |  |  |           Utils::LanguageExtension::All}}}; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSymbolIndexing, | 
					
						
							| 
									
										
										
										
											2018-09-03 14:38:01 +02:00
										 |  |  |                 updateProjectParts(projectParts)); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |     refactoringServer.updateProjectParts({Utils::clone(projectParts), {}}); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | TEST_F(RefactoringServer, SetProgress) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progress, 20), | 
					
						
							|  |  |  |                                                       Field(&ClangBackEnd::ProgressMessage::total, 30)))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.setProgress(20, 30); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | void RefactoringServer::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     temporaryFile.open(); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  |     refactoringServer.setClient(&mockRefactoringClient); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | void RefactoringServer::TearDown() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     refactoringServer.setGathererProcessingSlotCount(uint(processingSlotCount)); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     refactoringServer.waitThatSourceRangesForQueryMessagesAreFinished(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | } |