| 
									
										
										
										
											2016-09-08 15:49:54 +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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | #include "clangiasyncjob.h"
 | 
					
						
							|  |  |  | #include "dummyclangipcclient.h"
 | 
					
						
							|  |  |  | #include "processevents-utilities.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <clangdocument.h>
 | 
					
						
							|  |  |  | #include <clangdocumentprocessor.h>
 | 
					
						
							|  |  |  | #include <clangdocuments.h>
 | 
					
						
							|  |  |  | #include <clangjobrequest.h>
 | 
					
						
							|  |  |  | #include <clangjobs.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace ClangBackEnd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 15:20:15 +01:00
										 |  |  | class DocumentProcessor : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							|  |  |  |     void TearDown() override; | 
					
						
							|  |  |  |     bool waitUntilAllJobsFinished(int timeOutInMs = 10000) const; | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 15:20:15 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  |     ClangBackEnd::UnsavedFiles unsavedFiles; | 
					
						
							| 
									
										
										
										
											2018-09-25 09:41:32 +02:00
										 |  |  |     ClangBackEnd::Documents documents{unsavedFiles}; | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DummyIpcClient dummyIpcClient; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp")}; | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     std::unique_ptr<ClangBackEnd::DocumentProcessor> documentProcessor; | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | using DocumentProcessorSlowTest = DocumentProcessor; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | TEST_F(DocumentProcessor, ProcessEmpty) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     const JobRequests jobsStarted = documentProcessor->process(); | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(jobsStarted.size(), 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST_F(DocumentProcessorSlowTest, ProcessSingleJob) | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     const JobRequest jobRequest | 
					
						
							| 
									
										
										
										
											2018-05-31 15:21:53 +02:00
										 |  |  |             = documentProcessor->createJobRequest(JobRequest::Type::UpdateAnnotations); | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     documentProcessor->addJob(jobRequest); | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     const JobRequests jobsStarted = documentProcessor->process(); | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(jobsStarted.size(), 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DocumentProcessor::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-25 09:41:32 +02:00
										 |  |  |     const QVector<FileContainer> fileContainer{FileContainer(filePath)}; | 
					
						
							| 
									
										
										
										
											2017-11-29 15:20:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ClangBackEnd::Document document = {documents.create(fileContainer).front()}; | 
					
						
							|  |  |  |     documents.setVisibleInEditors({filePath}); | 
					
						
							|  |  |  |     documents.setUsedByCurrentEditor(filePath); | 
					
						
							|  |  |  |     documentProcessor = std::make_unique<ClangBackEnd::DocumentProcessor>( | 
					
						
							| 
									
										
										
										
											2018-09-25 09:41:32 +02:00
										 |  |  |                 document, documents, unsavedFiles, dummyIpcClient); | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DocumentProcessor::TearDown() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_TRUE(waitUntilAllJobsFinished()); // QFuture/QFutureWatcher is implemented with events
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DocumentProcessor::waitUntilAllJobsFinished(int timeOutInMs) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-04 12:43:38 +02:00
										 |  |  |     const auto noJobsRunningAnymore = [this](){ return documentProcessor->runningJobs().isEmpty(); }; | 
					
						
							| 
									
										
										
										
											2016-09-08 15:49:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ProcessEventUtilities::processEventsUntilTrue(noJobsRunningAnymore, timeOutInMs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // anonymous
 |