forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -35,6 +35,14 @@
|
|||||||
|
|
||||||
#include <QString>
|
#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 Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|||||||
@@ -28,12 +28,13 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
|
#include "cppeditorplugin.h"
|
||||||
|
#include "cppeditortestcase.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <cplusplus/CppDocument.h>
|
|
||||||
#include <cppeditor/cppeditor.h>
|
|
||||||
#include <cppeditor/cppeditorplugin.h>
|
|
||||||
#include <cpptools/cppmodelmanagerinterface.h>
|
#include <cpptools/cppmodelmanagerinterface.h>
|
||||||
|
|
||||||
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -58,46 +59,31 @@ typedef QByteArray _;
|
|||||||
* Encapsulates the whole process of setting up an editor,
|
* Encapsulates the whole process of setting up an editor,
|
||||||
* pressing ENTER and checking the result.
|
* pressing ENTER and checking the result.
|
||||||
*/
|
*/
|
||||||
struct TestCase
|
class TestCase : public CppEditor::Internal::Tests::TestCase
|
||||||
{
|
{
|
||||||
QByteArray originalText;
|
public:
|
||||||
int pos;
|
|
||||||
CPPEditor *editor;
|
|
||||||
CPPEditorWidget *editorWidget;
|
|
||||||
|
|
||||||
TestCase(const QByteArray &input);
|
TestCase(const QByteArray &input);
|
||||||
~TestCase();
|
|
||||||
|
|
||||||
void run(const QByteArray &expected, int undoCount = 1);
|
void run(const QByteArray &expected, int undoCount = 1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestCase(const TestCase &);
|
CppEditor::Internal::Tests::TestDocument testDocument;
|
||||||
TestCase &operator=(const TestCase &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The '|' in the input denotes the cursor position.
|
/// The '|' in the input denotes the cursor position.
|
||||||
TestCase::TestCase(const QByteArray &input)
|
TestCase::TestCase(const QByteArray &input)
|
||||||
: originalText(input)
|
: testDocument("file.cpp", input, '|')
|
||||||
{
|
{
|
||||||
pos = originalText.indexOf('|');
|
QVERIFY(testDocument.hasCursorMarker());
|
||||||
QVERIFY(pos != -1);
|
testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
|
||||||
originalText.remove(pos, 1);
|
QVERIFY(testDocument.writeToDisk());
|
||||||
QString fileName(QDir::tempPath() + QLatin1String("/file.cpp"));
|
|
||||||
Utils::FileSaver srcSaver(fileName);
|
|
||||||
srcSaver.write(originalText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
|
|
||||||
// Update Code Model
|
// Update Code Model
|
||||||
CppTools::CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
|
QVERIFY(parseFiles(testDocument.filePath()));
|
||||||
mmi->updateSourceFiles(QStringList(fileName)).waitForFinished();
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QVERIFY(mmi->snapshot().contains(fileName));
|
|
||||||
|
|
||||||
// Open Editor
|
// Open Editor
|
||||||
editor = dynamic_cast<CPPEditor *>(EditorManager::openEditor(fileName));
|
QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor,
|
||||||
QVERIFY(editor);
|
&testDocument.m_editorWidget));
|
||||||
editorWidget = dynamic_cast<CPPEditorWidget *>(editor->editorWidget());
|
closeEditorAtEndOfTestCase(testDocument.m_editor);
|
||||||
QVERIFY(editorWidget);
|
|
||||||
|
|
||||||
// We want to test documents that start with a comment. By default, the
|
// We want to test documents that start with a comment. By default, the
|
||||||
// editor will fold the very first comment it encounters, assuming
|
// 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
|
// expected (some blocks are still hidden in some test cases, so the
|
||||||
// cursor movements are not as expected). For the time being, we just
|
// cursor movements are not as expected). For the time being, we just
|
||||||
// prepend a declaration before the initial test comment.
|
// prepend a declaration before the initial test comment.
|
||||||
// editorWidget->unfoldAll();
|
// testDocument.m_editorWidget->unfoldAll();
|
||||||
editor->setCursorPosition(pos);
|
testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
|
||||||
|
|
||||||
editorWidget->semanticRehighlight(true);
|
waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
|
||||||
// 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
|
|
||||||
|
|
||||||
// Remove the test file from the code-model
|
|
||||||
CppTools::CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
|
|
||||||
mmi->GC();
|
|
||||||
QCOMPARE(mmi->snapshot().size(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestCase::run(const QByteArray &expected, int undoCount)
|
void TestCase::run(const QByteArray &expected, int undoCount)
|
||||||
{
|
{
|
||||||
// Send 'ENTER' key press
|
// Send 'ENTER' key press
|
||||||
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
|
||||||
QCoreApplication::sendEvent(editorWidget, &event);
|
QCoreApplication::sendEvent(testDocument.m_editorWidget, &event);
|
||||||
const QByteArray result = editorWidget->document()->toPlainText().toUtf8();
|
const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
|
||||||
|
|
||||||
QCOMPARE(QLatin1String(result), QLatin1String(expected));
|
QCOMPARE(QLatin1String(result), QLatin1String(expected));
|
||||||
|
|
||||||
for (int i = 0; i < undoCount; ++i)
|
for (int i = 0; i < undoCount; ++i)
|
||||||
editorWidget->undo();
|
testDocument.m_editorWidget->undo();
|
||||||
const QByteArray contentsAfterUndo = editorWidget->document()->toPlainText().toUtf8();
|
const QByteArray contentsAfterUndo
|
||||||
QCOMPARE(contentsAfterUndo, originalText);
|
= testDocument.m_editorWidget->document()->toPlainText().toUtf8();
|
||||||
|
QCOMPARE(contentsAfterUndo, testDocument.m_source);
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,11 @@ RESOURCES += \
|
|||||||
|
|
||||||
equals(TEST, 1) {
|
equals(TEST, 1) {
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
cppeditortestcase.h \
|
||||||
cppquickfix_test_utils.h
|
cppquickfix_test_utils.h
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
cppdoxygen_test.cpp \
|
cppdoxygen_test.cpp \
|
||||||
|
cppeditortestcase.cpp \
|
||||||
cppincludehierarchy_test.cpp \
|
cppincludehierarchy_test.cpp \
|
||||||
cppquickfix_test.cpp \
|
cppquickfix_test.cpp \
|
||||||
cppquickfix_test_utils.cpp \
|
cppquickfix_test_utils.cpp \
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ QtcPlugin {
|
|||||||
condition: project.testsEnabled
|
condition: project.testsEnabled
|
||||||
files: [
|
files: [
|
||||||
"cppdoxygen_test.cpp",
|
"cppdoxygen_test.cpp",
|
||||||
|
"cppeditortestcase.cpp", "cppeditortestcase.h",
|
||||||
"cppincludehierarchy_test.cpp",
|
"cppincludehierarchy_test.cpp",
|
||||||
"cppquickfix_test.cpp",
|
"cppquickfix_test.cpp",
|
||||||
"cppquickfix_test_utils.cpp",
|
"cppquickfix_test_utils.cpp",
|
||||||
|
|||||||
97
src/plugins/cppeditor/cppeditortestcase.cpp
Normal file
97
src/plugins/cppeditor/cppeditortestcase.cpp
Normal file
@@ -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
|
||||||
75
src/plugins/cppeditor/cppeditortestcase.h
Normal file
75
src/plugins/cppeditor/cppeditortestcase.h
Normal file
@@ -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
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
|
#include "cppeditortestcase.h"
|
||||||
#include "cppincludehierarchymodel.h"
|
#include "cppincludehierarchymodel.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -44,12 +45,10 @@ using namespace CppEditor::Internal;
|
|||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class TestCase
|
class TestCase : public CppEditor::Internal::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestCase(const QList<QByteArray> &sourceList)
|
TestCase(const QList<QByteArray> &sourceList)
|
||||||
: m_cmm(CppModelManagerInterface::instance())
|
|
||||||
, m_editor(0)
|
|
||||||
{
|
{
|
||||||
QStringList filePaths;
|
QStringList filePaths;
|
||||||
const int sourceListSize = sourceList.size();
|
const int sourceListSize = sourceList.size();
|
||||||
@@ -59,48 +58,28 @@ public:
|
|||||||
// Write source to file
|
// Write source to file
|
||||||
const QString fileName = QString::fromLatin1("%1/file%2.h").arg(QDir::tempPath())
|
const QString fileName = QString::fromLatin1("%1/file%2.h").arg(QDir::tempPath())
|
||||||
.arg(i+1);
|
.arg(i+1);
|
||||||
Utils::FileSaver srcSaver(fileName);
|
QVERIFY(writeFile(fileName, source));
|
||||||
srcSaver.write(source);
|
|
||||||
srcSaver.finalize();
|
|
||||||
|
|
||||||
filePaths << fileName;
|
filePaths << fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Code Model
|
// Update Code Model
|
||||||
m_cmm->updateSourceFiles(filePaths).waitForFinished();
|
QVERIFY(parseFiles(filePaths));
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(int includesCount, int includedByCount)
|
void run(int includesCount, int includedByCount)
|
||||||
{
|
{
|
||||||
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
|
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
|
||||||
|
|
||||||
m_editor = qobject_cast<CPPEditor *>(Core::EditorManager::openEditor(fileName));
|
CPPEditor *editor;
|
||||||
QVERIFY(m_editor);
|
QVERIFY(openCppEditor(fileName, &editor));
|
||||||
|
closeEditorAtEndOfTestCase(editor);
|
||||||
|
|
||||||
CppIncludeHierarchyModel model(0);
|
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(0, 0)), includesCount);
|
||||||
QCOMPARE(model.rowCount(model.index(1, 0)), includedByCount);
|
QCOMPARE(model.rowCount(model.index(1, 0)), includedByCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
CppModelManagerInterface *m_cmm;
|
|
||||||
CPPEditor *m_editor;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -27,26 +27,28 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include "cppeditor.h"
|
||||||
#include <cplusplus/TranslationUnit.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 <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/cppmodelmanagerinterface.h>
|
||||||
#include <cpptools/cpptoolsplugin.h>
|
#include <cpptools/cpptoolsplugin.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <texteditor/basetextdocument.h>
|
#include <texteditor/basetextdocument.h>
|
||||||
|
|
||||||
|
#include <cplusplus/CppDocument.h>
|
||||||
|
#include <cplusplus/TranslationUnit.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QtAlgorithms>
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
#include <QtAlgorithms>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
@@ -81,7 +83,7 @@ using namespace TextEditor;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class TestActionsTestCase
|
class TestActionsTestCase : public CppEditor::Internal::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class AbstractAction
|
class AbstractAction
|
||||||
@@ -95,6 +97,8 @@ public:
|
|||||||
typedef QList<ActionPointer> Actions;
|
typedef QList<ActionPointer> Actions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TestActionsTestCase();
|
||||||
|
|
||||||
/// Run the given fileActions for each file and the given tokenActions for each token.
|
/// 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.
|
/// The cursor is positioned on the very first character of each token.
|
||||||
void run(const Actions &tokenActions = Actions(),
|
void run(const Actions &tokenActions = Actions(),
|
||||||
@@ -132,14 +136,18 @@ bool TestActionsTestCase::allProjectsConfigured = false;
|
|||||||
typedef TestActionsTestCase::Actions Actions;
|
typedef TestActionsTestCase::Actions Actions;
|
||||||
typedef TestActionsTestCase::ActionPointer ActionPointer;
|
typedef TestActionsTestCase::ActionPointer ActionPointer;
|
||||||
|
|
||||||
|
TestActionsTestCase::TestActionsTestCase()
|
||||||
|
: CppEditor::Internal::Tests::TestCase(/*runGarbageCollector=*/false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileActions)
|
void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileActions)
|
||||||
{
|
{
|
||||||
CppModelManagerInterface *mm = CppModelManagerInterface::instance();
|
|
||||||
|
|
||||||
// Collect files to process
|
// Collect files to process
|
||||||
QStringList filesToOpen;
|
QStringList filesToOpen;
|
||||||
QList<QPointer<ProjectExplorer::Project> > projects;
|
QList<QPointer<ProjectExplorer::Project> > projects;
|
||||||
const QList<CppModelManagerInterface::ProjectInfo> projectInfos = mm->projectInfos();
|
const QList<CppModelManagerInterface::ProjectInfo> projectInfos
|
||||||
|
= m_modelManager->projectInfos();
|
||||||
if (projectInfos.isEmpty())
|
if (projectInfos.isEmpty())
|
||||||
MSKIP_SINGLE("No project(s) loaded. Test operates only on loaded projects.");
|
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
|
// Open editor
|
||||||
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 0);
|
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 0);
|
||||||
CPPEditor *editor = dynamic_cast<CPPEditor *>(EditorManager::openEditor(filePath));
|
CPPEditor *editor;
|
||||||
QVERIFY(editor);
|
CPPEditorWidget *editorWidget;
|
||||||
|
QVERIFY(openCppEditor(filePath, &editor, &editorWidget));
|
||||||
|
|
||||||
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 1);
|
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 1);
|
||||||
QVERIFY(mm->isCppEditor(editor));
|
QVERIFY(m_modelManager->isCppEditor(editor));
|
||||||
QVERIFY(mm->workingCopy().contains(filePath));
|
QVERIFY(m_modelManager->workingCopy().contains(filePath));
|
||||||
|
|
||||||
// Rehighlight
|
// Rehighlight
|
||||||
CPPEditorWidget *editorWidget = dynamic_cast<CPPEditorWidget *>(editor->editorWidget());
|
waitForRehighlightedSemanticDocument(editorWidget);
|
||||||
QVERIFY(editorWidget);
|
|
||||||
editorWidget->semanticRehighlight(true);
|
|
||||||
while (editorWidget->semanticInfo().doc.isNull())
|
|
||||||
QApplication::processEvents();
|
|
||||||
|
|
||||||
// Run all file actions
|
// Run all file actions
|
||||||
executeActionsOnEditorWidget(editorWidget, fileActions);
|
executeActionsOnEditorWidget(editorWidget, fileActions);
|
||||||
@@ -194,7 +200,7 @@ void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileAc
|
|||||||
if (tokenActions.empty())
|
if (tokenActions.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Snapshot snapshot = mm->snapshot();
|
const Snapshot snapshot = globalSnapshot();
|
||||||
Document::Ptr document = snapshot.preprocessedDocument(
|
Document::Ptr document = snapshot.preprocessedDocument(
|
||||||
editorWidget->document()->toPlainText().toUtf8(), filePath);
|
editorWidget->document()->toPlainText().toUtf8(), filePath);
|
||||||
QVERIFY(document);
|
QVERIFY(document);
|
||||||
|
|||||||
@@ -29,13 +29,15 @@
|
|||||||
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
|
#include "cppeditortestcase.h"
|
||||||
#include "cppelementevaluator.h"
|
#include "cppelementevaluator.h"
|
||||||
#include "cppvirtualfunctionassistprovider.h"
|
#include "cppvirtualfunctionassistprovider.h"
|
||||||
#include "cppvirtualfunctionproposalitem.h"
|
#include "cppvirtualfunctionproposalitem.h"
|
||||||
|
|
||||||
#include <texteditor/codeassist/iassistproposal.h>
|
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
|
||||||
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
|
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
|
||||||
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
|
#include <texteditor/codeassist/iassistproposal.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -168,66 +170,40 @@ typedef QSharedPointer<TestDocument> TestDocumentPtr;
|
|||||||
* - a '@' character denotes the initial text cursor position
|
* - a '@' character denotes the initial text cursor position
|
||||||
* - a '$' character denotes the target text cursor position
|
* - a '$' character denotes the target text cursor position
|
||||||
*/
|
*/
|
||||||
class TestDocument
|
class TestDocument : public CppEditor::Internal::Tests::TestDocument
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestDocument(const QByteArray &theSource, const QString &fileName)
|
TestDocument(const QByteArray &source, const QByteArray &fileName)
|
||||||
: source(theSource)
|
: CppEditor::Internal::Tests::TestDocument(fileName, source)
|
||||||
, fileName(fileName)
|
, m_targetCursorPosition(source.indexOf('$'))
|
||||||
, initialCursorPosition(source.indexOf('@'))
|
|
||||||
, targetCursorPosition(source.indexOf('$'))
|
|
||||||
, editor(0)
|
|
||||||
, editorWidget(0)
|
|
||||||
{
|
{
|
||||||
if (initialCursorPosition != -1 || targetCursorPosition != -1)
|
if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
|
||||||
QVERIFY(initialCursorPosition != targetCursorPosition);
|
QVERIFY(m_cursorPosition != m_targetCursorPosition);
|
||||||
|
|
||||||
if (initialCursorPosition > targetCursorPosition) {
|
if (m_cursorPosition > m_targetCursorPosition) {
|
||||||
source.remove(initialCursorPosition, 1);
|
m_source.remove(m_cursorPosition, 1);
|
||||||
if (targetCursorPosition != -1) {
|
if (m_targetCursorPosition != -1) {
|
||||||
source.remove(targetCursorPosition, 1);
|
m_source.remove(m_targetCursorPosition, 1);
|
||||||
--initialCursorPosition;
|
--m_cursorPosition;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
source.remove(targetCursorPosition, 1);
|
m_source.remove(m_targetCursorPosition, 1);
|
||||||
if (initialCursorPosition != -1) {
|
if (m_cursorPosition != -1) {
|
||||||
source.remove(initialCursorPosition, 1);
|
m_source.remove(m_cursorPosition, 1);
|
||||||
--targetCursorPosition;
|
--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 m_targetCursorPosition != -1; }
|
||||||
bool hasTargetCursorMarker() const { return targetCursorPosition != -1; }
|
|
||||||
|
|
||||||
QString filePath() const
|
public:
|
||||||
{
|
int m_targetCursorPosition;
|
||||||
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;
|
|
||||||
|
|
||||||
CPPEditor *editor;
|
|
||||||
CPPEditorWidget *editorWidget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,7 +211,7 @@ public:
|
|||||||
* executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition
|
* executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition
|
||||||
* and checking the result.
|
* and checking the result.
|
||||||
*/
|
*/
|
||||||
class TestCase
|
class TestCase : public CppEditor::Internal::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum CppEditorAction {
|
enum CppEditorAction {
|
||||||
@@ -247,7 +223,6 @@ public:
|
|||||||
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
|
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
|
||||||
TestCase(CppEditorAction action, const QList<TestDocumentPtr> theTestFiles,
|
TestCase(CppEditorAction action, const QList<TestDocumentPtr> theTestFiles,
|
||||||
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
|
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
|
||||||
~TestCase();
|
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@@ -273,7 +248,7 @@ TestCase::TestCase(CppEditorAction action, const QByteArray &source,
|
|||||||
: m_action(action)
|
: m_action(action)
|
||||||
, m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal)
|
, m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal)
|
||||||
{
|
{
|
||||||
m_testFiles << TestDocument::create(source, QLatin1String("file.cpp"));
|
m_testFiles << TestDocument::create(source, "file.cpp");
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,74 +274,39 @@ void TestCase::init()
|
|||||||
"No test file with target cursor marker is provided.");
|
"No test file with target cursor marker is provided.");
|
||||||
|
|
||||||
// Write files to disk
|
// Write files to disk
|
||||||
const QString directoryPath = QDir::tempPath();
|
foreach (TestDocumentPtr testFile, m_testFiles)
|
||||||
foreach (TestDocumentPtr testFile, m_testFiles) {
|
QVERIFY(testFile->writeToDisk());
|
||||||
testFile->directoryPath = directoryPath;
|
|
||||||
testFile->writeToDisk();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Code Model
|
// Update Code Model
|
||||||
QStringList filePaths;
|
QStringList filePaths;
|
||||||
foreach (const TestDocumentPtr &testFile, m_testFiles)
|
foreach (const TestDocumentPtr &testFile, m_testFiles)
|
||||||
filePaths << testFile->filePath();
|
filePaths << testFile->filePath();
|
||||||
CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance();
|
QVERIFY(parseFiles(filePaths));
|
||||||
mmi->updateSourceFiles(filePaths).waitForFinished();
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
const Snapshot snapshot = mmi->snapshot();
|
|
||||||
QVERIFY(!snapshot.isEmpty());
|
|
||||||
foreach (const QString &filePath, filePaths)
|
|
||||||
QVERIFY(snapshot.contains(filePath));
|
|
||||||
|
|
||||||
// Open Files
|
// Open Files
|
||||||
foreach (TestDocumentPtr testFile, m_testFiles) {
|
foreach (TestDocumentPtr testFile, m_testFiles) {
|
||||||
testFile->editor
|
QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor,
|
||||||
= dynamic_cast<CPPEditor *>(EditorManager::openEditor(testFile->filePath()));
|
&testFile->m_editorWidget));
|
||||||
QVERIFY(testFile->editor);
|
closeEditorAtEndOfTestCase(testFile->m_editor);
|
||||||
|
|
||||||
testFile->editorWidget = dynamic_cast<CPPEditorWidget *>(testFile->editor->editorWidget());
|
|
||||||
QVERIFY(testFile->editorWidget);
|
|
||||||
|
|
||||||
// Wait until the indexer processed the just opened file.
|
// Wait until the indexer processed the just opened file.
|
||||||
// The file is "Full Checked" since it is in the working copy now,
|
// The file is "Full Checked" since it is in the working copy now,
|
||||||
// that is the function bodies are processed.
|
// that is the function bodies are processed.
|
||||||
forever {
|
forever {
|
||||||
Snapshot snapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
|
const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath());
|
||||||
if (Document::Ptr document = snapshot.document(testFile->filePath())) {
|
if (document->checkMode() == Document::FullCheck)
|
||||||
if (document->checkMode() == Document::FullCheck)
|
break;
|
||||||
break;
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rehighlight
|
// Rehighlight
|
||||||
testFile->editorWidget->semanticRehighlight(true);
|
waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
|
||||||
// Wait for the semantic info from the future
|
|
||||||
while (testFile->editorWidget->semanticInfo().doc.isNull())
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
TestDocumentPtr TestCase::testFileWithInitialCursorMarker()
|
||||||
{
|
{
|
||||||
foreach (const TestDocumentPtr testFile, m_testFiles) {
|
foreach (const TestDocumentPtr testFile, m_testFiles) {
|
||||||
if (testFile->hasInitialCursorMarker())
|
if (testFile->hasCursorMarker())
|
||||||
return testFile;
|
return testFile;
|
||||||
}
|
}
|
||||||
return TestDocumentPtr();
|
return TestDocumentPtr();
|
||||||
@@ -389,9 +329,9 @@ void TestCase::run()
|
|||||||
QVERIFY(targetTestFile);
|
QVERIFY(targetTestFile);
|
||||||
|
|
||||||
// Activate editor of initial test file
|
// 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 line:" << initialTestFile->editor->currentLine();
|
||||||
// qDebug() << "Initial column:" << initialTestFile->editor->currentColumn() - 1;
|
// qDebug() << "Initial column:" << initialTestFile->editor->currentColumn() - 1;
|
||||||
|
|
||||||
@@ -401,7 +341,7 @@ void TestCase::run()
|
|||||||
// Trigger the action
|
// Trigger the action
|
||||||
switch (m_action) {
|
switch (m_action) {
|
||||||
case FollowSymbolUnderCursorAction: {
|
case FollowSymbolUnderCursorAction: {
|
||||||
CPPEditorWidget *widget = initialTestFile->editorWidget;
|
CPPEditorWidget *widget = initialTestFile->m_editorWidget;
|
||||||
FollowSymbolUnderCursor *delegate = widget->followSymbolUnderCursorDelegate();
|
FollowSymbolUnderCursor *delegate = widget->followSymbolUnderCursorDelegate();
|
||||||
VirtualFunctionAssistProvider *original = delegate->virtualFunctionAssistProvider();
|
VirtualFunctionAssistProvider *original = delegate->virtualFunctionAssistProvider();
|
||||||
|
|
||||||
@@ -409,7 +349,7 @@ void TestCase::run()
|
|||||||
QScopedPointer<VirtualFunctionTestAssistProvider> testProvider(
|
QScopedPointer<VirtualFunctionTestAssistProvider> testProvider(
|
||||||
new VirtualFunctionTestAssistProvider(widget));
|
new VirtualFunctionTestAssistProvider(widget));
|
||||||
delegate->setVirtualFunctionAssistProvider(testProvider.data());
|
delegate->setVirtualFunctionAssistProvider(testProvider.data());
|
||||||
initialTestFile->editorWidget->openLinkUnderCursor();
|
initialTestFile->m_editorWidget->openLinkUnderCursor();
|
||||||
immediateVirtualSymbolResults = testProvider->m_immediateItems;
|
immediateVirtualSymbolResults = testProvider->m_immediateItems;
|
||||||
finalVirtualSymbolResults = testProvider->m_finalItems;
|
finalVirtualSymbolResults = testProvider->m_finalItems;
|
||||||
|
|
||||||
@@ -434,7 +374,7 @@ void TestCase::run()
|
|||||||
|
|
||||||
QCOMPARE(currentTextEditor->document()->filePath(), targetTestFile->filePath());
|
QCOMPARE(currentTextEditor->document()->filePath(), targetTestFile->filePath());
|
||||||
int expectedLine, expectedColumn;
|
int expectedLine, expectedColumn;
|
||||||
currentTextEditor->convertPosition(targetTestFile->targetCursorPosition,
|
currentTextEditor->convertPosition(targetTestFile->m_targetCursorPosition,
|
||||||
&expectedLine, &expectedColumn);
|
&expectedLine, &expectedColumn);
|
||||||
// qDebug() << "Expected line:" << expectedLine;
|
// qDebug() << "Expected line:" << expectedLine;
|
||||||
// qDebug() << "Expected column:" << expectedColumn;
|
// qDebug() << "Expected column:" << expectedColumn;
|
||||||
@@ -550,8 +490,8 @@ void CppEditorPlugin::test_SwitchMethodDeclarationDefinition()
|
|||||||
QFETCH(QByteArray, source);
|
QFETCH(QByteArray, source);
|
||||||
|
|
||||||
QList<TestDocumentPtr> testFiles;
|
QList<TestDocumentPtr> testFiles;
|
||||||
testFiles << TestDocument::create(header, QLatin1String("file.h"));
|
testFiles << TestDocument::create(header, "file.h");
|
||||||
testFiles << TestDocument::create(source, QLatin1String("file.cpp"));
|
testFiles << TestDocument::create(source, "file.cpp");
|
||||||
|
|
||||||
TestCase test(TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
|
TestCase test(TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
|
||||||
test.run();
|
test.run();
|
||||||
@@ -924,18 +864,18 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
|
|||||||
|
|
||||||
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
|
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
|
||||||
<< TestDocument::create("class $Foo {};\n",
|
<< TestDocument::create("class $Foo {};\n",
|
||||||
QLatin1String("defined.h"))
|
"defined.h")
|
||||||
<< TestDocument::create("class Foo;\n"
|
<< TestDocument::create("class Foo;\n"
|
||||||
"@Foo foo;\n",
|
"@Foo foo;\n",
|
||||||
QLatin1String("forwardDeclaredAndUsed.h"))
|
"forwardDeclaredAndUsed.h")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
|
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
|
||||||
<< TestDocument::create("template <class E> class $Container {};\n",
|
<< TestDocument::create("template <class E> class $Container {};\n",
|
||||||
QLatin1String("defined.h"))
|
"defined.h")
|
||||||
<< TestDocument::create("template <class E> class Container;\n"
|
<< TestDocument::create("template <class E> class Container;\n"
|
||||||
"@Container<int> 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>()
|
QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
||||||
<< TestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
<< TestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
||||||
QLatin1String("a.h"))
|
"a.h")
|
||||||
<< TestDocument::create("#include \"a.h\"\n"
|
<< TestDocument::create("#include \"a.h\"\n"
|
||||||
"struct B : A { void virt(int) {} };\n",
|
"struct B : A { void virt(int) {} };\n",
|
||||||
QLatin1String("b.h"))
|
"b.h")
|
||||||
<< TestDocument::create("#include \"a.h\"\n"
|
<< TestDocument::create("#include \"a.h\"\n"
|
||||||
"void f(A *o) { o->$@virt(42); }\n",
|
"void f(A *o) { o->$@virt(42); }\n",
|
||||||
QLatin1String("u.cpp"))
|
"u.cpp")
|
||||||
;
|
;
|
||||||
|
|
||||||
const OverrideItemList finalResults = OverrideItemList()
|
const OverrideItemList finalResults = OverrideItemList()
|
||||||
|
|||||||
@@ -27,8 +27,9 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "insertionpointlocator.h"
|
|
||||||
#include "cpptoolsplugin.h"
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
#include "insertionpointlocator.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
@@ -361,9 +362,7 @@ void CppToolsPlugin::test_codegen_definition_empty_class()
|
|||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
src->check();
|
||||||
@@ -371,9 +370,7 @@ void CppToolsPlugin::test_codegen_definition_empty_class()
|
|||||||
QCOMPARE(src->globalSymbolCount(), 1U);
|
QCOMPARE(src->globalSymbolCount(), 1U);
|
||||||
|
|
||||||
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
@@ -429,9 +426,7 @@ void CppToolsPlugin::test_codegen_definition_first_member()
|
|||||||
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
src->check();
|
||||||
@@ -441,9 +436,7 @@ void CppToolsPlugin::test_codegen_definition_first_member()
|
|||||||
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
||||||
Client::IncludeLocal));
|
Client::IncludeLocal));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
@@ -499,9 +492,7 @@ void CppToolsPlugin::test_codegen_definition_last_member()
|
|||||||
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
src->check();
|
||||||
@@ -511,9 +502,7 @@ void CppToolsPlugin::test_codegen_definition_last_member()
|
|||||||
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
||||||
Client::IncludeLocal));
|
Client::IncludeLocal));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
@@ -575,9 +564,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member()
|
|||||||
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
src->check();
|
||||||
@@ -587,9 +574,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member()
|
|||||||
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
||||||
Client::IncludeLocal));
|
Client::IncludeLocal));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
@@ -647,9 +632,7 @@ void CppToolsPlugin::test_codegen_definition_middle_member_surrounded_by_undefin
|
|||||||
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
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"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
||||||
Client::IncludeLocal));
|
Client::IncludeLocal));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
@@ -722,9 +703,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file()
|
|||||||
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
"int y;\n").arg(QDir::tempPath()).toLatin1();
|
||||||
|
|
||||||
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
|
||||||
Utils::FileSaver srcSaver(src->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(src->fileName(), srcText));
|
||||||
srcSaver.write(srcText);
|
|
||||||
srcSaver.finalize();
|
|
||||||
src->setUtf8Source(srcText);
|
src->setUtf8Source(srcText);
|
||||||
src->parse();
|
src->parse();
|
||||||
src->check();
|
src->check();
|
||||||
@@ -734,9 +713,7 @@ void CppToolsPlugin::test_codegen_definition_member_specific_file()
|
|||||||
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
|
||||||
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
dst->addIncludeFile(Document::Include(QLatin1String("file.h"), src->fileName(), 1,
|
||||||
Client::IncludeLocal));
|
Client::IncludeLocal));
|
||||||
Utils::FileSaver dstSaver(dst->fileName());
|
QVERIFY(CppTools::Tests::TestCase::writeFile(dst->fileName(), dstText));
|
||||||
dstSaver.write(dstText);
|
|
||||||
dstSaver.finalize();
|
|
||||||
dst->setUtf8Source(dstText);
|
dst->setUtf8Source(dstText);
|
||||||
dst->parse();
|
dst->parse();
|
||||||
dst->check();
|
dst->check();
|
||||||
|
|||||||
@@ -27,21 +27,22 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cpptoolsplugin.h"
|
|
||||||
#include "cppcompletionassist.h"
|
#include "cppcompletionassist.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <texteditor/plaintexteditor.h>
|
|
||||||
#include <texteditor/codeassist/iassistproposal.h>
|
#include <texteditor/codeassist/iassistproposal.h>
|
||||||
#include <texteditor/convenience.h>
|
#include <texteditor/convenience.h>
|
||||||
|
#include <texteditor/plaintexteditor.h>
|
||||||
|
|
||||||
#include <utils/changeset.h>
|
#include <utils/changeset.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QtTest>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextDocument>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Tests for code completion.
|
Tests for code completion.
|
||||||
@@ -52,15 +53,13 @@ using namespace CppTools::Internal;
|
|||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
namespace {
|
namespace { typedef QByteArray _; }
|
||||||
typedef QByteArray _;
|
|
||||||
|
|
||||||
class CompletionTestCase
|
class CompletionTestCase : public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
|
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
|
||||||
: position(-1), editorWidget(0), textDocument(0), editor(0),
|
: position(-1), editorWidget(0), textDocument(0), editor(0)
|
||||||
cmm(CppModelManager::instance())
|
|
||||||
{
|
{
|
||||||
source = sourceText;
|
source = sourceText;
|
||||||
position = source.indexOf('@');
|
position = source.indexOf('@');
|
||||||
@@ -69,22 +68,20 @@ public:
|
|||||||
|
|
||||||
// Write source to file
|
// Write source to file
|
||||||
const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
|
const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
|
||||||
Utils::FileSaver srcSaver(fileName);
|
QVERIFY(writeFile(fileName, source));
|
||||||
srcSaver.write(source);
|
|
||||||
srcSaver.finalize();
|
|
||||||
|
|
||||||
// Open in editor
|
// Open in editor
|
||||||
editor = EditorManager::openEditor(fileName);
|
editor = EditorManager::openEditor(fileName);
|
||||||
QVERIFY(editor);
|
QVERIFY(editor);
|
||||||
|
closeEditorAtEndOfTestCase(editor);
|
||||||
editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
|
editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
|
||||||
QVERIFY(editorWidget);
|
QVERIFY(editorWidget);
|
||||||
|
|
||||||
textDocument = editorWidget->document();
|
textDocument = editorWidget->document();
|
||||||
|
|
||||||
// Get Document
|
// Get Document
|
||||||
while (!cmm->snapshot().contains(fileName))
|
waitForFileInGlobalSnapshot(fileName);
|
||||||
QCoreApplication::processEvents();
|
const Document::Ptr document = globalSnapshot().document(fileName);
|
||||||
Document::Ptr document = cmm->snapshot().document(fileName);
|
|
||||||
|
|
||||||
snapshot.insert(document);
|
snapshot.insert(document);
|
||||||
|
|
||||||
@@ -92,13 +89,6 @@ public:
|
|||||||
insertText(textToInsert);
|
insertText(textToInsert);
|
||||||
}
|
}
|
||||||
|
|
||||||
~CompletionTestCase()
|
|
||||||
{
|
|
||||||
EditorManager::closeEditor(editor, /*askAboutModifiedEditors=*/ false);
|
|
||||||
cmm->GC();
|
|
||||||
QVERIFY(cmm->snapshot().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList getCompletions(bool *replaceAccessOperator = 0) const
|
QStringList getCompletions(bool *replaceAccessOperator = 0) const
|
||||||
{
|
{
|
||||||
QStringList completions;
|
QStringList completions;
|
||||||
@@ -151,12 +141,8 @@ private:
|
|||||||
BaseTextEditorWidget *editorWidget;
|
BaseTextEditorWidget *editorWidget;
|
||||||
QTextDocument *textDocument;
|
QTextDocument *textDocument;
|
||||||
IEditor *editor;
|
IEditor *editor;
|
||||||
|
|
||||||
CppModelManager *cmm;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_basic_1()
|
void CppToolsPlugin::test_completion_basic_1()
|
||||||
{
|
{
|
||||||
const QByteArray source =
|
const QByteArray source =
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "cppfunctionsfilter.h"
|
#include "cppfunctionsfilter.h"
|
||||||
#include "cpplocatorfilter.h"
|
#include "cpplocatorfilter.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/testdatadir.h>
|
#include <coreplugin/testdatadir.h>
|
||||||
@@ -58,69 +59,53 @@ Q_DECLARE_METATYPE(ILocatorFilter *)
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
QTC_DECLARE_MYTESTDATADIR("../../../tests/cpplocators/")
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyTestDataDir(const QString &testDataDirectory)
|
|
||||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/cpplocators/") + testDataDirectory) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CppLocatorFilterTest : public BasicLocatorFilterTest
|
inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
class CppLocatorFilterTest : public BasicLocatorFilterTest, public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CppLocatorFilterTest(ILocatorFilter *filter, const QString &fileName)
|
CppLocatorFilterTest(ILocatorFilter *filter, const QString &fileName)
|
||||||
: BasicLocatorFilterTest(filter)
|
: BasicLocatorFilterTest(filter)
|
||||||
, m_modelManager(CppModelManager::instance())
|
|
||||||
, m_fileName(fileName)
|
, m_fileName(fileName)
|
||||||
{
|
{
|
||||||
QVERIFY(!m_fileName.isEmpty());
|
QVERIFY(!m_fileName.isEmpty());
|
||||||
m_modelManager->GC();
|
QVERIFY(garbageCollectGlobalSnapshot());
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doBeforeLocatorRun()
|
virtual void doBeforeLocatorRun() { QVERIFY(parseFiles(m_fileName)); }
|
||||||
{
|
virtual void doAfterLocatorRun() { QVERIFY(garbageCollectGlobalSnapshot()); }
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
CppModelManager *m_modelManager;
|
|
||||||
const QString m_fileName;
|
const QString m_fileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CppCurrentDocumentFilterTest : public BasicLocatorFilterTest
|
class CppCurrentDocumentFilterTest
|
||||||
|
: public BasicLocatorFilterTest
|
||||||
|
, public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CppCurrentDocumentFilterTest(const QString &fileName)
|
CppCurrentDocumentFilterTest(const QString &fileName)
|
||||||
: BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>())
|
: BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>())
|
||||||
, m_modelManager(CppModelManager::instance())
|
|
||||||
, m_editor(0)
|
, m_editor(0)
|
||||||
, m_fileName(fileName)
|
, m_fileName(fileName)
|
||||||
{
|
{
|
||||||
QVERIFY(!m_fileName.isEmpty());
|
QVERIFY(!m_fileName.isEmpty());
|
||||||
m_modelManager->GC();
|
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doBeforeLocatorRun()
|
virtual void doBeforeLocatorRun()
|
||||||
{
|
{
|
||||||
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
|
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
|
||||||
m_modelManager->GC();
|
QVERIFY(garbageCollectGlobalSnapshot());
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
|
|
||||||
m_editor = EditorManager::openEditor(m_fileName);
|
m_editor = EditorManager::openEditor(m_fileName);
|
||||||
QVERIFY(m_editor);
|
QVERIFY(m_editor);
|
||||||
while (!m_modelManager->snapshot().contains(m_fileName))
|
|
||||||
QCoreApplication::processEvents();
|
waitForFileInGlobalSnapshot(m_fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void doAfterLocatorRun()
|
virtual void doAfterLocatorRun()
|
||||||
@@ -128,19 +113,13 @@ private:
|
|||||||
EditorManager::closeEditor(m_editor, /*askAboutModifiedEditors=*/ false);
|
EditorManager::closeEditor(m_editor, /*askAboutModifiedEditors=*/ false);
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
|
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
|
||||||
m_modelManager->GC();
|
QVERIFY(garbageCollectGlobalSnapshot());
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppModelManager *m_modelManager;
|
|
||||||
IEditor *m_editor;
|
IEditor *m_editor;
|
||||||
const QString m_fileName;
|
const QString m_fileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
|
|
||||||
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter()
|
void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter()
|
||||||
{
|
{
|
||||||
QFETCH(QString, testFile);
|
QFETCH(QString, testFile);
|
||||||
|
|||||||
@@ -27,9 +27,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cpptoolsplugin.h"
|
|
||||||
#include "cpppreprocessor.h"
|
#include "cpppreprocessor.h"
|
||||||
#include "cpptoolseditorsupport.h"
|
#include "cpptoolseditorsupport.h"
|
||||||
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
#include "modelmanagertesthelper.h"
|
#include "modelmanagertesthelper.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -181,19 +182,15 @@ public:
|
|||||||
return isFetchOk;
|
return isFetchOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeContents(const QByteArray &contents) const
|
bool writeContents(const QByteArray &contents) const
|
||||||
{
|
{
|
||||||
Utils::FileSaver fileSaver(m_filePath);
|
return CppTools::Tests::TestCase::writeFile(m_filePath, contents);
|
||||||
fileSaver.write(contents);
|
|
||||||
fileSaver.finalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void restoreContents() const
|
void restoreContents() const
|
||||||
{
|
{
|
||||||
Utils::FileSaver fileSaver(m_filePath);
|
CppTools::Tests::TestCase::writeFile(m_filePath, m_originalFileContents);
|
||||||
fileSaver.write(m_originalFileContents);
|
|
||||||
fileSaver.finalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray m_originalFileContents;
|
QByteArray m_originalFileContents;
|
||||||
@@ -554,7 +551,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
|
|||||||
QByteArray originalContents;
|
QByteArray originalContents;
|
||||||
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
|
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
|
||||||
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
|
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
|
||||||
fileChangerAndRestorer.writeContents(newFileContentes);
|
QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes));
|
||||||
|
|
||||||
// Add or remove source file. The configuration stays the same.
|
// Add or remove source file. The configuration stays the same.
|
||||||
part->files.clear();
|
part->files.clear();
|
||||||
|
|||||||
@@ -268,6 +268,8 @@ public:
|
|||||||
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
|
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
|
||||||
virtual CppIndexingSupport *indexingSupport() = 0;
|
virtual CppIndexingSupport *indexingSupport() = 0;
|
||||||
|
|
||||||
|
virtual void setIncludePaths(const QStringList &includePaths) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// Project data might be locked while this is emitted.
|
/// Project data might be locked while this is emitted.
|
||||||
void aboutToRemoveFiles(const QStringList &files);
|
void aboutToRemoveFiles(const QStringList &files);
|
||||||
|
|||||||
@@ -27,9 +27,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cpptoolsplugin.h"
|
|
||||||
#include "cpppointerdeclarationformatter.h"
|
#include "cpppointerdeclarationformatter.h"
|
||||||
#include "cpptoolsplugin.h"
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <texteditor/plaintexteditor.h>
|
#include <texteditor/plaintexteditor.h>
|
||||||
|
|
||||||
@@ -63,8 +64,9 @@ static QString stripCursor(const QString &source)
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestEnvironment
|
class TestEnvironment : public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
QByteArray source;
|
QByteArray source;
|
||||||
Snapshot snapshot;
|
Snapshot snapshot;
|
||||||
CppRefactoringFilePtr cppRefactoringFile;
|
CppRefactoringFilePtr cppRefactoringFile;
|
||||||
@@ -88,9 +90,7 @@ struct TestEnvironment
|
|||||||
// Write source to temprorary file
|
// Write source to temprorary file
|
||||||
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
|
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
|
||||||
document = Document::create(filePath);
|
document = Document::create(filePath);
|
||||||
Utils::FileSaver documentSaver(document->fileName());
|
QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1()));
|
||||||
documentSaver.write(sourceWithoutCursorMarker.toLatin1());
|
|
||||||
documentSaver.finalize();
|
|
||||||
|
|
||||||
// Preprocess source
|
// Preprocess source
|
||||||
Preprocessor preprocess(0, &env);
|
Preprocessor preprocess(0, &env);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
#include "cpppreprocessertesthelper.h"
|
#include "cpppreprocessertesthelper.h"
|
||||||
#include "cpppreprocessor.h"
|
#include "cpppreprocessor.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
@@ -62,9 +63,7 @@ public:
|
|||||||
if (QFileInfo(fileName).exists())
|
if (QFileInfo(fileName).exists())
|
||||||
return Document::Ptr(); // Test file was not removed.
|
return Document::Ptr(); // Test file was not removed.
|
||||||
|
|
||||||
Utils::FileSaver srcSaver(fileName);
|
CppTools::Tests::TestCase::writeFile(fileName, source);
|
||||||
srcSaver.write(source);
|
|
||||||
srcSaver.finalize();
|
|
||||||
|
|
||||||
CppPreprocessor pp((QPointer<CppModelManager>(m_cmm)));
|
CppPreprocessor pp((QPointer<CppModelManager>(m_cmm)));
|
||||||
pp.setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile()));
|
pp.setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile()));
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ FORMS += \
|
|||||||
equals(TEST, 1) {
|
equals(TEST, 1) {
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
cpppreprocessertesthelper.h \
|
cpppreprocessertesthelper.h \
|
||||||
|
cpptoolstestcase.h \
|
||||||
modelmanagertesthelper.h
|
modelmanagertesthelper.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
@@ -126,6 +127,7 @@ equals(TEST, 1) {
|
|||||||
cpppointerdeclarationformatter_test.cpp \
|
cpppointerdeclarationformatter_test.cpp \
|
||||||
cpppreprocessertesthelper.cpp \
|
cpppreprocessertesthelper.cpp \
|
||||||
cpppreprocessor_test.cpp \
|
cpppreprocessor_test.cpp \
|
||||||
|
cpptoolstestcase.cpp \
|
||||||
modelmanagertesthelper.cpp \
|
modelmanagertesthelper.cpp \
|
||||||
symbolsearcher_test.cpp \
|
symbolsearcher_test.cpp \
|
||||||
typehierarchybuilder_test.cpp
|
typehierarchybuilder_test.cpp
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ QtcPlugin {
|
|||||||
"cpppointerdeclarationformatter_test.cpp",
|
"cpppointerdeclarationformatter_test.cpp",
|
||||||
"cpppreprocessertesthelper.cpp", "cpppreprocessertesthelper.h",
|
"cpppreprocessertesthelper.cpp", "cpppreprocessertesthelper.h",
|
||||||
"cpppreprocessor_test.cpp",
|
"cpppreprocessor_test.cpp",
|
||||||
|
"cpptoolstestcase.cpp", "cpptoolstestcase.h",
|
||||||
"modelmanagertesthelper.cpp", "modelmanagertesthelper.h",
|
"modelmanagertesthelper.cpp", "modelmanagertesthelper.h",
|
||||||
"symbolsearcher_test.cpp",
|
"symbolsearcher_test.cpp",
|
||||||
"typehierarchybuilder_test.cpp",
|
"typehierarchybuilder_test.cpp",
|
||||||
|
|||||||
159
src/plugins/cpptools/cpptoolstestcase.cpp
Normal file
159
src/plugins/cpptools/cpptoolstestcase.cpp
Normal file
@@ -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
|
||||||
98
src/plugins/cpptools/cpptoolstestcase.h
Normal file
98
src/plugins/cpptools/cpptoolstestcase.h
Normal file
@@ -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
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "builtinindexingsupport.h"
|
#include "builtinindexingsupport.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
#include "searchsymbols.h"
|
#include "searchsymbols.h"
|
||||||
|
|
||||||
#include <coreplugin/testdatadir.h>
|
#include <coreplugin/testdatadir.h>
|
||||||
@@ -43,14 +44,7 @@ using namespace CppTools::Internal;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
QTC_DECLARE_MYTESTDATADIR("../../../tests/cppsymbolsearcher/")
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyTestDataDir(const QString &testDataDirectory)
|
|
||||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/cppsymbolsearcher/")
|
|
||||||
+ testDataDirectory)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ResultData
|
class ResultData
|
||||||
{
|
{
|
||||||
@@ -90,21 +84,16 @@ public:
|
|||||||
|
|
||||||
typedef ResultData::ResultDataList ResultDataList;
|
typedef ResultData::ResultDataList ResultDataList;
|
||||||
|
|
||||||
class SymbolSearcherTest
|
class SymbolSearcherTest : public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Takes no ownership of indexingSupportToUse
|
/// Takes no ownership of indexingSupportToUse
|
||||||
SymbolSearcherTest(const QString &testFile, CppIndexingSupport *indexingSupportToUse)
|
SymbolSearcherTest(const QString &testFile, CppIndexingSupport *indexingSupportToUse)
|
||||||
: m_modelManager(CppModelManager::instance())
|
: m_indexingSupportToUse(indexingSupportToUse)
|
||||||
, m_indexingSupportToUse(indexingSupportToUse)
|
|
||||||
, m_testFile(testFile)
|
, m_testFile(testFile)
|
||||||
{
|
{
|
||||||
QVERIFY(m_indexingSupportToUse);
|
QVERIFY(m_indexingSupportToUse);
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
QVERIFY(parseFiles(m_testFile));
|
||||||
m_modelManager->updateSourceFiles(QStringList(m_testFile)).waitForFinished();
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QVERIFY(m_modelManager->snapshot().contains(m_testFile));
|
|
||||||
|
|
||||||
m_indexingSupportToRestore = m_modelManager->indexingSupport();
|
m_indexingSupportToRestore = m_modelManager->indexingSupport();
|
||||||
m_modelManager->setIndexingSupport(m_indexingSupportToUse);
|
m_modelManager->setIndexingSupport(m_indexingSupportToUse);
|
||||||
}
|
}
|
||||||
@@ -124,12 +113,9 @@ public:
|
|||||||
~SymbolSearcherTest()
|
~SymbolSearcherTest()
|
||||||
{
|
{
|
||||||
m_modelManager->setIndexingSupport(m_indexingSupportToRestore);
|
m_modelManager->setIndexingSupport(m_indexingSupportToRestore);
|
||||||
m_modelManager->GC();
|
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CppModelManager *m_modelManager;
|
|
||||||
CppIndexingSupport *m_indexingSupportToRestore;
|
CppIndexingSupport *m_indexingSupportToRestore;
|
||||||
CppIndexingSupport *m_indexingSupportToUse;
|
CppIndexingSupport *m_indexingSupportToUse;
|
||||||
const QString m_testFile;
|
const QString m_testFile;
|
||||||
|
|||||||
@@ -30,10 +30,11 @@
|
|||||||
#include "cpptoolsplugin.h"
|
#include "cpptoolsplugin.h"
|
||||||
|
|
||||||
#include "cppmodelmanagerinterface.h"
|
#include "cppmodelmanagerinterface.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
#include "typehierarchybuilder.h"
|
#include "typehierarchybuilder.h"
|
||||||
|
|
||||||
#include <cplusplus/SymbolVisitor.h>
|
|
||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
|
#include <cplusplus/SymbolVisitor.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -92,46 +93,25 @@ private:
|
|||||||
Class *m_clazz;
|
Class *m_clazz;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestDocument
|
class TestCase : public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestDocument(const QString &fileName, const QString &contents)
|
TestCase(const QList<Tests::TestDocument> &documents, const QString &expectedHierarchy)
|
||||||
: fileName(fileName), contents(contents) {}
|
: m_documents(documents), m_expectedHierarchy(expectedHierarchy)
|
||||||
|
{}
|
||||||
QString fileName;
|
|
||||||
QString contents;
|
|
||||||
};
|
|
||||||
|
|
||||||
class 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
// Write files
|
// Write files
|
||||||
QStringList filePaths;
|
QStringList filePaths;
|
||||||
foreach (const TestDocument &document, m_documents) {
|
foreach (const Tests::TestDocument &document, m_documents) {
|
||||||
const QString filePath = QDir::tempPath() + QLatin1Char('/') + document.fileName;
|
QVERIFY(document.writeToDisk());
|
||||||
Utils::FileSaver documentSaver(filePath);
|
filePaths << document.filePath();
|
||||||
documentSaver.write(document.contents.toUtf8());
|
|
||||||
documentSaver.finalize();
|
|
||||||
filePaths << filePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse files
|
// Parse files
|
||||||
m_modelManager->updateSourceFiles(filePaths).waitForFinished();
|
QVERIFY(parseFiles(filePaths));
|
||||||
QCoreApplication::processEvents();
|
const Snapshot snapshot = globalSnapshot();
|
||||||
const Snapshot snapshot = m_modelManager->snapshot();
|
|
||||||
QVERIFY(!snapshot.isEmpty());
|
|
||||||
foreach (const QString &filePath, filePaths)
|
|
||||||
QVERIFY(snapshot.contains(filePath));
|
|
||||||
|
|
||||||
// Get class for which to generate the hierarchy
|
// Get class for which to generate the hierarchy
|
||||||
const Document::Ptr firstDocument = snapshot.document(filePaths.first());
|
const Document::Ptr firstDocument = snapshot.document(filePaths.first());
|
||||||
@@ -148,37 +128,30 @@ public:
|
|||||||
QCOMPARE(actualHierarchy, m_expectedHierarchy);
|
QCOMPARE(actualHierarchy, m_expectedHierarchy);
|
||||||
}
|
}
|
||||||
|
|
||||||
~TestCase()
|
|
||||||
{
|
|
||||||
m_modelManager->GC();
|
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CppModelManagerInterface *m_modelManager;
|
QList<Tests::TestDocument> m_documents;
|
||||||
QList<TestDocument> m_documents;
|
|
||||||
QString m_expectedHierarchy;
|
QString m_expectedHierarchy;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QList<TestDocument>)
|
Q_DECLARE_METATYPE(QList<Tests::TestDocument>)
|
||||||
|
|
||||||
void CppToolsPlugin::test_typehierarchy_data()
|
void CppToolsPlugin::test_typehierarchy_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QList<TestDocument> >("documents");
|
QTest::addColumn<QList<Tests::TestDocument> >("documents");
|
||||||
QTest::addColumn<QString>("expectedHierarchy");
|
QTest::addColumn<QString>("expectedHierarchy");
|
||||||
|
|
||||||
typedef QLatin1String _;
|
typedef Tests::TestDocument TestDocument;
|
||||||
|
|
||||||
QTest::newRow("basic-single-document")
|
QTest::newRow("basic-single-document")
|
||||||
<< (QList<TestDocument>()
|
<< (QList<TestDocument>()
|
||||||
<< TestDocument(_("a.h"),
|
<< TestDocument("a.h",
|
||||||
_("class A {};\n"
|
"class A {};\n"
|
||||||
"class B : public A {};\n"
|
"class B : public A {};\n"
|
||||||
"class C1 : public B {};\n"
|
"class C1 : public B {};\n"
|
||||||
"class C2 : public B {};\n"
|
"class C2 : public B {};\n"
|
||||||
"class D : public C1 {};\n")))
|
"class D : public C1 {};\n"))
|
||||||
<< QString::fromLatin1(
|
<< QString::fromLatin1(
|
||||||
"A\n"
|
"A\n"
|
||||||
" B\n"
|
" B\n"
|
||||||
@@ -188,20 +161,20 @@ void CppToolsPlugin::test_typehierarchy_data()
|
|||||||
|
|
||||||
QTest::newRow("basic-multiple-documents")
|
QTest::newRow("basic-multiple-documents")
|
||||||
<< (QList<TestDocument>()
|
<< (QList<TestDocument>()
|
||||||
<< TestDocument(_("a.h"),
|
<< TestDocument("a.h",
|
||||||
_("class A {};"))
|
"class A {};")
|
||||||
<< TestDocument(_("b.h"),
|
<< TestDocument("b.h",
|
||||||
_("#include \"a.h\"\n"
|
"#include \"a.h\"\n"
|
||||||
"class B : public A {};"))
|
"class B : public A {};")
|
||||||
<< TestDocument(_("c1.h"),
|
<< TestDocument("c1.h",
|
||||||
_("#include \"b.h\"\n"
|
"#include \"b.h\"\n"
|
||||||
"class C1 : public B {};"))
|
"class C1 : public B {};")
|
||||||
<< TestDocument(_("c2.h"),
|
<< TestDocument("c2.h",
|
||||||
_("#include \"b.h\"\n"
|
"#include \"b.h\"\n"
|
||||||
"class C2 : public B {};"))
|
"class C2 : public B {};")
|
||||||
<< TestDocument(_("d.h"),
|
<< TestDocument("d.h",
|
||||||
_("#include \"c1.h\"\n"
|
"#include \"c1.h\"\n"
|
||||||
"class D : public C1 {};")))
|
"class D : public C1 {};"))
|
||||||
<< QString::fromLatin1(
|
<< QString::fromLatin1(
|
||||||
"A\n"
|
"A\n"
|
||||||
" B\n"
|
" B\n"
|
||||||
@@ -213,7 +186,7 @@ void CppToolsPlugin::test_typehierarchy_data()
|
|||||||
|
|
||||||
void CppToolsPlugin::test_typehierarchy()
|
void CppToolsPlugin::test_typehierarchy()
|
||||||
{
|
{
|
||||||
QFETCH(QList<TestDocument>, documents);
|
QFETCH(QList<Tests::TestDocument>, documents);
|
||||||
QFETCH(QString, expectedHierarchy);
|
QFETCH(QString, expectedHierarchy);
|
||||||
|
|
||||||
TestCase testCase(documents, expectedHierarchy);
|
TestCase testCase(documents, expectedHierarchy);
|
||||||
|
|||||||
@@ -34,10 +34,11 @@
|
|||||||
#else
|
#else
|
||||||
#include "formeditorw.h"
|
#include "formeditorw.h"
|
||||||
|
|
||||||
#include <coreplugin/testdatadir.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/testdatadir.h>
|
||||||
#include <cpptools/cppmodelmanager.h>
|
#include <cpptools/cppmodelmanager.h>
|
||||||
#include <cpptools/cpptoolseditorsupport.h>
|
#include <cpptools/cpptoolseditorsupport.h>
|
||||||
|
#include <cpptools/cpptoolstestcase.h>
|
||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
@@ -57,15 +58,7 @@ using namespace Designer::Internal;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir {
|
QTC_DECLARE_MYTESTDATADIR("../../../tests/designer/")
|
||||||
public:
|
|
||||||
MyTestDataDir()
|
|
||||||
: TestDataDir(QString())
|
|
||||||
{}
|
|
||||||
MyTestDataDir(const QString &dir)
|
|
||||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/designer/") + dir)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
class DocumentContainsFunctionDefinition: protected SymbolVisitor
|
class DocumentContainsFunctionDefinition: protected SymbolVisitor
|
||||||
{
|
{
|
||||||
@@ -157,25 +150,23 @@ bool documentContainsMemberFunctionDeclaration(const Document::Ptr &document,
|
|||||||
return DocumentContainsDeclaration()(document->globalNamespace(), declaration);
|
return DocumentContainsDeclaration()(document->globalNamespace(), declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
class GoToSlotTest
|
class GoToSlotTest : public CppTools::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GoToSlotTest(const QStringList &files)
|
GoToSlotTest(const QStringList &files)
|
||||||
: m_files(files)
|
: m_files(files)
|
||||||
, m_modelManager(CppModelManagerInterface::instance())
|
|
||||||
{
|
{
|
||||||
QCOMPARE(files.size(), 3);
|
QCOMPARE(files.size(), 3);
|
||||||
cleanup();
|
|
||||||
}
|
}
|
||||||
~GoToSlotTest() { cleanup(); }
|
|
||||||
|
|
||||||
void run() const
|
void run()
|
||||||
{
|
{
|
||||||
QList<TextEditor::BaseTextEditor *> editors;
|
QList<TextEditor::BaseTextEditor *> editors;
|
||||||
foreach (const QString &file, m_files) {
|
foreach (const QString &file, m_files) {
|
||||||
IEditor *editor = EditorManager::openEditor(file);
|
IEditor *editor = EditorManager::openEditor(file);
|
||||||
TextEditor::BaseTextEditor *e = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
TextEditor::BaseTextEditor *e = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
||||||
QVERIFY(e);
|
QVERIFY(e);
|
||||||
|
closeEditorAtEndOfTestCase(editor);
|
||||||
editors << e;
|
editors << e;
|
||||||
}
|
}
|
||||||
TextEditor::BaseTextEditor *cppFileEditor = editors.at(0);
|
TextEditor::BaseTextEditor *cppFileEditor = editors.at(0);
|
||||||
@@ -185,10 +176,7 @@ public:
|
|||||||
const QString hFile = m_files.at(1);
|
const QString hFile = m_files.at(1);
|
||||||
|
|
||||||
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), m_files.size());
|
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), m_files.size());
|
||||||
while (!m_modelManager->snapshot().contains(cppFile)
|
waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile);
|
||||||
|| !m_modelManager->snapshot().contains(hFile)) {
|
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute "Go To Slot"
|
// Execute "Go To Slot"
|
||||||
FormEditorW *few = FormEditorW::instance();
|
FormEditorW *few = FormEditorW::instance();
|
||||||
@@ -219,19 +207,8 @@ public:
|
|||||||
QLatin1String("Form::on_pushButton_clicked")));
|
QLatin1String("Form::on_pushButton_clicked")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void cleanup()
|
|
||||||
{
|
|
||||||
EditorManager::closeAllEditors(/*askAboutModifiedEditors =*/ false);
|
|
||||||
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty());
|
|
||||||
|
|
||||||
m_modelManager->GC();
|
|
||||||
QVERIFY(m_modelManager->snapshot().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_files;
|
QStringList m_files;
|
||||||
CppModelManagerInterface *m_modelManager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|||||||
@@ -44,12 +44,7 @@ using namespace Locator::Internal::Tests;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MyTestDataDir : public Core::Internal::Tests::TestDataDir
|
QTC_DECLARE_MYTESTDATADIR("../../../tests/locators/")
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyTestDataDir(const QString &testDataDirectory)
|
|
||||||
: TestDataDir(QLatin1String(SRCDIR "/../../../tests/locators/") + testDataDirectory) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class MyBaseFileFilter : public Locator::BaseFileFilter
|
class MyBaseFileFilter : public Locator::BaseFileFilter
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user