| 
									
										
										
										
											2016-12-16 13:10:43 +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 <cpptools/cppprojectpartchooser.h>
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | #include <cpptools/cpptools_utils.h>
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | #include <cpptools/projectpart.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using CppTools::Internal::ProjectPartChooser; | 
					
						
							|  |  |  | using CppTools::ProjectPart; | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | using CppTools::ProjectPartInfo; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  | using CppTools::Language; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | using testing::Eq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ProjectPartChooser : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPartInfo choose() const; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  |     static QList<ProjectPart::Ptr> createProjectPartsWithDifferentProjects(); | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  |     static QList<ProjectPart::Ptr> createCAndCxxProjectParts(); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | protected: | 
					
						
							|  |  |  |     QString filePath; | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     ProjectPart::Ptr currentProjectPart{new ProjectPart}; | 
					
						
							|  |  |  |     ProjectPartInfo currentProjectPartInfo{currentProjectPart, | 
					
						
							|  |  |  |                                            {currentProjectPart}, | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |                                            ProjectPartInfo::NoHint}; | 
					
						
							| 
									
										
										
										
											2017-01-19 12:52:16 +01:00
										 |  |  |     QString preferredProjectPartId; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  |     const ProjectExplorer::Project *activeProject = nullptr; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  |     Language languagePreference = Language::Cxx; | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  |     bool projectsChanged = false; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  |     ::ProjectPartChooser chooser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QList<ProjectPart::Ptr> projectPartsForFile; | 
					
						
							|  |  |  |     QList<ProjectPart::Ptr> projectPartsFromDependenciesForFile; | 
					
						
							|  |  |  |     ProjectPart::Ptr fallbackProjectPart; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, ChooseManuallySet) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 12:52:16 +01:00
										 |  |  |     ProjectPart::Ptr p1(new ProjectPart); | 
					
						
							|  |  |  |     ProjectPart::Ptr p2(new ProjectPart); | 
					
						
							|  |  |  |     p2->projectFile = preferredProjectPartId = "someId"; | 
					
						
							|  |  |  |     projectPartsForFile += {p1, p2}; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 12:52:16 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(p2)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  | TEST_F(ProjectPartChooser, IndicateManuallySet) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ProjectPart::Ptr p1(new ProjectPart); | 
					
						
							|  |  |  |     ProjectPart::Ptr p2(new ProjectPart); | 
					
						
							|  |  |  |     p2->projectFile = preferredProjectPartId = "someId"; | 
					
						
							|  |  |  |     projectPartsForFile += {p1, p2}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsPreferredMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, IndicateManuallySetForFallbackToProjectPartFromDependencies) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ProjectPart::Ptr p1(new ProjectPart); | 
					
						
							|  |  |  |     ProjectPart::Ptr p2(new ProjectPart); | 
					
						
							|  |  |  |     p2->projectFile = preferredProjectPartId = "someId"; | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += {p1, p2}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsPreferredMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, DoNotIndicateNotManuallySet) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(hints & ProjectPartInfo::IsPreferredMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultipleChooseFromActiveProject) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QList<ProjectPart::Ptr> projectParts = createProjectPartsWithDifferentProjects(); | 
					
						
							|  |  |  |     const ProjectPart::Ptr secondProjectPart = projectParts.at(1); | 
					
						
							|  |  |  |     projectPartsForFile += projectParts; | 
					
						
							|  |  |  |     activeProject = secondProjectPart->project; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(secondProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 15:30:08 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultiplePreferSelectedForBuilding) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPart::Ptr firstProjectPart{new ProjectPart}; | 
					
						
							|  |  |  |     const ProjectPart::Ptr secondProjectPart{new ProjectPart}; | 
					
						
							|  |  |  |     firstProjectPart->selectedForBuilding = false; | 
					
						
							|  |  |  |     secondProjectPart->selectedForBuilding = true; | 
					
						
							|  |  |  |     projectPartsForFile += firstProjectPart; | 
					
						
							|  |  |  |     projectPartsForFile += secondProjectPart; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 15:30:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(secondProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultipleFromDependenciesChooseFromActiveProject) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QList<ProjectPart::Ptr> projectParts = createProjectPartsWithDifferentProjects(); | 
					
						
							|  |  |  |     const ProjectPart::Ptr secondProjectPart = projectParts.at(1); | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += projectParts; | 
					
						
							|  |  |  |     activeProject = secondProjectPart->project; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(secondProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-15 11:21:44 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultipleCheckIfActiveProjectChanged) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QList<ProjectPart::Ptr> projectParts = createProjectPartsWithDifferentProjects(); | 
					
						
							|  |  |  |     const ProjectPart::Ptr firstProjectPart = projectParts.at(0); | 
					
						
							|  |  |  |     const ProjectPart::Ptr secondProjectPart = projectParts.at(1); | 
					
						
							|  |  |  |     projectPartsForFile += projectParts; | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     currentProjectPartInfo.projectPart = firstProjectPart; | 
					
						
							| 
									
										
										
										
											2016-12-15 11:21:44 +01:00
										 |  |  |     activeProject = secondProjectPart->project; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-15 11:21:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(secondProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultipleAndAmbigiousHeaderPreferCProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     languagePreference = Language::C; | 
					
						
							|  |  |  |     projectPartsForFile = createCAndCxxProjectParts(); | 
					
						
							|  |  |  |     const ProjectPart::Ptr cProjectPart = projectPartsForFile.at(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(cProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, ForMultipleAndAmbigiousHeaderPreferCxxProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     languagePreference = Language::Cxx; | 
					
						
							|  |  |  |     projectPartsForFile = createCAndCxxProjectParts(); | 
					
						
							|  |  |  |     const ProjectPart::Ptr cxxProjectPart = projectPartsForFile.at(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(cxxProjectPart)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | TEST_F(ProjectPartChooser, IndicateMultiple) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPart::Ptr p1{new ProjectPart}; | 
					
						
							|  |  |  |     const ProjectPart::Ptr p2{new ProjectPart}; | 
					
						
							|  |  |  |     projectPartsForFile += { p1, p2 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsAmbiguousMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, IndicateMultipleForFallbackToProjectPartFromDependencies) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPart::Ptr p1{new ProjectPart}; | 
					
						
							|  |  |  |     const ProjectPart::Ptr p2{new ProjectPart}; | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += { p1, p2 }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsAmbiguousMatch); | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ForMultipleChooseNewIfPreviousIsGone) | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     const ProjectPart::Ptr newProjectPart{new ProjectPart}; | 
					
						
							|  |  |  |     projectPartsForFile += newProjectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(newProjectPart)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  | TEST_F(ProjectPartChooser, FallbackToProjectPartFromDependencies) | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     const ProjectPart::Ptr fromDependencies{new ProjectPart}; | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += fromDependencies; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(fromDependencies)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  | TEST_F(ProjectPartChooser, FallbackToProjectPartFromModelManager) | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     fallbackProjectPart.reset(new ProjectPart); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(fallbackProjectPart)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  | TEST_F(ProjectPartChooser, ContinueUsingFallbackFromModelManagerIfProjectDoesNotChange) | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     // ...without re-calculating the dependency table.
 | 
					
						
							|  |  |  |     fallbackProjectPart.reset(new ProjectPart); | 
					
						
							|  |  |  |     currentProjectPartInfo.projectPart = fallbackProjectPart; | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch; | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     projectPartsFromDependenciesForFile += ProjectPart::Ptr(new ProjectPart); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(fallbackProjectPart)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  | TEST_F(ProjectPartChooser, StopUsingFallbackFromModelManagerIfProjectChanges1) | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     fallbackProjectPart.reset(new ProjectPart); | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     currentProjectPartInfo.projectPart = fallbackProjectPart; | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch; | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     const ProjectPart::Ptr addedProject(new ProjectPart); | 
					
						
							|  |  |  |     projectPartsForFile += addedProject; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |     ASSERT_THAT(chosen, Eq(addedProject)); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  | TEST_F(ProjectPartChooser, StopUsingFallbackFromModelManagerIfProjectChanges2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     fallbackProjectPart.reset(new ProjectPart); | 
					
						
							|  |  |  |     currentProjectPartInfo.projectPart = fallbackProjectPart; | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch; | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  |     const ProjectPart::Ptr addedProject(new ProjectPart); | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += addedProject; | 
					
						
							|  |  |  |     projectsChanged = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPart::Ptr chosen = choose().projectPart; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(chosen, Eq(addedProject)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | TEST_F(ProjectPartChooser, IndicateFallbacktoProjectPartFromModelManager) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     fallbackProjectPart.reset(new ProjectPart); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsFallbackMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, IndicateFromDependencies) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     projectPartsFromDependenciesForFile += ProjectPart::Ptr(new ProjectPart); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(hints & ProjectPartInfo::IsFromDependenciesMatch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectPartChooser, DoNotIndicateFromDependencies) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     projectPartsForFile += ProjectPart::Ptr(new ProjectPart); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPartInfo::Hints hints = choose().hints; | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 15:05:46 +01:00
										 |  |  |     ASSERT_FALSE(hints & ProjectPartInfo::IsFromDependenciesMatch); | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | void ProjectPartChooser::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  |     chooser.setFallbackProjectPart([&]() { | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  |         return fallbackProjectPart; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     chooser.setProjectPartsForFile([&](const QString &) { | 
					
						
							|  |  |  |         return projectPartsForFile; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     chooser.setProjectPartsFromDependenciesForFile([&](const QString &) { | 
					
						
							|  |  |  |         return projectPartsFromDependenciesForFile; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 15:27:31 +01:00
										 |  |  | const ProjectPartInfo ProjectPartChooser::choose() const | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return chooser.choose(filePath, | 
					
						
							| 
									
										
										
										
											2017-01-19 11:08:13 +01:00
										 |  |  |                           currentProjectPartInfo, | 
					
						
							| 
									
										
										
										
											2017-01-19 12:52:16 +01:00
										 |  |  |                           preferredProjectPartId, | 
					
						
							| 
									
										
										
										
											2016-12-15 11:21:44 +01:00
										 |  |  |                           activeProject, | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  |                           languagePreference, | 
					
						
							| 
									
										
										
										
											2017-01-19 15:46:40 +01:00
										 |  |  |                           projectsChanged); | 
					
						
							| 
									
										
										
										
											2016-12-16 13:12:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<ProjectPart::Ptr> ProjectPartChooser::createProjectPartsWithDifferentProjects() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QList<ProjectPart::Ptr> projectParts; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectPart::Ptr p1{new ProjectPart}; | 
					
						
							|  |  |  |     p1->project = reinterpret_cast<ProjectExplorer::Project *>(1 << 0); | 
					
						
							|  |  |  |     projectParts.append(p1); | 
					
						
							|  |  |  |     const ProjectPart::Ptr p2{new ProjectPart}; | 
					
						
							|  |  |  |     p2->project = reinterpret_cast<ProjectExplorer::Project *>(1 << 1); | 
					
						
							|  |  |  |     projectParts.append(p2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return projectParts; | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  | QList<ProjectPart::Ptr> ProjectPartChooser::createCAndCxxProjectParts() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QList<ProjectPart::Ptr> projectParts; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Create project part for C
 | 
					
						
							|  |  |  |     const ProjectPart::Ptr cprojectpart{new ProjectPart}; | 
					
						
							| 
									
										
										
										
											2018-10-08 09:49:02 +02:00
										 |  |  |     cprojectpart->languageVersion = ProjectExplorer::LanguageVersion::C11; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  |     projectParts.append(cprojectpart); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Create project part for CXX
 | 
					
						
							|  |  |  |     const ProjectPart::Ptr cxxprojectpart{new ProjectPart}; | 
					
						
							| 
									
										
										
										
											2018-10-08 09:49:02 +02:00
										 |  |  |     cxxprojectpart->languageVersion = ProjectExplorer::LanguageVersion::CXX98; | 
					
						
							| 
									
										
										
										
											2017-01-12 18:01:12 +01:00
										 |  |  |     projectParts.append(cxxprojectpart); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return projectParts; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 13:10:43 +01:00
										 |  |  | } // anonymous namespace
 |