| 
									
										
										
										
											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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | #include "mockrefactoringclient.h"
 | 
					
						
							|  |  |  | #include "mockrefactoringserver.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <writemessageblock.h>
 | 
					
						
							|  |  |  | #include <refactoringclientproxy.h>
 | 
					
						
							|  |  |  | #include <refactoringserverproxy.h>
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | #include <clangrefactoringmessages.h>
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QVariant>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace ClangBackEnd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ::testing::Args; | 
					
						
							|  |  |  | using ::testing::Property; | 
					
						
							|  |  |  | using ::testing::Eq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | using ClangBackEnd::RemoveGeneratedFilesMessage; | 
					
						
							|  |  |  | using ClangBackEnd::RemoveProjectPartsMessage; | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | using ClangBackEnd::UpdateProjectPartsMessage; | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | using ClangBackEnd::UpdateGeneratedFilesMessage; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | using ClangBackEnd::V2::FileContainer; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::ProjectPartContainer; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | class RefactoringClientServerInProcess : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     RefactoringClientServerInProcess(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void SetUp(); | 
					
						
							|  |  |  |     void TearDown(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void scheduleServerMessages(); | 
					
						
							|  |  |  |     void scheduleClientMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     QBuffer buffer; | 
					
						
							|  |  |  |     MockRefactoringClient mockRefactoringClient; | 
					
						
							|  |  |  |     MockRefactoringServer mockRefactoringServer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ClangBackEnd::RefactoringServerProxy serverProxy; | 
					
						
							|  |  |  |     ClangBackEnd::RefactoringClientProxy clientProxy; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringClientServerInProcess, SendEndMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringServer, end()); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.end(); | 
					
						
							|  |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringClientServerInProcess, SendAliveMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringClient, alive()); | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     clientProxy.alive(); | 
					
						
							|  |  |  |     scheduleClientMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SourceRangesAndDiagnosticsForQueryMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::SourceRangesContainer sourceRangesContainer; | 
					
						
							|  |  |  |     std::vector<ClangBackEnd::DynamicASTMatcherDiagnosticContainer> diagnosticContainers; | 
					
						
							|  |  |  |     ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage message(std::move(sourceRangesContainer), | 
					
						
							|  |  |  |                                                                     std::move(diagnosticContainers)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringClient, sourceRangesAndDiagnosticsForQueryMessage(message)); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     clientProxy.sourceRangesAndDiagnosticsForQueryMessage(message.clone()); | 
					
						
							|  |  |  |     scheduleClientMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SourceRangesForQueryMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::SourceRangesContainer sourceRangesContainer; | 
					
						
							|  |  |  |     ClangBackEnd::SourceRangesForQueryMessage message(std::move(sourceRangesContainer)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, sourceRangesForQueryMessage(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clientProxy.sourceRangesForQueryMessage(message.clone()); | 
					
						
							|  |  |  |     scheduleClientMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SendProgressMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::ProgressMessage message{ClangBackEnd::ProgressType::PrecompiledHeader, 10, 50}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringClient, progress(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     clientProxy.progress(message.clone()); | 
					
						
							|  |  |  |     scheduleClientMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQueryMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     RequestSourceRangesForQueryMessage message{ | 
					
						
							|  |  |  |         "functionDecl()", | 
					
						
							|  |  |  |         {{{TESTDATA_DIR, "query_simplefunction.cpp"}, "void f();", {"cc"}, 1}}, | 
					
						
							|  |  |  |         {{{TESTDATA_DIR, "query_simplefunction.h"}, "void f();", {}, 1}}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.requestSourceRangesForQueryMessage(message.clone()); | 
					
						
							|  |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(RefactoringClientServerInProcess, RequestSourceRangesForQueryMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:59:30 +01:00
										 |  |  |     RequestSourceRangesForQueryMessage message{ | 
					
						
							|  |  |  |         "functionDecl()", | 
					
						
							|  |  |  |         {{{TESTDATA_DIR, "query_simplefunction.cpp"}, | 
					
						
							|  |  |  |           "void f();", | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |               "cc", | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           1}}, | 
					
						
							|  |  |  |         {{{TESTDATA_DIR, "query_simplefunction.h"}, "void f();", {}, 1}}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.requestSourceRangesForQueryMessage(message.clone()); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:38:12 +01:00
										 |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SendUpdateProjectPartsMessage) | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     ProjectPartContainer projectPart2{ | 
					
						
							|  |  |  |         1, | 
					
						
							|  |  |  |         {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, | 
					
						
							|  |  |  |         {{"DEFINE", "1", 1}}, | 
					
						
							|  |  |  |         {IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, | 
					
						
							|  |  |  |          IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, | 
					
						
							|  |  |  |          IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System}}, | 
					
						
							|  |  |  |         {IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, | 
					
						
							|  |  |  |          IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}, | 
					
						
							|  |  |  |         {{1, 1}}, | 
					
						
							|  |  |  |         {{1, 2}}, | 
					
						
							|  |  |  |         Utils::Language::C, | 
					
						
							|  |  |  |         Utils::LanguageVersion::C11, | 
					
						
							|  |  |  |         Utils::LanguageExtension::All}; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |     UpdateProjectPartsMessage message{{projectPart2}, {"toolChainArgument"}}; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     EXPECT_CALL(mockRefactoringServer, updateProjectParts(message)); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     serverProxy.updateProjectParts(message.clone()); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SendUpdateGeneratedFilesMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FileContainer fileContainer{{"/path/to/", "file"}, "content", {}}; | 
					
						
							|  |  |  |     UpdateGeneratedFilesMessage message{{fileContainer}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringServer, updateGeneratedFiles(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.updateGeneratedFiles(message.clone()); | 
					
						
							|  |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SendRemoveProjectPartsMessage) | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     RemoveProjectPartsMessage message{{1, 2}}; | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     EXPECT_CALL(mockRefactoringServer, removeProjectParts(message)); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     serverProxy.removeProjectParts(message.clone()); | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, SendRemoveGeneratedFilesMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     RemoveGeneratedFilesMessage message{{{"/path/to/", "file"}}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockRefactoringServer, removeGeneratedFiles(message)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.removeGeneratedFiles(message.clone()); | 
					
						
							|  |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | TEST_F(RefactoringClientServerInProcess, CancelMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     EXPECT_CALL(mockRefactoringServer, cancel()); | 
					
						
							| 
									
										
										
										
											2016-11-23 13:13:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     serverProxy.cancel(); | 
					
						
							|  |  |  |     scheduleServerMessages(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 15:26:53 +02:00
										 |  |  | RefactoringClientServerInProcess::RefactoringClientServerInProcess() | 
					
						
							|  |  |  |     : serverProxy(&mockRefactoringClient, &buffer), | 
					
						
							|  |  |  |       clientProxy(&mockRefactoringServer, &buffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RefactoringClientServerInProcess::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     buffer.open(QIODevice::ReadWrite); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RefactoringClientServerInProcess::TearDown() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     buffer.close(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RefactoringClientServerInProcess::scheduleServerMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     buffer.seek(0); | 
					
						
							|  |  |  |     clientProxy.readMessages(); | 
					
						
							|  |  |  |     buffer.buffer().clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RefactoringClientServerInProcess::scheduleClientMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     buffer.seek(0); | 
					
						
							|  |  |  |     serverProxy.readMessages(); | 
					
						
							|  |  |  |     buffer.buffer().clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |