| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2017 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 "gtest-qt-printing.h"
 | 
					
						
							|  |  |  | #include "mimedatabase-utilities.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cpptools/cppprojectinfogenerator.h>
 | 
					
						
							|  |  |  | #include <cpptools/projectinfo.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <utils/mimetypes/mimedatabase.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using CppTools::Internal::ProjectInfoGenerator; | 
					
						
							|  |  |  | using CppTools::ProjectFile; | 
					
						
							|  |  |  | using CppTools::ProjectInfo; | 
					
						
							|  |  |  | using CppTools::ProjectPart; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  | using ProjectExplorer::Macros; | 
					
						
							| 
									
										
										
										
											2019-08-29 09:59:45 +02:00
										 |  |  | using ProjectExplorer::ProjectUpdateInfo; | 
					
						
							| 
									
										
										
										
											2019-08-28 18:22:45 +02:00
										 |  |  | using ProjectExplorer::RawProjectPart; | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | using ProjectExplorer::ToolChain; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::Eq; | 
					
						
							|  |  |  | using testing::UnorderedElementsAre; | 
					
						
							|  |  |  | using testing::PrintToString; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MATCHER_P2(IsProjectPart, languageVersion, fileKind, | 
					
						
							|  |  |  |            std::string(negation ? "isn't" : "is") | 
					
						
							|  |  |  |            + " project part with language version " + PrintToString(languageVersion) | 
					
						
							|  |  |  |            + " and file kind " + PrintToString(fileKind)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectPart::Ptr &projectPart = arg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return projectPart->languageVersion == languageVersion | 
					
						
							|  |  |  |         && projectPart->files.at(0).kind == fileKind; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ProjectInfoGenerator : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							|  |  |  |     ProjectInfo generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  |     ProjectUpdateInfo projectUpdateInfo; | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  |     RawProjectPart rawProjectPart; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, CreateNoProjectPartsForEmptyFileList) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(projectInfo.projectParts().isEmpty()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, CreateSingleProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.cpp", "foo.h"}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, CreateMultipleProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.cpp", "foo.h", "bar.c", "bar.h" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, ProjectPartIndicatesObjectiveCExtensionsByDefault) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.mm" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(1)); | 
					
						
							|  |  |  |     const ProjectPart &projectPart = *projectInfo.projectParts().at(0); | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |     ASSERT_TRUE(projectPart.languageExtensions & Utils::LanguageExtension::ObjectiveC); | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, ProjectPartHasLatestLanguageVersionByDefault) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.cpp" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(1)); | 
					
						
							|  |  |  |     const ProjectPart &projectPart = *projectInfo.projectParts().at(0); | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |     ASSERT_THAT(projectPart.languageVersion, Eq(Utils::LanguageVersion::LatestCxx)); | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  | TEST_F(ProjectInfoGenerator, UseMacroInspectionReportForLanguageVersion) | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  |     projectUpdateInfo.cxxToolChainInfo.macroInspectionRunner = [](const QStringList &) { | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |         return ToolChain::MacroInspectionReport{Macros(), Utils::LanguageVersion::CXX17}; | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  |     rawProjectPart.files = QStringList{ "foo.cpp" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(1)); | 
					
						
							|  |  |  |     const ProjectPart &projectPart = *projectInfo.projectParts().at(0); | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |     ASSERT_THAT(projectPart.languageVersion, Eq(Utils::LanguageVersion::CXX17)); | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  | TEST_F(ProjectInfoGenerator, UseCompilerFlagsForLanguageExtensions) | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.cpp" }; | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |     rawProjectPart.flagsForCxx.languageExtensions = Utils::LanguageExtension::Microsoft; | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts().size(), Eq(1)); | 
					
						
							|  |  |  |     const ProjectPart &projectPart = *projectInfo.projectParts().at(0); | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |     ASSERT_TRUE(projectPart.languageExtensions & Utils::LanguageExtension::Microsoft); | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ProjectInfoGenerator, ProjectFileKindsMatchProjectPartVersion) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     rawProjectPart.files = QStringList{ "foo.h" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ProjectInfo projectInfo = generate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projectInfo.projectParts(), | 
					
						
							| 
									
										
										
										
											2019-01-09 18:31:20 +01:00
										 |  |  |                 UnorderedElementsAre(IsProjectPart(Utils::LanguageVersion::LatestC, ProjectFile::CHeader), | 
					
						
							|  |  |  |                                      IsProjectPart(Utils::LanguageVersion::LatestC, ProjectFile::ObjCHeader), | 
					
						
							|  |  |  |                                      IsProjectPart(Utils::LanguageVersion::LatestCxx, ProjectFile::CXXHeader), | 
					
						
							|  |  |  |                                      IsProjectPart(Utils::LanguageVersion::LatestCxx, ProjectFile::ObjCXXHeader))); | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProjectInfoGenerator::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_TRUE(MimeDataBaseUtilities::addCppToolsMimeTypes()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ProjectInfo ProjectInfoGenerator::generate() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-10 17:55:54 +01:00
										 |  |  |     QFutureInterface<ProjectInfo> fi; | 
					
						
							| 
									
										
										
										
											2019-05-21 14:22:41 +02:00
										 |  |  |     ProjectExplorer::ConcreteToolChain aToolChain; | 
					
						
							| 
									
										
										
										
											2018-09-27 10:18:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  |     projectUpdateInfo.rawProjectParts += rawProjectPart; | 
					
						
							| 
									
										
										
										
											2019-05-21 14:22:41 +02:00
										 |  |  |     projectUpdateInfo.cxxToolChain = &aToolChain; | 
					
						
							|  |  |  |     projectUpdateInfo.cToolChain = &aToolChain; | 
					
						
							| 
									
										
										
										
											2017-02-06 16:59:53 +01:00
										 |  |  |     ::ProjectInfoGenerator generator(fi, projectUpdateInfo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return generator.generate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // anonymous namespace
 |