summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/plugins/coreplugin/testdatadir.h8
-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
-rw-r--r--src/plugins/cpptools/cppcodegen_test.cpp51
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp38
-rw-r--r--src/plugins/cpptools/cpplocatorfilter_test.cpp55
-rw-r--r--src/plugins/cpptools/cppmodelmanager_test.cpp15
-rw-r--r--src/plugins/cpptools/cppmodelmanagerinterface.h2
-rw-r--r--src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp10
-rw-r--r--src/plugins/cpptools/cpppreprocessor_test.cpp5
-rw-r--r--src/plugins/cpptools/cpptools.pro2
-rw-r--r--src/plugins/cpptools/cpptools.qbs1
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp159
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.h98
-rw-r--r--src/plugins/cpptools/symbolsearcher_test.cpp24
-rw-r--r--src/plugins/cpptools/typehierarchybuilder_test.cpp99
-rw-r--r--src/plugins/designer/gotoslot_test.cpp37
-rw-r--r--src/plugins/locator/locator_test.cpp7
25 files changed, 815 insertions, 660 deletions
diff --git a/src/plugins/coreplugin/testdatadir.h b/src/plugins/coreplugin/testdatadir.h
index d8d654ca02..867e2c781d 100644
--- a/src/plugins/coreplugin/testdatadir.h
+++ b/src/plugins/coreplugin/testdatadir.h
@@ -35,6 +35,14 @@
#include <QString>
+#define QTC_DECLARE_MYTESTDATADIR(PATH) \
+ class MyTestDataDir : public Core::Internal::Tests::TestDataDir \
+ { \
+ public: \
+ MyTestDataDir(const QString &testDataDirectory = QString()) \
+ : TestDataDir(QLatin1String(SRCDIR "/" PATH) + testDataDirectory) {} \
+ };
+
namespace Core {
namespace Internal {
namespace Tests {
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()
diff --git a/src/plugins/cpptools/cppcodegen_test.cpp b/src/plugins/cpptools/cppcodegen_test.cpp
index 7344abe7dd..22f55fd6be 100644
--- a/src/plugins/cpptools/cppcodegen_test.cpp
+++ b/src/plugins/cpptools/cppcodegen_test.cpp
@@ -27,8 +27,9 @@
**
****************************************************************************/
-#include "insertionpointlocator.h"
#include "cpptoolsplugin.h"
+#include "cpptoolstestcase.h"
+#include "insertionpointlocator.h"
#include <utils/fileutils.h>
@@ -361,9 +362,7 @@ void CppToolsPlugin::test_codegen_definition_empty_class()
"\n";
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -371,9 +370,7 @@ void CppToolsPlugin::test_codegen_definition_empty_class()
QCOMPARE(src->globalSymbolCount(), 1U);
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
@@ -429,9 +426,7 @@ void CppToolsPlugin::test_codegen_definition_first_member()
"int y;\n").arg(QDir::tempPath()).toLatin1();
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -441,9 +436,7 @@ void CppToolsPlugin::test_codegen_definition_first_member()
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
@@ -499,9 +492,7 @@ void CppToolsPlugin::test_codegen_definition_last_member()
"int y;\n").arg(QDir::tempPath()).toLatin1();
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -511,9 +502,7 @@ void CppToolsPlugin::test_codegen_definition_last_member()
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
@@ -575,9 +564,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member()
"int y;\n").arg(QDir::tempPath()).toLatin1();
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -587,9 +574,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member()
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
@@ -647,9 +632,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin
"int y;\n").arg(QDir::tempPath()).toLatin1();
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -659,9 +642,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
@@ -722,9 +703,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file()
"int y;\n").arg(QDir::tempPath()).toLatin1();
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
- Utils::FileSaver srcSaver(src->fileName());
- srcSaver.write(srcText);
- srcSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
src->setUtf8Source(srcText);
src->parse();
src->check();
@@ -734,9 +713,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file()
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
Client::IncludeLocal));
- Utils::FileSaver dstSaver(dst->fileName());
- dstSaver.write(dstText);
- dstSaver.finalize();
+ QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index d781a449e0..4fc45144bb 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -27,21 +27,22 @@
**
****************************************************************************/
-#include "cpptoolsplugin.h"
#include "cppcompletionassist.h"
#include "cppmodelmanager.h"
+#include "cpptoolsplugin.h"
+#include "cpptoolstestcase.h"
-#include <texteditor/plaintexteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/convenience.h>
+#include <texteditor/plaintexteditor.h>
#include <utils/changeset.h>
#include <utils/fileutils.h>
-#include <QtTest>
#include <QDebug>
-#include <QTextDocument>
#include <QDir>
+#include <QTextDocument>
+#include <QtTest>
/*!
Tests for code completion.
@@ -52,15 +53,13 @@ using namespace CppTools::Internal;
using namespace TextEditor;
using namespace Core;
-namespace {
-typedef QByteArray _;
+namespace { typedef QByteArray _; }
-class CompletionTestCase
+class CompletionTestCase : public CppTools::Tests::TestCase
{
public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
- : position(-1), editorWidget(0), textDocument(0), editor(0),
- cmm(CppModelManager::instance())
+ : position(-1), editorWidget(0), textDocument(0), editor(0)
{
source = sourceText;
position = source.indexOf('@');
@@ -69,22 +68,20 @@ public:
// Write source to file
const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(source);
- srcSaver.finalize();
+ QVERIFY(writeFile(fileName, source));
// Open in editor
editor = EditorManager::openEditor(fileName);
QVERIFY(editor);
+ closeEditorAtEndOfTestCase(editor);
editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
QVERIFY(editorWidget);
textDocument = editorWidget->document();
// Get Document
- while (!cmm->snapshot().contains(fileName))
- QCoreApplication::processEvents();
- Document::Ptr document = cmm->snapshot().document(fileName);
+ waitForFileInGlobalSnapshot(fileName);
+ const Document::Ptr document = globalSnapshot().document(fileName);
snapshot.insert(document);
@@ -92,13 +89,6 @@ public:
insertText(textToInsert);
}
- ~CompletionTestCase()
- {
- EditorManager::closeEditor(editor, /*askAboutModifiedEditors=*/ false);
- cmm->GC();
- QVERIFY(cmm->snapshot().isEmpty());
- }
-
QStringList getCompletions(bool *replaceAccessOperator = 0) const
{
QStringList completions;
@@ -151,12 +141,8 @@ private:
BaseTextEditorWidget *editorWidget;
QTextDocument *textDocument;
IEditor *editor;
-
- CppModelManager *cmm;
};
-} // namespace
-
void CppToolsPlugin::test_completion_basic_1()
{
const QByteArray source =
diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp
index 02262ccf6c..8c7040e817 100644
--- a/src/plugins/cpptools/cpplocatorfilter_test.cpp
+++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp
@@ -34,6 +34,7 @@
#include "cppfunctionsfilter.h"
#include "cpplocatorfilter.h"
#include "cppmodelmanager.h"
+#include "cpptoolstestcase.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/testdatadir.h>
@@ -58,69 +59,53 @@ Q_DECLARE_METATYPE(ILocatorFilter *)
namespace {
-class MyTestDataDir : public Core::Internal::Tests::TestDataDir
-{
-public:
- MyTestDataDir(const QString &testDataDirectory)
- : TestDataDir(QLatin1String(SRCDIR "/../../../tests/cpplocators/") + testDataDirectory) {}
-};
+QTC_DECLARE_MYTESTDATADIR("../../../tests/cpplocators/")
+
+inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
-class CppLocatorFilterTest : public BasicLocatorFilterTest
+} // anonymous namespace
+
+class CppLocatorFilterTest : public BasicLocatorFilterTest, public CppTools::Tests::TestCase
{
public:
CppLocatorFilterTest(ILocatorFilter *filter, const QString &fileName)
: BasicLocatorFilterTest(filter)
- , m_modelManager(CppModelManager::instance())
, m_fileName(fileName)
{
QVERIFY(!m_fileName.isEmpty());
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
+ QVERIFY(garbageCollectGlobalSnapshot());
}
private:
- virtual void doBeforeLocatorRun()
- {
- m_modelManager->updateSourceFiles(QStringList() << m_fileName).waitForFinished();
- QCoreApplication::processEvents();
- QVERIFY(m_modelManager->snapshot().contains(m_fileName));
- }
-
- virtual void doAfterLocatorRun()
- {
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
- }
+ virtual void doBeforeLocatorRun() { QVERIFY(parseFiles(m_fileName)); }
+ virtual void doAfterLocatorRun() { QVERIFY(garbageCollectGlobalSnapshot()); }
- CppModelManager *m_modelManager;
const QString m_fileName;
};
-class CppCurrentDocumentFilterTest : public BasicLocatorFilterTest
+class CppCurrentDocumentFilterTest
+ : public BasicLocatorFilterTest
+ , public CppTools::Tests::TestCase
{
public:
CppCurrentDocumentFilterTest(const QString &fileName)
: BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>())
- , m_modelManager(CppModelManager::instance())
, m_editor(0)
, m_fileName(fileName)
{
QVERIFY(!m_fileName.isEmpty());
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
}
private:
virtual void doBeforeLocatorRun()
{
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
+ QVERIFY(garbageCollectGlobalSnapshot());
m_editor = EditorManager::openEditor(m_fileName);
QVERIFY(m_editor);
- while (!m_modelManager->snapshot().contains(m_fileName))
- QCoreApplication::processEvents();
+
+ waitForFileInGlobalSnapshot(m_fileName);
}
virtual void doAfterLocatorRun()
@@ -128,19 +113,13 @@ private:
EditorManager::closeEditor(m_editor, /*askAboutModifiedEditors=*/ false);
QCoreApplication::processEvents();
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
+ QVERIFY(garbageCollectGlobalSnapshot());
}
- CppModelManager *m_modelManager;
IEditor *m_editor;
const QString m_fileName;
};
-inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
-
-} // anonymous namespace
-
void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter()
{
QFETCH(QString, testFile);
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp
index 9e33466a06..235d4e5c56 100644
--- a/src/plugins/cpptools/cppmodelmanager_test.cpp
+++ b/src/plugins/cpptools/cppmodelmanager_test.cpp
@@ -27,9 +27,10 @@
**
****************************************************************************/
-#include "cpptoolsplugin.h"
#include "cpppreprocessor.h"
#include "cpptoolseditorsupport.h"
+#include "cpptoolsplugin.h"
+#include "cpptoolstestcase.h"
#include "modelmanagertesthelper.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -181,19 +182,15 @@ public:
return isFetchOk;
}
- void writeContents(const QByteArray &contents) const
+ bool writeContents(const QByteArray &contents) const
{
- Utils::FileSaver fileSaver(m_filePath);
- fileSaver.write(contents);
- fileSaver.finalize();
+ return CppTools::Tests::TestCase::writeFile(m_filePath, contents);
}
private:
void restoreContents() const
{
- Utils::FileSaver fileSaver(m_filePath);
- fileSaver.write(m_originalFileContents);
- fileSaver.finalize();
+ CppTools::Tests::TestCase::writeFile(m_filePath, m_originalFileContents);
}
QByteArray m_originalFileContents;
@@ -554,7 +551,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
QByteArray originalContents;
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
- fileChangerAndRestorer.writeContents(newFileContentes);
+ QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes));
// Add or remove source file. The configuration stays the same.
part->files.clear();
diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h
index 6848fb058e..cb209f4340 100644
--- a/src/plugins/cpptools/cppmodelmanagerinterface.h
+++ b/src/plugins/cpptools/cppmodelmanagerinterface.h
@@ -268,6 +268,8 @@ public:
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
virtual CppIndexingSupport *indexingSupport() = 0;
+ virtual void setIncludePaths(const QStringList &includePaths) = 0;
+
signals:
/// Project data might be locked while this is emitted.
void aboutToRemoveFiles(const QStringList &files);
diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
index cddb4d0db2..458b9d2fb8 100644
--- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
+++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
@@ -27,9 +27,10 @@
**
****************************************************************************/
-#include "cpptoolsplugin.h"
#include "cpppointerdeclarationformatter.h"
#include "cpptoolsplugin.h"
+#include "cpptoolsplugin.h"
+#include "cpptoolstestcase.h"
#include <texteditor/plaintexteditor.h>
@@ -63,8 +64,9 @@ static QString stripCursor(const QString &source)
return copy;
}
-struct TestEnvironment
+class TestEnvironment : public CppTools::Tests::TestCase
{
+public:
QByteArray source;
Snapshot snapshot;
CppRefactoringFilePtr cppRefactoringFile;
@@ -88,9 +90,7 @@ struct TestEnvironment
// Write source to temprorary file
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
document = Document::create(filePath);
- Utils::FileSaver documentSaver(document->fileName());
- documentSaver.write(sourceWithoutCursorMarker.toLatin1());
- documentSaver.finalize();
+ QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1()));
// Preprocess source
Preprocessor preprocess(0, &env);
diff --git a/src/plugins/cpptools/cpppreprocessor_test.cpp b/src/plugins/cpptools/cpppreprocessor_test.cpp
index 38c197e6e6..7316fa3393 100644
--- a/src/plugins/cpptools/cpppreprocessor_test.cpp
+++ b/src/plugins/cpptools/cpppreprocessor_test.cpp
@@ -32,6 +32,7 @@
#include "cppmodelmanager.h"
#include "cpppreprocessertesthelper.h"
#include "cpppreprocessor.h"
+#include "cpptoolstestcase.h"
#include <cplusplus/CppDocument.h>
#include <utils/fileutils.h>
@@ -62,9 +63,7 @@ public:
if (QFileInfo(fileName).exists())
return Document::Ptr(); // Test file was not removed.
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(source);
- srcSaver.finalize();
+ CppTools::Tests::TestCase::writeFile(fileName, source);
CppPreprocessor pp((QPointer<CppModelManager>(m_cmm)));
pp.setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile()));
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index 31faa0d5ad..059cc06342 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -115,6 +115,7 @@ FORMS += \
equals(TEST, 1) {
HEADERS += \
cpppreprocessertesthelper.h \
+ cpptoolstestcase.h \
modelmanagertesthelper.h
SOURCES += \
@@ -126,6 +127,7 @@ equals(TEST, 1) {
cpppointerdeclarationformatter_test.cpp \
cpppreprocessertesthelper.cpp \
cpppreprocessor_test.cpp \
+ cpptoolstestcase.cpp \
modelmanagertesthelper.cpp \
symbolsearcher_test.cpp \
typehierarchybuilder_test.cpp
diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs
index 721620b6f0..18cf784cb8 100644
--- a/src/plugins/cpptools/cpptools.qbs
+++ b/src/plugins/cpptools/cpptools.qbs
@@ -87,6 +87,7 @@ QtcPlugin {
"cpppointerdeclarationformatter_test.cpp",
"cpppreprocessertesthelper.cpp", "cpppreprocessertesthelper.h",
"cpppreprocessor_test.cpp",
+ "cpptoolstestcase.cpp", "cpptoolstestcase.h",
"modelmanagertesthelper.cpp", "modelmanagertesthelper.h",
"symbolsearcher_test.cpp",
"typehierarchybuilder_test.cpp",
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
new file mode 100644
index 0000000000..be9e61fb03
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** 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 "cpptoolstestcase.h"
+
+#include <coreplugin/editormanager/editormanager.h>
+
+#include <cplusplus/CppDocument.h>
+#include <utils/fileutils.h>
+
+#include <QtTest>
+
+static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QStringList &filePaths)
+{
+ foreach (const QString &filePath, filePaths) {
+ if (!snapshot.contains(filePath)) {
+ const QString warning = QLatin1String("Missing file in snapshot: ") + filePath;
+ QWARN(qPrintable(warning));
+ return false;
+ }
+ }
+ return true;
+}
+
+namespace CppTools {
+namespace Tests {
+
+TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
+ : m_fileName(fileName), m_source(source), m_cursorMarker(cursorMarker)
+{}
+
+QString TestDocument::filePath() const
+{
+ const QString fileNameAsString = QString::fromUtf8(m_fileName);
+ if (!QFileInfo(fileNameAsString).isAbsolute())
+ return QDir::tempPath() + QLatin1Char('/') + fileNameAsString;
+ return fileNameAsString;
+}
+
+bool TestDocument::writeToDisk() const
+{
+ return TestCase::writeFile(filePath(), m_source);
+}
+
+TestCase::TestCase(bool runGarbageCollector)
+ : m_modelManager(CppModelManagerInterface::instance())
+ , m_runGarbageCollector(runGarbageCollector)
+{
+ if (m_runGarbageCollector)
+ QVERIFY(garbageCollectGlobalSnapshot());
+}
+
+TestCase::~TestCase()
+{
+ QVERIFY(Core::EditorManager::closeEditors(m_editorsToClose, false));
+ QCoreApplication::processEvents();
+
+ if (m_runGarbageCollector)
+ QVERIFY(garbageCollectGlobalSnapshot());
+}
+
+CPlusPlus::Snapshot TestCase::globalSnapshot()
+{
+ return CppModelManagerInterface::instance()->snapshot();
+}
+
+bool TestCase::garbageCollectGlobalSnapshot()
+{
+ CppModelManagerInterface::instance()->GC();
+ return globalSnapshot().isEmpty();
+}
+
+bool TestCase::parseFiles(const QStringList &filePaths)
+{
+ CppModelManagerInterface::instance()->updateSourceFiles(filePaths).waitForFinished();
+ QCoreApplication::processEvents();
+ const CPlusPlus::Snapshot snapshot = globalSnapshot();
+ if (snapshot.isEmpty()) {
+ QWARN("After parsing: snapshot is empty.");
+ return false;
+ }
+ if (!snapshotContains(snapshot, filePaths)) {
+ QWARN("After parsing: snapshot does not contain all expected files.");
+ return false;
+ }
+ return true;
+}
+
+bool TestCase::parseFiles(const QString &filePath)
+{
+ return parseFiles(QStringList(filePath));
+}
+
+void TestCase::closeEditorAtEndOfTestCase(Core::IEditor *editor)
+{
+ if (editor && !m_editorsToClose.contains(editor))
+ m_editorsToClose.append(editor);
+}
+
+CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath)
+{
+ return waitForFilesInGlobalSnapshot(QStringList(filePath)).first();
+}
+
+QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(
+ const QStringList &filePaths)
+{
+ QList<CPlusPlus::Document::Ptr> result;
+ foreach (const QString &filePath, filePaths) {
+ forever {
+ if (CPlusPlus::Document::Ptr document = globalSnapshot().document(filePath)) {
+ result.append(document);
+ break;
+ }
+ QCoreApplication::processEvents();
+ }
+ }
+ return result;
+}
+
+bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
+{
+ Utils::FileSaver saver(filePath);
+ if (!saver.write(contents) || !saver.finalize()) {
+ const QString warning = QLatin1String("Failed to write file to disk: ") + filePath;
+ QWARN(qPrintable(warning));
+ return false;
+ }
+ return true;
+}
+
+} // namespace Tests
+} // namespace CppTools
diff --git a/src/plugins/cpptools/cpptoolstestcase.h b/src/plugins/cpptools/cpptoolstestcase.h
new file mode 100644
index 0000000000..1c9b5b4f59
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolstestcase.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** 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 CPPTOOLSTESTCASE_H
+#define CPPTOOLSTESTCASE_H
+
+#include "cppmodelmanagerinterface.h"
+#include "cpptools_global.h"
+
+#include <coreplugin/editormanager/ieditor.h>
+
+#include <QStringList>
+
+namespace CPlusPlus {
+class Document;
+class Snapshot;
+}
+namespace Core {
+class IEditor;
+}
+
+namespace CppTools {
+namespace Tests {
+
+class CPPTOOLS_EXPORT TestDocument
+{
+public:
+ TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
+
+ QString filePath() const;
+ bool writeToDisk() const;
+
+public:
+ QByteArray m_fileName;
+ QByteArray m_source;
+ char m_cursorMarker;
+};
+
+class CPPTOOLS_EXPORT TestCase
+{
+ Q_DISABLE_COPY(TestCase)
+
+public:
+ TestCase(bool runGarbageCollector = true);
+ ~TestCase();
+
+ void closeEditorAtEndOfTestCase(Core::IEditor *editor);
+
+ static bool parseFiles(const QString &filePath);
+ static bool parseFiles(const QStringList &filePaths);
+
+ static CPlusPlus::Snapshot globalSnapshot();
+ static bool garbageCollectGlobalSnapshot();
+
+ static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(const QString &filePath);
+ static QList<CPlusPlus::Document::Ptr> waitForFilesInGlobalSnapshot(
+ const QStringList &filePaths);
+
+ static bool writeFile(const QString &filePath, const QByteArray &contents);
+
+protected:
+ CppModelManagerInterface *m_modelManager;
+
+private:
+ QList<Core::IEditor *> m_editorsToClose;
+ bool m_runGarbageCollector;
+};
+
+} // namespace Tests
+} // namespace CppTools
+
+#endif // CPPTOOLSTESTCASE_H
diff --git a/src/plugins/cpptools/symbolsearcher_test.cpp b/src/plugins/cpptools/symbolsearcher_test.cpp
index f11bdbcb8e..f75da4c23c 100644
--- a/src/plugins/cpptools/symbolsearcher_test.cpp
+++ b/src/plugins/cpptools/symbolsearcher_test.cpp
@@ -31,6 +31,7 @@
#include "builtinindexingsupport.h"
#include "cppmodelmanager.h"
+#include "cpptoolstestcase.h"
#include "searchsymbols.h"
#include <coreplugin/testdatadir.h>
@@ -43,14 +44,7 @@ using namespace CppTools::Internal;
namespace {
-class MyTestDataDir : public Core::Internal::Tests::TestDataDir
-{
-public:
- MyTestDataDir(const QString &testDataDirectory)
- : TestDataDir(QLatin1String(SRCDIR "/../../../tests/cppsymbolsearcher/")
- + testDataDirectory)
- {}
-};
+QTC_DECLARE_MYTESTDATADIR("../../../tests/cppsymbolsearcher/")
class ResultData
{
@@ -90,21 +84,16 @@ public:
typedef ResultData::ResultDataList ResultDataList;
-class SymbolSearcherTest
+class SymbolSearcherTest : public CppTools::Tests::TestCase
{
public:
/// Takes no ownership of indexingSupportToUse
SymbolSearcherTest(const QString &testFile, CppIndexingSupport *indexingSupportToUse)
- : m_modelManager(CppModelManager::instance())
- , m_indexingSupportToUse(indexingSupportToUse)
+ : m_indexingSupportToUse(indexingSupportToUse)
, m_testFile(testFile)
{
QVERIFY(m_indexingSupportToUse);
- QVERIFY(m_modelManager->snapshot().isEmpty());
- m_modelManager->updateSourceFiles(QStringList(m_testFile)).waitForFinished();
- QCoreApplication::processEvents();
- QVERIFY(m_modelManager->snapshot().contains(m_testFile));
-
+ QVERIFY(parseFiles(m_testFile));
m_indexingSupportToRestore = m_modelManager->indexingSupport();
m_modelManager->setIndexingSupport(m_indexingSupportToUse);
}
@@ -124,12 +113,9 @@ public:
~SymbolSearcherTest()
{
m_modelManager->setIndexingSupport(m_indexingSupportToRestore);
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
}
private:
- CppModelManager *m_modelManager;
CppIndexingSupport *m_indexingSupportToRestore;
CppIndexingSupport *m_indexingSupportToUse;
const QString m_testFile;
diff --git a/src/plugins/cpptools/typehierarchybuilder_test.cpp b/src/plugins/cpptools/typehierarchybuilder_test.cpp
index dbce776c6b..d3175ede21 100644
--- a/src/plugins/cpptools/typehierarchybuilder_test.cpp
+++ b/src/plugins/cpptools/typehierarchybuilder_test.cpp
@@ -30,10 +30,11 @@
#include "cpptoolsplugin.h"
#include "cppmodelmanagerinterface.h"
+#include "cpptoolstestcase.h"
#include "typehierarchybuilder.h"
-#include <cplusplus/SymbolVisitor.h>
#include <cplusplus/Overview.h>
+#include <cplusplus/SymbolVisitor.h>
#include <utils/fileutils.h>
#include <QDir>
@@ -92,46 +93,25 @@ private:
Class *m_clazz;
};
-struct TestDocument
-{
-public:
- TestDocument(const QString &fileName, const QString &contents)
- : fileName(fileName), contents(contents) {}
-
- QString fileName;
- QString contents;
-};
-
-class TestCase
+class TestCase : public CppTools::Tests::TestCase
{
public:
- TestCase(const QList<TestDocument> &documents, const QString &expectedHierarchy)
- : m_modelManager(CppModelManagerInterface::instance())
- , m_documents(documents)
- , m_expectedHierarchy(expectedHierarchy)
- {
- QVERIFY(m_modelManager->snapshot().isEmpty());
- }
+ TestCase(const QList<Tests::TestDocument> &documents, const QString &expectedHierarchy)
+ : m_documents(documents), m_expectedHierarchy(expectedHierarchy)
+ {}
void run()
{
// Write files
QStringList filePaths;
- foreach (const TestDocument &document, m_documents) {
- const QString filePath = QDir::tempPath() + QLatin1Char('/') + document.fileName;
- Utils::FileSaver documentSaver(filePath);
- documentSaver.write(document.contents.toUtf8());
- documentSaver.finalize();
- filePaths << filePath;
+ foreach (const Tests::TestDocument &document, m_documents) {
+ QVERIFY(document.writeToDisk());
+ filePaths << document.filePath();
}
// Parse files
- m_modelManager->updateSourceFiles(filePaths).waitForFinished();
- QCoreApplication::processEvents();
- const Snapshot snapshot = m_modelManager->snapshot();
- QVERIFY(!snapshot.isEmpty());
- foreach (const QString &filePath, filePaths)
- QVERIFY(snapshot.contains(filePath));
+ QVERIFY(parseFiles(filePaths));
+ const Snapshot snapshot = globalSnapshot();
// Get class for which to generate the hierarchy
const Document::Ptr firstDocument = snapshot.document(filePaths.first());
@@ -148,37 +128,30 @@ public:
QCOMPARE(actualHierarchy, m_expectedHierarchy);
}
- ~TestCase()
- {
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
- }
-
private:
- CppModelManagerInterface *m_modelManager;
- QList<TestDocument> m_documents;
+ QList<Tests::TestDocument> m_documents;
QString m_expectedHierarchy;
};
} // anonymous namespace
-Q_DECLARE_METATYPE(QList<TestDocument>)
+Q_DECLARE_METATYPE(QList<Tests::TestDocument>)
void CppToolsPlugin::test_typehierarchy_data()
{
- QTest::addColumn<QList<TestDocument> >("documents");
+ QTest::addColumn<QList<Tests::TestDocument> >("documents");
QTest::addColumn<QString>("expectedHierarchy");
- typedef QLatin1String _;
+ typedef Tests::TestDocument TestDocument;
QTest::newRow("basic-single-document")
<< (QList<TestDocument>()
- << TestDocument(_("a.h"),
- _("class A {};\n"
- "class B : public A {};\n"
- "class C1 : public B {};\n"
- "class C2 : public B {};\n"
- "class D : public C1 {};\n")))
+ << TestDocument("a.h",
+ "class A {};\n"
+ "class B : public A {};\n"
+ "class C1 : public B {};\n"
+ "class C2 : public B {};\n"
+ "class D : public C1 {};\n"))
<< QString::fromLatin1(
"A\n"
" B\n"
@@ -188,20 +161,20 @@ void CppToolsPlugin::test_typehierarchy_data()
QTest::newRow("basic-multiple-documents")
<< (QList<TestDocument>()
- << TestDocument(_("a.h"),
- _("class A {};"))
- << TestDocument(_("b.h"),
- _("#include \"a.h\"\n"
- "class B : public A {};"))
- << TestDocument(_("c1.h"),
- _("#include \"b.h\"\n"
- "class C1 : public B {};"))
- << TestDocument(_("c2.h"),
- _("#include \"b.h\"\n"
- "class C2 : public B {};"))
- << TestDocument(_("d.h"),
- _("#include \"c1.h\"\n"
- "class D : public C1 {};")))
+ << TestDocument("a.h",
+ "class A {};")
+ << TestDocument("b.h",
+ "#include \"a.h\"\n"
+ "class B : public A {};")
+ << TestDocument("c1.h",
+ "#include \"b.h\"\n"
+ "class C1 : public B {};")
+ << TestDocument("c2.h",
+ "#include \"b.h\"\n"
+ "class C2 : public B {};")
+ << TestDocument("d.h",
+ "#include \"c1.h\"\n"
+ "class D : public C1 {};"))
<< QString::fromLatin1(
"A\n"
" B\n"
@@ -213,7 +186,7 @@ void CppToolsPlugin::test_typehierarchy_data()
void CppToolsPlugin::test_typehierarchy()
{
- QFETCH(QList<TestDocument>, documents);
+ QFETCH(QList<Tests::TestDocument>, documents);
QFETCH(QString, expectedHierarchy);
TestCase testCase(documents, expectedHierarchy);
diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp
index c8b4d851f0..facbd0c72e 100644
--- a/src/plugins/designer/gotoslot_test.cpp
+++ b/src/plugins/designer/gotoslot_test.cpp
@@ -34,10 +34,11 @@
#else
#include "formeditorw.h"
-#include <coreplugin/testdatadir.h>
#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/testdatadir.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cpptoolseditorsupport.h>
+#include <cpptools/cpptoolstestcase.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h>
@@ -57,15 +58,7 @@ using namespace Designer::Internal;
namespace {
-class MyTestDataDir : public Core::Internal::Tests::TestDataDir {
-public:
- MyTestDataDir()
- : TestDataDir(QString())
- {}
- MyTestDataDir(const QString &dir)
- : TestDataDir(QLatin1String(SRCDIR "/../../../tests/designer/") + dir)
- {}
-};
+QTC_DECLARE_MYTESTDATADIR("../../../tests/designer/")
class DocumentContainsFunctionDefinition: protected SymbolVisitor
{
@@ -157,25 +150,23 @@ bool documentContainsMemberFunctionDeclaration(const Document::Ptr &document,
return DocumentContainsDeclaration()(document->globalNamespace(), declaration);
}
-class GoToSlotTest
+class GoToSlotTest : public CppTools::Tests::TestCase
{
public:
GoToSlotTest(const QStringList &files)
: m_files(files)
- , m_modelManager(CppModelManagerInterface::instance())
{
QCOMPARE(files.size(), 3);
- cleanup();
}
- ~GoToSlotTest() { cleanup(); }
- void run() const
+ void run()
{
QList<TextEditor::BaseTextEditor *> editors;
foreach (const QString &file, m_files) {
IEditor *editor = EditorManager::openEditor(file);
TextEditor::BaseTextEditor *e = qobject_cast<TextEditor::BaseTextEditor *>(editor);
QVERIFY(e);
+ closeEditorAtEndOfTestCase(editor);
editors << e;
}
TextEditor::BaseTextEditor *cppFileEditor = editors.at(0);
@@ -185,10 +176,7 @@ public:
const QString hFile = m_files.at(1);
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), m_files.size());
- while (!m_modelManager->snapshot().contains(cppFile)
- || !m_modelManager->snapshot().contains(hFile)) {
- QApplication::processEvents();
- }
+ waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile);
// Execute "Go To Slot"
FormEditorW *few = FormEditorW::instance();
@@ -220,18 +208,7 @@ public:
}
private:
- void cleanup()
- {
- EditorManager::closeAllEditors(/*askAboutModifiedEditors =*/ false);
- QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
-
- m_modelManager->GC();
- QVERIFY(m_modelManager->snapshot().isEmpty());
- }
-
-private:
QStringList m_files;
- CppModelManagerInterface *m_modelManager;
};
} // anonymous namespace
diff --git a/src/plugins/locator/locator_test.cpp b/src/plugins/locator/locator_test.cpp
index 1d433bab36..b8a9e42a41 100644
--- a/src/plugins/locator/locator_test.cpp
+++ b/src/plugins/locator/locator_test.cpp
@@ -44,12 +44,7 @@ using namespace Locator::Internal::Tests;
namespace {
-class MyTestDataDir : public Core::Internal::Tests::TestDataDir
-{
-public:
- MyTestDataDir(const QString &testDataDirectory)
- : TestDataDir(QLatin1String(SRCDIR "/../../../tests/locators/") + testDataDirectory) {}
-};
+QTC_DECLARE_MYTESTDATADIR("../../../tests/locators/")
class MyBaseFileFilter : public Locator::BaseFileFilter
{