summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-12-16 16:02:45 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-01-07 14:19:13 +0100
commit5c8df5fa4ec4a8f30261dc4d53a810f7be65df51 (patch)
tree2abcbc02f94c15f4d26a5399c1ea31b4183923e7 /src/plugins/cppeditor
parent5aa8a63f90934619072242ac0f6f5fca128edd39 (diff)
downloadqt-creator-5c8df5fa4ec4a8f30261dc4d53a810f7be65df51.tar.gz
CppEditor/CppTools: Introduce Test{Case,Document}
Move common functionality of the 12 test classes into base classes. Change-Id: If64d3cec876807ac6f991151189860a99b8ff4ca Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/cppdoxygen_test.cpp75
-rw-r--r--src/plugins/cppeditor/cppeditor.pro2
-rw-r--r--src/plugins/cppeditor/cppeditor.qbs1
-rw-r--r--src/plugins/cppeditor/cppeditortestcase.cpp97
-rw-r--r--src/plugins/cppeditor/cppeditortestcase.h75
-rw-r--r--src/plugins/cppeditor/cppincludehierarchy_test.cpp37
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp359
-rw-r--r--src/plugins/cppeditor/fileandtokenactions_test.cpp54
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp164
9 files changed, 440 insertions, 424 deletions
diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp
index b1ffbc61a1..41d940e4cb 100644
--- a/src/plugins/cppeditor/cppdoxygen_test.cpp
+++ b/src/plugins/cppeditor/cppdoxygen_test.cpp
@@ -28,12 +28,13 @@
****************************************************************************/
#include "cppeditor.h"
+#include "cppeditorplugin.h"
+#include "cppeditortestcase.h"
#include <coreplugin/editormanager/editormanager.h>
-#include <cplusplus/CppDocument.h>
-#include <cppeditor/cppeditor.h>
-#include <cppeditor/cppeditorplugin.h>
#include <cpptools/cppmodelmanagerinterface.h>
+
+#include <cplusplus/CppDocument.h>
#include <utils/fileutils.h>
#include <QCoreApplication>
@@ -58,46 +59,31 @@ typedef QByteArray _;
* Encapsulates the whole process of setting up an editor,
* pressing ENTER and checking the result.
*/
-struct TestCase
+class TestCase : public CppEditor::Internal::Tests::TestCase
{
- QByteArray originalText;
- int pos;
- CPPEditor *editor;
- CPPEditorWidget *editorWidget;
-
+public:
TestCase(const QByteArray &input);
- ~TestCase();
-
void run(const QByteArray &expected, int undoCount = 1);
private:
- TestCase(const TestCase &);
- TestCase &operator=(const TestCase &);
+ CppEditor::Internal::Tests::TestDocument testDocument;
};
/// The '|' in the input denotes the cursor position.
TestCase::TestCase(const QByteArray &input)
- : originalText(input)
+ : testDocument("file.cpp", input, '|')
{
- pos = originalText.indexOf('|');
- QVERIFY(pos != -1);
- originalText.remove(pos, 1);
- QString fileName(QDir::tempPath() + QLatin1String("/file.cpp"));
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(originalText);
- srcSaver.finalize();
+ QVERIFY(testDocument.hasCursorMarker());
+ testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
+ QVERIFY(testDocument.writeToDisk());
// Update Code Model
- CppTools::CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
- mmi->updateSourceFiles(QStringList(fileName)).waitForFinished();
- QCoreApplication::processEvents();
- QVERIFY(mmi->snapshot().contains(fileName));
+ QVERIFY(parseFiles(testDocument.filePath()));
// Open Editor
- editor = dynamic_cast<CPPEditor *>(EditorManager::openEditor(fileName));
- QVERIFY(editor);
- editorWidget = dynamic_cast<CPPEditorWidget *>(editor->editorWidget());
- QVERIFY(editorWidget);
+ QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor,
+ &testDocument.m_editorWidget));
+ closeEditorAtEndOfTestCase(testDocument.m_editor);
// We want to test documents that start with a comment. By default, the
// editor will fold the very first comment it encounters, assuming
@@ -105,39 +91,26 @@ TestCase::TestCase(const QByteArray &input)
// expected (some blocks are still hidden in some test cases, so the
// cursor movements are not as expected). For the time being, we just
// prepend a declaration before the initial test comment.
-// editorWidget->unfoldAll();
- editor->setCursorPosition(pos);
-
- editorWidget->semanticRehighlight(true);
- // Wait for the semantic info from the future:
- while (editorWidget->semanticInfo().doc.isNull())
- QCoreApplication::processEvents();
-}
-
-TestCase::~TestCase()
-{
- EditorManager::closeEditor(editor, false);
- QCoreApplication::processEvents(); // process any pending events
+// testDocument.m_editorWidget->unfoldAll();
+ testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
- // Remove the test file from the code-model
- CppTools::CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
- mmi->GC();
- QCOMPARE(mmi->snapshot().size(), 0);
+ waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
}
void TestCase::run(const QByteArray &expected, int undoCount)
{
// Send 'ENTER' key press
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
- QCoreApplication::sendEvent(editorWidget, &event);
- const QByteArray result = editorWidget->document()->toPlainText().toUtf8();
+ QCoreApplication::sendEvent(testDocument.m_editorWidget, &event);
+ const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
QCOMPARE(QLatin1String(result), QLatin1String(expected));
for (int i = 0; i < undoCount; ++i)
- editorWidget->undo();
- const QByteArray contentsAfterUndo = editorWidget->document()->toPlainText().toUtf8();
- QCOMPARE(contentsAfterUndo, originalText);
+ testDocument.m_editorWidget->undo();
+ const QByteArray contentsAfterUndo
+ = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
+ QCOMPARE(contentsAfterUndo, testDocument.m_source);
}
} // anonymous namespace
diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro
index 9cd0d80acb..3ab35cdf4c 100644
--- a/src/plugins/cppeditor/cppeditor.pro
+++ b/src/plugins/cppeditor/cppeditor.pro
@@ -67,9 +67,11 @@ RESOURCES += \
equals(TEST, 1) {
HEADERS += \
+ cppeditortestcase.h \
cppquickfix_test_utils.h
SOURCES += \
cppdoxygen_test.cpp \
+ cppeditortestcase.cpp \
cppincludehierarchy_test.cpp \
cppquickfix_test.cpp \
cppquickfix_test_utils.cpp \
diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs
index f8f9746e73..8a2f724306 100644
--- a/src/plugins/cppeditor/cppeditor.qbs
+++ b/src/plugins/cppeditor/cppeditor.qbs
@@ -51,6 +51,7 @@ QtcPlugin {
condition: project.testsEnabled
files: [
"cppdoxygen_test.cpp",
+ "cppeditortestcase.cpp", "cppeditortestcase.h",
"cppincludehierarchy_test.cpp",
"cppquickfix_test.cpp",
"cppquickfix_test_utils.cpp",
diff --git a/src/plugins/cppeditor/cppeditortestcase.cpp b/src/plugins/cppeditor/cppeditortestcase.cpp
new file mode 100644
index 0000000000..403f1b82c7
--- /dev/null
+++ b/src/plugins/cppeditor/cppeditortestcase.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+
+#include "cppeditortestcase.h"
+
+#include "cppeditor.h"
+
+#include <coreplugin/editormanager/editormanager.h>
+#include <cplusplus/CppDocument.h>
+
+#include <QDir>
+
+namespace CppEditor {
+namespace Internal {
+namespace Tests {
+
+TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
+ : CppTools::Tests::TestDocument(fileName, source, cursorMarker)
+ , m_cursorPosition(source.indexOf(m_cursorMarker))
+ , m_editor(0)
+ , m_editorWidget(0)
+{
+}
+
+bool TestDocument::hasCursorMarker() const { return m_cursorPosition != -1; }
+
+TestCase::TestCase(bool runGarbageCollector)
+ : CppTools::Tests::TestCase(runGarbageCollector)
+{
+}
+
+TestCase::~TestCase()
+{
+}
+
+bool TestCase::openCppEditor(const QString &fileName,
+ Internal::CPPEditor **editor,
+ Internal::CPPEditorWidget **editorWidget)
+{
+ using namespace CppEditor::Internal;
+ if (CPPEditor *e = dynamic_cast<CPPEditor *>(Core::EditorManager::openEditor(fileName))) {
+ if (editor)
+ *editor = e;
+ if (editorWidget) {
+ if (CPPEditorWidget *w = dynamic_cast<CPPEditorWidget *>(e->editorWidget())) {
+ *editorWidget = w;
+ return true;
+ } else {
+ return false; // no or wrong widget
+ }
+ } else {
+ return true; // ok since no widget requested
+ }
+ } else {
+ return false; // no or wrong editor
+ }
+}
+
+CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(
+ Internal::CPPEditorWidget *editorWidget)
+{
+ editorWidget->semanticRehighlight(true);
+ while (editorWidget->semanticInfo().doc.isNull())
+ QCoreApplication::processEvents();
+ return editorWidget->semanticInfo().doc;
+}
+
+} // namespace Tests
+} // namespace Internal
+} // namespace CppEditor
diff --git a/src/plugins/cppeditor/cppeditortestcase.h b/src/plugins/cppeditor/cppeditortestcase.h
new file mode 100644
index 0000000000..dc0b4514ec
--- /dev/null
+++ b/src/plugins/cppeditor/cppeditortestcase.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+
+#ifndef CPPEDITORTESTCASE_H
+#define CPPEDITORTESTCASE_H
+
+#include <cpptools/cpptoolstestcase.h>
+
+namespace CppEditor {
+
+namespace Internal {
+class CPPEditor;
+class CPPEditorWidget;
+
+namespace Tests {
+
+class TestDocument : public CppTools::Tests::TestDocument
+{
+public:
+ TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
+
+ bool hasCursorMarker() const;
+
+public:
+ int m_cursorPosition;
+ Internal::CPPEditor *m_editor;
+ Internal::CPPEditorWidget *m_editorWidget;
+};
+
+class TestCase : public CppTools::Tests::TestCase
+{
+public:
+ TestCase(bool runGarbageCollector = true);
+ ~TestCase();
+
+ static bool openCppEditor(const QString &fileName,
+ Internal::CPPEditor **editor,
+ Internal::CPPEditorWidget **editorWidget = 0);
+
+ static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
+ Internal::CPPEditorWidget *editorWidget);
+};
+
+} // namespace Tests
+} // namespace Internal
+} // namespace CppEditor
+
+#endif // CPPEDITORTESTCASE_H
diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp
index a5ee149f65..f19f99106a 100644
--- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp
+++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp
@@ -28,6 +28,7 @@
****************************************************************************/
#include "cppeditorplugin.h"
+#include "cppeditortestcase.h"
#include "cppincludehierarchymodel.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -44,12 +45,10 @@ using namespace CppEditor::Internal;
using namespace CppTools;
namespace {
-class TestCase
+class TestCase : public CppEditor::Internal::Tests::TestCase
{
public:
TestCase(const QList<QByteArray> &sourceList)
- : m_cmm(CppModelManagerInterface::instance())
- , m_editor(0)
{
QStringList filePaths;
const int sourceListSize = sourceList.size();
@@ -59,48 +58,28 @@ public:
// Write source to file
const QString fileName = QString::fromLatin1("%1/file%2.h").arg(QDir::tempPath())
.arg(i+1);
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(source);
- srcSaver.finalize();
+ QVERIFY(writeFile(fileName, source));
filePaths << fileName;
}
// Update Code Model
- m_cmm->updateSourceFiles(filePaths).waitForFinished();
- QCoreApplication::processEvents();
- const Snapshot snapshot = m_cmm->snapshot();
- QVERIFY(!snapshot.isEmpty());
- foreach (const QString &filePath, filePaths)
- QVERIFY(snapshot.contains(filePath));
- }
-
- ~TestCase()
- {
- // Close editor
- if (m_editor)
- Core::EditorManager::closeEditor(m_editor, false);
-
- m_cmm->GC();
- QVERIFY(m_cmm->snapshot().isEmpty());
+ QVERIFY(parseFiles(filePaths));
}
void run(int includesCount, int includedByCount)
{
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
- m_editor = qobject_cast<CPPEditor *>(Core::EditorManager::openEditor(fileName));
- QVERIFY(m_editor);
+ CPPEditor *editor;
+ QVERIFY(openCppEditor(fileName, &editor));
+ closeEditorAtEndOfTestCase(editor);
CppIncludeHierarchyModel model(0);
- model.buildHierarchy(m_editor, fileName);
+ model.buildHierarchy(editor, fileName);
QCOMPARE(model.rowCount(model.index(0, 0)), includesCount);
QCOMPARE(model.rowCount(model.index(1, 0)), includedByCount);
}
-
-private:
- CppModelManagerInterface *m_cmm;
- CPPEditor *m_editor;
};
}
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 3804e2daa0..8335019012 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -31,13 +31,14 @@
#include "cppeditor.h"
#include "cppeditorplugin.h"
+#include "cppeditortestcase.h"
#include "cppquickfixassistant.h"
#include "cppquickfixes.h"
#include <cpptools/cppcodestylepreferences.h>
#include <cpptools/cppmodelmanager.h>
-#include <cpptools/cpppreprocessor.h>
#include <cpptools/cpppreprocessertesthelper.h>
+#include <cpptools/cpppreprocessor.h>
#include <cpptools/cpptoolssettings.h>
#include <cpptools/includeutils.h>
@@ -68,64 +69,39 @@ typedef QSharedPointer<TestDocument> TestDocumentPtr;
/**
* Represents a test document before and after applying the quick fix.
*
- * A TestDocument's originalSource may contain an '@' character to denote
+ * A TestDocument's source may contain an '@' character to denote
* the cursor position. This marker is removed before the Editor reads
* the document.
*/
-class TestDocument
+class TestDocument : public CppEditor::Internal::Tests::TestDocument
{
public:
- TestDocument(const QByteArray &theOriginalSource, const QByteArray &theExpectedSource,
- const QString &fileName)
- : originalSource(theOriginalSource)
- , expectedSource(theExpectedSource)
- , fileName(fileName)
- , cursorMarkerPosition(theOriginalSource.indexOf('@'))
- , editor(0)
- , editorWidget(0)
- {
- originalSource.remove(cursorMarkerPosition, 1);
- expectedSource.remove(theExpectedSource.indexOf('@'), 1);
- }
-
- static TestDocumentPtr create(const QByteArray &theOriginalSource,
- const QByteArray &theExpectedSource,const QString &fileName)
- {
- return TestDocumentPtr(new TestDocument(theOriginalSource, theExpectedSource, fileName));
- }
-
- bool hasCursorMarkerPosition() const { return cursorMarkerPosition != -1; }
- bool changesExpected() const { return originalSource != expectedSource; }
-
- QString filePath() const
+ TestDocument(const QByteArray &fileName, const QByteArray &source,
+ const QByteArray &expectedSource)
+ : CppEditor::Internal::Tests::TestDocument(fileName, source)
+ , m_expectedSource(expectedSource)
{
- if (!QFileInfo(fileName).isAbsolute())
- return QDir::tempPath() + QLatin1Char('/') + fileName;
- return fileName;
+ m_source.remove(m_cursorPosition, 1);
+ m_expectedSource.remove(expectedSource.indexOf(m_cursorMarker), 1);
}
- void writeToDisk() const
+ static TestDocumentPtr create(const QByteArray &fileName, const QByteArray &source,
+ const QByteArray &expectedSource)
{
- Utils::FileSaver srcSaver(filePath());
- srcSaver.write(originalSource);
- srcSaver.finalize();
+ return TestDocumentPtr(new TestDocument(fileName, source, expectedSource));
}
- QByteArray originalSource;
- QByteArray expectedSource;
+ bool changesExpected() const { return m_source != m_expectedSource; }
- const QString fileName;
- const int cursorMarkerPosition;
-
- CPPEditor *editor;
- CPPEditorWidget *editorWidget;
+public:
+ QByteArray m_expectedSource;
};
/**
* Encapsulates the whole process of setting up an editor, getting the
* quick-fix, applying it, and checking the result.
*/
-class TestCase
+class TestCase : public CppEditor::Internal::Tests::TestCase
{
public:
TestCase(const QByteArray &originalSource, const QByteArray &expectedSource,
@@ -141,9 +117,6 @@ public:
void run(CppQuickFixFactory *factory, int resultIndex = 0);
private:
- TestCase(const TestCase &);
- TestCase &operator=(const TestCase &);
-
void init(const QStringList &includePaths);
private:
@@ -171,7 +144,7 @@ TestCase::TestCase(const QByteArray &originalSource, const QByteArray &expectedS
const QStringList &includePaths)
: cppCodeStylePreferences(0), restoreIncludePaths(false)
{
- testFiles << TestDocument::create(originalSource, expectedSource, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", originalSource, expectedSource);
init(includePaths);
}
@@ -187,7 +160,7 @@ void TestCase::init(const QStringList &includePaths)
// Check if there is exactly one cursor marker
unsigned cursorMarkersCount = 0;
foreach (const TestDocumentPtr testFile, testFiles) {
- if (testFile->hasCursorMarkerPosition())
+ if (testFile->hasCursorMarker())
++cursorMarkersCount;
}
QVERIFY2(cursorMarkersCount == 1, "Exactly one cursor marker is allowed.");
@@ -196,45 +169,31 @@ void TestCase::init(const QStringList &includePaths)
foreach (TestDocumentPtr testFile, testFiles)
testFile->writeToDisk();
- CppTools::Internal::CppModelManager *cmm = CppTools::Internal::CppModelManager::instance();
-
// Set appropriate include paths
if (!includePaths.isEmpty()) {
restoreIncludePaths = true;
- includePathsToRestore = cmm->includePaths();
- cmm->setIncludePaths(includePaths);
+ includePathsToRestore = m_modelManager->includePaths();
+ m_modelManager->setIncludePaths(includePaths);
}
// Update Code Model
QStringList filePaths;
foreach (const TestDocumentPtr &testFile, testFiles)
filePaths << testFile->filePath();
- cmm->updateSourceFiles(filePaths).waitForFinished();
- QCoreApplication::processEvents();
- const Snapshot snapshot = cmm->snapshot();
- QVERIFY(!snapshot.isEmpty());
- foreach (const QString &filePath, filePaths)
- QVERIFY(snapshot.contains(filePath));
+ QVERIFY(parseFiles(filePaths));
// Open Files
foreach (TestDocumentPtr testFile, testFiles) {
- testFile->editor
- = dynamic_cast<CPPEditor *>(EditorManager::openEditor(testFile->filePath()));
- QVERIFY(testFile->editor);
+ QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor, &testFile->m_editorWidget));
+ closeEditorAtEndOfTestCase(testFile->m_editor);
// Set cursor position
- const int cursorPosition = testFile->hasCursorMarkerPosition()
- ? testFile->cursorMarkerPosition : 0;
- testFile->editor->setCursorPosition(cursorPosition);
-
- testFile->editorWidget = dynamic_cast<CPPEditorWidget *>(testFile->editor->editorWidget());
- QVERIFY(testFile->editorWidget);
+ const int cursorPosition = testFile->hasCursorMarker()
+ ? testFile->m_cursorPosition : 0;
+ testFile->m_editor->setCursorPosition(cursorPosition);
// Rehighlight
- testFile->editorWidget->semanticRehighlight(true);
- // Wait for the semantic info from the future
- while (testFile->editorWidget->semanticInfo().doc.isNull())
- QCoreApplication::processEvents();
+ waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
}
// Enforce the default cpp code style, so we are independent of config file settings.
@@ -251,23 +210,9 @@ TestCase::~TestCase()
if (cppCodeStylePreferences)
cppCodeStylePreferences->setCurrentDelegate(cppCodeStylePreferencesOriginalDelegateId);
- // Close editors
- QList<Core::IEditor *> editorsToClose;
- foreach (const TestDocumentPtr testFile, testFiles) {
- if (testFile->editor)
- editorsToClose << testFile->editor;
- }
- EditorManager::closeEditors(editorsToClose, false);
- QCoreApplication::processEvents(); // process any pending events
-
- // Remove the test files from the code-model
- CppModelManagerInterface *mmi = CppModelManagerInterface::instance();
- mmi->GC();
- QCOMPARE(mmi->snapshot().size(), 0);
-
// Restore include paths
if (restoreIncludePaths)
- CppTools::Internal::CppModelManager::instance()->setIncludePaths(includePathsToRestore);
+ m_modelManager->setIncludePaths(includePathsToRestore);
// Remove created files from file system
foreach (const TestDocumentPtr &testDocument, testFiles)
@@ -299,12 +244,12 @@ void TestCase::run(CppQuickFixFactory *factory, int resultIndex)
// Run the fix in the file having the cursor marker
TestDocumentPtr testFile;
foreach (const TestDocumentPtr file, testFiles) {
- if (file->hasCursorMarkerPosition())
+ if (file->hasCursorMarker())
testFile = file;
}
QVERIFY2(testFile, "No test file with cursor marker found");
- if (QuickFixOperation::Ptr fix = getFix(factory, testFile->editorWidget, resultIndex))
+ if (QuickFixOperation::Ptr fix = getFix(factory, testFile->m_editorWidget, resultIndex))
fix->perform();
else
qDebug() << "Quickfix was not triggered";
@@ -312,15 +257,15 @@ void TestCase::run(CppQuickFixFactory *factory, int resultIndex)
// Compare all files
foreach (const TestDocumentPtr testFile, testFiles) {
// Check
- QByteArray result = testFile->editorWidget->document()->toPlainText().toUtf8();
+ QByteArray result = testFile->m_editorWidget->document()->toPlainText().toUtf8();
removeTrailingWhitespace(result);
- QCOMPARE(QLatin1String(result), QLatin1String(testFile->expectedSource));
+ QCOMPARE(QLatin1String(result), QLatin1String(testFile->m_expectedSource));
// Undo the change
for (int i = 0; i < 100; ++i)
- testFile->editorWidget->undo();
- result = testFile->editorWidget->document()->toPlainText().toUtf8();
- QCOMPARE(result, testFile->originalSource);
+ testFile->m_editorWidget->undo();
+ result = testFile->m_editorWidget->document()->toPlainText().toUtf8();
+ QCOMPARE(result, testFile->m_source);
}
}
@@ -1280,7 +1225,7 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAn
" void setIt(int value);\n"
"};\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1300,7 +1245,7 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAn
" it = value;\n"
"}\n\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
GenerateGetterSetter factory;
TestCase data(testFiles);
@@ -1334,7 +1279,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass()
"{\n\n}\n"
"\n"
"class Bar {};\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1344,7 +1289,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass()
"{\n\n"
"}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1367,7 +1312,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic1()
" Foo()@;\n"
"};\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original.resize(0);
@@ -1378,7 +1323,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic1()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1397,7 +1342,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic2()
// Header File
original = "void f()@;\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1417,7 +1362,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic2()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1433,7 +1378,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic3()
QByteArray expected;
// Empty Header File
- testFiles << TestDocument::create("", "\n", QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", "", "\n");
// Source File
original =
@@ -1449,7 +1394,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic3()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1474,7 +1419,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace1()
"};\n"
"}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original.resize(0);
@@ -1485,7 +1430,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace1()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1510,7 +1455,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace2()
"};\n"
"}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1525,7 +1470,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace2()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1584,7 +1529,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
"};\n"
"}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File #1
original =
@@ -1595,7 +1540,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
"}\n"
"\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
// Source File #2
@@ -1611,7 +1556,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
"{\n\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file2.cpp"));
+ testFiles << TestDocument::create("file2.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1638,7 +1583,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGenerated
"};\n"
"}\n";
expected = original + '\n';
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File #1
original =
@@ -1658,7 +1603,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGenerated
"{\n\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
// Source File #2
original =
@@ -1668,7 +1613,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGenerated
"{\n\n"
"}\n";
expected = original + '\n';
- testFiles << TestDocument::create(original, expected, QLatin1String("file2.cpp"));
+ testFiles << TestDocument::create("file2.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1739,7 +1684,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1()
// Header File
original = "void f()@;\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1764,7 +1709,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1()
"MACRO(int)\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1783,7 +1728,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2()
// Header File
original = "void f()@;\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1806,7 +1751,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2()
"MACRO(int)\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1824,7 +1769,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfF
// Header File
original = "void f()@;\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1845,7 +1790,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfF
"MissingSemicolon(int)\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1863,7 +1808,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference()
// Header File
original = "void f(Foo &&)@;\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original = "";
@@ -1875,7 +1820,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
TestCase data(testFiles);
@@ -1901,7 +1846,7 @@ void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
+ section + ":\n" +
" Foo();\n"
"@};\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -1913,7 +1858,7 @@ void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
"\n"
;
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertDeclFromDef factory;
TestCase data(testFiles);
@@ -1934,9 +1879,7 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef()
QList<Include> includesForSource(const QByteArray &source)
{
const QString fileName = TestIncludePaths::directoryOfTestFile() + QLatin1String("/file.cpp");
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(source);
- srcSaver.finalize();
+ TestCase::writeFile(fileName, source);
using namespace CppTools::Internal;
@@ -2100,8 +2043,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal()
// Header File
original = "class Foo {};\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("afile.h"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8() + "/afile.h",
+ original, expected);
// Source File
original =
@@ -2122,8 +2065,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal()
"}\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("afile.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/afile.cpp", original, expected);
// Do not use the test factory, at least once we want to go through the "full stack".
AddIncludeForUndefinedIdentifier factory;
@@ -2150,8 +2093,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc()
"#include \"file.moc\";\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2177,8 +2120,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop(
"#include \"z.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2204,8 +2147,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingMidd
"#include \"z.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2231,8 +2174,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingBott
"#include \"file.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2258,8 +2201,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_appendToUns
"#include \"file.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8() +
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2286,8 +2229,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalI
"#include <b.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2317,8 +2260,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobal
"void f();\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<file.h>"));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2348,8 +2291,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_preferGroup
"#include \"foo.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"prefixc.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2376,8 +2319,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfO
"#include \"file.h\"\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2405,8 +2348,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSo
"#include <utils/file.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<firstlib/file.h>"));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2434,8 +2377,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUn
"#include <lastlib/file.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lastlib/file.h>"));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2461,8 +2404,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
"#include <global.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"z.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2488,8 +2431,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
"#include <global.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"a.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2515,8 +2458,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
"#include <global.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"lib/file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2542,8 +2485,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
"#include <lib/file.h>\n"
"\n\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lib/file.h>"));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2567,8 +2510,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noinclude()
"void f();\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2598,8 +2541,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
"void @f();\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2633,8 +2576,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
"void @f();\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
@@ -2659,8 +2602,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomet
"QDir dir;\n"
"\n"
;
- testFiles << TestDocument::create(original, expected, TestIncludePaths::directoryOfTestFile() + QLatin1Char('/')
- + QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(TestIncludePaths::directoryOfTestFile().toUtf8()
+ + "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifier factory;
TestCase data(testFiles, QStringList(TestIncludePaths::globalQtCoreIncludePath()));
@@ -2690,7 +2633,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
"\n"
" void bar();\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2704,7 +2647,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
" return 5;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -2733,7 +2676,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS()
" int ba@r();\n"
"};\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2751,7 +2694,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS()
"}\n"
"\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -2821,7 +2764,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2()
"{\n"
" return 1;\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2829,7 +2772,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2()
"void Foo::f1() {}\n"
"void Foo::f3() {}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -2859,7 +2802,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS()
" inline int number() const;\n"
"};\n"
"}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2873,7 +2816,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS()
" return 5;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -2903,7 +2846,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing()
" inline int number() const;\n"
"};\n"
"}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2919,7 +2862,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing()
" return 5;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -2970,7 +2913,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCpp()
expected =
"int number() const;\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -2984,7 +2927,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCpp()
" return 5;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -3011,7 +2954,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS()
"int number() const;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3025,7 +2968,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS()
" return 5;\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -3056,7 +2999,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization1()
" int a;\n"
" float b;\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original ="#include \"file.h\"\n";
@@ -3066,7 +3009,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization1()
"\n"
"Foo::Foo() : a(42), b(3.141) {}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -3100,7 +3043,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization2()
"\n"
" int member;\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original ="#include \"file.h\"\n";
@@ -3112,7 +3055,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization2()
"{\n"
"}\n"
"\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -3145,7 +3088,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass()
"void Foo::a() {}\n"
"\n"
"class Bar {};\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3155,7 +3098,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass()
"{\n\n"
"}\n";
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
TestCase data(testFiles);
@@ -3224,7 +3167,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
"class Foo {\n"
" inline int number() const {return 5;}\n"
"};\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3234,7 +3177,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
expected =
"#include \"file.h\"\n"
"\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3291,7 +3234,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS()
" }\n"
"};\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3302,7 +3245,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS()
" return 5;\n"
"}\n";
expected = "#include \"file.h\"\n\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3332,7 +3275,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNSUsing()
" }\n"
"};\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3347,7 +3290,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNSUsing()
"#include \"file.h\"\n"
"using namespace MyNs;\n"
"\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3396,7 +3339,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp()
"{\n"
" return 5;\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3408,7 +3351,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp()
" return 5;\n"
"}\n";
expected = "#include \"file.h\"\n\n\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3434,7 +3377,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS()
" return 5;\n"
"}\n"
"}\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3447,7 +3390,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS()
expected =
"#include \"file.h\"\n"
"\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3478,7 +3421,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_CtorWithInitialization()
" int a;\n"
" float b;\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3487,7 +3430,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_CtorWithInitialization()
"Foo::F@oo() : a(42), b(3.141) {}"
;
expected ="#include \"file.h\"\n\n\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
TestCase data(testFiles);
@@ -3537,7 +3480,7 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
"};\n"
;
expected = original + "\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3552,7 +3495,7 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
" List<int> list;\n"
" int localFirst = list.first();\n"
"}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
AssignToLocalVariable factory;
TestCase data(testFiles);
@@ -3635,7 +3578,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separ
"void foo(const char *a, long b = 1);";
expected =
"void foo(const char *a, long b = 1, int newParameter = 156);\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3644,7 +3587,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separ
expected =
"void foo(const char *a, long b, int newParameter)\n"
"{return newParameter + 123 + newParameter;}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
ExtractLiteralAsParameter factory;
TestCase data(testFiles);
@@ -3668,7 +3611,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_sep
"public:\n"
" int zort(int newParameter = 155);\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original =
@@ -3679,7 +3622,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_sep
"#include \"file.h\"\n\n"
"int Narf::zort(int newParameter)\n"
"{ return newParameter + 1; }\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
ExtractLiteralAsParameter factory;
TestCase data(testFiles);
@@ -4022,7 +3965,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
"public:\n"
" virtual int a();\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original = "#include \"file.h\"\n";
@@ -4031,7 +3974,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
"\n\n"
"int Derived::a()\n"
"{\n}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
@@ -4075,7 +4018,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
"public:\n"
" virtual BaseNS::BaseEnum a(BaseNS::BaseEnum e);\n"
"};\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
+ testFiles << TestDocument::create("file.h", original, expected);
// Source File
original = "#include \"file.h\"\n";
@@ -4084,7 +4027,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
"\n\n"
"BaseNS::BaseEnum Derived::a(BaseNS::BaseEnum e)\n"
"{\n}\n";
- testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create("file.cpp", original, expected);
InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp
index 984ea24e8f..3b7306bffd 100644
--- a/src/plugins/cppeditor/fileandtokenactions_test.cpp
+++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp
@@ -27,26 +27,28 @@
**
****************************************************************************/
-#include <cplusplus/CppDocument.h>
-#include <cplusplus/TranslationUnit.h>
+#include "cppeditor.h"
+#include "cppeditorplugin.h"
+#include "cppeditortestcase.h"
+#include "cppquickfix.h"
+#include "cppquickfix_test_utils.h"
+#include "cppquickfixassistant.h"
+#include "cppquickfixes.h"
#include <coreplugin/editormanager/editormanager.h>
-#include <cppeditor/cppeditor.h>
-#include <cppeditor/cppeditorplugin.h>
-#include <cppeditor/cppquickfixassistant.h>
-#include <cppeditor/cppquickfixes.h>
-#include <cppeditor/cppquickfix.h>
-#include <cppeditor/cppquickfix_test_utils.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/cpptoolsplugin.h>
#include <extensionsystem/pluginmanager.h>
-#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
+#include <projectexplorer/projectexplorer.h>
#include <texteditor/basetextdocument.h>
+#include <cplusplus/CppDocument.h>
+#include <cplusplus/TranslationUnit.h>
+
#include <QDebug>
-#include <QtAlgorithms>
#include <QTextDocument>
+#include <QtAlgorithms>
#include <QtTest>
#if QT_VERSION >= 0x050000
@@ -81,7 +83,7 @@ using namespace TextEditor;
namespace {
-class TestActionsTestCase
+class TestActionsTestCase : public CppEditor::Internal::Tests::TestCase
{
public:
class AbstractAction
@@ -95,6 +97,8 @@ public:
typedef QList<ActionPointer> Actions;
public:
+ TestActionsTestCase();
+
/// Run the given fileActions for each file and the given tokenActions for each token.
/// The cursor is positioned on the very first character of each token.
void run(const Actions &tokenActions = Actions(),
@@ -132,14 +136,18 @@ bool TestActionsTestCase::allProjectsConfigured = false;
typedef TestActionsTestCase::Actions Actions;
typedef TestActionsTestCase::ActionPointer ActionPointer;
-void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileActions)
+TestActionsTestCase::TestActionsTestCase()
+ : CppEditor::Internal::Tests::TestCase(/*runGarbageCollector=*/false)
{
- CppModelManagerInterface *mm = CppModelManagerInterface::instance();
+}
+void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileActions)
+{
// Collect files to process
QStringList filesToOpen;
QList<QPointer<ProjectExplorer::Project> > projects;
- const QList<CppModelManagerInterface::ProjectInfo> projectInfos = mm->projectInfos();
+ const QList<CppModelManagerInterface::ProjectInfo> projectInfos
+ = m_modelManager->projectInfos();
if (projectInfos.isEmpty())
MSKIP_SINGLE("No project(s) loaded. Test operates only on loaded projects.");
@@ -175,18 +183,16 @@ void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileAc
// Open editor
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 0);
- CPPEditor *editor = dynamic_cast<CPPEditor *>(EditorManager::openEditor(filePath));
- QVERIFY(editor);
+ CPPEditor *editor;
+ CPPEditorWidget *editorWidget;
+ QVERIFY(openCppEditor(filePath, &editor, &editorWidget));
+
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 1);
- QVERIFY(mm->isCppEditor(editor));
- QVERIFY(mm->workingCopy().contains(filePath));
+ QVERIFY(m_modelManager->isCppEditor(editor));
+ QVERIFY(m_modelManager->workingCopy().contains(filePath));
// Rehighlight
- CPPEditorWidget *editorWidget = dynamic_cast<CPPEditorWidget *>(editor->editorWidget());
- QVERIFY(editorWidget);
- editorWidget->semanticRehighlight(true);
- while (editorWidget->semanticInfo().doc.isNull())
- QApplication::processEvents();
+ waitForRehighlightedSemanticDocument(editorWidget);
// Run all file actions
executeActionsOnEditorWidget(editorWidget, fileActions);
@@ -194,7 +200,7 @@ void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileAc
if (tokenActions.empty())
continue;
- Snapshot snapshot = mm->snapshot();
+ const Snapshot snapshot = globalSnapshot();
Document::Ptr document = snapshot.preprocessedDocument(
editorWidget->document()->toPlainText().toUtf8(), filePath);
QVERIFY(document);
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 4a0a1b9bda..4e59cfce74 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -29,13 +29,15 @@
#include "cppeditor.h"
#include "cppeditorplugin.h"
+#include "cppeditortestcase.h"
#include "cppelementevaluator.h"
#include "cppvirtualfunctionassistprovider.h"
#include "cppvirtualfunctionproposalitem.h"
-#include <texteditor/codeassist/iassistproposal.h>
-#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
+#include <texteditor/codeassist/iassistprocessor.h>
+#include <texteditor/codeassist/iassistproposal.h>
+
#include <utils/fileutils.h>
#include <QDebug>
@@ -168,66 +170,40 @@ typedef QSharedPointer<TestDocument> TestDocumentPtr;
* - a '@' character denotes the initial text cursor position
* - a '$' character denotes the target text cursor position
*/
-class TestDocument
+class TestDocument : public CppEditor::Internal::Tests::TestDocument
{
public:
- TestDocument(const QByteArray &theSource, const QString &fileName)
- : source(theSource)
- , fileName(fileName)
- , initialCursorPosition(source.indexOf('@'))
- , targetCursorPosition(source.indexOf('$'))
- , editor(0)
- , editorWidget(0)
+ TestDocument(const QByteArray &source, const QByteArray &fileName)
+ : CppEditor::Internal::Tests::TestDocument(fileName, source)
+ , m_targetCursorPosition(source.indexOf('$'))
{
- if (initialCursorPosition != -1 || targetCursorPosition != -1)
- QVERIFY(initialCursorPosition != targetCursorPosition);
-
- if (initialCursorPosition > targetCursorPosition) {
- source.remove(initialCursorPosition, 1);
- if (targetCursorPosition != -1) {
- source.remove(targetCursorPosition, 1);
- --initialCursorPosition;
+ if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
+ QVERIFY(m_cursorPosition != m_targetCursorPosition);
+
+ if (m_cursorPosition > m_targetCursorPosition) {
+ m_source.remove(m_cursorPosition, 1);
+ if (m_targetCursorPosition != -1) {
+ m_source.remove(m_targetCursorPosition, 1);
+ --m_cursorPosition;
}
} else {
- source.remove(targetCursorPosition, 1);
- if (initialCursorPosition != -1) {
- source.remove(initialCursorPosition, 1);
- --targetCursorPosition;
+ m_source.remove(m_targetCursorPosition, 1);
+ if (m_cursorPosition != -1) {
+ m_source.remove(m_cursorPosition, 1);
+ --m_targetCursorPosition;
}
}
}
- static TestDocumentPtr create(const QByteArray &theOriginalSource, const QString &fileName)
+ static TestDocumentPtr create(const QByteArray &source, const QByteArray &fileName)
{
- return TestDocumentPtr(new TestDocument(theOriginalSource, fileName));
+ return TestDocumentPtr(new TestDocument(source, fileName));
}
- bool hasInitialCursorMarker() const { return initialCursorPosition != -1; }
- bool hasTargetCursorMarker() const { return targetCursorPosition != -1; }
-
- QString filePath() const
- {
- if (directoryPath.isEmpty())
- qDebug() << "directoryPath not set!";
- return directoryPath + QLatin1Char('/') + fileName;
- }
-
- void writeToDisk() const
- {
- Utils::FileSaver srcSaver(filePath());
- srcSaver.write(source);
- srcSaver.finalize();
- }
-
- QByteArray source;
-
- const QString fileName;
- QString directoryPath;
- int initialCursorPosition;
- int targetCursorPosition;
+ bool hasTargetCursorMarker() const { return m_targetCursorPosition != -1; }
- CPPEditor *editor;
- CPPEditorWidget *editorWidget;
+public:
+ int m_targetCursorPosition;
};
/**
@@ -235,7 +211,7 @@ public:
* executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition
* and checking the result.
*/
-class TestCase
+class TestCase : public CppEditor::Internal::Tests::TestCase
{
public:
enum CppEditorAction {
@@ -247,7 +223,6 @@ public:
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
TestCase(CppEditorAction action, const QList<TestDocumentPtr> theTestFiles,
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
- ~TestCase();
void run();
@@ -273,7 +248,7 @@ TestCase::TestCase(CppEditorAction action, const QByteArray &source,
: m_action(action)
, m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal)
{
- m_testFiles << TestDocument::create(source, QLatin1String("file.cpp"));
+ m_testFiles << TestDocument::create(source, "file.cpp");
init();
}
@@ -299,74 +274,39 @@ void TestCase::init()
"No test file with target cursor marker is provided.");
// Write files to disk
- const QString directoryPath = QDir::tempPath();
- foreach (TestDocumentPtr testFile, m_testFiles) {
- testFile->directoryPath = directoryPath;
- testFile->writeToDisk();
- }
+ foreach (TestDocumentPtr testFile, m_testFiles)
+ QVERIFY(testFile->writeToDisk());
// Update Code Model
QStringList filePaths;
foreach (const TestDocumentPtr &testFile, m_testFiles)
filePaths << testFile->filePath();
- CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
- mmi->updateSourceFiles(filePaths).waitForFinished();
- QCoreApplication::processEvents();
- const Snapshot snapshot = mmi->snapshot();
- QVERIFY(!snapshot.isEmpty());
- foreach (const QString &filePath, filePaths)
- QVERIFY(snapshot.contains(filePath));
+ QVERIFY(parseFiles(filePaths));
// Open Files
foreach (TestDocumentPtr testFile, m_testFiles) {
- testFile->editor
- = dynamic_cast<CPPEditor *>(EditorManager::openEditor(testFile->filePath()));
- QVERIFY(testFile->editor);
-
- testFile->editorWidget = dynamic_cast<CPPEditorWidget *>(testFile->editor->editorWidget());
- QVERIFY(testFile->editorWidget);
+ QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor,
+ &testFile->m_editorWidget));
+ closeEditorAtEndOfTestCase(testFile->m_editor);
// Wait until the indexer processed the just opened file.
// The file is "Full Checked" since it is in the working copy now,
// that is the function bodies are processed.
forever {
- Snapshot snapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
- if (Document::Ptr document = snapshot.document(testFile->filePath())) {
- if (document->checkMode() == Document::FullCheck)
- break;
- QCoreApplication::processEvents();
- }
+ const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath());
+ if (document->checkMode() == Document::FullCheck)
+ break;
}
// Rehighlight
- testFile->editorWidget->semanticRehighlight(true);
- // Wait for the semantic info from the future
- while (testFile->editorWidget->semanticInfo().doc.isNull())
- QCoreApplication::processEvents();
+ waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
}
}
-TestCase::~TestCase()
-{
- // Close editors
- QList<Core::IEditor *> editorsToClose;
- foreach (const TestDocumentPtr testFile, m_testFiles) {
- if (testFile->editor)
- editorsToClose << testFile->editor;
- }
- EditorManager::closeEditors(editorsToClose, false);
- QCoreApplication::processEvents(); // process any pending events
-
- // Remove the test files from the code-model
- CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
- mmi->GC();
- QCOMPARE(mmi->snapshot().size(), 0);
-}
-
TestDocumentPtr TestCase::testFileWithInitialCursorMarker()
{
foreach (const TestDocumentPtr testFile, m_testFiles) {
- if (testFile->hasInitialCursorMarker())
+ if (testFile->hasCursorMarker())
return testFile;
}
return TestDocumentPtr();
@@ -389,9 +329,9 @@ void TestCase::run()
QVERIFY(targetTestFile);
// Activate editor of initial test file
- EditorManager::activateEditor(initialTestFile->editor);
+ EditorManager::activateEditor(initialTestFile->m_editor);
- initialTestFile->editor->setCursorPosition(initialTestFile->initialCursorPosition);
+ initialTestFile->m_editor->setCursorPosition(initialTestFile->m_cursorPosition);
// qDebug() << "Initial line:" << initialTestFile->editor->currentLine();
// qDebug() << "Initial column:" << initialTestFile->editor->currentColumn() - 1;
@@ -401,7 +341,7 @@ void TestCase::run()
// Trigger the action
switch (m_action) {
case FollowSymbolUnderCursorAction: {
- CPPEditorWidget *widget = initialTestFile->editorWidget;
+ CPPEditorWidget *widget = initialTestFile->m_editorWidget;
FollowSymbolUnderCursor *delegate = widget->followSymbolUnderCursorDelegate();
VirtualFunctionAssistProvider *original = delegate->virtualFunctionAssistProvider();
@@ -409,7 +349,7 @@ void TestCase::run()
QScopedPointer<VirtualFunctionTestAssistProvider> testProvider(
new VirtualFunctionTestAssistProvider(widget));
delegate->setVirtualFunctionAssistProvider(testProvider.data());
- initialTestFile->editorWidget->openLinkUnderCursor();
+ initialTestFile->m_editorWidget->openLinkUnderCursor();
immediateVirtualSymbolResults = testProvider->m_immediateItems;
finalVirtualSymbolResults = testProvider->m_finalItems;
@@ -434,7 +374,7 @@ void TestCase::run()
QCOMPARE(currentTextEditor->document()->filePath(), targetTestFile->filePath());
int expectedLine, expectedColumn;
- currentTextEditor->convertPosition(targetTestFile->targetCursorPosition,
+ currentTextEditor->convertPosition(targetTestFile->m_targetCursorPosition,
&expectedLine, &expectedColumn);
// qDebug() << "Expected line:" << expectedLine;
// qDebug() << "Expected column:" << expectedColumn;
@@ -550,8 +490,8 @@ void CppEditorPlugin::test_SwitchMethodDeclarationDefinition()
QFETCH(QByteArray, source);
QList<TestDocumentPtr> testFiles;
- testFiles << TestDocument::create(header, QLatin1String("file.h"));
- testFiles << TestDocument::create(source, QLatin1String("file.cpp"));
+ testFiles << TestDocument::create(header, "file.h");
+ testFiles << TestDocument::create(source, "file.cpp");
TestCase test(TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
test.run();
@@ -924,18 +864,18 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
<< TestDocument::create("class $Foo {};\n",
- QLatin1String("defined.h"))
+ "defined.h")
<< TestDocument::create("class Foo;\n"
"@Foo foo;\n",
- QLatin1String("forwardDeclaredAndUsed.h"))
+ "forwardDeclaredAndUsed.h")
);
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
<< TestDocument::create("template <class E> class $Container {};\n",
- QLatin1String("defined.h"))
+ "defined.h")
<< TestDocument::create("template <class E> class Container;\n"
"@Container<int> container;\n",
- QLatin1String("forwardDeclaredAndUsed.h"))
+ "forwardDeclaredAndUsed.h")
);
}
@@ -1371,13 +1311,13 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_multipleD
{
QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
<< TestDocument::create("struct A { virtual void virt(int) = 0; };\n",
- QLatin1String("a.h"))
+ "a.h")
<< TestDocument::create("#include \"a.h\"\n"
"struct B : A { void virt(int) {} };\n",
- QLatin1String("b.h"))
+ "b.h")
<< TestDocument::create("#include \"a.h\"\n"
"void f(A *o) { o->$@virt(42); }\n",
- QLatin1String("u.cpp"))
+ "u.cpp")
;
const OverrideItemList finalResults = OverrideItemList()