CppEditor: Merge two TestCase classes

Change-Id: I53c7db9cda0a82706bee898d091f128c2c4bf32f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-09-07 11:39:33 +02:00
parent a09ec2e0e9
commit 473746e8fd
13 changed files with 43 additions and 68 deletions

View File

@@ -41,6 +41,7 @@
namespace { typedef QByteArray _; } namespace { typedef QByteArray _; }
using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::TemporaryDir;
using CppEditor::Tests::TestCase;
using CppEditor::Tests::VerifyCleanCppModelManager; using CppEditor::Tests::VerifyCleanCppModelManager;
namespace CppEditor { namespace CppEditor {

View File

@@ -34,7 +34,6 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <QDir> #include <QDir>
@@ -78,43 +77,6 @@ bool GenericCppTestDocument::hasCursorMarker() const { return m_cursorPosition !
bool GenericCppTestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; } bool GenericCppTestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; }
TestCase::TestCase(bool runGarbageCollector) : CppEditor::Tests::TestCase(runGarbageCollector)
{
}
bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget)
{
if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditor(fileName))) {
if (editor) {
*editor = e;
TextEditor::StorageSettings s = e->textDocument()->storageSettings();
s.m_addFinalNewLine = false;
e->textDocument()->setStorageSettings(s);
}
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(
CppEditorWidget *editorWidget)
{
while (!editorWidget->isSemanticInfoValid())
QCoreApplication::processEvents();
return editorWidget->semanticInfo().doc;
}
} // namespace Tests } // namespace Tests
} // namespace Internal } // namespace Internal
} // namespace CppEditor } // namespace CppEditor

View File

@@ -57,19 +57,6 @@ public:
using TestDocuments = QVector<GenericCppTestDocument>; using TestDocuments = QVector<GenericCppTestDocument>;
class TestCase : public CppEditor::Tests::TestCase
{
public:
TestCase(bool runGarbageCollector = true);
static bool openCppEditor(const QString &fileName,
TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget = 0);
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
CppEditorWidget *editorWidget);
};
} // namespace Tests } // namespace Tests
} // namespace Internal } // namespace Internal
} // namespace CppEditor } // namespace CppEditor

View File

@@ -38,7 +38,6 @@ namespace CppEditor {
class CppEditorWidget; class CppEditorWidget;
namespace Internal { namespace Internal {
class FunctionDeclDefLink; class FunctionDeclDefLink;
class FunctionDeclDefLinkFinder : public QObject class FunctionDeclDefLinkFinder : public QObject

View File

@@ -70,7 +70,7 @@ QString toString(CppIncludeHierarchyModel &model)
+ toString(model, model.index(1, 0)); + toString(model, model.index(1, 0));
} }
class IncludeHierarchyTestCase : public Tests::TestCase class IncludeHierarchyTestCase : public CppEditor::Tests::TestCase
{ {
public: public:
IncludeHierarchyTestCase(const QList<QByteArray> &sourceList, IncludeHierarchyTestCase(const QList<QByteArray> &sourceList,

View File

@@ -1182,7 +1182,7 @@ void ModelManagerTest::testDocumentsAndRevisions()
// Open editor for file 1 // Open editor for file 1
TextEditor::BaseTextEditor *editor1; TextEditor::BaseTextEditor *editor1;
QVERIFY(helper.openBaseTextEditor(filePath1, &editor1)); QVERIFY(helper.openCppEditor(filePath1, &editor1));
helper.closeEditorAtEndOfTestCase(editor1); helper.closeEditorAtEndOfTestCase(editor1);
QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1));
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U);
@@ -1195,7 +1195,7 @@ void ModelManagerTest::testDocumentsAndRevisions()
// Open editor for file 2 // Open editor for file 2
TextEditor::BaseTextEditor *editor2; TextEditor::BaseTextEditor *editor2;
QVERIFY(helper.openBaseTextEditor(filePath2, &editor2)); QVERIFY(helper.openCppEditor(filePath2, &editor2));
helper.closeEditorAtEndOfTestCase(editor2); helper.closeEditorAtEndOfTestCase(editor2);
QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2));
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U);

View File

@@ -69,7 +69,7 @@ public:
QString m_expectedSource; QString m_expectedSource;
}; };
class BaseQuickFixTestCase : public 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 '@'

View File

@@ -126,7 +126,7 @@ void SourceProcessorTest::testIncludesCyclic()
// Open editor // Open editor
TextEditor::BaseTextEditor *editor; TextEditor::BaseTextEditor *editor;
QVERIFY(testCase.openBaseTextEditor(fileName1, &editor)); QVERIFY(testCase.openCppEditor(fileName1, &editor));
testCase.closeEditorAtEndOfTestCase(editor); testCase.closeEditorAtEndOfTestCase(editor);
// Check editor snapshot // Check editor snapshot

View File

@@ -27,9 +27,10 @@
#include "baseeditordocumentparser.h" #include "baseeditordocumentparser.h"
#include "baseeditordocumentprocessor.h" #include "baseeditordocumentprocessor.h"
#include "editordocumenthandle.h" #include "cppeditorwidget.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cppworkingcopy.h" #include "cppworkingcopy.h"
#include "editordocumenthandle.h"
#include "projectinfo.h" #include "projectinfo.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -40,6 +41,7 @@
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <texteditor/codeassist/iassistproposal.h> #include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/codeassist/iassistproposalmodel.h> #include <texteditor/codeassist/iassistproposalmodel.h>
#include <texteditor/storagesettings.h>
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
#include <utils/executeondestruction.h> #include <utils/executeondestruction.h>
@@ -119,16 +121,29 @@ bool TestCase::succeededSoFar() const
return m_succeededSoFar; return m_succeededSoFar;
} }
bool TestCase::openBaseTextEditor(const QString &fileName, TextEditor::BaseTextEditor **editor) bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget)
{ {
using BTEditor = TextEditor::BaseTextEditor; if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditor(fileName))) {
if (auto e = qobject_cast<BTEditor *>(Core::EditorManager::openEditor(fileName))) {
if (editor) { if (editor) {
*editor = e; *editor = e;
TextEditor::StorageSettings s = e->textDocument()->storageSettings();
s.m_addFinalNewLine = false;
e->textDocument()->setStorageSettings(s);
}
if (editorWidget) {
if (CppEditorWidget *w = dynamic_cast<CppEditorWidget *>(e->editorWidget())) {
*editorWidget = w;
return true; return true;
} else {
return false; // no or wrong widget
} }
} else {
return true; // ok since no widget requested
}
} else {
return false; // no or wrong editor
} }
return false;
} }
CPlusPlus::Snapshot TestCase::globalSnapshot() CPlusPlus::Snapshot TestCase::globalSnapshot()
@@ -167,6 +182,13 @@ bool TestCase::waitForProcessedEditorDocument(const QString &filePath, int timeO
return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs); return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs);
} }
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEditorWidget *editorWidget)
{
while (!editorWidget->isSemanticInfoValid())
QCoreApplication::processEvents();
return editorWidget->semanticInfo().doc;
}
bool TestCase::parseFiles(const QSet<QString> &filePaths) bool TestCase::parseFiles(const QSet<QString> &filePaths)
{ {
CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished();

View File

@@ -53,6 +53,7 @@ class IAssistProposal;
} }
namespace CppEditor { namespace CppEditor {
class CppEditorWidget;
class CppModelManager; class CppModelManager;
namespace Tests { namespace Tests {
@@ -102,7 +103,8 @@ public:
~TestCase(); ~TestCase();
bool succeededSoFar() const; bool succeededSoFar() const;
bool openBaseTextEditor(const QString &fileName, TextEditor::BaseTextEditor **editor); static bool openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget = nullptr);
void closeEditorAtEndOfTestCase(Core::IEditor *editor); void closeEditorAtEndOfTestCase(Core::IEditor *editor);
static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor); static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor);
@@ -114,6 +116,8 @@ public:
static bool garbageCollectGlobalSnapshot(); static bool garbageCollectGlobalSnapshot();
static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000); static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000);
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
CppEditorWidget *editorWidget);
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ }; enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project, static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project,

View File

@@ -65,7 +65,7 @@ namespace Tests {
// Check: If the user puts the cursor on e.g. a function-local variable, // Check: If the user puts the cursor on e.g. a function-local variable,
// a type name or a macro use, all occurrences of that entity are highlighted. // a type name or a macro use, all occurrences of that entity are highlighted.
class UseSelectionsTestCase : public TestCase class UseSelectionsTestCase : public CppEditor::Tests::TestCase
{ {
public: public:
UseSelectionsTestCase(GenericCppTestDocument &testDocument, UseSelectionsTestCase(GenericCppTestDocument &testDocument,

View File

@@ -77,7 +77,7 @@ namespace CppEditor::Internal::Tests {
namespace { namespace {
class TestActionsTestCase : public Tests::TestCase class TestActionsTestCase : public CppEditor::Tests::TestCase
{ {
public: public:
class AbstractAction class AbstractAction
@@ -141,7 +141,7 @@ static bool waitUntilAProjectIsLoaded(int timeOutInMs = 30000)
} }
TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions) TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions)
: Tests::TestCase(/*runGarbageCollector=*/false) : CppEditor::Tests::TestCase(/*runGarbageCollector=*/false)
{ {
QVERIFY(succeededSoFar()); QVERIFY(succeededSoFar());

View File

@@ -245,7 +245,7 @@ QList<TestDocumentPtr> singleDocument(const QByteArray &source)
* 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 F2TestCase : public Tests::TestCase class F2TestCase : public CppEditor::Tests::TestCase
{ {
public: public:
enum CppEditorAction { enum CppEditorAction {