| 
									
										
										
										
											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 "mockpchmanagernotifier.h"
 | 
					
						
							|  |  |  | #include "mockpchmanagerserver.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | #include "mockprecompiledheaderstorage.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | #include "mockprogressmanager.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | #include "mockprojectpartsstorage.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <pchmanagerclient.h>
 | 
					
						
							| 
									
										
										
										
											2017-08-17 12:44:52 +02:00
										 |  |  | #include <pchmanagerprojectupdater.h>
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 16:51:22 +02:00
										 |  |  | #include <clangindexingsettingsmanager.h>
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  | #include <filepathcaching.h>
 | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | #include <precompiledheadersupdatedmessage.h>
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | #include <progressmessage.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-07 16:51:22 +02:00
										 |  |  | #include <refactoringdatabaseinitializer.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:00 +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 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ClangBackEnd::PrecompiledHeadersUpdatedMessage; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PchManagerClient : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2019-02-19 20:46:08 +01:00
										 |  |  |     NiceMock<MockProgressManager> mockPchCreationProgressManager; | 
					
						
							|  |  |  |     NiceMock<MockProgressManager> mockDependencyCreationProgressManager; | 
					
						
							|  |  |  |     ClangPchManager::PchManagerClient client{mockPchCreationProgressManager, | 
					
						
							|  |  |  |                                              mockDependencyCreationProgressManager}; | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     NiceMock<MockPchManagerServer> mockPchManagerServer; | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     NiceMock<MockProjectPartsStorage> mockProjectPartsStorage; | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  |     NiceMock<MockPchManagerNotifier> mockPchManagerNotifier{client}; | 
					
						
							| 
									
										
										
										
											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}; | 
					
						
							| 
									
										
										
										
											2019-05-07 16:51:22 +02:00
										 |  |  |     ClangPchManager::ClangIndexingSettingsManager settingsManager; | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     ClangPchManager::PchManagerProjectUpdater projectUpdater{mockPchManagerServer, | 
					
						
							|  |  |  |                                                              client, | 
					
						
							|  |  |  |                                                              filePathCache, | 
					
						
							| 
									
										
										
										
											2019-05-07 16:51:22 +02:00
										 |  |  |                                                              mockProjectPartsStorage, | 
					
						
							|  |  |  |                                                              settingsManager}; | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     ClangBackEnd::ProjectPartId projectPartId{1}; | 
					
						
							| 
									
										
										
										
											2019-07-10 09:30:30 +02:00
										 |  |  |     PrecompiledHeadersUpdatedMessage message{projectPartId}; | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     ClangBackEnd::ProjectPartId projectPartId2{2}; | 
					
						
							| 
									
										
										
										
											2019-07-10 09:30:30 +02:00
										 |  |  |     PrecompiledHeadersUpdatedMessage message2{projectPartId2}; | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerClient, NotifierAttached) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     MockPchManagerNotifier notifier(client); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(client.notifiers(), Contains(¬ifier)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerClient, NotifierDetached) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     MockPchManagerNotifier *notifierPointer = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MockPchManagerNotifier notifier(client); | 
					
						
							|  |  |  |         notifierPointer = ¬ifier; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(client.notifiers(), Not(Contains(notifierPointer))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerClient, Update) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-22 12:26:58 +02:00
										 |  |  |     EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId)); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.precompiledHeadersUpdated(message.clone()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(PchManagerClient, Remove) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId)).Times(2); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     projectUpdater.removeProjectParts({projectPartId, projectPartId}); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 20:46:08 +01:00
										 |  |  | TEST_F(PchManagerClient, SetPchCreationProgress) | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-19 20:46:08 +01:00
										 |  |  |     EXPECT_CALL(mockPchCreationProgressManager, setProgress(10, 20)); | 
					
						
							| 
									
										
										
										
											2018-09-27 17:52:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.progress({ClangBackEnd::ProgressType::PrecompiledHeader, 10, 20}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 20:46:08 +01:00
										 |  |  | TEST_F(PchManagerClient, SetDependencyCreationProgress) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockDependencyCreationProgressManager, setProgress(30, 40)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.progress({ClangBackEnd::ProgressType::DependencyCreation, 30, 40}); | 
					
						
							| 
									
										
										
										
											2017-01-30 11:24:46 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-19 20:46:08 +01:00
										 |  |  | } // namespace
 |