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 _; }
using CppEditor::Tests::TemporaryDir;
using CppEditor::Tests::TestCase;
using CppEditor::Tests::VerifyCleanCppModelManager;
namespace CppEditor {

View File

@@ -34,7 +34,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <cplusplus/CppDocument.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditor.h>
#include <QDir>
@@ -78,43 +77,6 @@ bool GenericCppTestDocument::hasCursorMarker() const { return m_cursorPosition !
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 Internal
} // namespace CppEditor

View File

@@ -57,19 +57,6 @@ public:
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 Internal
} // namespace CppEditor

View File

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

View File

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

View File

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

View File

@@ -69,7 +69,7 @@ public:
QString m_expectedSource;
};
class BaseQuickFixTestCase : public TestCase
class BaseQuickFixTestCase : public CppEditor::Tests::TestCase
{
public:
/// Exactly one QuickFixTestDocument must contain the cursor position marker '@'

View File

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

View File

@@ -27,9 +27,10 @@
#include "baseeditordocumentparser.h"
#include "baseeditordocumentprocessor.h"
#include "editordocumenthandle.h"
#include "cppeditorwidget.h"
#include "cppmodelmanager.h"
#include "cppworkingcopy.h"
#include "editordocumenthandle.h"
#include "projectinfo.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -40,6 +41,7 @@
#include <texteditor/texteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/codeassist/iassistproposalmodel.h>
#include <texteditor/storagesettings.h>
#include <cplusplus/CppDocument.h>
#include <utils/executeondestruction.h>
@@ -119,16 +121,29 @@ bool TestCase::succeededSoFar() const
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 (auto e = qobject_cast<BTEditor *>(Core::EditorManager::openEditor(fileName))) {
if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditor(fileName))) {
if (editor) {
*editor = e;
return true;
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
}
return false;
}
CPlusPlus::Snapshot TestCase::globalSnapshot()
@@ -167,6 +182,13 @@ bool TestCase::waitForProcessedEditorDocument(const QString &filePath, int timeO
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)
{
CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished();

View File

@@ -53,6 +53,7 @@ class IAssistProposal;
}
namespace CppEditor {
class CppEditorWidget;
class CppModelManager;
namespace Tests {
@@ -102,7 +103,8 @@ public:
~TestCase();
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);
static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor);
@@ -114,6 +116,8 @@ public:
static bool garbageCollectGlobalSnapshot();
static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000);
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
CppEditorWidget *editorWidget);
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
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,
// 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:
UseSelectionsTestCase(GenericCppTestDocument &testDocument,

View File

@@ -77,7 +77,7 @@ namespace CppEditor::Internal::Tests {
namespace {
class TestActionsTestCase : public Tests::TestCase
class TestActionsTestCase : public CppEditor::Tests::TestCase
{
public:
class AbstractAction
@@ -141,7 +141,7 @@ static bool waitUntilAProjectIsLoaded(int timeOutInMs = 30000)
}
TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions)
: Tests::TestCase(/*runGarbageCollector=*/false)
: CppEditor::Tests::TestCase(/*runGarbageCollector=*/false)
{
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
* and checking the result.
*/
class F2TestCase : public Tests::TestCase
class F2TestCase : public CppEditor::Tests::TestCase
{
public:
enum CppEditorAction {