| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01: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-11-18 17:07:44 +01: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-11-18 17:07:44 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 17:41:41 +02:00
										 |  |  | #include "googletest.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-23 09:49:22 +02:00
										 |  |  | #include "testenvironment.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-15 17:41:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | #include <chunksreportedmonitor.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <clangdocument.h>
 | 
					
						
							|  |  |  | #include <clangdocuments.h>
 | 
					
						
							| 
									
										
										
										
											2016-05-31 16:07:09 +02:00
										 |  |  | #include <cursor.h>
 | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  | #include <tokeninfocontainer.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | #include <tokenprocessor.h>
 | 
					
						
							|  |  |  | #include <clanghighlightingresultreporter.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | #include <projectpart.h>
 | 
					
						
							|  |  |  | #include <projects.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ClangBackEnd::Cursor; | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | using ClangBackEnd::TokenProcessor; | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  | using ClangBackEnd::TokenInfoContainer; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | using ClangBackEnd::HighlightingType; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | using ClangBackEnd::Document; | 
					
						
							|  |  |  | using ClangBackEnd::Documents; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | using ClangBackEnd::UnsavedFiles; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPart; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectParts; | 
					
						
							|  |  |  | using ClangBackEnd::ChunksReportedMonitor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct Data { | 
					
						
							|  |  |  |     ProjectParts projects; | 
					
						
							|  |  |  |     UnsavedFiles unsavedFiles; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |     Documents documents{projects, unsavedFiles}; | 
					
						
							|  |  |  |     Document document{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp"), | 
					
						
							|  |  |  |                       ProjectPart(Utf8StringLiteral("projectPartId"), | 
					
						
							| 
									
										
										
										
											2017-05-23 09:49:22 +02:00
										 |  |  |                                   TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14")})), | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |                       {}, | 
					
						
							|  |  |  |                       documents}; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | class HighlightingResultReporter : public ::testing::Test | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static void SetUpTestCase(); | 
					
						
							|  |  |  |     static void TearDownTestCase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     static Data *d; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  | QVector<TokenInfoContainer> noTokenInfos() | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  |     return QVector<TokenInfoContainer>(); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  | QVector<TokenInfoContainer> generateTokenInfos(uint count) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  |     auto container = QVector<TokenInfoContainer>(); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (uint i = 0; i < count; ++i) { | 
					
						
							|  |  |  |         const uint line = i + 1; | 
					
						
							| 
									
										
										
										
											2018-02-23 12:28:30 +01:00
										 |  |  |         ClangBackEnd::HighlightingTypes types; | 
					
						
							|  |  |  |         types.mainHighlightingType = ClangBackEnd::HighlightingType::Type; | 
					
						
							|  |  |  |         container.append(TokenInfoContainer(line, 1, 1, types)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return container; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, StartAndFinish) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(noTokenInfos()); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     future.waitForFinished(); | 
					
						
							|  |  |  |     ASSERT_THAT(future.isFinished(), true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportNothingIfNothingToReport) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(generateTokenInfos(0)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 0L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportSingleResultAsOneChunk) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(generateTokenInfos(1)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     reporter->setChunkSize(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 1L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportRestIfChunkSizeNotReached) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(generateTokenInfos(1)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     const int notReachedChunkSize = 100; | 
					
						
							|  |  |  |     reporter->setChunkSize(notReachedChunkSize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 1L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportChunksWithoutRest) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(generateTokenInfos(4)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     reporter->setChunkSize(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 2L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportSingleChunkAndRest) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(generateTokenInfos(5)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     reporter->setChunkSize(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 2L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | TEST_F(HighlightingResultReporter, ReportCompleteLines) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-23 12:28:30 +01:00
										 |  |  |     ClangBackEnd::HighlightingTypes types; | 
					
						
							|  |  |  |     types.mainHighlightingType = ClangBackEnd::HighlightingType::Type; | 
					
						
							| 
									
										
										
										
											2017-12-05 09:42:35 +01:00
										 |  |  |     QVector<TokenInfoContainer> tokenInfos { | 
					
						
							| 
									
										
										
										
											2018-02-23 12:28:30 +01:00
										 |  |  |         TokenInfoContainer(1, 1, 1, types), | 
					
						
							|  |  |  |         TokenInfoContainer(1, 2, 1, types), | 
					
						
							|  |  |  |         TokenInfoContainer(2, 1, 1, types), | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  |     auto reporter = new ClangCodeModel::HighlightingResultReporter(tokenInfos); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     reporter->setChunkSize(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto future = reporter->start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ChunksReportedMonitor monitor(future); | 
					
						
							|  |  |  |     ASSERT_THAT(monitor.resultsReadyCounter(), 2L); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | Data *HighlightingResultReporter::d; | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | void HighlightingResultReporter::SetUpTestCase() | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     d = new Data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 15:48:24 +01:00
										 |  |  | void HighlightingResultReporter::TearDownTestCase() | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     delete d; | 
					
						
							|  |  |  |     d = nullptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // anonymous
 |