forked from qt-creator/qt-creator
CppTools: Avoid self-include
...in CPlusPlus::Document due to cyclic includes. Task-number: QTCREATORBUG-11457 Change-Id: I1ca19c901c26d9984d795a61879dd6b41c57096c Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user