| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2018 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 "mockbuilddependenciesprovider.h"
 | 
					
						
							| 
									
										
										
										
											2019-07-03 16:41:59 +02:00
										 |  |  | #include "mockpchtaskqueue.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  | #include "mockpchtasksmerger.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <pchtaskgenerator.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-13 13:36:27 +01:00
										 |  |  | #include <progresscounter.h>
 | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ClangBackEnd::BuildDependencies; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::BuildDependency; | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  | using ClangBackEnd::CompilerMacro; | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | using ClangBackEnd::FilePathId; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | using ClangBackEnd::IncludeSearchPath; | 
					
						
							|  |  |  | using ClangBackEnd::IncludeSearchPathType; | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | using ClangBackEnd::PchTask; | 
					
						
							| 
									
										
										
										
											2018-12-03 17:44:38 +01:00
										 |  |  | using ClangBackEnd::PchTaskSet; | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | using ClangBackEnd::ProjectPartId; | 
					
						
							| 
									
										
										
										
											2018-10-25 11:08:39 +02:00
										 |  |  | using ClangBackEnd::SourceEntries; | 
					
						
							|  |  |  | using ClangBackEnd::SourceType; | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  | using ClangBackEnd::UsedMacro; | 
					
						
							|  |  |  | using ClangBackEnd::UsedMacros; | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PchTaskGenerator : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     NiceMock<MockBuildDependenciesProvider> mockBuildDependenciesProvider; | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  |     NiceMock<MockPchTasksMerger> mockPchTaskMerger; | 
					
						
							| 
									
										
										
										
											2019-07-03 16:41:59 +02:00
										 |  |  |     NiceMock<MockPchTaskQueue> mockPchTaskQueue; | 
					
						
							| 
									
										
										
										
											2019-02-13 13:36:27 +01:00
										 |  |  |     NiceMock<MockFunction<void(int, int)>> mockProgressCounterCallback; | 
					
						
							|  |  |  |     ClangBackEnd::ProgressCounter progressCounter{mockProgressCounterCallback.AsStdFunction()}; | 
					
						
							|  |  |  |     ClangBackEnd::PchTaskGenerator generator{mockBuildDependenciesProvider, | 
					
						
							|  |  |  |                                              mockPchTaskMerger, | 
					
						
							| 
									
										
										
										
											2019-07-03 16:41:59 +02:00
										 |  |  |                                              progressCounter, | 
					
						
							|  |  |  |                                              mockPchTaskQueue}; | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectPart1{ | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |         1, | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |         {"--yi"}, | 
					
						
							|  |  |  |         {{"YI", "1", 1}, | 
					
						
							|  |  |  |          {"QI", "7", 1}, | 
					
						
							|  |  |  |          {"ER", "2", 2}, | 
					
						
							|  |  |  |          {"SAN", "3", 3}, | 
					
						
							|  |  |  |          {"SE", "4", 4}, | 
					
						
							|  |  |  |          {"BA", "8", 4}, | 
					
						
							|  |  |  |          {"WU", "5", 5}, | 
					
						
							|  |  |  |          {"LUI", "6", 6}, | 
					
						
							|  |  |  |          {"JIU", "9", 9}, | 
					
						
							|  |  |  |          {"SHI", "10", 10}}, | 
					
						
							|  |  |  |         {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::Cxx, | 
					
						
							|  |  |  |         Utils::LanguageVersion::CXX11, | 
					
						
							|  |  |  |         Utils::LanguageExtension::All}; | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  |     SourceEntries firstSources{{1, SourceType::ProjectInclude, 1}, | 
					
						
							|  |  |  |                                {2, SourceType::UserInclude, 1}, | 
					
						
							|  |  |  |                                {3, SourceType::TopProjectInclude, 1}, | 
					
						
							|  |  |  |                                {4, SourceType::SystemInclude, 1}, | 
					
						
							| 
									
										
										
										
											2019-06-20 18:34:02 +02:00
										 |  |  |                                {5, SourceType::TopSystemInclude, 1}, | 
					
						
							|  |  |  |                                {6, SourceType::Source, 1}}; | 
					
						
							| 
									
										
										
										
											2018-11-27 11:49:58 +01:00
										 |  |  |     UsedMacros usedMacros{{"LIANG", 0},{"YI", 1}, {"ER", 2}, {"SAN", 3}, {"SE", 4}, {"WU", 5}}; | 
					
						
							|  |  |  |     BuildDependency buildDependency{firstSources, usedMacros, {}, {}, {}}; | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | TEST_F(PchTaskGenerator, AddProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL( | 
					
						
							|  |  |  |         mockPchTaskMerger, | 
					
						
							|  |  |  |         mergeTasks( | 
					
						
							|  |  |  |             ElementsAre(AllOf( | 
					
						
							| 
									
										
										
										
											2019-02-04 18:14:44 +01:00
										 |  |  |                 Field(&PchTaskSet::system, | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |                       AllOf(Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), | 
					
						
							| 
									
										
										
										
											2019-02-04 18:14:44 +01:00
										 |  |  |                             Field(&PchTask::includes, ElementsAre(5)), | 
					
						
							| 
									
										
										
										
											2019-06-20 18:34:02 +02:00
										 |  |  |                             Field(&PchTask::watchedSystemIncludes, IsEmpty()), | 
					
						
							|  |  |  |                             Field(&PchTask::watchedProjectIncludes, IsEmpty()), | 
					
						
							|  |  |  |                             Field(&PchTask::watchedUserIncludes, IsEmpty()), | 
					
						
							|  |  |  |                             Field(&PchTask::watchedUserSources, IsEmpty()), | 
					
						
							| 
									
										
										
										
											2019-02-04 18:14:44 +01:00
										 |  |  |                             Field(&PchTask::compilerMacros, | 
					
						
							|  |  |  |                                   ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})), | 
					
						
							|  |  |  |                             Field(&PchTask::systemIncludeSearchPaths, | 
					
						
							|  |  |  |                                   ElementsAre( | 
					
						
							|  |  |  |                                       IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, | 
					
						
							|  |  |  |                                       IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, | 
					
						
							|  |  |  |                                       IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), | 
					
						
							|  |  |  |                             Field(&PchTask::projectIncludeSearchPaths, IsEmpty()), | 
					
						
							|  |  |  |                             Field(&PchTask::toolChainArguments, ElementsAre("--yi")), | 
					
						
							|  |  |  |                             Field(&PchTask::language, Eq(Utils::Language::Cxx)), | 
					
						
							|  |  |  |                             Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), | 
					
						
							|  |  |  |                             Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))), | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |                 AllOf(Field( | 
					
						
							|  |  |  |                     &PchTaskSet::project, | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |                     AllOf(Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), | 
					
						
							| 
									
										
										
										
											2019-02-04 18:14:44 +01:00
										 |  |  |                           Field(&PchTask::includes, ElementsAre(3)), | 
					
						
							| 
									
										
										
										
											2019-06-20 18:34:02 +02:00
										 |  |  |                           Field(&PchTask::watchedSystemIncludes, ElementsAre(4, 5)), | 
					
						
							|  |  |  |                           Field(&PchTask::watchedProjectIncludes, ElementsAre(1, 3)), | 
					
						
							|  |  |  |                           Field(&PchTask::watchedUserIncludes, ElementsAre(2)), | 
					
						
							|  |  |  |                           Field(&PchTask::watchedUserSources, ElementsAre(6)), | 
					
						
							| 
									
										
										
										
											2019-02-04 18:14:44 +01:00
										 |  |  |                           Field(&PchTask::compilerMacros, | 
					
						
							|  |  |  |                                 ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})), | 
					
						
							|  |  |  |                           Field(&PchTask::systemIncludeSearchPaths, | 
					
						
							|  |  |  |                                 ElementsAre( | 
					
						
							|  |  |  |                                     IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, | 
					
						
							|  |  |  |                                     IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, | 
					
						
							|  |  |  |                                     IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), | 
					
						
							|  |  |  |                           Field(&PchTask::projectIncludeSearchPaths, | 
					
						
							|  |  |  |                                 ElementsAre( | 
					
						
							|  |  |  |                                     IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, | 
					
						
							|  |  |  |                                     IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})), | 
					
						
							|  |  |  |                           Field(&PchTask::toolChainArguments, ElementsAre("--yi")), | 
					
						
							|  |  |  |                           Field(&PchTask::language, Eq(Utils::Language::Cxx)), | 
					
						
							|  |  |  |                           Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), | 
					
						
							|  |  |  |                           Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))), | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  |             ElementsAre(Eq("ToolChainArgument")))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     generator.addProjectParts({projectPart1}, {"ToolChainArgument"}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 16:41:59 +02:00
										 |  |  | TEST_F(PchTaskGenerator, AddNonSystemProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL( | 
					
						
							|  |  |  |         mockPchTaskQueue, | 
					
						
							|  |  |  |         addProjectPchTasks(ElementsAre(AllOf( | 
					
						
							|  |  |  |             Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), | 
					
						
							|  |  |  |             Field(&PchTask::includes, ElementsAre(3)), | 
					
						
							|  |  |  |             Field(&PchTask::watchedSystemIncludes, ElementsAre(4, 5)), | 
					
						
							|  |  |  |             Field(&PchTask::watchedProjectIncludes, ElementsAre(1, 3)), | 
					
						
							|  |  |  |             Field(&PchTask::watchedUserIncludes, ElementsAre(2)), | 
					
						
							|  |  |  |             Field(&PchTask::watchedUserSources, ElementsAre(6)), | 
					
						
							|  |  |  |             Field(&PchTask::compilerMacros, | 
					
						
							|  |  |  |                   ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})), | 
					
						
							|  |  |  |             Field(&PchTask::systemIncludeSearchPaths, | 
					
						
							|  |  |  |                   ElementsAre(IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, | 
					
						
							|  |  |  |                               IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, | 
					
						
							|  |  |  |                               IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), | 
					
						
							|  |  |  |             Field(&PchTask::projectIncludeSearchPaths, | 
					
						
							|  |  |  |                   ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, | 
					
						
							|  |  |  |                               IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})), | 
					
						
							|  |  |  |             Field(&PchTask::toolChainArguments, ElementsAre("--yi")), | 
					
						
							|  |  |  |             Field(&PchTask::language, Eq(Utils::Language::Cxx)), | 
					
						
							|  |  |  |             Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), | 
					
						
							|  |  |  |             Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     generator.addNonSystemProjectParts({projectPart1}, {"ToolChainArgument"}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 13:36:27 +01:00
										 |  |  | TEST_F(PchTaskGenerator, ProgressCounter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockProgressCounterCallback, Call(0, 3)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockProgressCounterCallback, Call(1, 3)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockProgressCounterCallback, Call(2, 3)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockProgressCounterCallback, Call(3, 3)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     generator.addProjectParts({projectPart1, projectPart1, projectPart1}, {"ToolChainArgument"}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 12:06:57 +01:00
										 |  |  | TEST_F(PchTaskGenerator, RemoveProjectParts) | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     EXPECT_CALL(mockPchTaskMerger, removePchTasks(ElementsAre(ProjectPartId{1}, ProjectPartId{2}))); | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  |     generator.removeProjectParts({1, 2}); | 
					
						
							| 
									
										
										
										
											2018-10-24 16:46:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |