forked from qt-creator/qt-creator
CppEditor: Merge the four TestDocument classes
Change-Id: Ie3d5a4ac2b8e3beee92f5abb88583c845056842e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -134,7 +134,6 @@ extend_qtc_plugin(CppEditor
|
|||||||
cppcodegen_test.cpp cppcodegen_test.h
|
cppcodegen_test.cpp cppcodegen_test.h
|
||||||
cppcompletion_test.cpp cppcompletion_test.h
|
cppcompletion_test.cpp cppcompletion_test.h
|
||||||
cppdoxygen_test.cpp cppdoxygen_test.h
|
cppdoxygen_test.cpp cppdoxygen_test.h
|
||||||
cppeditortestcase.cpp cppeditortestcase.h
|
|
||||||
cppheadersource_test.cpp cppheadersource_test.h
|
cppheadersource_test.cpp cppheadersource_test.h
|
||||||
cppincludehierarchy_test.cpp cppincludehierarchy_test.h
|
cppincludehierarchy_test.cpp cppincludehierarchy_test.h
|
||||||
cpplocalsymbols_test.cpp cpplocalsymbols_test.h
|
cpplocalsymbols_test.cpp cpplocalsymbols_test.h
|
||||||
|
@@ -41,6 +41,8 @@
|
|||||||
*/
|
*/
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
|
using CppEditor::Tests::TemporaryDir;
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -56,7 +58,7 @@ Document::Ptr createDocument(const QString &filePath, const QByteArray &text,
|
|||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr createDocumentAndFile(Tests::TemporaryDir *temporaryDir,
|
Document::Ptr createDocumentAndFile(TemporaryDir *temporaryDir,
|
||||||
const QByteArray relativeFilePath,
|
const QByteArray relativeFilePath,
|
||||||
const QByteArray text,
|
const QByteArray text,
|
||||||
int expectedGlobalSymbolCount)
|
int expectedGlobalSymbolCount)
|
||||||
@@ -334,7 +336,7 @@ void CodegenTest::testQtdesignerIntegration()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionEmptyClass()
|
void CodegenTest::testDefinitionEmptyClass()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
@@ -380,7 +382,7 @@ void CodegenTest::testDefinitionEmptyClass()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionFirstMember()
|
void CodegenTest::testDefinitionFirstMember()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
@@ -438,7 +440,7 @@ void CodegenTest::testDefinitionFirstMember()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionLastMember()
|
void CodegenTest::testDefinitionLastMember()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
@@ -497,7 +499,7 @@ void CodegenTest::testDefinitionLastMember()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionMiddleMember()
|
void CodegenTest::testDefinitionMiddleMember()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
@@ -563,7 +565,7 @@ void CodegenTest::testDefinitionMiddleMember()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
|
void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
@@ -623,7 +625,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
|
|||||||
|
|
||||||
void CodegenTest::testDefinitionMemberSpecificFile()
|
void CodegenTest::testDefinitionMemberSpecificFile()
|
||||||
{
|
{
|
||||||
Tests::TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QByteArray headerText = "\n"
|
const QByteArray headerText = "\n"
|
||||||
|
@@ -57,7 +57,7 @@ namespace {
|
|||||||
|
|
||||||
using _ = QByteArray;
|
using _ = QByteArray;
|
||||||
|
|
||||||
class CompletionTestCase : public Tests::TestCase
|
class CompletionTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray(),
|
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray(),
|
||||||
@@ -72,7 +72,7 @@ public:
|
|||||||
m_source[m_position] = ' ';
|
m_source[m_position] = ' ';
|
||||||
|
|
||||||
// Write source to file
|
// Write source to file
|
||||||
m_temporaryDir.reset(new Tests::TemporaryDir());
|
m_temporaryDir.reset(new CppEditor::Tests::TemporaryDir());
|
||||||
QVERIFY(m_temporaryDir->isValid());
|
QVERIFY(m_temporaryDir->isValid());
|
||||||
const QByteArray fileExt = isObjC ? "mm" : "h";
|
const QByteArray fileExt = isObjC ? "mm" : "h";
|
||||||
const QString fileName = m_temporaryDir->createFile("file." + fileExt, m_source);
|
const QString fileName = m_temporaryDir->createFile("file." + fileExt, m_source);
|
||||||
@@ -155,7 +155,7 @@ private:
|
|||||||
QByteArray m_source;
|
QByteArray m_source;
|
||||||
int m_position = -1;
|
int m_position = -1;
|
||||||
Snapshot m_snapshot;
|
Snapshot m_snapshot;
|
||||||
QScopedPointer<Tests::TemporaryDir> m_temporaryDir;
|
QScopedPointer<CppEditor::Tests::TemporaryDir> m_temporaryDir;
|
||||||
TextEditorWidget *m_editorWidget = nullptr;
|
TextEditorWidget *m_editorWidget = nullptr;
|
||||||
QTextDocument *m_textDocument = nullptr;
|
QTextDocument *m_textDocument = nullptr;
|
||||||
IEditor *m_editor = nullptr;
|
IEditor *m_editor = nullptr;
|
||||||
|
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "cppdoxygen_test.h"
|
#include "cppdoxygen_test.h"
|
||||||
|
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cpptoolssettings.h"
|
#include "cpptoolssettings.h"
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ namespace { typedef QByteArray _; }
|
|||||||
|
|
||||||
using CppEditor::Tests::TemporaryDir;
|
using CppEditor::Tests::TemporaryDir;
|
||||||
using CppEditor::Tests::TestCase;
|
using CppEditor::Tests::TestCase;
|
||||||
using CppEditor::Tests::VerifyCleanCppModelManager;
|
using CppEditor::Internal::Tests::VerifyCleanCppModelManager;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -377,7 +376,7 @@ void DoxygenTest::testWithMacroFromHeaderBeforeFunction()
|
|||||||
" */\n"
|
" */\n"
|
||||||
"API void f();\n";
|
"API void f();\n";
|
||||||
|
|
||||||
const GenericCppTestDocument headerDocumentDefiningMacro("header.h", "#define API\n");
|
const CppTestDocument headerDocumentDefiningMacro("header.h", "#define API\n");
|
||||||
|
|
||||||
runTest(given, expected, /*settings=*/ 0, {headerDocumentDefiningMacro});
|
runTest(given, expected, /*settings=*/ 0, {headerDocumentDefiningMacro});
|
||||||
}
|
}
|
||||||
@@ -423,12 +422,12 @@ void DoxygenTest::runTest(const QByteArray &original,
|
|||||||
// Write files to disk
|
// Write files to disk
|
||||||
TemporaryDir temporaryDir;
|
TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
GenericCppTestDocument testDocument("file.cpp", original, '|');
|
CppTestDocument testDocument("file.cpp", original, '|');
|
||||||
QVERIFY(testDocument.hasCursorMarker());
|
QVERIFY(testDocument.hasCursorMarker());
|
||||||
testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
|
testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
|
||||||
testDocument.setBaseDirectory(temporaryDir.path());
|
testDocument.setBaseDirectory(temporaryDir.path());
|
||||||
QVERIFY(testDocument.writeToDisk());
|
QVERIFY(testDocument.writeToDisk());
|
||||||
foreach (GenericCppTestDocument testDocument, includedHeaderDocuments) {
|
foreach (CppTestDocument testDocument, includedHeaderDocuments) {
|
||||||
testDocument.setBaseDirectory(temporaryDir.path());
|
testDocument.setBaseDirectory(temporaryDir.path());
|
||||||
QVERIFY(testDocument.writeToDisk());
|
QVERIFY(testDocument.writeToDisk());
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cppeditortestcase.h"
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <texteditor/commentssettings.h>
|
#include <texteditor/commentssettings.h>
|
||||||
|
|
||||||
|
@@ -243,7 +243,6 @@ equals(TEST, 1) {
|
|||||||
cppcodegen_test.h \
|
cppcodegen_test.h \
|
||||||
cppcompletion_test.h \
|
cppcompletion_test.h \
|
||||||
cppdoxygen_test.h \
|
cppdoxygen_test.h \
|
||||||
cppeditortestcase.h \
|
|
||||||
cppheadersource_test.h \
|
cppheadersource_test.h \
|
||||||
cppincludehierarchy_test.h \
|
cppincludehierarchy_test.h \
|
||||||
cpplocalsymbols_test.h \
|
cpplocalsymbols_test.h \
|
||||||
@@ -267,7 +266,6 @@ equals(TEST, 1) {
|
|||||||
cppcodegen_test.cpp \
|
cppcodegen_test.cpp \
|
||||||
cppcompletion_test.cpp \
|
cppcompletion_test.cpp \
|
||||||
cppdoxygen_test.cpp \
|
cppdoxygen_test.cpp \
|
||||||
cppeditortestcase.cpp \
|
|
||||||
cppheadersource_test.cpp \
|
cppheadersource_test.cpp \
|
||||||
cppincludehierarchy_test.cpp \
|
cppincludehierarchy_test.cpp \
|
||||||
cpplocalsymbols_test.cpp \
|
cpplocalsymbols_test.cpp \
|
||||||
|
@@ -280,8 +280,6 @@ QtcPlugin {
|
|||||||
"cppcompletion_test.h",
|
"cppcompletion_test.h",
|
||||||
"cppdoxygen_test.cpp",
|
"cppdoxygen_test.cpp",
|
||||||
"cppdoxygen_test.h",
|
"cppdoxygen_test.h",
|
||||||
"cppeditortestcase.cpp",
|
|
||||||
"cppeditortestcase.h",
|
|
||||||
"cppheadersource_test.cpp",
|
"cppheadersource_test.cpp",
|
||||||
"cppheadersource_test.h",
|
"cppheadersource_test.h",
|
||||||
"cppincludehierarchy_test.cpp",
|
"cppincludehierarchy_test.cpp",
|
||||||
|
@@ -1,82 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** 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 The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
|
|
||||||
#include "cppcodemodelsettings.h"
|
|
||||||
#include "cppeditorwidget.h"
|
|
||||||
#include "cppeditordocument.h"
|
|
||||||
#include "cppeditorplugin.h"
|
|
||||||
#include "cppsemanticinfo.h"
|
|
||||||
#include "cpptoolsreuse.h"
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <cplusplus/CppDocument.h>
|
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
|
|
||||||
using namespace CppEditor::Internal;
|
|
||||||
|
|
||||||
namespace CppEditor {
|
|
||||||
namespace Internal {
|
|
||||||
namespace Tests {
|
|
||||||
|
|
||||||
GenericCppTestDocument::GenericCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
|
||||||
char cursorMarker)
|
|
||||||
: CppEditor::Tests::BaseCppTestDocument(fileName, source, cursorMarker)
|
|
||||||
, m_cursorPosition(-1)
|
|
||||||
, m_anchorPosition(-1)
|
|
||||||
, m_selectionStartMarker(QLatin1Char(m_cursorMarker) + QLatin1String("{start}"))
|
|
||||||
, m_selectionEndMarker(QLatin1Char(m_cursorMarker) + QLatin1String("{end}"))
|
|
||||||
, m_editor(0)
|
|
||||||
, m_editorWidget(0)
|
|
||||||
{
|
|
||||||
// Try to find selection markers
|
|
||||||
const int selectionStartIndex = m_source.indexOf(m_selectionStartMarker);
|
|
||||||
const int selectionEndIndex = m_source.indexOf(m_selectionEndMarker);
|
|
||||||
const bool bothSelectionMarkersFound = selectionStartIndex != -1 && selectionEndIndex != -1;
|
|
||||||
const bool noneSelectionMarkersFounds = selectionStartIndex == -1 && selectionEndIndex == -1;
|
|
||||||
QTC_ASSERT(bothSelectionMarkersFound || noneSelectionMarkersFounds, return);
|
|
||||||
|
|
||||||
if (selectionStartIndex != -1) {
|
|
||||||
m_cursorPosition = selectionEndIndex;
|
|
||||||
m_anchorPosition = selectionStartIndex;
|
|
||||||
|
|
||||||
// No selection markers found, so check for simple cursorMarker
|
|
||||||
} else {
|
|
||||||
m_cursorPosition = m_source.indexOf(QLatin1Char(cursorMarker));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GenericCppTestDocument::hasCursorMarker() const { return m_cursorPosition != -1; }
|
|
||||||
|
|
||||||
bool GenericCppTestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
|
|
||||||
|
|
||||||
} // namespace Tests
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace CppEditor
|
|
@@ -1,62 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** 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 The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "cpptoolstestcase.h"
|
|
||||||
|
|
||||||
#include <QVector>
|
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace CppEditor {
|
|
||||||
class CppEditorWidget;
|
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
namespace Tests {
|
|
||||||
|
|
||||||
class GenericCppTestDocument : public CppEditor::Tests::BaseCppTestDocument
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GenericCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
|
||||||
char cursorMarker = '@');
|
|
||||||
|
|
||||||
bool hasCursorMarker() const;
|
|
||||||
bool hasAnchorMarker() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
int m_cursorPosition;
|
|
||||||
int m_anchorPosition;
|
|
||||||
QString m_selectionStartMarker;
|
|
||||||
QString m_selectionEndMarker;
|
|
||||||
TextEditor::BaseTextEditor *m_editor;
|
|
||||||
CppEditorWidget *m_editorWidget;
|
|
||||||
};
|
|
||||||
|
|
||||||
using TestDocuments = QVector<GenericCppTestDocument>;
|
|
||||||
|
|
||||||
} // namespace Tests
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace CppEditor
|
|
@@ -58,7 +58,7 @@ void HeaderSourceTest::test()
|
|||||||
QFETCH(QString, sourceFileName);
|
QFETCH(QString, sourceFileName);
|
||||||
QFETCH(QString, headerFileName);
|
QFETCH(QString, headerFileName);
|
||||||
|
|
||||||
Tests::TemporaryDir temporaryDir;
|
CppEditor::Tests::TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
|
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
|
||||||
|
@@ -26,9 +26,9 @@
|
|||||||
#include "cppincludehierarchy_test.h"
|
#include "cppincludehierarchy_test.h"
|
||||||
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppincludehierarchy.h"
|
#include "cppincludehierarchy.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
@@ -1889,7 +1889,7 @@ void InsertVirtualMethodsTest::test()
|
|||||||
/// Check: Insert in implementation file
|
/// Check: Insert in implementation file
|
||||||
void InsertVirtualMethodsTest::testImplementationFile()
|
void InsertVirtualMethodsTest::testImplementationFile()
|
||||||
{
|
{
|
||||||
QList<Tests::QuickFixTestDocument::Ptr> testFiles;
|
QList<Tests::TestDocumentPtr> testFiles;
|
||||||
QByteArray original;
|
QByteArray original;
|
||||||
QByteArray expected;
|
QByteArray expected;
|
||||||
|
|
||||||
@@ -1916,7 +1916,7 @@ void InsertVirtualMethodsTest::testImplementationFile()
|
|||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a(const std::vector<int> &v);\n"
|
" virtual int a(const std::vector<int> &v);\n"
|
||||||
"};\n";
|
"};\n";
|
||||||
testFiles << Tests::QuickFixTestDocument::create("file.h", original, expected);
|
testFiles << Tests::CppTestDocument::create("file.h", original, expected);
|
||||||
|
|
||||||
// Source File
|
// Source File
|
||||||
original = "#include \"file.h\"\n";
|
original = "#include \"file.h\"\n";
|
||||||
@@ -1925,7 +1925,7 @@ void InsertVirtualMethodsTest::testImplementationFile()
|
|||||||
"\n\n"
|
"\n\n"
|
||||||
"int Derived::a(const std::vector<int> &v)\n"
|
"int Derived::a(const std::vector<int> &v)\n"
|
||||||
"{\n}";
|
"{\n}";
|
||||||
testFiles << Tests::QuickFixTestDocument::create("file.cpp", original, expected);
|
testFiles << Tests::CppTestDocument::create("file.cpp", original, expected);
|
||||||
|
|
||||||
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
|
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
|
||||||
InsertVirtualMethodsDialog::ModeImplementationFile,
|
InsertVirtualMethodsDialog::ModeImplementationFile,
|
||||||
@@ -1937,7 +1937,7 @@ void InsertVirtualMethodsTest::testImplementationFile()
|
|||||||
/// Check: Qualified names.
|
/// Check: Qualified names.
|
||||||
void InsertVirtualMethodsTest::testBaseClassInNamespace()
|
void InsertVirtualMethodsTest::testBaseClassInNamespace()
|
||||||
{
|
{
|
||||||
QList<Tests::QuickFixTestDocument::Ptr> testFiles;
|
QList<Tests::TestDocumentPtr> testFiles;
|
||||||
QByteArray original;
|
QByteArray original;
|
||||||
QByteArray expected;
|
QByteArray expected;
|
||||||
|
|
||||||
@@ -1970,7 +1970,7 @@ void InsertVirtualMethodsTest::testBaseClassInNamespace()
|
|||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual BaseNS::BaseEnum a(BaseNS::BaseEnum e);\n"
|
" virtual BaseNS::BaseEnum a(BaseNS::BaseEnum e);\n"
|
||||||
"};\n";
|
"};\n";
|
||||||
testFiles << Tests::QuickFixTestDocument::create("file.h", original, expected);
|
testFiles << Tests::CppTestDocument::create("file.h", original, expected);
|
||||||
|
|
||||||
// Source File
|
// Source File
|
||||||
original = "#include \"file.h\"\n";
|
original = "#include \"file.h\"\n";
|
||||||
@@ -1979,7 +1979,7 @@ void InsertVirtualMethodsTest::testBaseClassInNamespace()
|
|||||||
"\n\n"
|
"\n\n"
|
||||||
"BaseNS::BaseEnum Derived::a(BaseNS::BaseEnum e)\n"
|
"BaseNS::BaseEnum Derived::a(BaseNS::BaseEnum e)\n"
|
||||||
"{\n}";
|
"{\n}";
|
||||||
testFiles << Tests::QuickFixTestDocument::create("file.cpp", original, expected);
|
testFiles << Tests::CppTestDocument::create("file.cpp", original, expected);
|
||||||
|
|
||||||
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
|
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
|
||||||
InsertVirtualMethodsDialog::ModeImplementationFile,
|
InsertVirtualMethodsDialog::ModeImplementationFile,
|
||||||
|
@@ -61,7 +61,7 @@ using CppEditor::Tests::ProjectOpenerAndCloser;
|
|||||||
using CppEditor::Tests::TemporaryCopiedDir;
|
using CppEditor::Tests::TemporaryCopiedDir;
|
||||||
using CppEditor::Tests::TemporaryDir;
|
using CppEditor::Tests::TemporaryDir;
|
||||||
using CppEditor::Tests::TestCase;
|
using CppEditor::Tests::TestCase;
|
||||||
using CppEditor::Tests::VerifyCleanCppModelManager;
|
using CppEditor::Internal::Tests::VerifyCleanCppModelManager;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(CppEditor::ProjectFile)
|
Q_DECLARE_METATYPE(CppEditor::ProjectFile)
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QStringList toAbsolutePaths(const QStringList &relativePathList,
|
QStringList toAbsolutePaths(const QStringList &relativePathList,
|
||||||
const Tests::TemporaryCopiedDir &temporaryDir)
|
const TemporaryCopiedDir &temporaryDir)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
foreach (const QString &file, relativePathList)
|
foreach (const QString &file, relativePathList)
|
||||||
@@ -157,13 +157,13 @@ public:
|
|||||||
|
|
||||||
bool writeContents(const QByteArray &contents) const
|
bool writeContents(const QByteArray &contents) const
|
||||||
{
|
{
|
||||||
return Tests::TestCase::writeFile(m_filePath, contents);
|
return TestCase::writeFile(m_filePath, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void restoreContents() const
|
void restoreContents() const
|
||||||
{
|
{
|
||||||
Tests::TestCase::writeFile(m_filePath, m_originalFileContents);
|
TestCase::writeFile(m_filePath, m_originalFileContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray m_originalFileContents;
|
QByteArray m_originalFileContents;
|
||||||
@@ -463,8 +463,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
|||||||
QFETCH(QStringList, initialProjectFiles);
|
QFETCH(QStringList, initialProjectFiles);
|
||||||
QFETCH(QStringList, finalProjectFiles);
|
QFETCH(QStringList, finalProjectFiles);
|
||||||
|
|
||||||
Tests::TemporaryCopiedDir temporaryDir(
|
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path());
|
||||||
MyTestDataDir(QLatin1String("testdata_refresh2")).path());
|
|
||||||
fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8());
|
fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8());
|
||||||
initialProjectFiles = toAbsolutePaths(initialProjectFiles, temporaryDir);
|
initialProjectFiles = toAbsolutePaths(initialProjectFiles, temporaryDir);
|
||||||
finalProjectFiles = toAbsolutePaths(finalProjectFiles, temporaryDir);
|
finalProjectFiles = toAbsolutePaths(finalProjectFiles, temporaryDir);
|
||||||
@@ -715,7 +714,7 @@ struct EditorCloser {
|
|||||||
~EditorCloser()
|
~EditorCloser()
|
||||||
{
|
{
|
||||||
if (editor)
|
if (editor)
|
||||||
QVERIFY(Tests::TestCase::closeEditorWithoutGarbageCollectorInvocation(editor));
|
QVERIFY(TestCase::closeEditorWithoutGarbageCollectorInvocation(editor));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ QString stripCursor(const QString &source)
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerDeclarationFormatterTestCase : public Tests::TestCase
|
class PointerDeclarationFormatterTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PointerDeclarationFormatterTestCase(const QByteArray &source,
|
PointerDeclarationFormatterTestCase(const QByteArray &source,
|
||||||
@@ -83,7 +83,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write source to temprorary file
|
// Write source to temprorary file
|
||||||
Tests::TemporaryDir temporaryDir;
|
CppEditor::Tests::TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
const QString filePath = temporaryDir.createFile("file.h",
|
const QString filePath = temporaryDir.createFile("file.h",
|
||||||
sourceWithoutCursorMarker.toUtf8());
|
sourceWithoutCursorMarker.toUtf8());
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,8 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppquickfix.h"
|
#include "cppquickfix.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <projectexplorer/headerpath.h>
|
#include <projectexplorer/headerpath.h>
|
||||||
|
|
||||||
@@ -42,47 +42,20 @@ class CppCodeStylePreferences;
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
///
|
|
||||||
/// Represents a test document before and after applying the quick fix.
|
|
||||||
///
|
|
||||||
/// A TestDocument's source may contain an '@' character to denote
|
|
||||||
/// the cursor position. For selections the markers "@{start}" and
|
|
||||||
/// "@{end}" can be used. The markers are removed before the editor
|
|
||||||
/// reads the document.
|
|
||||||
///
|
|
||||||
|
|
||||||
class QuickFixTestDocument : public GenericCppTestDocument
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef QSharedPointer<QuickFixTestDocument> Ptr;
|
|
||||||
|
|
||||||
QuickFixTestDocument(const QByteArray &fileName, const QByteArray &source,
|
|
||||||
const QByteArray &expectedSource);
|
|
||||||
|
|
||||||
static Ptr create(const QByteArray &fileName, const QByteArray &source,
|
|
||||||
const QByteArray &expectedSource);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void removeMarkers();
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString m_expectedSource;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BaseQuickFixTestCase : public CppEditor::Tests::TestCase
|
class BaseQuickFixTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Exactly one QuickFixTestDocument must contain the cursor position marker '@'
|
/// Exactly one QuickFixTestDocument must contain the cursor position marker '@'
|
||||||
/// or "@{start}" and "@{end}"
|
/// or "@{start}" and "@{end}"
|
||||||
BaseQuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &testDocuments,
|
BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDocuments,
|
||||||
const ProjectExplorer::HeaderPaths &headerPaths
|
const ProjectExplorer::HeaderPaths &headerPaths
|
||||||
= ProjectExplorer::HeaderPaths());
|
= ProjectExplorer::HeaderPaths());
|
||||||
|
|
||||||
~BaseQuickFixTestCase();
|
~BaseQuickFixTestCase();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QuickFixTestDocument::Ptr m_documentWithMarker;
|
TestDocumentPtr m_documentWithMarker;
|
||||||
QList<QuickFixTestDocument::Ptr> m_testDocuments;
|
QList<TestDocumentPtr> m_testDocuments;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<CppEditor::Tests::TemporaryDir> m_temporaryDirectory;
|
QScopedPointer<CppEditor::Tests::TemporaryDir> m_temporaryDirectory;
|
||||||
@@ -98,20 +71,20 @@ private:
|
|||||||
class QuickFixOperationTest : public BaseQuickFixTestCase
|
class QuickFixOperationTest : public BaseQuickFixTestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QuickFixOperationTest(const QList<QuickFixTestDocument::Ptr> &testDocuments,
|
QuickFixOperationTest(const QList<TestDocumentPtr> &testDocuments,
|
||||||
CppQuickFixFactory *factory,
|
CppQuickFixFactory *factory,
|
||||||
const ProjectExplorer::HeaderPaths &headerPaths
|
const ProjectExplorer::HeaderPaths &headerPaths
|
||||||
= ProjectExplorer::HeaderPaths(),
|
= ProjectExplorer::HeaderPaths(),
|
||||||
int operationIndex = 0,
|
int operationIndex = 0,
|
||||||
const QByteArray &expectedFailMessage = QByteArray());
|
const QByteArray &expectedFailMessage = QByteArray());
|
||||||
|
|
||||||
static void run(const QList<QuickFixTestDocument::Ptr> &testDocuments,
|
static void run(const QList<TestDocumentPtr> &testDocuments,
|
||||||
CppQuickFixFactory *factory,
|
CppQuickFixFactory *factory,
|
||||||
const QString &headerPath,
|
const QString &headerPath,
|
||||||
int operationIndex = 0);
|
int operationIndex = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<QuickFixTestDocument::Ptr> singleDocument(const QByteArray &original,
|
QList<TestDocumentPtr> singleDocument(const QByteArray &original,
|
||||||
const QByteArray &expected);
|
const QByteArray &expected);
|
||||||
|
|
||||||
class QuickfixTest : public QObject
|
class QuickfixTest : public QObject
|
||||||
|
@@ -54,6 +54,136 @@
|
|||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace CppEditor::Internal::Tests {
|
||||||
|
|
||||||
|
CppTestDocument::CppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||||
|
char cursorMarker)
|
||||||
|
: m_fileName(QString::fromUtf8(fileName))
|
||||||
|
, m_source(QString::fromUtf8(source))
|
||||||
|
, m_cursorMarker(cursorMarker)
|
||||||
|
, m_targetCursorPosition(m_source.indexOf(QLatin1Char('$')))
|
||||||
|
, m_selectionStartMarker(QLatin1Char(m_cursorMarker) + QLatin1String("{start}"))
|
||||||
|
, m_selectionEndMarker(QLatin1Char(m_cursorMarker) + QLatin1String("{end}"))
|
||||||
|
{
|
||||||
|
// Try to find selection markers
|
||||||
|
const int selectionStartIndex = m_source.indexOf(m_selectionStartMarker);
|
||||||
|
const int selectionEndIndex = m_source.indexOf(m_selectionEndMarker);
|
||||||
|
const bool bothSelectionMarkersFound = selectionStartIndex != -1 && selectionEndIndex != -1;
|
||||||
|
const bool noneSelectionMarkersFounds = selectionStartIndex == -1 && selectionEndIndex == -1;
|
||||||
|
QTC_ASSERT(bothSelectionMarkersFound || noneSelectionMarkersFounds, return);
|
||||||
|
|
||||||
|
if (selectionStartIndex != -1) {
|
||||||
|
m_cursorPosition = selectionEndIndex;
|
||||||
|
m_anchorPosition = selectionStartIndex;
|
||||||
|
|
||||||
|
// No selection markers found, so check for simple cursorMarker
|
||||||
|
} else {
|
||||||
|
m_cursorPosition = m_source.indexOf(QLatin1Char(cursorMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
|
||||||
|
QVERIFY(m_cursorPosition != m_targetCursorPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestDocumentPtr CppTestDocument::create(const QByteArray &source, const QByteArray &fileName)
|
||||||
|
{
|
||||||
|
const TestDocumentPtr doc(new CppTestDocument(fileName, source));
|
||||||
|
doc->removeMarkers();
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestDocumentPtr CppTestDocument::create(const QByteArray &fileName, const QByteArray &source,
|
||||||
|
const QByteArray &expectedSource)
|
||||||
|
{
|
||||||
|
const TestDocumentPtr doc(new CppTestDocument(fileName, source));
|
||||||
|
doc->m_expectedSource = QString::fromUtf8(expectedSource);
|
||||||
|
doc->removeMarkers();
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CppTestDocument::filePath() const
|
||||||
|
{
|
||||||
|
if (!m_baseDirectory.isEmpty())
|
||||||
|
return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName);
|
||||||
|
|
||||||
|
if (!QFileInfo(m_fileName).isAbsolute())
|
||||||
|
return Utils::TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName;
|
||||||
|
|
||||||
|
return m_fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CppTestDocument::writeToDisk() const
|
||||||
|
{
|
||||||
|
return CppEditor::Tests::TestCase::writeFile(filePath(), m_source.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppTestDocument::removeMarkers()
|
||||||
|
{
|
||||||
|
// Remove selection markers
|
||||||
|
if (m_anchorPosition != -1) {
|
||||||
|
if (m_anchorPosition < m_cursorPosition) {
|
||||||
|
m_source.remove(m_anchorPosition, m_selectionStartMarker.size());
|
||||||
|
m_cursorPosition -= m_selectionStartMarker.size();
|
||||||
|
m_source.remove(m_cursorPosition, m_selectionEndMarker.size());
|
||||||
|
} else {
|
||||||
|
m_source.remove(m_cursorPosition, m_selectionEndMarker.size());
|
||||||
|
m_anchorPosition -= m_selectionEndMarker.size();
|
||||||
|
m_source.remove(m_anchorPosition, m_selectionStartMarker.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove simple cursor marker
|
||||||
|
} else if (m_cursorPosition != -1 || m_targetCursorPosition != -1) {
|
||||||
|
if (m_cursorPosition > m_targetCursorPosition) {
|
||||||
|
m_source.remove(m_cursorPosition, 1);
|
||||||
|
if (m_targetCursorPosition != -1) {
|
||||||
|
m_source.remove(m_targetCursorPosition, 1);
|
||||||
|
--m_cursorPosition;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_source.remove(m_targetCursorPosition, 1);
|
||||||
|
if (m_cursorPosition != -1) {
|
||||||
|
m_source.remove(m_cursorPosition, 1);
|
||||||
|
--m_targetCursorPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int cursorPositionInExpectedSource
|
||||||
|
= m_expectedSource.indexOf(QLatin1Char(m_cursorMarker));
|
||||||
|
if (cursorPositionInExpectedSource > -1)
|
||||||
|
m_expectedSource.remove(cursorPositionInExpectedSource, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifyCleanCppModelManager::VerifyCleanCppModelManager()
|
||||||
|
{
|
||||||
|
QVERIFY(isClean());
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifyCleanCppModelManager::~VerifyCleanCppModelManager() {
|
||||||
|
QVERIFY(isClean());
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RETURN_FALSE_IF_NOT(check) if (!(check)) return false;
|
||||||
|
|
||||||
|
bool VerifyCleanCppModelManager::isClean(bool testOnlyForCleanedProjects)
|
||||||
|
{
|
||||||
|
CppModelManager *mm = CppModelManager::instance();
|
||||||
|
RETURN_FALSE_IF_NOT(mm->projectInfos().isEmpty());
|
||||||
|
RETURN_FALSE_IF_NOT(mm->headerPaths().isEmpty());
|
||||||
|
RETURN_FALSE_IF_NOT(mm->definedMacros().isEmpty());
|
||||||
|
RETURN_FALSE_IF_NOT(mm->projectFiles().isEmpty());
|
||||||
|
if (!testOnlyForCleanedProjects) {
|
||||||
|
RETURN_FALSE_IF_NOT(mm->snapshot().isEmpty());
|
||||||
|
RETURN_FALSE_IF_NOT(mm->workingCopy().size() == 1);
|
||||||
|
RETURN_FALSE_IF_NOT(mm->workingCopy().contains(mm->configurationFileName()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef RETURN_FALSE_IF_NOT
|
||||||
|
|
||||||
|
} // namespace CppEditor::Internal::Tests
|
||||||
|
|
||||||
namespace CppEditor::Tests {
|
namespace CppEditor::Tests {
|
||||||
|
|
||||||
static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors)
|
static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors)
|
||||||
@@ -75,28 +205,6 @@ static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<QSt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseCppTestDocument::BaseCppTestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
|
|
||||||
: m_fileName(QString::fromUtf8(fileName))
|
|
||||||
, m_source(QString::fromUtf8(source))
|
|
||||||
, m_cursorMarker(cursorMarker)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QString BaseCppTestDocument::filePath() const
|
|
||||||
{
|
|
||||||
if (!m_baseDirectory.isEmpty())
|
|
||||||
return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName);
|
|
||||||
|
|
||||||
if (!QFileInfo(m_fileName).isAbsolute())
|
|
||||||
return Utils::TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName;
|
|
||||||
|
|
||||||
return m_fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BaseCppTestDocument::writeToDisk() const
|
|
||||||
{
|
|
||||||
return TestCase::writeFile(filePath(), m_source.toUtf8());
|
|
||||||
}
|
|
||||||
|
|
||||||
TestCase::TestCase(bool runGarbageCollector)
|
TestCase::TestCase(bool runGarbageCollector)
|
||||||
: m_modelManager(CppModelManager::instance())
|
: m_modelManager(CppModelManager::instance())
|
||||||
, m_succeededSoFar(false)
|
, m_succeededSoFar(false)
|
||||||
@@ -389,52 +497,6 @@ QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
|
|||||||
return m_temporaryDir.filePath(QString::fromUtf8(relativePath)).path();
|
return m_temporaryDir.filePath(QString::fromUtf8(relativePath)).path();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteArray &contents)
|
|
||||||
: m_filePath(filePath)
|
|
||||||
{
|
|
||||||
if (QFileInfo::exists(filePath)) {
|
|
||||||
qWarning().nospace() << "Will not overwrite existing file: " << m_filePath << "."
|
|
||||||
<< " If this file is left over due to a(n) abort/crash, please remove manually.";
|
|
||||||
m_writtenSuccessfully = false;
|
|
||||||
} else {
|
|
||||||
m_writtenSuccessfully = TestCase::writeFile(filePath, contents);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileWriterAndRemover::~FileWriterAndRemover()
|
|
||||||
{
|
|
||||||
if (m_writtenSuccessfully && !QFile::remove(m_filePath))
|
|
||||||
qWarning() << "Failed to remove file from disk:" << qPrintable(m_filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
VerifyCleanCppModelManager::VerifyCleanCppModelManager()
|
|
||||||
{
|
|
||||||
QVERIFY(isClean());
|
|
||||||
}
|
|
||||||
|
|
||||||
VerifyCleanCppModelManager::~VerifyCleanCppModelManager() {
|
|
||||||
QVERIFY(isClean());
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RETURN_FALSE_IF_NOT(check) if (!(check)) return false;
|
|
||||||
|
|
||||||
bool VerifyCleanCppModelManager::isClean(bool testOnlyForCleanedProjects)
|
|
||||||
{
|
|
||||||
CppModelManager *mm = CppModelManager::instance();
|
|
||||||
RETURN_FALSE_IF_NOT(mm->projectInfos().isEmpty());
|
|
||||||
RETURN_FALSE_IF_NOT(mm->headerPaths().isEmpty());
|
|
||||||
RETURN_FALSE_IF_NOT(mm->definedMacros().isEmpty());
|
|
||||||
RETURN_FALSE_IF_NOT(mm->projectFiles().isEmpty());
|
|
||||||
if (!testOnlyForCleanedProjects) {
|
|
||||||
RETURN_FALSE_IF_NOT(mm->snapshot().isEmpty());
|
|
||||||
RETURN_FALSE_IF_NOT(mm->workingCopy().size() == 1);
|
|
||||||
RETURN_FALSE_IF_NOT(mm->workingCopy().contains(mm->configurationFileName()));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef RETURN_FALSE_IF_NOT
|
|
||||||
|
|
||||||
int clangdIndexingTimeout()
|
int clangdIndexingTimeout()
|
||||||
{
|
{
|
||||||
const QByteArray timeoutAsByteArray = qgetenv("QTC_CLANGD_INDEXING_TIMEOUT");
|
const QByteArray timeoutAsByteArray = qgetenv("QTC_CLANGD_INDEXING_TIMEOUT");
|
||||||
|
@@ -56,6 +56,67 @@ namespace CppEditor {
|
|||||||
class CppEditorWidget;
|
class CppEditorWidget;
|
||||||
class CppModelManager;
|
class CppModelManager;
|
||||||
|
|
||||||
|
namespace Internal::Tests {
|
||||||
|
|
||||||
|
class CppTestDocument;
|
||||||
|
typedef QSharedPointer<CppTestDocument> TestDocumentPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a test document.
|
||||||
|
*
|
||||||
|
* The source can contain special characters:
|
||||||
|
* - A '@' character denotes the initial text cursor position
|
||||||
|
* - A '$' character denotes the target text cursor position (for "follow symbol" type of tests)
|
||||||
|
* - For selections, the markers "@{start}" and "@{end}" can be used.
|
||||||
|
*/
|
||||||
|
class CppTestDocument
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||||
|
char cursorMarker = '@');
|
||||||
|
|
||||||
|
static TestDocumentPtr create(const QByteArray &source, const QByteArray &fileName);
|
||||||
|
static TestDocumentPtr create(const QByteArray &fileName, const QByteArray &source,
|
||||||
|
const QByteArray &expectedSource);
|
||||||
|
|
||||||
|
QString baseDirectory() const { return m_baseDirectory; }
|
||||||
|
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
|
||||||
|
|
||||||
|
QString filePath() const;
|
||||||
|
bool writeToDisk() const;
|
||||||
|
|
||||||
|
bool hasCursorMarker() const { return m_cursorPosition != -1; }
|
||||||
|
bool hasAnchorMarker() const { return m_anchorPosition != -1; }
|
||||||
|
bool hasTargetCursorMarker() const { return m_targetCursorPosition != -1; }
|
||||||
|
|
||||||
|
void removeMarkers();
|
||||||
|
|
||||||
|
QString m_baseDirectory;
|
||||||
|
QString m_fileName;
|
||||||
|
QString m_source;
|
||||||
|
char m_cursorMarker;
|
||||||
|
int m_targetCursorPosition;
|
||||||
|
int m_cursorPosition = -1;
|
||||||
|
int m_anchorPosition = -1;
|
||||||
|
QString m_selectionStartMarker;
|
||||||
|
QString m_selectionEndMarker;
|
||||||
|
QString m_expectedSource;
|
||||||
|
TextEditor::BaseTextEditor *m_editor = nullptr;
|
||||||
|
CppEditorWidget *m_editorWidget = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
using TestDocuments = QVector<CppTestDocument>;
|
||||||
|
|
||||||
|
class VerifyCleanCppModelManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VerifyCleanCppModelManager();
|
||||||
|
~VerifyCleanCppModelManager();
|
||||||
|
static bool isClean(bool testCleanedProjects = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal::Tests
|
||||||
|
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
int CPPEDITOR_EXPORT clangdIndexingTimeout();
|
int CPPEDITOR_EXPORT clangdIndexingTimeout();
|
||||||
@@ -75,25 +136,6 @@ template <typename Signal> inline bool waitForSignalOrTimeout(
|
|||||||
return timer.isActive();
|
return timer.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT BaseCppTestDocument
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BaseCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
|
||||||
char cursorMarker = '@');
|
|
||||||
|
|
||||||
QString baseDirectory() const { return m_baseDirectory; }
|
|
||||||
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
|
|
||||||
|
|
||||||
QString filePath() const;
|
|
||||||
bool writeToDisk() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString m_baseDirectory;
|
|
||||||
QString m_fileName;
|
|
||||||
QString m_source;
|
|
||||||
char m_cursorMarker;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT TestCase
|
class CPPEDITOR_EXPORT TestCase
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(TestCase)
|
Q_DISABLE_COPY(TestCase)
|
||||||
@@ -182,25 +224,5 @@ private:
|
|||||||
TemporaryCopiedDir();
|
TemporaryCopiedDir();
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT VerifyCleanCppModelManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
VerifyCleanCppModelManager();
|
|
||||||
~VerifyCleanCppModelManager();
|
|
||||||
static bool isClean(bool testCleanedProjects = true);
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileWriterAndRemover
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileWriterAndRemover(const QString &filePath, const QByteArray &contents); // Writes file
|
|
||||||
bool writtenSuccessfully() const { return m_writtenSuccessfully; }
|
|
||||||
~FileWriterAndRemover(); // Removes file
|
|
||||||
|
|
||||||
private:
|
|
||||||
const QString m_filePath;
|
|
||||||
bool m_writtenSuccessfully;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -26,8 +26,8 @@
|
|||||||
#include "cppuseselections_test.h"
|
#include "cppuseselections_test.h"
|
||||||
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@@ -68,7 +68,7 @@ namespace Tests {
|
|||||||
class UseSelectionsTestCase : public CppEditor::Tests::TestCase
|
class UseSelectionsTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UseSelectionsTestCase(GenericCppTestDocument &testDocument,
|
UseSelectionsTestCase(CppTestDocument &testDocument,
|
||||||
const SelectionList &expectedSelections);
|
const SelectionList &expectedSelections);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -80,7 +80,7 @@ private:
|
|||||||
CppEditorWidget *m_editorWidget = nullptr;
|
CppEditorWidget *m_editorWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
UseSelectionsTestCase::UseSelectionsTestCase(GenericCppTestDocument &testFile,
|
UseSelectionsTestCase::UseSelectionsTestCase(CppTestDocument &testFile,
|
||||||
const SelectionList &expectedSelections)
|
const SelectionList &expectedSelections)
|
||||||
{
|
{
|
||||||
QVERIFY(succeededSoFar());
|
QVERIFY(succeededSoFar());
|
||||||
@@ -251,7 +251,7 @@ void SelectionsTest::testUseSelections()
|
|||||||
QFETCH(QByteArray, source);
|
QFETCH(QByteArray, source);
|
||||||
QFETCH(SelectionList, expectedSelections);
|
QFETCH(SelectionList, expectedSelections);
|
||||||
|
|
||||||
Tests::GenericCppTestDocument testDocument("file.cpp", source);
|
Tests::CppTestDocument testDocument("file.cpp", source);
|
||||||
Tests::UseSelectionsTestCase(testDocument, expectedSelections);
|
Tests::UseSelectionsTestCase(testDocument, expectedSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#include "fileandtokenactions_test.h"
|
#include "fileandtokenactions_test.h"
|
||||||
|
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppquickfix.h"
|
#include "cppquickfix.h"
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
@@ -34,6 +33,7 @@
|
|||||||
#include "cppinsertvirtualmethods.h"
|
#include "cppinsertvirtualmethods.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
#include "cppworkingcopy.h"
|
#include "cppworkingcopy.h"
|
||||||
#include "projectinfo.h"
|
#include "projectinfo.h"
|
||||||
|
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "cppcodemodelsettings.h"
|
#include "cppcodemodelsettings.h"
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
#include "cppeditortestcase.h"
|
|
||||||
#include "cppeditorwidget.h"
|
#include "cppeditorwidget.h"
|
||||||
#include "cppelementevaluator.h"
|
#include "cppelementevaluator.h"
|
||||||
#include "cppfollowsymbolundercursor.h"
|
#include "cppfollowsymbolundercursor.h"
|
||||||
@@ -189,55 +188,9 @@ private:
|
|||||||
CppEditorWidget *m_editorWidget;
|
CppEditorWidget *m_editorWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FollowSymbolTestDocument;
|
|
||||||
typedef QSharedPointer<FollowSymbolTestDocument> TestDocumentPtr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a test document.
|
|
||||||
*
|
|
||||||
* A TestDocument's source can contain special characters:
|
|
||||||
* - a '@' character denotes the initial text cursor position
|
|
||||||
* - a '$' character denotes the target text cursor position
|
|
||||||
*/
|
|
||||||
class FollowSymbolTestDocument : public Tests::GenericCppTestDocument
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FollowSymbolTestDocument(const QByteArray &source, const QByteArray &fileName)
|
|
||||||
: Tests::GenericCppTestDocument(fileName, source)
|
|
||||||
, m_targetCursorPosition(m_source.indexOf(QLatin1Char('$')))
|
|
||||||
{
|
|
||||||
if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
|
|
||||||
QVERIFY(m_cursorPosition != m_targetCursorPosition);
|
|
||||||
|
|
||||||
if (m_cursorPosition > m_targetCursorPosition) {
|
|
||||||
m_source.remove(m_cursorPosition, 1);
|
|
||||||
if (m_targetCursorPosition != -1) {
|
|
||||||
m_source.remove(m_targetCursorPosition, 1);
|
|
||||||
--m_cursorPosition;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_source.remove(m_targetCursorPosition, 1);
|
|
||||||
if (m_cursorPosition != -1) {
|
|
||||||
m_source.remove(m_cursorPosition, 1);
|
|
||||||
--m_targetCursorPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static TestDocumentPtr create(const QByteArray &source, const QByteArray &fileName)
|
|
||||||
{
|
|
||||||
return TestDocumentPtr(new FollowSymbolTestDocument(source, fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasTargetCursorMarker() const { return m_targetCursorPosition != -1; }
|
|
||||||
|
|
||||||
public:
|
|
||||||
int m_targetCursorPosition;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<TestDocumentPtr> singleDocument(const QByteArray &source)
|
QList<TestDocumentPtr> singleDocument(const QByteArray &source)
|
||||||
{
|
{
|
||||||
return QList<TestDocumentPtr>() << FollowSymbolTestDocument::create(source, "file.cpp");
|
return QList<TestDocumentPtr>() << CppTestDocument::create(source, "file.cpp");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,7 +290,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
} projectCloser;
|
} projectCloser;
|
||||||
|
|
||||||
if (useClangd) {
|
if (useClangd) {
|
||||||
FollowSymbolTestDocument projectFile(projectFileContent.toUtf8(), "project.qbs");
|
CppTestDocument projectFile("project.qbs", projectFileContent.toUtf8());
|
||||||
projectFile.setBaseDirectory(temporaryDir.path());
|
projectFile.setBaseDirectory(temporaryDir.path());
|
||||||
QVERIFY(projectFile.writeToDisk());
|
QVERIFY(projectFile.writeToDisk());
|
||||||
const auto openProjectResult =
|
const auto openProjectResult =
|
||||||
@@ -865,8 +818,8 @@ void FollowSymbolTest::testSwitchMethodDeclDef()
|
|||||||
QFETCH(QByteArray, source);
|
QFETCH(QByteArray, source);
|
||||||
|
|
||||||
const QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
const QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create(header, "file.h")
|
<< CppTestDocument::create(header, "file.h")
|
||||||
<< FollowSymbolTestDocument::create(source, "file.cpp");
|
<< CppTestDocument::create(source, "file.cpp");
|
||||||
|
|
||||||
F2TestCase(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
|
F2TestCase(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
|
||||||
}
|
}
|
||||||
@@ -1439,87 +1392,87 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
|||||||
QTest::addColumn<QList<TestDocumentPtr> >("documents");
|
QTest::addColumn<QList<TestDocumentPtr> >("documents");
|
||||||
|
|
||||||
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
|
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class $Foo {};\n",
|
<< CppTestDocument::create("class $Foo {};\n",
|
||||||
"defined.h")
|
"defined.h")
|
||||||
<< FollowSymbolTestDocument::create("class Foo;\n"
|
<< CppTestDocument::create("class Foo;\n"
|
||||||
"@Foo foo;\n",
|
"@Foo foo;\n",
|
||||||
"forwardDeclaredAndUsed.h")
|
"forwardDeclaredAndUsed.h")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
|
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("template <class E> class $Container {};\n",
|
<< CppTestDocument::create("template <class E> class $Container {};\n",
|
||||||
"defined.h")
|
"defined.h")
|
||||||
<< FollowSymbolTestDocument::create("template <class E> class Container;\n"
|
<< CppTestDocument::create("template <class E> class Container;\n"
|
||||||
"@Container<int> container;\n",
|
"@Container<int> container;\n",
|
||||||
"forwardDeclaredAndUsed.h")
|
"forwardDeclaredAndUsed.h")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignature") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignature") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
<< CppTestDocument::create("class Foo {\n"
|
||||||
" void @foo(int);\n"
|
" void @foo(int);\n"
|
||||||
" void foo() {}\n"
|
" void foo() {}\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"void Foo::$foo(int) {}\n",
|
"void Foo::$foo(int) {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignature2") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignature2") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("namespace N { class C; }\n"
|
<< CppTestDocument::create("namespace N { class C; }\n"
|
||||||
"bool *@fun(N::C *) const;\n",
|
"bool *@fun(N::C *) const;\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"using namespace N;\n"
|
"using namespace N;\n"
|
||||||
"bool *$fun(C *) const {}\n",
|
"bool *$fun(C *) const {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignatureFuzzy1Forward") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignatureFuzzy1Forward") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
<< CppTestDocument::create("class Foo {\n"
|
||||||
" void @foo(int);\n"
|
" void @foo(int);\n"
|
||||||
" void foo();\n"
|
" void foo();\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"void Foo::$foo() {}\n",
|
"void Foo::$foo() {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignatureFuzzy1Backward") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignatureFuzzy1Backward") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
<< CppTestDocument::create("class Foo {\n"
|
||||||
" void $foo(int);\n"
|
" void $foo(int);\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"void Foo::@foo() {}\n",
|
"void Foo::@foo() {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignatureFuzzy2Forward") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignatureFuzzy2Forward") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
<< CppTestDocument::create("class Foo {\n"
|
||||||
" void foo(int);\n"
|
" void foo(int);\n"
|
||||||
" void @foo();\n"
|
" void @foo();\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"void Foo::$foo(int) {}\n",
|
"void Foo::$foo(int) {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("matchFunctionSignatureFuzzy2Backward") << (QList<TestDocumentPtr>()
|
QTest::newRow("matchFunctionSignatureFuzzy2Backward") << (QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
<< CppTestDocument::create("class Foo {\n"
|
||||||
" void $foo();\n"
|
" void $foo();\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
"foo.h")
|
"foo.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
<< CppTestDocument::create("#include \"foo.h\"\n"
|
||||||
"void Foo::@foo(int) {}\n",
|
"void Foo::@foo(int) {}\n",
|
||||||
"foo.cpp")
|
"foo.cpp")
|
||||||
);
|
);
|
||||||
|
|
||||||
QTest::newRow("globalVar") << QList<TestDocumentPtr>{
|
QTest::newRow("globalVar") << QList<TestDocumentPtr>{
|
||||||
FollowSymbolTestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"),
|
CppTestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"),
|
||||||
FollowSymbolTestDocument::create(
|
CppTestDocument::create(
|
||||||
"int globalVar;\n"
|
"int globalVar;\n"
|
||||||
"namespace NS {\n"
|
"namespace NS {\n"
|
||||||
"extern int globalVar;\n"
|
"extern int globalVar;\n"
|
||||||
@@ -1527,7 +1480,7 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
|||||||
"}\n", "file.cpp")};
|
"}\n", "file.cpp")};
|
||||||
|
|
||||||
QTest::newRow("staticMemberVar") << QList<TestDocumentPtr>{
|
QTest::newRow("staticMemberVar") << QList<TestDocumentPtr>{
|
||||||
FollowSymbolTestDocument::create(
|
CppTestDocument::create(
|
||||||
"namespace NS {\n"
|
"namespace NS {\n"
|
||||||
"class Test {\n"
|
"class Test {\n"
|
||||||
" static int @var;\n"
|
" static int @var;\n"
|
||||||
@@ -1535,7 +1488,7 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
|||||||
"class OtherClass { static int var; };\n"
|
"class OtherClass { static int var; };\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"class OtherClass { static int var; };\n", "file.h"),
|
"class OtherClass { static int var; };\n", "file.h"),
|
||||||
FollowSymbolTestDocument::create(
|
CppTestDocument::create(
|
||||||
"#include \"file.h\"\n"
|
"#include \"file.h\"\n"
|
||||||
"int var;\n"
|
"int var;\n"
|
||||||
"int OtherClass::var;\n"
|
"int OtherClass::var;\n"
|
||||||
@@ -2058,12 +2011,12 @@ void FollowSymbolTest::testFollowVirtualFunctionCall()
|
|||||||
void FollowSymbolTest::testFollowVirtualFunctionCallMultipleDocuments()
|
void FollowSymbolTest::testFollowVirtualFunctionCallMultipleDocuments()
|
||||||
{
|
{
|
||||||
QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
||||||
<< FollowSymbolTestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
<< CppTestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
||||||
"a.h")
|
"a.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"a.h\"\n"
|
<< CppTestDocument::create("#include \"a.h\"\n"
|
||||||
"struct B : A { void virt(int) {} };\n",
|
"struct B : A { void virt(int) {} };\n",
|
||||||
"b.h")
|
"b.h")
|
||||||
<< FollowSymbolTestDocument::create("#include \"a.h\"\n"
|
<< CppTestDocument::create("#include \"a.h\"\n"
|
||||||
"void f(A *o) { o->$@virt(42); }\n",
|
"void f(A *o) { o->$@virt(42); }\n",
|
||||||
"u.cpp")
|
"u.cpp")
|
||||||
;
|
;
|
||||||
|
@@ -64,13 +64,13 @@ ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent,
|
|||||||
this, &ModelManagerTestHelper::gcFinished);
|
this, &ModelManagerTestHelper::gcFinished);
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
QVERIFY(Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
|
QVERIFY(Internal::Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelManagerTestHelper::~ModelManagerTestHelper()
|
ModelManagerTestHelper::~ModelManagerTestHelper()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
QVERIFY(Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
|
QVERIFY(Internal::Tests::VerifyCleanCppModelManager::isClean(m_testOnlyForCleanedProjects));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerTestHelper::cleanup()
|
void ModelManagerTestHelper::cleanup()
|
||||||
|
@@ -99,7 +99,7 @@ QT_END_NAMESPACE
|
|||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class SymbolSearcherTestCase : public Tests::TestCase
|
class SymbolSearcherTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolSearcherTestCase(const QString &testFile,
|
SymbolSearcherTestCase(const QString &testFile,
|
||||||
|
@@ -38,9 +38,9 @@
|
|||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using CppEditor::Tests::BaseCppTestDocument;
|
using CppEditor::Internal::Tests::CppTestDocument;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QList<BaseCppTestDocument>)
|
Q_DECLARE_METATYPE(QList<CppTestDocument>)
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor::Internal {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -90,18 +90,18 @@ private:
|
|||||||
Class *m_clazz = nullptr;
|
Class *m_clazz = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeHierarchyBuilderTestCase : public Tests::TestCase
|
class TypeHierarchyBuilderTestCase : public CppEditor::Tests::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TypeHierarchyBuilderTestCase(const QList<BaseCppTestDocument> &documents,
|
TypeHierarchyBuilderTestCase(const QList<CppTestDocument> &documents,
|
||||||
const QString &expectedHierarchy)
|
const QString &expectedHierarchy)
|
||||||
{
|
{
|
||||||
QVERIFY(succeededSoFar());
|
QVERIFY(succeededSoFar());
|
||||||
|
|
||||||
Tests::TemporaryDir temporaryDir;
|
CppEditor::Tests::TemporaryDir temporaryDir;
|
||||||
QVERIFY(temporaryDir.isValid());
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
|
||||||
QList<BaseCppTestDocument> documents_ = documents;
|
QList<CppTestDocument> documents_ = documents;
|
||||||
|
|
||||||
// Write files
|
// Write files
|
||||||
QSet<QString> filePaths;
|
QSet<QString> filePaths;
|
||||||
@@ -137,12 +137,12 @@ public:
|
|||||||
|
|
||||||
void TypeHierarchyBuilderTest::test_data()
|
void TypeHierarchyBuilderTest::test_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QList<BaseCppTestDocument> >("documents");
|
QTest::addColumn<QList<CppTestDocument> >("documents");
|
||||||
QTest::addColumn<QString>("expectedHierarchy");
|
QTest::addColumn<QString>("expectedHierarchy");
|
||||||
|
|
||||||
QTest::newRow("basic-single-document")
|
QTest::newRow("basic-single-document")
|
||||||
<< (QList<BaseCppTestDocument>()
|
<< (QList<CppTestDocument>()
|
||||||
<< BaseCppTestDocument("a.h",
|
<< CppTestDocument("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"
|
||||||
@@ -156,19 +156,19 @@ void TypeHierarchyBuilderTest::test_data()
|
|||||||
" C2\n" );
|
" C2\n" );
|
||||||
|
|
||||||
QTest::newRow("basic-multiple-documents")
|
QTest::newRow("basic-multiple-documents")
|
||||||
<< (QList<BaseCppTestDocument>()
|
<< (QList<CppTestDocument>()
|
||||||
<< BaseCppTestDocument("a.h",
|
<< CppTestDocument("a.h",
|
||||||
"class A {};")
|
"class A {};")
|
||||||
<< BaseCppTestDocument("b.h",
|
<< CppTestDocument("b.h",
|
||||||
"#include \"a.h\"\n"
|
"#include \"a.h\"\n"
|
||||||
"class B : public A {};")
|
"class B : public A {};")
|
||||||
<< BaseCppTestDocument("c1.h",
|
<< CppTestDocument("c1.h",
|
||||||
"#include \"b.h\"\n"
|
"#include \"b.h\"\n"
|
||||||
"class C1 : public B {};")
|
"class C1 : public B {};")
|
||||||
<< BaseCppTestDocument("c2.h",
|
<< CppTestDocument("c2.h",
|
||||||
"#include \"b.h\"\n"
|
"#include \"b.h\"\n"
|
||||||
"class C2 : public B {};")
|
"class C2 : public B {};")
|
||||||
<< BaseCppTestDocument("d.h",
|
<< CppTestDocument("d.h",
|
||||||
"#include \"c1.h\"\n"
|
"#include \"c1.h\"\n"
|
||||||
"class D : public C1 {};"))
|
"class D : public C1 {};"))
|
||||||
<< QString::fromLatin1(
|
<< QString::fromLatin1(
|
||||||
@@ -182,7 +182,7 @@ void TypeHierarchyBuilderTest::test_data()
|
|||||||
|
|
||||||
void TypeHierarchyBuilderTest::test()
|
void TypeHierarchyBuilderTest::test()
|
||||||
{
|
{
|
||||||
QFETCH(QList<BaseCppTestDocument>, documents);
|
QFETCH(QList<CppTestDocument>, documents);
|
||||||
QFETCH(QString, expectedHierarchy);
|
QFETCH(QString, expectedHierarchy);
|
||||||
|
|
||||||
TypeHierarchyBuilderTestCase(documents, expectedHierarchy);
|
TypeHierarchyBuilderTestCase(documents, expectedHierarchy);
|
||||||
|
Reference in New Issue
Block a user