| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							|  |  |  | #include <QTemporaryFile>
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::AllOf; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | using ClangBackEnd::SourceRangesForQueryMessage; | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | using ClangBackEnd::SourceRangesContainer; | 
					
						
							|  |  |  | using ClangBackEnd::V2::FileContainer; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | using ClangBackEnd::V2::FileContainers; | 
					
						
							|  |  |  | using ClangBackEnd::V2::ProjectPartContainer; | 
					
						
							|  |  |  | using ClangBackEnd::V2::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
										 |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01: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}; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  |     ClangBackEnd::RefactoringServer refactoringServer{mockSymbolIndexing, filePathCache}; | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  |     Utils::SmallString sourceContent{"void f()\n {}"}; | 
					
						
							|  |  |  |     FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, | 
					
						
							|  |  |  |                          sourceContent.clone(), | 
					
						
							| 
									
										
										
										
											2017-07-03 19:53:32 +02:00
										 |  |  |                          {"cc", toNativePath(TESTDATA_DIR"/query_simplefunction.cpp")}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     QTemporaryFile temporaryFile{QDir::tempPath() + "/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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     RequestSourceLocationsForRenamingMessage message{{TESTDATA_DIR, "renamevariable.cpp"}, | 
					
						
							|  |  |  |                                                      1, | 
					
						
							|  |  |  |                                                      5, | 
					
						
							|  |  |  |                                                      "int v;\n\nint x = v + 3;\n", | 
					
						
							|  |  |  |                                                      {"cc", "renamevariable.cpp"}, | 
					
						
							|  |  |  |                                                      1}; | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceLocationsForRenamingMessage( | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |                     AllOf(Property(&SourceLocationsForRenamingMessage::textDocumentRevision, 1), | 
					
						
							|  |  |  |                           Property(&SourceLocationsForRenamingMessage::symbolName, "v"), | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  |                           Property(&SourceLocationsForRenamingMessage::sourceLocations, | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |                                    Property(&SourceLocationsContainer::sourceLocationContainers, | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  |                                             AllOf(Contains(IsSourceLocation(1, 5)), | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |                                                   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( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2016-11-30 15:29:36 +01:00
										 |  |  |                              Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |                                       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\"", | 
					
						
							|  |  |  |                          {"cc", "query_simplefunction.cpp"}}; | 
					
						
							|  |  |  |     FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, | 
					
						
							|  |  |  |                           unsavedContent.clone(), | 
					
						
							|  |  |  |                           {}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     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( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |                              Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |                                       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( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |                              Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                                       Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                              Property(&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( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |                              Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                                       Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |                 sourceRangesForQueryMessage( | 
					
						
							|  |  |  |                     Property(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                              Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       Not(Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent))))))) | 
					
						
							|  |  |  |             .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) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()", | 
					
						
							|  |  |  |                                                              {FilePath(temporaryFile.fileName()), | 
					
						
							|  |  |  |                                                               "void f() {}", | 
					
						
							|  |  |  |                                                               {"cc", toNativePath(temporaryFile.fileName())}}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceRangesAndDiagnosticsForQueryMessage( | 
					
						
							|  |  |  |                     AllOf( | 
					
						
							|  |  |  |                         Property(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                  Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                           Contains(IsSourceRangeWithText(1, 1, 1, 12, "void f() {}")))), | 
					
						
							|  |  |  |                         Property(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, | 
					
						
							|  |  |  |                                  IsEmpty())))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     RequestSourceRangesAndDiagnosticsForQueryMessage message("func()", | 
					
						
							|  |  |  |                                                              {FilePath(temporaryFile.fileName()), | 
					
						
							|  |  |  |                                                               "void f() {}", | 
					
						
							|  |  |  |                                                               {"cc", toNativePath(temporaryFile.fileName())}}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, | 
					
						
							|  |  |  |                 sourceRangesAndDiagnosticsForQueryMessage( | 
					
						
							|  |  |  |                     AllOf( | 
					
						
							|  |  |  |                         Property(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                  Property(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                           IsEmpty())), | 
					
						
							|  |  |  |                         Property(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, | 
					
						
							|  |  |  |                                  Not(IsEmpty()))))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | TEST_F(RefactoringServer, UpdatePchProjectPartsCallsSymbolIndexingUpdateProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ProjectPartContainers projectParts{{{"projectPartId", | 
					
						
							|  |  |  |                                         {"-I", TESTDATA_DIR}, | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |                                         {filePathId("header1.h")}, | 
					
						
							|  |  |  |                                         {filePathId("main.cpp")}}}}; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  |     FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, | 
					
						
							|  |  |  |                             "void f();", | 
					
						
							|  |  |  |                             {}}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockSymbolIndexing, | 
					
						
							|  |  |  |                 updateProjectParts(projectParts, unsaved)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     refactoringServer.updatePchProjectParts({Utils::clone(projectParts), Utils::clone(unsaved)}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } |