diff options
Diffstat (limited to 'src/plugins/cpptools/cpppreprocessor_test.cpp')
-rw-r--r-- | src/plugins/cpptools/cpppreprocessor_test.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpppreprocessor_test.cpp b/src/plugins/cpptools/cpppreprocessor_test.cpp index 5f6729bb0c..17ab615b02 100644 --- a/src/plugins/cpptools/cpppreprocessor_test.cpp +++ b/src/plugins/cpptools/cpppreprocessor_test.cpp @@ -32,8 +32,12 @@ #include "cppmodelmanager.h" #include "cpppreprocessertesthelper.h" #include "cpppreprocessor.h" +#include "cppsnapshotupdater.h" +#include "cpptoolseditorsupport.h" #include "cpptoolstestcase.h" +#include <texteditor/basetexteditor.h> + #include <cplusplus/CppDocument.h> #include <utils/fileutils.h> @@ -117,3 +121,43 @@ void CppToolsPlugin::test_cpppreprocessor_includes_resolvedUnresolved() QCOMPARE(unresolvedIncludes.at(0).unresolvedFileName(), QLatin1String("notresolvable.h")); QVERIFY(unresolvedIncludes.at(0).resolvedFileName().isEmpty()); } + +/// Check: Avoid self-include entries due to cyclic includes. +void CppToolsPlugin::test_cpppreprocessor_includes_cyclic() +{ + const QString fileName1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h")); + const QString fileName2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h")); + const QStringList sourceFiles = QStringList() << fileName1 << fileName2; + + // Create global snapshot (needed in SnapshotUpdater) + TestCase testCase; + testCase.parseFiles(sourceFiles); + + // Open editor + TextEditor::BaseTextEditor *editor; + QVERIFY(testCase.openBaseTextEditor(fileName1, &editor)); + testCase.closeEditorAtEndOfTestCase(editor); + + // Get editor snapshot + CppEditorSupport *cppEditorSupport = CppModelManagerInterface::instance() + ->cppEditorSupport(editor); + QVERIFY(cppEditorSupport); + QSharedPointer<SnapshotUpdater> snapshotUpdater = cppEditorSupport->snapshotUpdater(); + QVERIFY(snapshotUpdater); + Snapshot snapshot = snapshotUpdater->snapshot(); + QCOMPARE(snapshot.size(), 3); // Configuration file included + + // Check includes + Document::Ptr doc1 = snapshot.document(fileName1); + QVERIFY(doc1); + Document::Ptr doc2 = snapshot.document(fileName2); + QVERIFY(doc2); + + QCOMPARE(doc1->unresolvedIncludes().size(), 0); + QCOMPARE(doc1->resolvedIncludes().size(), 1); + QCOMPARE(doc1->resolvedIncludes().first().resolvedFileName(), fileName2); + + QCOMPARE(doc2->unresolvedIncludes().size(), 0); + QCOMPARE(doc2->resolvedIncludes().size(), 1); + QCOMPARE(doc2->resolvedIncludes().first().resolvedFileName(), fileName1); +} |