CppTools: fix showing cyclic in a wrong level of IncludeHierarchy

File path for which we build hierarchy was not consider in cyclic checking.

Added tests for cyclic cases

Change-Id: I0c2e60034c6e8f3aa69ab723350b4c05530fcdfb
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent b33c3c88
......@@ -143,6 +143,35 @@ void CppEditorPlugin::test_includehierarchy_data()
"Included by\n"
" file3.h\n"
);
QTest::newRow("simple-cyclic")
<< (QList<QByteArray>()
<< QByteArray("#include \"file2.h\"\n")
<< QByteArray("#include \"file1.h\"\n"))
<< QString::fromLatin1(
"Includes\n"
" file2.h\n"
" file1.h (cyclic)\n"
"Included by\n"
" file2.h\n"
" file1.h (cyclic)\n"
);
QTest::newRow("complex-cyclic")
<< (QList<QByteArray>()
<< QByteArray("#include \"file2.h\"\n")
<< QByteArray("#include \"file3.h\"\n")
<< QByteArray("#include \"file1.h\"\n"))
<< QString::fromLatin1(
"Includes\n"
" file2.h\n"
" file3.h\n"
" file1.h (cyclic)\n"
"Included by\n"
" file3.h\n"
" file2.h\n"
" file1.h (cyclic)\n"
);
}
void CppEditorPlugin::test_includehierarchy()
......
......@@ -161,6 +161,7 @@ void CppIncludeHierarchyModel::fetchMore(const QModelIndex &parent)
if (parentItem->needChildrenPopulate()) {
QSet<QString> cyclic;
cyclic << m_editor->document()->filePath();
CppIncludeHierarchyItem *item = parentItem->parent();
while (!(item == m_includesItem || item == m_includedByItem)) {
cyclic << item->filePath();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment