| 
									
										
										
										
											2015-11-17 13:33:31 +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-17 13:33:31 +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-17 13:33:31 +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-17 13:33:31 +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-17 13:33:31 +01:00
										 |  |  | #include <cursor.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | #include <clangdocument.h>
 | 
					
						
							|  |  |  | #include <clangdocuments.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | #include <clangstring.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  | #include <clangtranslationunit.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | #include <projectpart.h>
 | 
					
						
							|  |  |  | #include <projects.h>
 | 
					
						
							|  |  |  | #include <skippedsourceranges.h>
 | 
					
						
							|  |  |  | #include <sourcelocation.h>
 | 
					
						
							|  |  |  | #include <sourcerange.h>
 | 
					
						
							|  |  |  | #include <unsavedfiles.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <sourcerangecontainer.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QVector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using ClangBackEnd::Cursor; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  | using ClangBackEnd::Document; | 
					
						
							|  |  |  | using ClangBackEnd::Documents; | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  | using ClangBackEnd::TranslationUnit; | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | using ClangBackEnd::UnsavedFiles; | 
					
						
							|  |  |  | using ClangBackEnd::ProjectPart; | 
					
						
							|  |  |  | using ClangBackEnd::ClangString; | 
					
						
							|  |  |  | using ClangBackEnd::SourceRange; | 
					
						
							|  |  |  | using ClangBackEnd::SkippedSourceRanges; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using testing::IsNull; | 
					
						
							|  |  |  | using testing::NotNull; | 
					
						
							|  |  |  | using testing::Gt; | 
					
						
							|  |  |  | using testing::Contains; | 
					
						
							|  |  |  | using testing::EndsWith; | 
					
						
							|  |  |  | using testing::AllOf; | 
					
						
							|  |  |  | using testing::Not; | 
					
						
							|  |  |  | using testing::IsEmpty; | 
					
						
							|  |  |  | using testing::SizeIs; | 
					
						
							|  |  |  | using testing::PrintToString; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MATCHER_P4(IsSourceLocation, filePath, line, column, offset, | 
					
						
							|  |  |  |            std::string(negation ? "isn't" : "is") | 
					
						
							|  |  |  |            + " source location with file path "+ PrintToString(filePath) | 
					
						
							|  |  |  |            + ", line " + PrintToString(line) | 
					
						
							|  |  |  |            + ", column " + PrintToString(column) | 
					
						
							|  |  |  |            + " and offset " + PrintToString(offset) | 
					
						
							|  |  |  |            ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!arg.filePath().endsWith(filePath) | 
					
						
							| 
									
										
										
										
											2016-01-01 15:58:43 +02:00
										 |  |  |      || arg.line() != uint(line) | 
					
						
							|  |  |  |      || arg.column() != uint(column) | 
					
						
							|  |  |  |      || arg.offset() != uint(offset)) { | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct Data { | 
					
						
							| 
									
										
										
										
											2016-06-05 19:59:23 +02:00
										 |  |  |     Data() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |         document.parse(); | 
					
						
							| 
									
										
										
										
											2016-06-05 19:59:23 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  |     ClangBackEnd::ProjectParts projects; | 
					
						
							|  |  |  |     ClangBackEnd::UnsavedFiles unsavedFiles; | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |     ClangBackEnd::Documents documents{projects, unsavedFiles}; | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  |     Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/skippedsourceranges.cpp"); | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |     Document document{filePath, | 
					
						
							|  |  |  |                       ProjectPart(Utf8StringLiteral("projectPartId"), | 
					
						
							| 
									
										
										
										
											2017-05-23 09:49:22 +02:00
										 |  |  |                                  TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++11"), | 
					
						
							|  |  |  |                                                                         Utf8StringLiteral("-DBLAH")})), | 
					
						
							| 
									
										
										
										
											2016-09-07 10:42:12 +02:00
										 |  |  |                       {}, | 
					
						
							|  |  |  |                       documents}; | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  |     TranslationUnit translationUnit{filePath, | 
					
						
							| 
									
										
										
										
											2016-09-13 10:41:22 +02:00
										 |  |  |                                     filePath, | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  |                                     document.translationUnit().cxIndex(), | 
					
						
							|  |  |  |                                     document.translationUnit().cxTranslationUnit()}; | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SkippedSourceRanges : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static void SetUpTestCase(); | 
					
						
							|  |  |  |     static void TearDownTestCase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     static Data *d; | 
					
						
							| 
									
										
										
										
											2016-09-07 14:50:58 +02:00
										 |  |  |     const TranslationUnit &translationUnit = d->translationUnit; | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  |     const Utf8String &filePath = d->filePath; | 
					
						
							| 
									
										
										
										
											2017-06-16 10:45:05 +02:00
										 |  |  |     ::SkippedSourceRanges skippedSourceRanges{d->translationUnit.skippedSourceRanges()}; | 
					
						
							|  |  |  |     ::SkippedSourceRanges otherSkippedSourceRanges{d->translationUnit.skippedSourceRanges()}; | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Data *SkippedSourceRanges::d; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 10:45:05 +02:00
										 |  |  | TEST_F(SkippedSourceRanges, MoveConstructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const auto other = std::move(skippedSourceRanges); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(skippedSourceRanges.isNull()); | 
					
						
							|  |  |  |     ASSERT_FALSE(other.isNull()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SkippedSourceRanges, MoveAssignment) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     skippedSourceRanges = std::move(otherSkippedSourceRanges); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(otherSkippedSourceRanges.isNull()); | 
					
						
							|  |  |  |     ASSERT_FALSE(skippedSourceRanges.isNull()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | TEST_F(SkippedSourceRanges, RangeWithZero) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto ranges = skippedSourceRanges.sourceRanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(ranges, SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 13:30:56 +01:00
										 |  |  | TEST_F(SkippedSourceRanges, DISABLED_ON_WINDOWS(RangeOne)) | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto ranges = skippedSourceRanges.sourceRanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(ranges[0].start(), IsSourceLocation(filePath, 1, 2, 1)); | 
					
						
							| 
									
										
										
										
											2017-06-16 10:45:05 +02:00
										 |  |  |     ASSERT_THAT(ranges[0].end(), IsSourceLocation(filePath, 5, 1, 18)); | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 13:30:56 +01:00
										 |  |  | TEST_F(SkippedSourceRanges, DISABLED_ON_WINDOWS(RangeTwo)) | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto ranges = skippedSourceRanges.sourceRanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(ranges[1].start(), IsSourceLocation(filePath, 7, 2, 27)); | 
					
						
							| 
									
										
										
										
											2017-06-16 10:45:05 +02:00
										 |  |  |     ASSERT_THAT(ranges[1].end(), IsSourceLocation(filePath, 12, 1, 57)); | 
					
						
							| 
									
										
										
										
											2015-11-17 13:33:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(SkippedSourceRanges, RangeContainerSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto ranges = skippedSourceRanges.toSourceRangeContainers(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(ranges, SizeIs(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SkippedSourceRanges::SetUpTestCase() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     d = new Data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SkippedSourceRanges::TearDownTestCase() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete d; | 
					
						
							|  |  |  |     d = nullptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |