| 
									
										
										
										
											2018-08-14 18:30:47 +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 <sourcesmanager.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SourcesManager : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     ClangBackEnd::SourcesManager sources; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TouchFilePathIdFirstTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_FALSE(sources.alreadyParsed(1, 56)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TouchFilePathIdTwoTimesWithSameTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_FALSE(sources.alreadyParsed(1, 56)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithSameTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(1, 56)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithOlderTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(1, 55)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithNewerTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_FALSE(sources.alreadyParsed(1, 57)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, MultipleFileIds) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 455); | 
					
						
							|  |  |  |     sources.alreadyParsed(4, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(3, 85); | 
					
						
							|  |  |  |     sources.alreadyParsed(6, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(2, 45); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(3, 85)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, UpdateModifiedTimeStampsWithNewerTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 455); | 
					
						
							|  |  |  |     sources.alreadyParsed(4, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(3, 85); | 
					
						
							|  |  |  |     sources.alreadyParsed(6, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(2, 45); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(3, 86); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(3, 86)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, DontUpdateModifiedTimeStampsWithOlderTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 455); | 
					
						
							|  |  |  |     sources.alreadyParsed(4, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(3, 85); | 
					
						
							|  |  |  |     sources.alreadyParsed(6, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(2, 45); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(3, 84); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(3, 85)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, ZeroTime) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 0); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(1, 0)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, TimeIsUpdated) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(1, 57); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_TRUE(sources.alreadyParsed(1, 57)); | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_FALSE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsModified) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_TRUE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsModifiedAfterParsingTwoTimesSameTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_TRUE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_FALSE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterNotAlreadyPared) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_FALSE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterAlreadyPared) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 57); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_TRUE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AnyDependFileIsModifiedAfterUpdateNewTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsed(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(1, 57); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsed(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:17:42 +02:00
										 |  |  |     ASSERT_TRUE(sources.dependentFilesModified()); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsedAllDependentFiles(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 57); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(alreadyParsed); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewSecondTimeStamp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsedAllDependentFiles(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 57); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(alreadyParsed); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateSameTimeStamps) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 56); | 
					
						
							|  |  |  |     sources.alreadyParsedAllDependentFiles(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  |     sources.updateModifiedTimeStamps(); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     sources.alreadyParsedAllDependentFiles(1, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); | 
					
						
							| 
									
										
										
										
											2018-08-16 18:01:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(alreadyParsed); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 18:30:47 +02:00
										 |  |  | } |