summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cppquickfix_test.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2014-11-27 18:00:10 +0100
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2014-11-28 14:01:10 +0100
commit2fc4acbc356cbb310663f6568a6e73a66b649a8e (patch)
treea8342b2652b9b2a26ab707119ddd99ff53d346ca /src/plugins/cppeditor/cppquickfix_test.cpp
parentc58b029319d229c9af0cbe5696e042d9b5ed09c1 (diff)
downloadqt-creator-2fc4acbc356cbb310663f6568a6e73a66b649a8e.tar.gz
CppEditor: Avoid duplicate "Add #include XYZ"
Task-number: QTCREATORBUG-13422 Change-Id: I3648bf44760fdac4e8e1e79652519136af6032c8 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src/plugins/cppeditor/cppquickfix_test.cpp')
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 2403cdd3b1..c32e96bf58 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -245,6 +245,26 @@ void QuickFixOperationTest::run(const QList<QuickFixTestDocument::Ptr> &testDocu
QuickFixOperationTest(testDocuments, factory, headerPaths, operationIndex);
}
+QuickFixOfferedOperationsTest::QuickFixOfferedOperationsTest(
+ const QList<QuickFixTestDocument::Ptr> &testDocuments,
+ CppQuickFixFactory *factory,
+ const ProjectPart::HeaderPaths &headerPaths,
+ const QStringList &expectedOperations)
+ : BaseQuickFixTestCase(testDocuments, headerPaths)
+{
+ // Get operations
+ CppQuickFixInterface quickFixInterface(m_documentWithMarker->m_editorWidget, ExplicitlyInvoked);
+ TextEditor::QuickFixOperations actualOperations;
+ factory->match(quickFixInterface, actualOperations);
+
+ // Convert to QStringList
+ QStringList actualOperationsAsStringList;
+ foreach (const QuickFixOperation::Ptr &operation, actualOperations)
+ actualOperationsAsStringList << operation->description();
+
+ QCOMPARE(actualOperationsAsStringList, expectedOperations);
+}
+
/// Delegates directly to AddIncludeForUndefinedIdentifierOp for easier testing.
class AddIncludeForUndefinedIdentifierTestFactory : public CppQuickFixFactory
{
@@ -3090,7 +3110,32 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_inserting_c
AddIncludeForUndefinedIdentifier factory;
QuickFixOperationTest::run(testFiles, &factory, TestIncludePaths::globalQtCoreIncludePath());
+}
+
+void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noDoubleQtHeaderInclude()
+{
+ QList<QuickFixTestDocument::Ptr> testFiles;
+
+ QByteArray original;
+ QByteArray expected;
+
+ const QByteArray base = TestIncludePaths::directoryOfTestFile().toUtf8();
+ // This file makes the QDir definition available so that locator finds it.
+ original = expected = "#include <QDir>\n"
+ "void avoidBeingRecognizedAsForwardingHeader();";
+ testFiles << QuickFixTestDocument::create(base + "/fileUsingQDir.cpp", original, expected);
+
+ original = expected = "@QDir dir;\n";
+ testFiles << QuickFixTestDocument::create(base + "/fileWantsToUseQDir.cpp", original, expected);
+
+ ProjectPart::HeaderPaths headerPaths;
+ headerPaths += ProjectPart::HeaderPath(TestIncludePaths::globalQtCoreIncludePath(),
+ ProjectPart::HeaderPath::IncludePath);
+
+ AddIncludeForUndefinedIdentifier factory;
+ const QStringList expectedOperations = QStringList() << QLatin1String("Add #include <QDir>");
+ QuickFixOfferedOperationsTest(testFiles, &factory, headerPaths, expectedOperations);
}
/// Check: Move definition from header to cpp.