| 
									
										
										
										
											2017-01-30 11:24:46 +01: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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "mockclangpathwatcher.h"
 | 
					
						
							|  |  |  | #include "mockpchmanagerclient.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  | #include "mockprojectpartqueue.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | #include "mockprojectparts.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  | #include "mockgeneratedfiles.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  | #include <filepathcaching.h>
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | #include <pchmanagerserver.h>
 | 
					
						
							|  |  |  | #include <precompiledheadersupdatedmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | #include <progressmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  | #include <refactoringdatabaseinitializer.h>
 | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  | #include <removegeneratedfilesmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | #include <removeprojectpartsmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | #include <updategeneratedfilesmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | #include <updateprojectpartsmessage.h>
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2017-02-01 13:43:28 +01:00
										 |  |  | using Utils::PathString; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | using Utils::SmallString; | 
					
						
							| 
									
										
										
										
											2017-02-01 13:43:28 +01:00
										 |  |  | using ClangBackEnd::V2::FileContainer; | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  | using ClangBackEnd::V2::FileContainers; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | using ClangBackEnd::V2::ProjectPartContainer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PchManagerServer : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     void SetUp() override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         server.setClient(&mockPchManagerClient); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ON_CALL(mockProjectParts, update(projectParts)) | 
					
						
							|  |  |  |                 .WillByDefault(Return(projectParts)); | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     ClangBackEnd::FilePathId id(Utils::SmallStringView path) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return filePathCache.filePathId(ClangBackEnd::FilePathView(path)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     NiceMock<MockProjectPartQueue> mockProjectPartQueue; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  |     NiceMock<MockClangPathWatcher> mockClangPathWatcher; | 
					
						
							|  |  |  |     NiceMock<MockProjectParts> mockProjectParts; | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  |     NiceMock<MockGeneratedFiles> mockGeneratedFiles; | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; | 
					
						
							|  |  |  |     ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database}; | 
					
						
							|  |  |  |     ClangBackEnd::FilePathCaching filePathCache{database}; | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     ClangBackEnd::PchManagerServer server{mockClangPathWatcher, mockProjectPartQueue, mockProjectParts, mockGeneratedFiles}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  |     NiceMock<MockPchManagerClient> mockPchManagerClient; | 
					
						
							|  |  |  |     SmallString projectPartId1 = "project1"; | 
					
						
							|  |  |  |     SmallString projectPartId2 = "project2"; | 
					
						
							| 
									
										
										
										
											2018-11-12 19:27:51 +01:00
										 |  |  |     PathString main1Path = TESTDATA_DIR "/BuildDependencyCollector_main3.cpp"; | 
					
						
							|  |  |  |     PathString main2Path = TESTDATA_DIR "/BuildDependencyCollector_main2.cpp"; | 
					
						
							|  |  |  |     PathString header1Path = TESTDATA_DIR "/BuildDependencyCollector_header1.h"; | 
					
						
							|  |  |  |     PathString header2Path = TESTDATA_DIR "/BuildDependencyCollector_header2.h"; | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ClangBackEnd::IdPaths idPath{projectPartId1, {1, 2}}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  |     ProjectPartContainer projectPart1{projectPartId1.clone(), | 
					
						
							|  |  |  |                                       {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, | 
					
						
							| 
									
										
										
										
											2018-11-21 20:11:07 +01:00
										 |  |  |                                       {{"DEFINE", "1", 1}}, | 
					
						
							| 
									
										
										
										
											2018-02-08 12:48:46 +01:00
										 |  |  |                                       {"/includes"}, | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |                                       {id(header1Path)}, | 
					
						
							|  |  |  |                                       {id(main1Path)}}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  |     ProjectPartContainer projectPart2{projectPartId2.clone(), | 
					
						
							|  |  |  |                                       {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, | 
					
						
							| 
									
										
										
										
											2018-11-21 20:11:07 +01:00
										 |  |  |                                       {{"DEFINE", "1", 1}}, | 
					
						
							| 
									
										
										
										
											2018-02-08 12:48:46 +01:00
										 |  |  |                                       {"/includes"}, | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |                                       {id(header2Path)}, | 
					
						
							|  |  |  |                                       {id(main2Path)}}; | 
					
						
							| 
									
										
										
										
											2017-02-01 13:43:28 +01:00
										 |  |  |     std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2}; | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |         std::vector<ProjectPartContainer> projectParts2{projectPart2}; | 
					
						
							| 
									
										
										
										
											2017-02-01 13:43:28 +01:00
										 |  |  |     FileContainer generatedFile{{"/path/to/", "file"}, "content", {}}; | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     ClangBackEnd::UpdateProjectPartsMessage updateProjectPartsMessage{Utils::clone(projectParts)}; | 
					
						
							|  |  |  |     ClangBackEnd::RemoveProjectPartsMessage removeProjectPartsMessage{{projectPart1.projectPartId.clone(), | 
					
						
							| 
									
										
										
										
											2018-04-04 18:25:23 +02:00
										 |  |  |                                                                        projectPart2.projectPartId.clone()}}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  | TEST_F(PchManagerServer, FilterProjectPartsAndSendThemToQueue) | 
					
						
							| 
									
										
										
										
											2017-01-31 14:21:05 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     InSequence s; | 
					
						
							| 
									
										
										
										
											2017-01-31 14:21:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     EXPECT_CALL(mockProjectParts, update(updateProjectPartsMessage.projectsParts)).WillOnce(Return(projectParts2)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockProjectPartQueue, addProjectParts(Eq(projectParts2))); | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     server.updateProjectParts(updateProjectPartsMessage.clone()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  | TEST_F(PchManagerServer, UpdateGeneratedFilesCallsUpdate) | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  |     ClangBackEnd::UpdateGeneratedFilesMessage updateGeneratedFilesMessage{{generatedFile}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles)); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     server.updateGeneratedFiles(updateGeneratedFilesMessage.clone()); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 14:02:59 +02:00
										 |  |  | TEST_F(PchManagerServer, RemoveGeneratedFilesCallsRemove) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::RemoveGeneratedFilesMessage removeGeneratedFilesMessage{{generatedFile.filePath}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockGeneratedFiles, remove(Utils::clone(removeGeneratedFilesMessage.generatedFiles))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     server.removeGeneratedFiles(removeGeneratedFilesMessage.clone()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | TEST_F(PchManagerServer, RemoveIncludesFromFileWatcher) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     EXPECT_CALL(mockClangPathWatcher, removeIds(removeProjectPartsMessage.projectsPartIds)); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     server.removeProjectParts(removeProjectPartsMessage.clone()); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerServer, RemoveProjectPartsFromProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     EXPECT_CALL(mockProjectParts, remove(removeProjectPartsMessage.projectsPartIds)); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +02:00
										 |  |  |     server.removeProjectParts(removeProjectPartsMessage.clone()); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerServer, SetPathWatcherNotifier) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockClangPathWatcher, setNotifier(_)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     ClangBackEnd::PchManagerServer server{mockClangPathWatcher, mockProjectPartQueue, mockProjectParts, mockGeneratedFiles}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  | TEST_F(PchManagerServer, UpdateProjectPartQueueByPathIds) | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-11 17:02:45 +02:00
										 |  |  |     EXPECT_CALL(mockProjectParts, projects(ElementsAre(projectPart1.projectPartId))) | 
					
						
							|  |  |  |             .WillOnce(Return(std::vector<ClangBackEnd::V2::ProjectPartContainer>{{projectPart1}})); | 
					
						
							|  |  |  |     EXPECT_CALL(mockProjectPartQueue, addProjectParts(ElementsAre(projectPart1))); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     server.pathsWithIdsChanged({projectPartId1}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | TEST_F(PchManagerServer, SetProgress) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockPchManagerClient, progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progress, 20), | 
					
						
							|  |  |  |                                                      Field(&ClangBackEnd::ProgressMessage::total, 30)))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     server.setProgress(20, 30); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } |