forked from qt-creator/qt-creator
CppTools/CppEditor: Rename the TestDocument classes
It was not helpful that we had four different classes with the same name. Note that they look suspiciously similar and could possibly be merged into a single class at some point. Change-Id: I7d4c10a09408226037bc0d276940bca39dc5f576 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -375,7 +375,7 @@ void DoxygenTest::testWithMacroFromHeaderBeforeFunction()
|
||||
" */\n"
|
||||
"API void f();\n";
|
||||
|
||||
const TestDocument headerDocumentDefiningMacro("header.h", "#define API\n");
|
||||
const GenericCppTestDocument headerDocumentDefiningMacro("header.h", "#define API\n");
|
||||
|
||||
runTest(given, expected, /*settings=*/ 0, {headerDocumentDefiningMacro});
|
||||
}
|
||||
@@ -421,12 +421,12 @@ void DoxygenTest::runTest(const QByteArray &original,
|
||||
// Write files to disk
|
||||
CppTools::Tests::TemporaryDir temporaryDir;
|
||||
QVERIFY(temporaryDir.isValid());
|
||||
TestDocument testDocument("file.cpp", original, '|');
|
||||
GenericCppTestDocument testDocument("file.cpp", original, '|');
|
||||
QVERIFY(testDocument.hasCursorMarker());
|
||||
testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
|
||||
testDocument.setBaseDirectory(temporaryDir.path());
|
||||
QVERIFY(testDocument.writeToDisk());
|
||||
foreach (TestDocument testDocument, includedHeaderDocuments) {
|
||||
foreach (GenericCppTestDocument testDocument, includedHeaderDocuments) {
|
||||
testDocument.setBaseDirectory(temporaryDir.path());
|
||||
QVERIFY(testDocument.writeToDisk());
|
||||
}
|
||||
|
@@ -47,8 +47,9 @@ namespace CppEditor {
|
||||
namespace Internal {
|
||||
namespace Tests {
|
||||
|
||||
TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
|
||||
: CppTools::Tests::TestDocument(fileName, source, cursorMarker)
|
||||
GenericCppTestDocument::GenericCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||
char cursorMarker)
|
||||
: CppTools::Tests::BaseCppTestDocument(fileName, source, cursorMarker)
|
||||
, m_cursorPosition(-1)
|
||||
, m_anchorPosition(-1)
|
||||
, m_selectionStartMarker(QLatin1Char(m_cursorMarker) + QLatin1String("{start}"))
|
||||
@@ -73,9 +74,9 @@ TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||
}
|
||||
}
|
||||
|
||||
bool TestDocument::hasCursorMarker() const { return m_cursorPosition != -1; }
|
||||
bool GenericCppTestDocument::hasCursorMarker() const { return m_cursorPosition != -1; }
|
||||
|
||||
bool TestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
|
||||
bool GenericCppTestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
|
||||
|
||||
TestCase::TestCase(bool runGarbageCollector)
|
||||
: CppTools::Tests::TestCase(runGarbageCollector)
|
||||
|
@@ -37,10 +37,11 @@ class CppEditorWidget;
|
||||
|
||||
namespace Tests {
|
||||
|
||||
class TestDocument : public CppTools::Tests::TestDocument
|
||||
class GenericCppTestDocument : public CppTools::Tests::BaseCppTestDocument
|
||||
{
|
||||
public:
|
||||
TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
|
||||
GenericCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||
char cursorMarker = '@');
|
||||
|
||||
bool hasCursorMarker() const;
|
||||
bool hasAnchorMarker() const;
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
CppEditorWidget *m_editorWidget;
|
||||
};
|
||||
|
||||
using TestDocuments = QVector<TestDocument>;
|
||||
using TestDocuments = QVector<GenericCppTestDocument>;
|
||||
|
||||
class TestCase : public CppTools::Tests::TestCase
|
||||
{
|
||||
|
@@ -86,7 +86,7 @@ QuickFixTestDocument::Ptr QuickFixTestDocument::create(const QByteArray &fileNam
|
||||
QuickFixTestDocument::QuickFixTestDocument(const QByteArray &fileName,
|
||||
const QByteArray &source,
|
||||
const QByteArray &expectedSource)
|
||||
: TestDocument(fileName, source)
|
||||
: GenericCppTestDocument(fileName, source)
|
||||
, m_expectedSource(QString::fromUtf8(expectedSource))
|
||||
{
|
||||
removeMarkers();
|
||||
|
@@ -50,7 +50,7 @@ namespace Tests {
|
||||
/// reads the document.
|
||||
///
|
||||
|
||||
class QuickFixTestDocument : public TestDocument
|
||||
class QuickFixTestDocument : public GenericCppTestDocument
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<QuickFixTestDocument> Ptr;
|
||||
|
@@ -70,7 +70,7 @@ namespace Tests {
|
||||
class UseSelectionsTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
UseSelectionsTestCase(TestDocument &testDocument,
|
||||
UseSelectionsTestCase(GenericCppTestDocument &testDocument,
|
||||
const SelectionList &expectedSelections);
|
||||
|
||||
private:
|
||||
@@ -82,7 +82,7 @@ private:
|
||||
CppEditorWidget *m_editorWidget = nullptr;
|
||||
};
|
||||
|
||||
UseSelectionsTestCase::UseSelectionsTestCase(TestDocument &testFile,
|
||||
UseSelectionsTestCase::UseSelectionsTestCase(GenericCppTestDocument &testFile,
|
||||
const SelectionList &expectedSelections)
|
||||
{
|
||||
QVERIFY(succeededSoFar());
|
||||
@@ -253,7 +253,7 @@ void SelectionsTest::testUseSelections()
|
||||
QFETCH(QByteArray, source);
|
||||
QFETCH(SelectionList, expectedSelections);
|
||||
|
||||
Tests::TestDocument testDocument("file.cpp", source);
|
||||
Tests::GenericCppTestDocument testDocument("file.cpp", source);
|
||||
Tests::UseSelectionsTestCase(testDocument, expectedSelections);
|
||||
}
|
||||
|
||||
|
@@ -192,8 +192,8 @@ private:
|
||||
CppEditorWidget *m_editorWidget;
|
||||
};
|
||||
|
||||
class TestDocument;
|
||||
typedef QSharedPointer<TestDocument> TestDocumentPtr;
|
||||
class FollowSymbolTestDocument;
|
||||
typedef QSharedPointer<FollowSymbolTestDocument> TestDocumentPtr;
|
||||
|
||||
/**
|
||||
* Represents a test document.
|
||||
@@ -202,11 +202,11 @@ typedef QSharedPointer<TestDocument> TestDocumentPtr;
|
||||
* - a '@' character denotes the initial text cursor position
|
||||
* - a '$' character denotes the target text cursor position
|
||||
*/
|
||||
class TestDocument : public Tests::TestDocument
|
||||
class FollowSymbolTestDocument : public Tests::GenericCppTestDocument
|
||||
{
|
||||
public:
|
||||
TestDocument(const QByteArray &source, const QByteArray &fileName)
|
||||
: Tests::TestDocument(fileName, source)
|
||||
FollowSymbolTestDocument(const QByteArray &source, const QByteArray &fileName)
|
||||
: Tests::GenericCppTestDocument(fileName, source)
|
||||
, m_targetCursorPosition(m_source.indexOf(QLatin1Char('$')))
|
||||
{
|
||||
if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
|
||||
static TestDocumentPtr create(const QByteArray &source, const QByteArray &fileName)
|
||||
{
|
||||
return TestDocumentPtr(new TestDocument(source, fileName));
|
||||
return TestDocumentPtr(new FollowSymbolTestDocument(source, fileName));
|
||||
}
|
||||
|
||||
bool hasTargetCursorMarker() const { return m_targetCursorPosition != -1; }
|
||||
@@ -240,7 +240,7 @@ public:
|
||||
|
||||
QList<TestDocumentPtr> singleDocument(const QByteArray &source)
|
||||
{
|
||||
return QList<TestDocumentPtr>() << TestDocument::create(source, "file.cpp");
|
||||
return QList<TestDocumentPtr>() << FollowSymbolTestDocument::create(source, "file.cpp");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,7 +340,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
||||
} projectCloser;
|
||||
|
||||
if (useClangd) {
|
||||
TestDocument projectFile(projectFileContent.toUtf8(), "project.qbs");
|
||||
FollowSymbolTestDocument projectFile(projectFileContent.toUtf8(), "project.qbs");
|
||||
projectFile.setBaseDirectory(temporaryDir.path());
|
||||
QVERIFY(projectFile.writeToDisk());
|
||||
const auto openProjectResult =
|
||||
@@ -870,8 +870,8 @@ void FollowSymbolTest::testSwitchMethodDeclDef()
|
||||
QFETCH(QByteArray, source);
|
||||
|
||||
const QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
||||
<< TestDocument::create(header, "file.h")
|
||||
<< TestDocument::create(source, "file.cpp");
|
||||
<< FollowSymbolTestDocument::create(header, "file.h")
|
||||
<< FollowSymbolTestDocument::create(source, "file.cpp");
|
||||
|
||||
F2TestCase(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
|
||||
}
|
||||
@@ -1444,87 +1444,87 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
||||
QTest::addColumn<QList<TestDocumentPtr> >("documents");
|
||||
|
||||
QTest::newRow("skipForwardDeclarationBasic") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class $Foo {};\n",
|
||||
<< FollowSymbolTestDocument::create("class $Foo {};\n",
|
||||
"defined.h")
|
||||
<< TestDocument::create("class Foo;\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo;\n"
|
||||
"@Foo foo;\n",
|
||||
"forwardDeclaredAndUsed.h")
|
||||
);
|
||||
|
||||
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("template <class E> class $Container {};\n",
|
||||
<< FollowSymbolTestDocument::create("template <class E> class $Container {};\n",
|
||||
"defined.h")
|
||||
<< TestDocument::create("template <class E> class Container;\n"
|
||||
<< FollowSymbolTestDocument::create("template <class E> class Container;\n"
|
||||
"@Container<int> container;\n",
|
||||
"forwardDeclaredAndUsed.h")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignature") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class Foo {\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
||||
" void @foo(int);\n"
|
||||
" void foo() {}\n"
|
||||
"};\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"void Foo::$foo(int) {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignature2") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("namespace N { class C; }\n"
|
||||
<< FollowSymbolTestDocument::create("namespace N { class C; }\n"
|
||||
"bool *@fun(N::C *) const;\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"using namespace N;\n"
|
||||
"bool *$fun(C *) const {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignatureFuzzy1Forward") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class Foo {\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
||||
" void @foo(int);\n"
|
||||
" void foo();\n"
|
||||
"};\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"void Foo::$foo() {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignatureFuzzy1Backward") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class Foo {\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
||||
" void $foo(int);\n"
|
||||
"};\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"void Foo::@foo() {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignatureFuzzy2Forward") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class Foo {\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
||||
" void foo(int);\n"
|
||||
" void @foo();\n"
|
||||
"};\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"void Foo::$foo(int) {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("matchFunctionSignatureFuzzy2Backward") << (QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("class Foo {\n"
|
||||
<< FollowSymbolTestDocument::create("class Foo {\n"
|
||||
" void $foo();\n"
|
||||
"};\n",
|
||||
"foo.h")
|
||||
<< TestDocument::create("#include \"foo.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"foo.h\"\n"
|
||||
"void Foo::@foo(int) {}\n",
|
||||
"foo.cpp")
|
||||
);
|
||||
|
||||
QTest::newRow("globalVar") << QList<TestDocumentPtr>{
|
||||
TestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"),
|
||||
TestDocument::create(
|
||||
FollowSymbolTestDocument::create("namespace NS { extern int @globalVar; }\n", "file.h"),
|
||||
FollowSymbolTestDocument::create(
|
||||
"int globalVar;\n"
|
||||
"namespace NS {\n"
|
||||
"extern int globalVar;\n"
|
||||
@@ -1532,7 +1532,7 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
||||
"}\n", "file.cpp")};
|
||||
|
||||
QTest::newRow("staticMemberVar") << QList<TestDocumentPtr>{
|
||||
TestDocument::create(
|
||||
FollowSymbolTestDocument::create(
|
||||
"namespace NS {\n"
|
||||
"class Test {\n"
|
||||
" static int @var;\n"
|
||||
@@ -1540,7 +1540,7 @@ void FollowSymbolTest::testFollowSymbolMultipleDocuments_data()
|
||||
"class OtherClass { static int var; };\n"
|
||||
"}\n"
|
||||
"class OtherClass { static int var; };\n", "file.h"),
|
||||
TestDocument::create(
|
||||
FollowSymbolTestDocument::create(
|
||||
"#include \"file.h\"\n"
|
||||
"int var;\n"
|
||||
"int OtherClass::var;\n"
|
||||
@@ -2063,12 +2063,12 @@ void FollowSymbolTest::testFollowVirtualFunctionCall()
|
||||
void FollowSymbolTest::testFollowVirtualFunctionCallMultipleDocuments()
|
||||
{
|
||||
QList<TestDocumentPtr> testFiles = QList<TestDocumentPtr>()
|
||||
<< TestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
||||
<< FollowSymbolTestDocument::create("struct A { virtual void virt(int) = 0; };\n",
|
||||
"a.h")
|
||||
<< TestDocument::create("#include \"a.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"a.h\"\n"
|
||||
"struct B : A { void virt(int) {} };\n",
|
||||
"b.h")
|
||||
<< TestDocument::create("#include \"a.h\"\n"
|
||||
<< FollowSymbolTestDocument::create("#include \"a.h\"\n"
|
||||
"void f(A *o) { o->$@virt(42); }\n",
|
||||
"u.cpp")
|
||||
;
|
||||
|
@@ -74,13 +74,13 @@ static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<QSt
|
||||
return true;
|
||||
}
|
||||
|
||||
TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
|
||||
BaseCppTestDocument::BaseCppTestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
|
||||
: m_fileName(QString::fromUtf8(fileName))
|
||||
, m_source(QString::fromUtf8(source))
|
||||
, m_cursorMarker(cursorMarker)
|
||||
{}
|
||||
|
||||
QString TestDocument::filePath() const
|
||||
QString BaseCppTestDocument::filePath() const
|
||||
{
|
||||
if (!m_baseDirectory.isEmpty())
|
||||
return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName);
|
||||
@@ -91,7 +91,7 @@ QString TestDocument::filePath() const
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
bool TestDocument::writeToDisk() const
|
||||
bool BaseCppTestDocument::writeToDisk() const
|
||||
{
|
||||
return TestCase::writeFile(filePath(), m_source.toUtf8());
|
||||
}
|
||||
|
@@ -74,10 +74,11 @@ template <typename Signal> inline bool waitForSignalOrTimeout(
|
||||
return timer.isActive();
|
||||
}
|
||||
|
||||
class CPPTOOLS_EXPORT TestDocument
|
||||
class CPPTOOLS_EXPORT BaseCppTestDocument
|
||||
{
|
||||
public:
|
||||
TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
|
||||
BaseCppTestDocument(const QByteArray &fileName, const QByteArray &source,
|
||||
char cursorMarker = '@');
|
||||
|
||||
QString baseDirectory() const { return m_baseDirectory; }
|
||||
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
|
||||
|
@@ -40,9 +40,9 @@
|
||||
using namespace CPlusPlus;
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
using Tests::TestDocument;
|
||||
using Tests::BaseCppTestDocument;
|
||||
|
||||
Q_DECLARE_METATYPE(QList<TestDocument>)
|
||||
Q_DECLARE_METATYPE(QList<BaseCppTestDocument>)
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
class TypeHierarchyBuilderTestCase : public Tests::TestCase
|
||||
{
|
||||
public:
|
||||
TypeHierarchyBuilderTestCase(const QList<TestDocument> &documents,
|
||||
TypeHierarchyBuilderTestCase(const QList<BaseCppTestDocument> &documents,
|
||||
const QString &expectedHierarchy)
|
||||
{
|
||||
QVERIFY(succeededSoFar());
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
Tests::TemporaryDir temporaryDir;
|
||||
QVERIFY(temporaryDir.isValid());
|
||||
|
||||
QList<TestDocument> documents_ = documents;
|
||||
QList<BaseCppTestDocument> documents_ = documents;
|
||||
|
||||
// Write files
|
||||
QSet<QString> filePaths;
|
||||
@@ -138,12 +138,12 @@ public:
|
||||
|
||||
void TypeHierarchyBuilderTest::test_data()
|
||||
{
|
||||
QTest::addColumn<QList<TestDocument> >("documents");
|
||||
QTest::addColumn<QList<BaseCppTestDocument> >("documents");
|
||||
QTest::addColumn<QString>("expectedHierarchy");
|
||||
|
||||
QTest::newRow("basic-single-document")
|
||||
<< (QList<TestDocument>()
|
||||
<< TestDocument("a.h",
|
||||
<< (QList<BaseCppTestDocument>()
|
||||
<< BaseCppTestDocument("a.h",
|
||||
"class A {};\n"
|
||||
"class B : public A {};\n"
|
||||
"class C1 : public B {};\n"
|
||||
@@ -157,19 +157,19 @@ void TypeHierarchyBuilderTest::test_data()
|
||||
" C2\n" );
|
||||
|
||||
QTest::newRow("basic-multiple-documents")
|
||||
<< (QList<TestDocument>()
|
||||
<< TestDocument("a.h",
|
||||
<< (QList<BaseCppTestDocument>()
|
||||
<< BaseCppTestDocument("a.h",
|
||||
"class A {};")
|
||||
<< TestDocument("b.h",
|
||||
<< BaseCppTestDocument("b.h",
|
||||
"#include \"a.h\"\n"
|
||||
"class B : public A {};")
|
||||
<< TestDocument("c1.h",
|
||||
<< BaseCppTestDocument("c1.h",
|
||||
"#include \"b.h\"\n"
|
||||
"class C1 : public B {};")
|
||||
<< TestDocument("c2.h",
|
||||
<< BaseCppTestDocument("c2.h",
|
||||
"#include \"b.h\"\n"
|
||||
"class C2 : public B {};")
|
||||
<< TestDocument("d.h",
|
||||
<< BaseCppTestDocument("d.h",
|
||||
"#include \"c1.h\"\n"
|
||||
"class D : public C1 {};"))
|
||||
<< QString::fromLatin1(
|
||||
@@ -183,7 +183,7 @@ void TypeHierarchyBuilderTest::test_data()
|
||||
|
||||
void TypeHierarchyBuilderTest::test()
|
||||
{
|
||||
QFETCH(QList<TestDocument>, documents);
|
||||
QFETCH(QList<BaseCppTestDocument>, documents);
|
||||
QFETCH(QString, expectedHierarchy);
|
||||
|
||||
TypeHierarchyBuilderTestCase(documents, expectedHierarchy);
|
||||
|
Reference in New Issue
Block a user