| 
									
										
										
										
											2015-10-01 12:45:06 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** 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 | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 17:41:41 +02:00
										 |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  | #include <clangclock.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <projectpart.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-09 14:25:59 +02:00
										 |  |  | #include <clangexceptions.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-16 12:38:04 +02:00
										 |  |  | #include <projects.h>
 | 
					
						
							|  |  |  | #include <utf8stringvector.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | #include <thread>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::ElementsAre; | 
					
						
							|  |  |  | using testing::Pointwise; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | using testing::Gt; | 
					
						
							|  |  |  | using testing::Not; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, CreateProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Utf8String projectPath(Utf8StringLiteral("/tmp/blah.pro")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(projectPath); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 17:57:59 +02:00
										 |  |  |     ASSERT_THAT(project.id(), projectPath); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, CreateProjectPartWithProjectPartContainer) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(projectContainer); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 17:57:59 +02:00
										 |  |  |     ASSERT_THAT(project.id(), Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(project.arguments(), Contains(Utf8StringLiteral("-O"))); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, SetArguments) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(project.arguments(), ElementsAre(Utf8StringLiteral("-O"), Utf8StringLiteral("-fast"))); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, ArgumentCount) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(project.arguments().count(), 2); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, TimeStampIsUpdatedAsArgumentChanged) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(Utf8StringLiteral("/tmp/blah.pro")); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     auto lastChangeTimePoint = project.lastChangeTimePoint(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     std::this_thread::sleep_for(ClangBackEnd::Duration(1)); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     project.setArguments(Utf8StringVector({Utf8StringLiteral("-O"), Utf8StringLiteral("-fast")})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(project.lastChangeTimePoint(), Gt(lastChangeTimePoint)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, GetNonExistingPoject) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ASSERT_THROW(projects.project(Utf8StringLiteral("pathToProjectPart.pro")), ClangBackEnd::ProjectPartDoNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, AddProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ASSERT_THAT(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPart(projectContainer)); | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(Utf8StringLiteral("-O"))); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, UpdateProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectPartContainer projectContainerWithNewArguments(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-fast")}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     projects.createOrUpdate({projectContainerWithNewArguments}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ASSERT_THAT(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPart(projectContainer)); | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(projects.project(projectContainer.projectPartId()).arguments(), ElementsAre(Utf8StringLiteral("-fast"))); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, ThrowExceptionForAccesingRemovedProjectParts) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     projects.remove({projectContainer.projectPartId()}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ASSERT_THROW(projects.project(projectContainer.projectPartId()), ClangBackEnd::ProjectPartDoNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, ProjectPartProjectPartIdIsEmptyfterRemoving) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro"), {Utf8StringLiteral("-O")}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project(projects.project(projectContainer.projectPartId())); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     projects.remove({projectContainer.projectPartId()}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 17:57:59 +02:00
										 |  |  |     ASSERT_TRUE(project.id().isEmpty()); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-16 11:54:11 +02:00
										 |  |  | TEST(ProjectPart, ThrowsForNotExistingProjectPartButRemovesAllExistingProject) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPart project = *projects.findProjectPart(Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     EXPECT_THROW(projects.remove({Utf8StringLiteral("doesnotexist.pro"), projectContainer.projectPartId()}),  ClangBackEnd::ProjectPartDoNotExistException); | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(projects.projects(), Not(Contains(project))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-16 12:32:02 +02:00
										 |  |  | TEST(ProjectPart, ProjectPartIsClearedAfterRemove) | 
					
						
							| 
									
										
										
										
											2015-07-16 11:54:11 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							|  |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectPart project = *projects.findProjectPart(projectContainer.projectPartId()); | 
					
						
							| 
									
										
										
										
											2015-07-16 12:32:02 +02:00
										 |  |  |     const auto lastChangeTimePoint = project.lastChangeTimePoint(); | 
					
						
							| 
									
										
										
										
											2016-09-15 11:56:25 +02:00
										 |  |  |     std::this_thread::sleep_for(ClangBackEnd::Duration(1)); | 
					
						
							| 
									
										
										
										
											2015-07-16 11:54:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     projects.remove({projectContainer.projectPartId()}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 17:57:59 +02:00
										 |  |  |     ASSERT_THAT(project.id(), Utf8String()); | 
					
						
							| 
									
										
										
										
											2016-05-30 10:25:52 +02:00
										 |  |  |     ASSERT_THAT(project.arguments().count(), 0); | 
					
						
							| 
									
										
										
										
											2015-07-16 12:32:02 +02:00
										 |  |  |     ASSERT_THAT(project.lastChangeTimePoint(), Gt(lastChangeTimePoint)); | 
					
						
							| 
									
										
										
										
											2015-07-16 11:54:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  | TEST(ProjectPart, HasProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(projects.hasProjectPart(projectContainer.projectPartId())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST(ProjectPart, DoNotHasProjectPart) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-16 11:56:00 +02:00
										 |  |  |     ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral("pathToProjectPart.pro")); | 
					
						
							|  |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							| 
									
										
										
										
											2015-06-01 18:51:55 +02:00
										 |  |  |     projects.createOrUpdate({projectContainer}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(projects.hasProjectPart(Utf8StringLiteral("doesnotexist.pro"))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |