| 
									
										
										
										
											2017-06-26 14:00:32 +02: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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 19:53:32 +02:00
										 |  |  | #include "filesystem-utilities.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | #include "sourcerangecontainer-matcher.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <filecontainerv2.h>
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | #include <filepathcaching.h>
 | 
					
						
							|  |  |  | #include <refactoringdatabaseinitializer.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <sqlitedatabase.h>
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <clangquerygatherer.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | #include <QDir>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::AllOf; | 
					
						
							|  |  |  | using testing::AtLeast; | 
					
						
							|  |  |  | using testing::AtMost; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | using testing::Each; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  | using testing::ElementsAre; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | using testing::Eq; | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  | using testing::Field; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | using testing::Ge; | 
					
						
							|  |  |  | using testing::IsEmpty; | 
					
						
							|  |  |  | using testing::Le; | 
					
						
							|  |  |  | using testing::NiceMock; | 
					
						
							|  |  |  | using testing::Pair; | 
					
						
							|  |  |  | using testing::PrintToString; | 
					
						
							|  |  |  | using testing::SizeIs; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  | using testing::UnorderedElementsAre; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | using testing::_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ClangBackEnd::V2::FileContainer; | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | using ClangBackEnd::SourceRangesForQueryMessage; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | using ClangBackEnd::SourceRangesContainer; | 
					
						
							|  |  |  | using ClangBackEnd::SourceRangesContainer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MATCHER_P2(Contains, line, column, | 
					
						
							|  |  |  |            std::string(negation ? "isn't " : "is ") | 
					
						
							|  |  |  |            + "(" + PrintToString(line) | 
					
						
							|  |  |  |            + ", " + PrintToString(column) | 
					
						
							|  |  |  |            + ")" | 
					
						
							|  |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |     return arg.line == uint(line) | 
					
						
							|  |  |  |         && arg.column == uint(column); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ClangQueryGatherer : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     void SetUp() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2017-10-18 13:34:05 +02:00
										 |  |  |     Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; | 
					
						
							|  |  |  |     ClangBackEnd::FilePathCaching filePathCache{database}; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     Utils::SmallString sourceContent{"#include \"query_simplefunction.h\"\nvoid f() {}"}; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, | 
					
						
							|  |  |  |                          sourceContent.clone(), | 
					
						
							| 
									
										
										
										
											2019-01-31 10:30:58 +01:00
										 |  |  |                          {"cc", | 
					
						
							|  |  |  |                           toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), | 
					
						
							|  |  |  |                           "-I", | 
					
						
							|  |  |  |                           TESTDATA_DIR}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     FileContainer source2{{TESTDATA_DIR, "query_simplefunction2.cpp"}, | 
					
						
							|  |  |  |                           {}, | 
					
						
							| 
									
										
										
										
											2019-01-31 10:30:58 +01:00
										 |  |  |                           {"cc", | 
					
						
							|  |  |  |                            toNativePath(TESTDATA_DIR "/query_simplefunction2.cpp").path(), | 
					
						
							|  |  |  |                            "-I", | 
					
						
							|  |  |  |                            TESTDATA_DIR}}; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     FileContainer source3{{TESTDATA_DIR, "query_simplefunction3.cpp"}, | 
					
						
							|  |  |  |                           {}, | 
					
						
							| 
									
										
										
										
											2019-01-31 10:30:58 +01:00
										 |  |  |                           {"cc", | 
					
						
							|  |  |  |                            toNativePath(TESTDATA_DIR "/query_simplefunction3.cpp").path(), | 
					
						
							|  |  |  |                            "-I", | 
					
						
							|  |  |  |                            TESTDATA_DIR}}; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     Utils::SmallString unsavedContent{"void f();"}; | 
					
						
							|  |  |  |     FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, | 
					
						
							|  |  |  |                           unsavedContent.clone(), | 
					
						
							|  |  |  |                           {}}; | 
					
						
							|  |  |  |     Utils::SmallString query{"functionDecl()"}; | 
					
						
							| 
									
										
										
										
											2017-07-03 11:12:00 +02:00
										 |  |  |     ClangBackEnd::ClangQueryGatherer gatherer{&filePathCache, {source.clone()}, {unsaved.clone()}, query.clone()}; | 
					
						
							|  |  |  |     ClangBackEnd::ClangQueryGatherer manyGatherer{&filePathCache, | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                                                   {source3.clone(), source2.clone(), source.clone()}, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |                                                   {unsaved.clone()}, | 
					
						
							|  |  |  |                                                   query.clone()}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CreateSourceRanges) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     auto sourceRangesAndDiagnostics = gatherer.createSourceRangesForSource(&filePathCache, source.clone(), {unsaved}, query.clone()); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceRangesAndDiagnostics, | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                 Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                       Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                             Contains(IsSourceRangeWithText(2, 1, 2, 12, "void f() {}"))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CreateSourceRangessWithUnsavedContent) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     auto sourceRangesAndDiagnostics = gatherer.createSourceRangesForSource(&filePathCache, source.clone(), {unsaved}, query.clone()); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceRangesAndDiagnostics, | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                 Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                       Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                             Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CanCreateSourceRangesIfItHasSources) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     ASSERT_TRUE(gatherer.canCreateSourceRanges()); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CanNotCreateSourceRangesIfItHasNoSources) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 11:12:00 +02:00
										 |  |  |     ClangBackEnd::ClangQueryGatherer empthyGatherer{&filePathCache, {}, {unsaved.clone()}, query.clone()}; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     ASSERT_FALSE(empthyGatherer.canCreateSourceRanges()); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CreateSourceRangesForNextSource) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     auto sourceRangesAndDiagnostics = gatherer.createNextSourceRanges(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceRangesAndDiagnostics, | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                 Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                       Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                             Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, CreateSourceRangesForNextSourcePopsSource) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.createNextSourceRanges(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sources(), SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, StartCreateSourceRangesForNextSource) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     auto future = gatherer.startCreateNextSourceRangesMessage(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     future.wait(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(future.get(), | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                 Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                       Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                             Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, StartCreateSourceRangesForNextSourcePopsSource) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessage(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sources(), SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, AfterStartCreateSourceRangesMessagesFutureCountIsTwos) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, AfterRestartCreateSourceRangesMessagesFutureCountIsTwos) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  | TEST_F(ClangQueryGatherer, AfterStartCreateSourceRangesMessagesGetCollected) | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.allCurrentProcessedMessages(), | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                 UnorderedElementsAre( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 UnorderedElementsAre(IsSourceRangeWithText(1, 1, 1, 9, "void f();"), | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                                                            IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                     Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                           Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                 UnorderedElementsAre( | 
					
						
							|  |  |  |                                     IsSourceRangeWithText(1, 1, 1, 13, "int header();"), | 
					
						
							|  |  |  |                                     IsSourceRangeWithText(3, 1, 3, 15, "int function();")))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, GetFinishedMessages) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto messages = manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(messages, | 
					
						
							|  |  |  |                 AllOf(SizeIs(2), | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                       UnorderedElementsAre( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(1, 1, 1, 9, "void f();"), | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), | 
					
						
							|  |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(1, 1, 1, 13, "int header();"), | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, GetFinishedMessagesAfterSecondPass) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto messages = manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(messages, | 
					
						
							|  |  |  |                 AllOf(SizeIs(1), | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |                       ElementsAre( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, FilterDuplicates) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     manyGatherer.setProcessingSlotCount(3); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-07-03 11:53:47 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto messages = manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(messages, | 
					
						
							|  |  |  |                 AllOf(SizeIs(3), | 
					
						
							|  |  |  |                       UnorderedElementsAre( | 
					
						
							| 
									
										
										
										
											2018-04-08 01:20:42 +03:00
										 |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(1, 1, 1, 9, "void f();"), | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), | 
					
						
							|  |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(1, 1, 1, 13, "int header();"), | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(3, 1, 3, 15, "int function();")))), | 
					
						
							|  |  |  |                           Field(&SourceRangesForQueryMessage::sourceRanges, | 
					
						
							|  |  |  |                                 Field(&SourceRangesContainer::sourceRangeWithTextContainers, | 
					
						
							|  |  |  |                                       UnorderedElementsAre( | 
					
						
							|  |  |  |                                           IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, AfterGetFinishedMessagesFuturesAreReduced) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(0)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, SourceFutureIsOneInTheSecondRun) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, GetOneMessageInTheSecondRun) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto messages = manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(messages, SizeIs(1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, IsNotFinishedIfSourcesExists) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool isFinished = manyGatherer.isFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(isFinished); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, IsNotFinishedIfSourceFuturesExists) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool isFinished = manyGatherer.isFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(isFinished); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangQueryGatherer, IsFinishedIfNoSourceAndSourceFuturesExists) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:35:58 +02:00
										 |  |  |     manyGatherer.startCreateNextSourceRangesMessages(); | 
					
						
							| 
									
										
										
										
											2017-06-26 14:00:32 +02:00
										 |  |  |     manyGatherer.waitForFinished(); | 
					
						
							|  |  |  |     manyGatherer.finishedMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool isFinished = manyGatherer.isFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(isFinished); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangQueryGatherer::SetUp() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     manyGatherer.setProcessingSlotCount(2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |